com.bumptech.glide.load.engine.cache.DiskCache Java Examples

The following examples show how to use com.bumptech.glide.load.engine.cache.DiskCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GlideConfiguration.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);// Bitmap格式转换到ARGB_8888
    //内存缓存
    MemorySizeCalculator memorySizeCalculator = new MemorySizeCalculator(context);
    int defaultMemoryCacheSize = memorySizeCalculator.getMemoryCacheSize();
    int defalutBitmapPoolSize = memorySizeCalculator.getBitmapPoolSize();
    builder.setMemoryCache(new LruResourceCache((int) (defalutBitmapPoolSize * 1.2)));//内部
    builder.setBitmapPool(new LruBitmapPool((int) (defalutBitmapPoolSize * 1.2)));
    //磁盘缓存
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 1024 * 1024 * 10));//内部磁盘缓存
    builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 10 * 1024 * 1024));//磁盘缓存到外部存储
    //指定缓存目录1
    String downLoadPath = Environment.getDownloadCacheDirectory().getPath();
    builder.setDiskCache(new DiskLruCacheFactory(downLoadPath, defaultMemoryCacheSize));
    //指定缓存目录2
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File cacheLocation = new File(FileUtils.getCacheDir(context), "GlideCache");
            return DiskLruCacheWrapper.get(cacheLocation, 1024 * 1024 * 10);
        }
    });

}
 
Example #2
Source File: GlideUtils.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
public static void init(final Context context) {
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setReadTimeout(30, TimeUnit.SECONDS);
        okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS);
//        okHttpClient.setProtocols(Arrays.asList(Protocol.HTTP_1_1));

        GlideBuilder glideBuilder = new GlideBuilder(context)
                .setDiskCache(new DiskCache.Factory() {
                    @Override
                    public DiskCache build() {
                        // Careful: the external cache directory doesn't enforce permissions
                        File cacheLocation = new File(context.getExternalCacheDir(), AppConfig.CACHE_IMAGE_DIR);
                        cacheLocation.mkdirs();
                        return DiskLruCacheWrapper.get(cacheLocation, 100 * 1024 * 1024);
                    }
                });
        if (!Glide.isSetup()) {
            Glide.setup(glideBuilder);
        }

        Glide.get(context).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(okHttpClient));
    }
 
Example #3
Source File: AptoideGlideModule.java    From aptoide-client with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            File pathIcons = new File(Configuration.PATH_CACHE_ICONS);
            pathIcons.mkdirs();
            return DiskLruCacheWrapper.get(pathIcons, DEFAULT_DISK_CACHE_SIZE);
        }
    });

    final MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    final int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize / 2));
    final int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
    builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize / 2));
}
 
Example #4
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
/**
 * 无法同步判断
 * 参见:https://github.com/bumptech/glide/issues/639
 *
 * 4.0以上可用:
 * val file: File? = try {
         Glide.with(view.context).downloadOnly().load(url).apply(RequestOptions().onlyRetrieveFromCache(true)).submit().get()
         } catch (e: Exception) {
         e.printStackTrace()
         null
         }
 *https://github.com/bumptech/glide/issues/2972
 *
 * @param url
 * @return
 */
