Search in sources :

Example 1 with OkHttpImageDownloader

use of me.ccrama.redditslide.util.OkHttpImageDownloader in project Slide by ccrama.

the class ImageLoaderUnescape method initImageLoader.

public static void initImageLoader(Context context) {
    long discCacheSize = 1024 * 1024;
    DiskCache discCache;
    File dir = getCacheDirectory(context);
    int threadPoolSize;
    discCacheSize *= 100;
    threadPoolSize = 7;
    if (discCacheSize > 0) {
        try {
            dir.mkdir();
            discCache = new LruDiskCache(dir, new Md5FileNameGenerator(), discCacheSize);
        } catch (IOException e) {
            discCache = new UnlimitedDiskCache(dir);
        }
    } else {
        discCache = new UnlimitedDiskCache(dir);
    }
    options = new DisplayImageOptions.Builder().cacheOnDisk(true).bitmapConfig(Bitmap.Config.RGB_565).imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2).cacheInMemory(false).resetViewBeforeLoading(false).displayer(new FadeInBitmapDisplayer(250)).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(threadPoolSize).denyCacheImageMultipleSizesInMemory().diskCache(discCache).threadPoolSize(4).imageDownloader(new OkHttpImageDownloader(context)).defaultDisplayImageOptions(options).build();
    if (ImageLoader.getInstance().isInited()) {
        ImageLoader.getInstance().destroy();
    }
    imageLoader = ImageLoaderUnescape.getInstance();
    imageLoader.init(config);
}
Also used : Md5FileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator) IOException(java.io.IOException) DiskCache(com.nostra13.universalimageloader.cache.disc.DiskCache) UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) LruDiskCache(com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache) UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) OkHttpImageDownloader(me.ccrama.redditslide.util.OkHttpImageDownloader) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer) LruDiskCache(com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Example 2 with OkHttpImageDownloader

use of me.ccrama.redditslide.util.OkHttpImageDownloader in project Slide by ccrama.

the class ImageFlairs method initFlairImageLoader.

public static FlairImageLoader initFlairImageLoader(Context context) {
    // 100 MB limit
    long discCacheSize = 1024 * 1024 * 100;
    DiskCache discCache;
    File dir = getCacheDirectory(context);
    discCacheSize *= 100;
    int threadPoolSize = 7;
    if (discCacheSize > 0) {
        try {
            dir.mkdir();
            discCache = new LruDiskCache(dir, new Md5FileNameGenerator(), discCacheSize);
        } catch (IOException e) {
            discCache = new UnlimitedDiskCache(dir);
        }
    } else {
        discCache = new UnlimitedDiskCache(dir);
    }
    options = new DisplayImageOptions.Builder().cacheOnDisk(true).imageScaleType(ImageScaleType.NONE).cacheInMemory(false).resetViewBeforeLoading(false).build();
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(threadPoolSize).denyCacheImageMultipleSizesInMemory().diskCache(discCache).threadPoolSize(4).imageDownloader(new OkHttpImageDownloader(context)).defaultDisplayImageOptions(options).build();
    if (FlairImageLoader.getInstance().isInited()) {
        FlairImageLoader.getInstance().destroy();
    }
    imageLoader = FlairImageLoader.getInstance();
    imageLoader.init(config);
    return imageLoader;
}
Also used : UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) OkHttpImageDownloader(me.ccrama.redditslide.util.OkHttpImageDownloader) Md5FileNameGenerator(com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator) LruDiskCache(com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache) IOException(java.io.IOException) UnlimitedDiskCache(com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache) DiskCache(com.nostra13.universalimageloader.cache.disc.DiskCache) LruDiskCache(com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache) File(java.io.File) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration)

Aggregations

DiskCache (com.nostra13.universalimageloader.cache.disc.DiskCache)2 UnlimitedDiskCache (com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache)2 LruDiskCache (com.nostra13.universalimageloader.cache.disc.impl.ext.LruDiskCache)2 Md5FileNameGenerator (com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator)2 ImageLoaderConfiguration (com.nostra13.universalimageloader.core.ImageLoaderConfiguration)2 File (java.io.File)2 IOException (java.io.IOException)2 OkHttpImageDownloader (me.ccrama.redditslide.util.OkHttpImageDownloader)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)1