Search in sources :

Example 11 with DiskCache

use of com.nostra13.universalimageloader.cache.disc.DiskCache 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)

Example 12 with DiskCache

use of com.nostra13.universalimageloader.cache.disc.DiskCache in project AndLang by wugemu.

the class BaseLangApplication method initImageLoad.

private void initImageLoad() {
    // 配置uil工具
    File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), tmpImageDir);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).memoryCacheExtraOptions(480, // default = device screen dimensions
    800).threadPriority(// default
    Thread.NORM_PRIORITY - 1).tasksProcessingOrder(// default
    QueueProcessingType.FIFO).threadPoolSize(3).denyCacheImageMultipleSizesInMemory().memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(// default
    13).diskCache(new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 缓冲大小
    50 * 1024 * 1024).diskCacheFileCount(// 缓冲文件数目
    100).diskCacheFileNameGenerator(// default
    new HashCodeFileNameGenerator()).imageDownloader(// default
    new BaseImageDownloader(this)).defaultDisplayImageOptions(// default
    DisplayImageOptions.createSimple()).writeDebugLogs().build();
    // 2.单例ImageLoader类的初始化
    ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(config);
    ImageLoadUtils.setImageSetter(new IInnerImageSetter() {

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().display(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrlCenterCrop(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGifCenterCrop(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayCenterCrop(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrlFitCenter(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGifFitCenter(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayFitCenter(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadCircleImageUrl(@NonNull IMAGE view, @Nullable String url) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayHead(getApplicationContext(), url, view);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageRound(@NonNull IMAGE view, @Nullable String url, float round) {
            if (!BaseLangUtil.isEmpty(url)) {
                if (url.toLowerCase().contains(".gif")) {
                    GlideUtil.getInstance().displayGif(getApplicationContext(), url, view);
                } else {
                    GlideUtil.getInstance().displayRoundImg(getApplicationContext(), url, view, round);
                }
            }
        }

        @Override
        public <IMAGE extends ImageView> void doLoadByImageLoader(@NonNull IMAGE view, @Nullable String url) {
            // 测试比较加载速度使用
            ImageLoader.getInstance().displayImage(url, view, BOUTIQUE_OPTIPON);
        }

        @Override
        public <IMAGE extends ImageView> void doLoadImageRes(@NonNull IMAGE view, @Nullable int resId) {
            GlideUtil.getInstance().displayLocRes(getApplicationContext(), resId, view);
        }
    });
}
Also used : HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) IInnerImageSetter(com.example.test.andlang.util.imageload.IInnerImageSetter) UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) LruMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) ImageLoader(com.nostra13.universalimageloader.core.ImageLoader) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Example 13 with DiskCache

use of com.nostra13.universalimageloader.cache.disc.DiskCache in project QuickAndroid by ImKarl.

the class QAImageLoaderConfig method getConfig.

/**
 * 获取加载配置
 * @param context
 * @param imageOnLoadingRes 加载中显示的图片
 * @param imageOnFailRes 加载失败显示的图片
 * @return
 */
public static ImageLoaderConfiguration getConfig(Context context, int imageOnLoadingRes, int imageOnFailRes) {
    DisplayImageOptions options = new DisplayImageOptions.Builder().showImageOnLoading(// 加载中
    imageOnLoadingRes).showImageForEmptyUri(// 图片Uri为空或是错误的时候显示的图片
    imageOnFailRes).showImageOnFail(// resource or drawable
    imageOnFailRes).resetViewBeforeLoading(// default
    false).delayBeforeLoading(// 加载前延迟时长
    50).cacheInMemory(// default = false 是否使用内存缓存
    true).cacheOnDisk(// default = false 是否使用文件缓存
    true).considerExifParams(// default = false
    false).imageScaleType(// default
    ImageScaleType.IN_SAMPLE_POWER_OF_2).bitmapConfig(// default
    Bitmap.Config.ARGB_8888).displayer(// default = new SimpleBitmapDisplayer()
    new FadeInBitmapDisplayer(100)).build();
    File cacheDir = new File(QAFileManager.getUsableDir(context.getPackageName()));
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(// default 线程池大小
    3).threadPriority(// default 线程优先级
    Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().memoryCache(// 内存缓存
    new LruMemoryCache(8 * 1024 * 1024)).diskCache(// default 磁盘缓存
    new UnlimitedDiskCache(cacheDir)).diskCacheSize(// 磁盘缓存大小
    30 * 1024 * 1024).diskCacheFileNameGenerator(// default 磁盘缓存文件名
    new HashCodeFileNameGenerator()).imageDownloader(// default 图片下载器
    new BaseImageDownloader(context)).imageDecoder(// default 图片解码器
    new BaseImageDecoder(QACore.isDebug())).defaultDisplayImageOptions(// default=DisplayImageOptions.createSimple() 图片显示选项
    options).build();
    return config;
}
Also used : UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) LruMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache) BaseImageDownloader(com.nostra13.universalimageloader.core.download.BaseImageDownloader) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions) BaseImageDecoder(com.nostra13.universalimageloader.core.decode.BaseImageDecoder)

Example 14 with DiskCache

use of com.nostra13.universalimageloader.cache.disc.DiskCache in project PLDroidPlayer by pili-engineering.

the class MainActivity method initImageLoader.

private void initImageLoader() {
    // sdcard目录
    File cacheDir = StorageUtils.getOwnCacheDirectory(this, DEFAULT_CACHE_DIR_NAME);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).diskCache(// default 可以自定义缓存路径
    new UnlimitedDiskCache(cacheDir)).diskCacheSize(50 * 1024 * 1024).diskCacheFileCount(100).memoryCache(new LruMemoryCache(2 * 1024 * 1024)).memoryCacheSize(2 * 1024 * 1024).memoryCacheSizePercentage(13).build();
    ImageLoader.getInstance().init(config);
}
Also used : UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) LruMemoryCache(com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Example 15 with DiskCache

use of com.nostra13.universalimageloader.cache.disc.DiskCache in project yellowmessenger-sdk by yellowmessenger.

the class DrawableManager method getInstance.

public static DrawableManager getInstance(Context context) {
    if (drawableManager == null) {
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).displayer(new FadeInBitmapDisplayer(500)).resetViewBeforeLoading(true).build();
        // for caching
        File cacheDir = StorageUtils.getOwnCacheDirectory(context, "image_cache");
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).defaultDisplayImageOptions(defaultOptions).diskCache(new UnlimitedDiskCache(cacheDir)).threadPoolSize(5).memoryCacheSize(20000000).denyCacheImageMultipleSizesInMemory().diskCacheFileNameGenerator(new HashCodeFileNameGenerator()).build();
        ImageLoader.getInstance().init(config);
        drawableManager = new DrawableManager();
    }
    return drawableManager;
}
Also used : UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) HashCodeFileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Aggregations

File (java.io.File)18 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)16 UnlimitedDiskCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache)15 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)9 LruMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache)8 LruDiskCache (com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache)5 HashCodeFileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator)5 Md5FileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator)5 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)5 BaseImageDownloader (com.nostra13.universalimageloader.core.download.BaseImageDownloader)5 IOException (java.io.IOException)5 DiskCache (com.nostra13.universalimageloader.cache.disc.DiskCache)3 UnlimitedDiscCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache)3 BaseImageDecoder (com.nostra13.universalimageloader.core.decode.BaseImageDecoder)3 WeakMemoryCache (com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache)2 OkHttpImageDownloader (me.ccrama.redditslide.util.OkHttpImageDownloader)2 Options (android.graphics.BitmapFactory.Options)1 IInnerImageSetter (com.example.test.andlang.util.imageload.IInnerImageSetter)1 LimitedAgeDiskCache (com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiskCache)1 Builder (com.nostra13.universalimageloader.core.DisplayImageOptions.Builder)1