@Override
public boolean isCached(String url) {


       OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
       SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
       String safeKey = safeKeyGenerator.getSafeKey(originalKey);
       try {
           DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
           DiskLruCache.Value value = diskLruCache.get(safeKey);
           if (value != null && value.getFile(0).exists() && value.getFile(0).length() > 30) {
               return true;
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
       return false;

}
 
Example #5
Source File: GlideConfiguration.java    From AcgClub with MIT License 6 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
  builder.setDiskCache(new DiskCache.Factory() {
    @Override
    public DiskCache build() {
      // Careful: the external cache directory doesn't enforce permissions
      return DiskLruCacheWrapper
          .create(FileUtils.makeDirs(new File(Utils.getAppComponent().cacheFile(), "Glide")),
              IMAGE_DISK_CACHE_MAX_SIZE);
    }
  });

  MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
  int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
  int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

  int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
  int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

  builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
  builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

}
 
Example #6
Source File: ImageLoader.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 获取是否有某张原图的缓存
 * 缓存模式必须是:DiskCacheStrategy.SOURCE 才能获取到缓存文件
 */
public static File getGlideCacheFile(Context context, String url) {
    try {
        url = QtalkStringUtils.findRealUrl(url);
        OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
        SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
        String safeKey = safeKeyGenerator.getSafeKey(originalKey);
        File file = new File(context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR);
        DiskLruCache diskLruCache = DiskLruCache.open(file, 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
        DiskLruCache.Value value = diskLruCache.get(safeKey);
        if (value != null) {
            return value.getFile(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #7
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
/**
 * 无法同步判断
 * 参见:https://github.com/bumptech/glide/issues/639
 *
 * 4.0以上可用:
 * val file: File? = try {
         Glide.with(view.context).downloadOnly().load(url).apply(RequestOptions().onlyRetrieveFromCache(true)).submit().get()
         } catch (e: Exception) {
         e.printStackTrace()
         null
         }
 *https://github.com/bumptech/glide/issues/2972
 *
 * @param url
 * @return
 */
@Override
public boolean isCached(String url) {


       OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
       SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
       String safeKey = safeKeyGenerator.getSafeKey(originalKey);
       try {
           DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
           DiskLruCache.Value value = diskLruCache.get(safeKey);
           if (value != null && value.getFile(0).exists() && value.getFile(0).length() > 30) {
               return true;
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
       return false;

}
 
Example #8
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Context context, int cacheSizeInM) {//glide默认最大容量250MB的文件缓存

    /*Glide.get(context)
            .setMemoryCategory(MemoryCategory.NORMAL);*/
    BigImageViewer.initialize(GlideBigLoader.with(context,null));
    GlobalConfig.cacheFolderName = DiskCache.Factory.DEFAULT_DISK_CACHE_DIR;
    GlobalConfig.cacheMaxSize =  DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE/1024/1024;

}
 
Example #9
Source File: SampleGlideModule.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
  builder.setDiskCache(
      new DiskCache.Factory() {
        @Override
        public DiskCache build() {
          return DiskLruCacheWrapper.get(
              Glide.getPhotoCacheDir(context), ConfigConstants.MAX_DISK_CACHE_SIZE);
        }
      });
  builder.setMemoryCache(new LruResourceCache(ConfigConstants.MAX_MEMORY_CACHE_SIZE));
}
 
Example #10
Source File: VideoListGlideModule.java    From VideoListPlayer with MIT License 5 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    ViewTarget.setTagId(R.id.glide_loader);
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
 
Example #11
Source File: OkHttpGlideModule.java    From AndroidBase with Apache License 2.0 5 votes vote down vote up
@Override
  public void applyOptions(Context context, GlideBuilder builder) {

//    int deskacheize = 1024 * 1024 * 30;
    int maxMemory = (int)Runtime.getRuntime().maxMemory();
    int memoryCheSize = maxMemory / 8;
//    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", deskacheize));
    builder.setDiskCache(new DiskLruCacheFactory(FileUtil.getCacheDir(),"glide", DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    builder.setMemoryCache(new LruResourceCache(memoryCheSize));
    builder.setBitmapPool(new LruBitmapPool(memoryCheSize));
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
  }
 
Example #12
Source File: GlideConfiguration.java    From MVVMArms with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    super.applyOptions(context, builder);
    builder.setDiskCache(new DiskCache.Factory() {
        @Nullable
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(
                    new File(RepositoryUtils.INSTANCE.obtainRepositoryComponent(context).cacheFile(), "Glide")),
                    IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利

    BaseImageLoaderStrategy imageLoaderStrategy = ArmsUtils.INSTANCE.obtainArmsComponent(context).imageLoader().getStrategy();
    if (imageLoaderStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) imageLoaderStrategy).applyGlideOptions(context, builder);
    }
}
 
Example #13
Source File: GlideConfiguration.java    From Aurora with Apache License 2.0 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });

    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build();
    int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
    int defaultBitmapPoolSize = calculator.getBitmapPoolSize();

    int customMemoryCacheSize = (int) (1.2 * defaultMemoryCacheSize);
    int customBitmapPoolSize = (int) (1.2 * defaultBitmapPoolSize);

    builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize));

    //将配置 Glide 的机会转交给 GlideImageLoaderStrategy,如你觉得框架提供的 GlideImageLoaderStrategy
    //并不能满足自己的需求,想自定义 BaseImageLoaderStrategy,那请你最好实现 GlideAppliesOptions
    //因为只有成为 GlideAppliesOptions 的实现类,这里才能调用 applyGlideOptions(),让你具有配置 Glide 的权利
    BaseImageLoaderStrategy loadImgStrategy = appComponent.imageLoader().getLoadImgStrategy();
    if (loadImgStrategy instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) loadImgStrategy).applyGlideOptions(context, builder);
    }
}
 
