Search in sources :

Example 1 with MemorySizeCalculator

use of com.bumptech.glide.load.engine.cache.MemorySizeCalculator in project MVPFrames by RockyQu.

the class GlideConfiguration method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    final AppComponent component = AppUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.getCacheFile(), "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));
    // 图片框架最终会走到 GlideImageLoader 的 load 方法中进行处理
    // 如果你想自己自定义图片框架或自己实现 Glide BaseImageLoader 你需要实现 GlideAppliesOptions 接口
    BaseImageLoader baseImageLoader = component.getImageLoader().getImageLoader();
    if (baseImageLoader instanceof GlideAppliesOptions) {
        ((GlideAppliesOptions) baseImageLoader).applyGlideOptions(context, builder);
    }
}
Also used : BaseImageLoader(com.tool.common.widget.imageloader.BaseImageLoader) AppComponent(com.tool.common.di.component.AppComponent) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) DiskCache(com.bumptech.glide.load.engine.cache.DiskCache) File(java.io.File)

Example 2 with MemorySizeCalculator

use of com.bumptech.glide.load.engine.cache.MemorySizeCalculator in project LeafPic by HoraApps.

the class CustomGlideModule method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // Apply options to the builder here.
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    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));
    int cacheSize100MegaBytes = 104857600;
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes));
}
Also used : MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) InternalCacheDiskCacheFactory(com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory)

Example 3 with MemorySizeCalculator

use of com.bumptech.glide.load.engine.cache.MemorySizeCalculator in project MVPArms by JessYanCoding.

the class GlideConfiguration method applyOptions.

@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            // Careful: the external cache directory doesn't enforce permissions
            File cacheDirectory = new File(DataHelper.getCacheFile(UiUtils.getContext()), "Glide");
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(cacheDirectory), IMAGE_DISK_CACHE_MAX_SIZE);
        }
    });
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    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));
}
Also used : MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) DiskCache(com.bumptech.glide.load.engine.cache.DiskCache) File(java.io.File)

Example 4 with MemorySizeCalculator

use of com.bumptech.glide.load.engine.cache.MemorySizeCalculator in project MVPArms by JessYanCoding.

the class GlideConfiguration method applyOptions.

@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    final AppComponent appComponent = ArmsUtils.obtainAppComponentFromContext(context);
    builder.setDiskCache(() -> {
        // Careful: the external cache directory doesn't enforce permissions
        return DiskLruCacheWrapper.create(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);
    }
}
Also used : BaseImageLoaderStrategy(com.jess.arms.http.imageloader.BaseImageLoaderStrategy) AppComponent(com.jess.arms.di.component.AppComponent) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache) File(java.io.File)

Example 5 with MemorySizeCalculator

use of com.bumptech.glide.load.engine.cache.MemorySizeCalculator in project anitrend-app by AniTrend.

the class GlideAppModule method applyOptions.

@Override
public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
    boolean isLowRamDevice = CompatUtil.isLowRamDevice(context);
    MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).setMemoryCacheScreens(isLowRamDevice ? 2 : 3).build();
    // Increasing cache & pool by 25% - default is 250MB
    int memoryCacheSize = (int) (1.25 * calculator.getMemoryCacheSize());
    int bitmapPoolSize = (int) (1.25 * calculator.getBitmapPoolSize());
    int storageCacheSize = 1024 * 1024 * 350;
    if (context.getExternalCacheDir() != null) {
        long total = context.getExternalCacheDir().getTotalSpace();
        storageCacheSize = (int) (total * 0.2);
    }
    builder.setMemoryCache(new LruResourceCache(memoryCacheSize));
    builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize));
    builder.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, storageCacheSize));
    // Setting default params for glide
    RequestOptions options = new RequestOptions().format(isLowRamDevice ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888).timeout(KeyUtil.GLIDE_REQUEST_TIMEOUT).diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).error(CompatUtil.getDrawable(context, R.drawable.ic_broken_image_white_48dp, R.color.colorStateOrange));
    builder.setDefaultRequestOptions(options);
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) MemorySizeCalculator(com.bumptech.glide.load.engine.cache.MemorySizeCalculator) GlideBuilder(com.bumptech.glide.GlideBuilder) LruBitmapPool(com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool) ExternalPreferredCacheDiskCacheFactory(com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory) LruResourceCache(com.bumptech.glide.load.engine.cache.LruResourceCache)

Aggregations

LruBitmapPool (com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool)5 LruResourceCache (com.bumptech.glide.load.engine.cache.LruResourceCache)5 MemorySizeCalculator (com.bumptech.glide.load.engine.cache.MemorySizeCalculator)5 File (java.io.File)3 DiskCache (com.bumptech.glide.load.engine.cache.DiskCache)2 GlideBuilder (com.bumptech.glide.GlideBuilder)1 ExternalPreferredCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.ExternalPreferredCacheDiskCacheFactory)1 InternalCacheDiskCacheFactory (com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory)1 RequestOptions (com.bumptech.glide.request.RequestOptions)1 AppComponent (com.jess.arms.di.component.AppComponent)1 BaseImageLoaderStrategy (com.jess.arms.http.imageloader.BaseImageLoaderStrategy)1 AppComponent (com.tool.common.di.component.AppComponent)1 BaseImageLoader (com.tool.common.widget.imageloader.BaseImageLoader)1