Search in sources :

Example 1 with LimitedAgeDiskCache

use of com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache in project CustomViews by AndroidStudy233.

the class MyApplication method initImageLoader.

/**
 * 初始化ImageLoader
 */
private void initImageLoader() {
    File cacheDir = getCacheDir();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).memoryCacheExtraOptions(480, // max width, max height,即保存的每个缓存文件的最大长宽
    800).threadPoolSize(// 线程池内加载的数量
    3).threadPriority(// 线程优先级
    Thread.NORM_PRIORITY - 1).denyCacheImageMultipleSizesInMemory().memoryCache(new WeakMemoryCache()).memoryCacheSize(// 内存缓存2MB
    2 * 1024 * 1024).tasksProcessingOrder(QueueProcessingType.LIFO).diskCache(// 限制缓存时长
    new LimitedAgeDiskCache(cacheDir, 7 * 24 * 60 * 60)).diskCacheSize(// 本地缓存50MB
    50 * 1024 * 1024).diskCacheFileNameGenerator(// MD5加密名字
    new Md5FileNameGenerator()).defaultDisplayImageOptions(// 设置默认选项
    DisplayImageOptions.createSimple()).imageDownloader(// connectTimeout (5 s), readTimeout (30 s)超时时间
    new BaseImageDownloader(getApplicationContext(), 5 * 1000, 20 * 1000)).build();
    // 开始构建
    ImageLoader.getInstance().init(config);
}
Also used : WeakMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache) Md5FileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) LimitedAgeDiskCache(com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache)

Aggregations

LimitedAgeDiskCache (com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache)1 Md5FileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator)1 WeakMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache)1 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)1 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)1 File (java.io.File)1