Example #14
Source File: Glide4Loader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
public File getCacheFile(String url) {
    OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
    SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
    String safeKey = safeKeyGenerator.getSafeKey(originalKey);
    try {
        DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
        DiskLruCache.Value value = diskLruCache.get(safeKey);
        if (value != null) {
            return value.getFile(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #15
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Context context, int cacheSizeInM) {//glide默认最大容量250MB的文件缓存

    /*Glide.get(context)
            .setMemoryCategory(MemoryCategory.NORMAL);*/
    BigImageViewer.initialize(GlideBigLoader.with(context,MyUtil.getClient(GlobalConfig.ignoreCertificateVerify)));
    GlobalConfig.cacheFolderName = DiskCache.Factory.DEFAULT_DISK_CACHE_DIR;
    GlobalConfig.cacheMaxSize =  DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE/1024/1024;

}
 
Example #16
Source File: GlideLoader.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
public File getCacheFile(String url) {
    OriginalKey originalKey = new OriginalKey(url, EmptySignature.obtain());
    SafeKeyGenerator safeKeyGenerator = new SafeKeyGenerator();
    String safeKey = safeKeyGenerator.getSafeKey(originalKey);
    try {
        DiskLruCache diskLruCache = DiskLruCache.open(new File(GlobalConfig.context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR), 1, 1, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
        DiskLruCache.Value value = diskLruCache.get(safeKey);
        if (value != null) {
            return value.getFile(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #17
Source File: OkHttpProgressGlideModule.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    File cacheDir = new File(context.getCacheDir(), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR);
    cache = DiskLruCacheWrapper.get(cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE);
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            return cache;
        }
    });
}
 
Example #18
Source File: Engine.java    From giffun with Apache License 2.0 5 votes vote down vote up
Engine(MemoryCache cache, DiskCache.Factory diskCacheFactory, ExecutorService diskCacheService,
        ExecutorService sourceService, Map<Key, EngineJob> jobs, EngineKeyFactory keyFactory,
        Map<Key, WeakReference<EngineResource<?>>> activeResources, EngineJobFactory engineJobFactory,
        ResourceRecycler resourceRecycler) {
    this.cache = cache;
    this.diskCacheProvider = new LazyDiskCacheProvider(diskCacheFactory);

    if (activeResources == null) {
        activeResources = new HashMap<Key, WeakReference<EngineResource<?>>>();
    }
    this.activeResources = activeResources;

    if (keyFactory == null) {
        keyFactory = new EngineKeyFactory();
    }
    this.keyFactory = keyFactory;

    if (jobs == null) {
        jobs = new HashMap<Key, EngineJob>();
    }
    this.jobs = jobs;

    if (engineJobFactory == null) {
        engineJobFactory = new EngineJobFactory(diskCacheService, sourceService, this);
    }
    this.engineJobFactory = engineJobFactory;

    if (resourceRecycler == null) {
        resourceRecycler = new ResourceRecycler();
    }
    this.resourceRecycler = resourceRecycler;

    cache.setResourceRemovedListener(this);
}
 
Example #19
Source File: Glide.java    From giffun with Apache License 2.0 4 votes vote down vote up
Glide(Engine engine, MemoryCache memoryCache, BitmapPool bitmapPool, Context context, DecodeFormat decodeFormat, DiskCache.Factory diskCacheFactory) {
    this.engine = engine;
    this.bitmapPool = bitmapPool;
    this.memoryCache = memoryCache;
    this.decodeFormat = decodeFormat;
    this.diskCacheFactory = diskCacheFactory;
    loaderFactory = new GenericLoaderFactory(context);
    mainHandler = new Handler(Looper.getMainLooper());
    bitmapPreFiller = new BitmapPreFiller(memoryCache, bitmapPool, decodeFormat);

    dataLoadProviderRegistry = new DataLoadProviderRegistry();

    StreamBitmapDataLoadProvider streamBitmapLoadProvider =
            new StreamBitmapDataLoadProvider(bitmapPool, decodeFormat);
    dataLoadProviderRegistry.register(InputStream.class, Bitmap.class, streamBitmapLoadProvider);

    FileDescriptorBitmapDataLoadProvider fileDescriptorLoadProvider =
            new FileDescriptorBitmapDataLoadProvider(bitmapPool, decodeFormat);
    dataLoadProviderRegistry.register(ParcelFileDescriptor.class, Bitmap.class, fileDescriptorLoadProvider);

    ImageVideoDataLoadProvider imageVideoDataLoadProvider =
            new ImageVideoDataLoadProvider(streamBitmapLoadProvider, fileDescriptorLoadProvider);
    dataLoadProviderRegistry.register(ImageVideoWrapper.class, Bitmap.class, imageVideoDataLoadProvider);

    GifDrawableLoadProvider gifDrawableLoadProvider =
            new GifDrawableLoadProvider(context, bitmapPool);
    dataLoadProviderRegistry.register(InputStream.class, GifDrawable.class, gifDrawableLoadProvider);

    dataLoadProviderRegistry.register(ImageVideoWrapper.class, GifBitmapWrapper.class,
            new ImageVideoGifDrawableLoadProvider(imageVideoDataLoadProvider, gifDrawableLoadProvider, bitmapPool));

    dataLoadProviderRegistry.register(InputStream.class, File.class, new StreamFileDataLoadProvider());

    register(File.class, ParcelFileDescriptor.class, new FileDescriptorFileLoader.Factory());
    register(File.class, InputStream.class, new StreamFileLoader.Factory());
    register(int.class, ParcelFileDescriptor.class, new FileDescriptorResourceLoader.Factory());
    register(int.class, InputStream.class, new StreamResourceLoader.Factory());
    register(Integer.class, ParcelFileDescriptor.class, new FileDescriptorResourceLoader.Factory());
    register(Integer.class, InputStream.class, new StreamResourceLoader.Factory());
    register(String.class, ParcelFileDescriptor.class, new FileDescriptorStringLoader.Factory());
    register(String.class, InputStream.class, new StreamStringLoader.Factory());
    register(Uri.class, ParcelFileDescriptor.class, new FileDescriptorUriLoader.Factory());
    register(Uri.class, InputStream.class, new StreamUriLoader.Factory());
    register(URL.class, InputStream.class, new StreamUrlLoader.Factory());
    register(GlideUrl.class, InputStream.class, new HttpUrlGlideUrlLoader.Factory());
    register(byte[].class, InputStream.class, new StreamByteArrayLoader.Factory());

    transcoderRegistry.register(Bitmap.class, GlideBitmapDrawable.class,
            new GlideBitmapDrawableTranscoder(context.getResources(), bitmapPool));
    transcoderRegistry.register(GifBitmapWrapper.class, GlideDrawable.class,
            new GifBitmapWrapperDrawableTranscoder(
                    new GlideBitmapDrawableTranscoder(context.getResources(), bitmapPool)));

    bitmapCenterCrop = new CenterCrop(bitmapPool);
    drawableCenterCrop = new GifBitmapWrapperTransformation(bitmapPool, bitmapCenterCrop);

    bitmapFitCenter = new FitCenter(bitmapPool);
    drawableFitCenter = new GifBitmapWrapperTransformation(bitmapPool, bitmapFitCenter);
}
 
Example #20
Source File: SilenceGlideModule.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DiskCache build() {
  return new DiskCacheAdapter();
}
 
Example #21
Source File: HHGlideModel.java    From HHComicViewer with Apache License 2.0 4 votes vote down vote up
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    SharedPreferencesManager manager = new SharedPreferencesManager(context);
    final String cacheSize = manager.getString(DISK_CACHE_KEY, DISK_CACHE_160MB);
    String decodeFormat = manager.getString(DECODE_FORMAT_KEY, DECODE_FORMAT_ARGB_8888);
    final String cacheName = manager.getString(DISK_CACHE_NAME_KEY, DEFAULT_CACHE_NAME);

    DecodeFormat format = null;
    switch (decodeFormat) {
        case DECODE_FORMAT_RGB_565:
            format = DecodeFormat.PREFER_RGB_565;
            break;
        default:
        case DECODE_FORMAT_ARGB_8888:
            format = DecodeFormat.PREFER_ARGB_8888;
            break;
    }
    // 高版本配置,没有禁用Hardware Bitmaps,仅Android O以上版本的新特性
    // 参阅https://muyangmin.github.io/glide-docs-cn/doc/hardwarebitmaps.html了解不能使用Hardware Bitmaps的情况
    // 不禁用可能会导致错误,但是有着节省内存和避免内存抖动的优点
    builder.setDefaultRequestOptions(new RequestOptions()
    .format(format)
    );

    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            int sizeInMB = 160;
            switch (cacheSize) {
                case DISK_CACHE_40MB:
                    sizeInMB = 40;
                    break;
                case DISK_CACHE_80MB:
                    sizeInMB = 80;
                    break;
                case DISK_CACHE_160MB:
                    sizeInMB = 160;
                    break;
                case DISK_CACHE_320MB:
                    sizeInMB = 320;
                    break;
                default:
                case DISK_CACHE_640MB:
                    sizeInMB = 640;
                    break;
            }

            File path = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                path = context.getExternalCacheDirs()[(context.getExternalCacheDirs().length - 1)];
            } else {
                path = context.getExternalCacheDir();
            }
            File cacheLocation = new File(path, cacheName);
            cacheLocation.mkdirs();
            return DiskLruCacheWrapper.create(cacheLocation, sizeInMB * 1024 * 1024);
        }
    });
}
 
