package ai.pai.lensman;

import android.app.Application;
import android.content.Context;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.utils.StorageUtils;

import ai.pai.lensman.utils.Constants;

/**
 * Created by sky on 2015/7/6.
 */
public class App extends Application {

    private static Context   mInstance;

    public static Context getAppContext(){
        return mInstance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        initImageLoader();
        mInstance = this.getApplicationContext();
    }


    private void initImageLoader() {

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .memoryCacheExtraOptions(320, 320)
                .diskCacheExtraOptions(320, 320, null)
                .threadPriority(Thread.NORM_PRIORITY - 2)
                .denyCacheImageMultipleSizesInMemory()
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .diskCache(new UnlimitedDiskCache(StorageUtils.getOwnCacheDirectory(this, Constants.TMP_DIR_NAME)))
                .diskCacheSize(50 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO)
                .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(20)
                .threadPoolSize(4)
                .build();
        ImageLoader.getInstance().init(config);
    }

}