Example #22
Source File: Glide.java    From giffun with Apache License 2.0 4 votes vote down vote up
public DiskCache.Factory getDiskCacheFactory() {
    return diskCacheFactory;
}
 
Example #23
Source File: CacheLoader.java    From giffun with Apache License 2.0 4 votes vote down vote up
public CacheLoader(DiskCache diskCache) {
    this.diskCache = diskCache;
}
 
Example #24
Source File: StealingDiskCacheFactory.java    From glide-support with The Unlicense 4 votes vote down vote up
@Override public DiskCache build() {
	DiskCache cache = factory.build();
	App.getInstance().setDiskCache(cache);
	return cache;
}
 
Example #25
Source File: App.java    From glide-support with The Unlicense 4 votes vote down vote up
public DiskCache getDiskCache() {
	return diskCache;
}
 
Example #26
Source File: App.java    From glide-support with The Unlicense 4 votes vote down vote up
public void setDiskCache(DiskCache diskCache) {
	this.diskCache = diskCache;
}
 
Example #27
Source File: Engine.java    From giffun with Apache License 2.0 4 votes vote down vote up
public Engine(MemoryCache memoryCache, DiskCache.Factory diskCacheFactory, ExecutorService diskCacheService,
        ExecutorService sourceService) {
    this(memoryCache, diskCacheFactory, diskCacheService, sourceService, null, null, null, null, null);
}
 
Example #28
Source File: Engine.java    From giffun with Apache License 2.0 4 votes vote down vote up
public LazyDiskCacheProvider(DiskCache.Factory factory) {
    this.factory = factory;
}
 
Example #29
Source File: SignalGlideModule.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DiskCache build() {
  return new DiskCacheAdapter();
}
 
Example #30
Source File: SignalGlideModule.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public DiskCache build() {
  return new DiskCacheAdapter();
}