Java 类com.bumptech.glide.load.engine.cache.DiskCache 实例源码

项目:GitHub    文件:GlideConfiguration.java   
@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));

}
项目:GitHub    文件:Engine.java   
public Engine(MemoryCache memoryCache,
    DiskCache.Factory diskCacheFactory,
    GlideExecutor diskCacheExecutor,
    GlideExecutor sourceExecutor,
    GlideExecutor sourceUnlimitedExecutor,
    GlideExecutor animationExecutor) {
  this(
      memoryCache,
      diskCacheFactory,
      diskCacheExecutor,
      sourceExecutor,
      sourceUnlimitedExecutor,
      animationExecutor,
      /*jobs=*/ null,
      /*keyFactory=*/ null,
      /*activeResources=*/ null,
      /*engineJobFactory=*/ null,
      /*decodeJobFactory=*/ null,
      /*resourceRecycler=*/ null);
}
项目:GitHub    文件:EngineTest.java   
Engine getEngine() {
  if (engine == null) {
    engine =
        new Engine(
            cache,
            mock(DiskCache.Factory.class),
            GlideExecutor.newDiskCacheExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            MockGlideExecutor.newMainThreadExecutor(),
            jobs,
            keyFactory,
            activeResources,
            engineJobFactory,
            decodeJobFactory,
            resourceRecycler);
  }
  return engine;
}
项目:yyox    文件:GlideConfiguration.java   
@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
            return DiskLruCacheWrapper.get(DataHelper.getCacheFile(UiUtils.getContext()), 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));

}
项目:MVVMFrames    文件:GlideConfiguration.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {

    // 缓存目录
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            AppComponent component = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(FileUtils.makeDirs(new File(component.cacheFile(), "Glide")), DISK_SIZE);
        }
    });

    // 自定义内存缓存和图片池大小
    MemorySizeCalculator calculator = new MemorySizeCalculator(context);
    builder.setMemoryCache(new LruResourceCache((int) (1.2 * calculator.getMemoryCacheSize())));
    builder.setBitmapPool(new LruBitmapPool((int) (1.2 * calculator.getBitmapPoolSize())));

    // 图片格式
    builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认
}
项目:AppCommonFrame    文件:GlideConfiguration.java   
@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.get(Glide.getPhotoCacheDir(context), ConfigConstants.MAX_DISK_CACHE_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));

}
项目:Hotspot-master-devp    文件:CustomCachingGlideModule.java   
@Override public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File cacheLocation = new File(AppUtils.getPath(context, AppUtils.StorageFile.cache));
                cacheLocation.mkdirs();
                return DiskLruCacheWrapper.get(cacheLocation, DISK_CACHE_SIZE);
            }
        });
//        MemorySizeCalculator calculator = new MemorySizeCalculator(context);
//        int defaultMemoryCacheSize = calculator.getMemoryCacheSize();
//        int defaultBitmapPoolSize = calculator.getBitmapPoolSize();
//
//        int customMemoryCacheSize = (int) (0.25 * defaultMemoryCacheSize);
//        int customBitmapPoolSize = (int) (0.25* defaultBitmapPoolSize);
//
//        builder.setMemoryCache( new LruResourceCache( customMemoryCacheSize ));
//        builder.setBitmapPool( new LruBitmapPool( customBitmapPoolSize ));
    }
项目:MVPArms_Fragment-fragment    文件:GlideConfiguration.java   
@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
            AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), 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));

}
项目:PicShow-zhaipin    文件:GlideConfiguration.java   
@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
            return DiskLruCacheWrapper.get(DataHelper.getCacheFile(UiUtils.getContext()), 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));

}
项目:mvparms    文件:GlideConfiguration.java   
@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));

}
项目:MVPArmsTest1    文件:GlideConfiguration.java   
@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
            AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
            return DiskLruCacheWrapper.get(DataHelper.makeDirs(new File(appComponent.cacheFile(), "Glide")), 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));

}
项目:aptoide-client    文件:AptoideGlideModule.java   
@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));
}
项目:BigApp_Discuz_Android    文件:GlideUtils.java   
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));
    }
项目:ImageSwitcher    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 设置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 缓存到data目录下最大50M
    // 缓存目录为程序内部缓存目录
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它应用访问)且缓存最大为250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 缓存到外部磁盘SD卡上,字节
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_DISK_CACHE_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));
}
项目:GankGirl    文件:GlideConfiguration.java   
@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);
        }
    });

}
项目:ImageLoaderDemo    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    // 设置格式
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    // 缓存到data目录下最大50M
    // 缓存目录为程序内部缓存目录
    // /data/data/your_package_name/image_manager_disk_cache/
    // (不能被其它应用访问)且缓存最大为250MB
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
    // 缓存到外部磁盘SD卡上,字节
    // builder.setDiskCache(new ExternalCacheDiskCacheFactory(
    // context,DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
    // DiskCache.Factory.DEFAULT_DISK_CACHE_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));
}
项目:saarang-iosched    文件:VolleyDiskCacheWrapper.java   
@Override
public void put(final String key, final Entry entry) {
    diskCache.put(new StringKey(key), new DiskCache.Writer() {
        @Override
        public boolean write(OutputStream os) {
            CacheHeader header = new CacheHeader(key, entry);
            boolean success = header.writeHeader(os);
            if (success) {
                try {
                    os.write(entry.data);
                } catch (IOException e) {
                    success = false;
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Unable to write data", e);
                    }
                }
            }
            return success;
        }
    });
}
项目:AppDevFestSudeste2015    文件:VolleyDiskCacheWrapper.java   
@Override
public void put(final String key, final Entry entry) {
    diskCache.put(new StringKey(key), new DiskCache.Writer() {
        @Override
        public boolean write(OutputStream os) {
            CacheHeader header = new CacheHeader(key, entry);
            boolean success = header.writeHeader(os);
            if (success) {
                try {
                    os.write(entry.data);
                } catch (IOException e) {
                    success = false;
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Unable to write data", e);
                    }
                }
            }
            return success;
        }
    });
}
项目:devfestnorte-app    文件:VolleyDiskCacheWrapper.java   
@Override
public void put(final String key, final Entry entry) {
    diskCache.put(new StringKey(key), new DiskCache.Writer() {
        @Override
        public boolean write(OutputStream os) {
            CacheHeader header = new CacheHeader(key, entry);
            boolean success = header.writeHeader(os);
            if (success) {
                try {
                    os.write(entry.data);
                } catch (IOException e) {
                    success = false;
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Unable to write data", e);
                    }
                }
            }
            return success;
        }
    });
}
项目:Orpheus    文件:ArtworkGlideModule.java   
@Override
    public void applyOptions(final Context context, GlideBuilder builder) {
        builder.setDiskCache(new DiskCache.Factory() {
            @Override
            public DiskCache build() {
                File dir = CacheUtil.getCacheDir(context, "glide/1");
                return DiskLruCacheWrapper.get(dir, 50 * 1024 * 1024);
            }
        });
        //blows up
//        RequestOptions options = new RequestOptions()
//                .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
//                .centerCrop(context)
//                .placeholder(R.drawable.default_artwork)
//                ;
//        builder.setDefaultRequestOptions(options);
        if (BuildConfig.LOGVV) {
            builder.setLogLevel(Log.DEBUG);
        }
    }
项目:saarang-iosched    文件:VolleyDiskCacheWrapper.java   
@Override
public void put(final String key, final Entry entry) {
    diskCache.put(new StringKey(key), new DiskCache.Writer() {
        @Override
        public boolean write(OutputStream os) {
            CacheHeader header = new CacheHeader(key, entry);
            boolean success = header.writeHeader(os);
            if (success) {
                try {
                    os.write(entry.data);
                } catch (IOException e) {
                    success = false;
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        Log.d(TAG, "Unable to write data", e);
                    }
                }
            }
            return success;
        }
    });
}
项目:GitHub    文件:Engine.java   
public Engine(MemoryCache memoryCache,
    DiskCache.Factory diskCacheFactory,
    GlideExecutor diskCacheExecutor,
    GlideExecutor sourceExecutor,
    GlideExecutor sourceUnlimitedExecutor) {
  this(memoryCache, diskCacheFactory, diskCacheExecutor, sourceExecutor, sourceUnlimitedExecutor,
      null, null, null, null, null, null);
}
项目:GitHub    文件:GlideTest.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
  // Run all tasks on the main thread so they complete synchronously.
  GlideExecutor executor = MockGlideExecutor.newMainThreadExecutor();

  DiskCache.Factory diskCacheFactory = mock(DiskCache.Factory.class);
  when(diskCacheFactory.build()).thenReturn(mock(DiskCache.class));

  builder.setMemoryCache(mock(MemoryCache.class)).setDiskCache(diskCacheFactory)
      .setResizeExecutor(executor).setDiskCacheExecutor(executor);
}
项目:GitHub    文件:EngineTest.java   
public EngineTestHarness() {
  when(keyFactory.buildKey(eq(model), eq(signature), anyInt(), anyInt(), eq(transformations),
      eq(Object.class), eq(Object.class), eq(options))).thenReturn(cacheKey);

  job = mock(EngineJob.class);

  engine = new Engine(cache, mock(DiskCache.Factory.class),
      GlideExecutor.newDiskCacheExecutor(),
      MockGlideExecutor.newMainThreadExecutor(),
      MockGlideExecutor.newMainThreadUnlimitedExecutor(),
      jobs, keyFactory, activeResources,
      engineJobFactory, decodeJobFactory, resourceRecycler);
}
项目:GitHub    文件:SampleGlideModule.java   
@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));
}
项目:Hitalk    文件:VideoListGlideModule.java   
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter
            () {
        @Override
        public File getCacheDirectory() {
            return context.getExternalCacheDir();
        }
    }, DiskCache.Factory.DEFAULT_DISK_CACHE_SIZE));
}
项目:MoligyMvpArms    文件:GlideConfiguration.java   
@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);
    }
}
项目:Aurora    文件:GlideConfiguration.java   
@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);
    }
}
项目:NeiHanDuanZiTV    文件:GlideConfiguration.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    AppComponent appComponent = ((App) context.getApplicationContext()).getAppComponent();
    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);
    }
}
项目:decoy    文件:NIMGlideModule.java   
/**
 * ************************ Disk Cache ************************
 */
private static synchronized DiskCache getDiskCache() {
    if (diskCache == null) {
        diskCache = createDiskCache();
    }
    return diskCache;
}
项目:decoy    文件:NIMGlideModule.java   
private static synchronized DiskCache createDiskCache() {
    final Context context = NimUIKit.getContext();
    File cacheDir = StorageUtils.getOwnCacheDirectory(context, context.getPackageName() + "/cache/image/");
    if (!cacheDir.exists()) {
        cacheDir.mkdirs();
    }
    return DiskLruCacheWrapper.get(cacheDir, MAX_DISK_CACHE_SIZE);
}
项目:decoy    文件:NIMGlideModule.java   
/**
 * ************************ GlideModule override ************************
 */
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDiskCache(new DiskCache.Factory() {
        @Override
        public DiskCache build() {
            return getDiskCache();
        }
    });

    LogUtil.i(TAG, "NIMGlideModule apply options");
}
项目:MVVMArms    文件:GlideConfiguration.java   
@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);
    }
}
项目:ImageSwitcherJarPackage    文件:CustomGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    builder.setDiskCache(new InternalCacheDiskCacheFactory(context,
            DiskCache.Factory.DEFAULT_DISK_CACHE_DIR,
            DiskCache.Factory.DEFAULT_DISK_CACHE_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));
}
项目:MVPFrames    文件:GlideConfiguration.java   
@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);
    }
}
项目:MVPArms    文件:GlideConfiguration.java   
@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);
    }
}
项目:AndroidBase    文件:OkHttpGlideModule.java   
@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);
  }
项目:VideoListPlayer    文件:VideoListGlideModule.java   
@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));
}
项目:QingNianTuZhai    文件:SaveImgsService.java   
private void saveImg(String url){
    //检查是否有sd卡
    if (saveDir == null) {
        showToast(R.string.save_not_sd);
        return;
    }

    // 检查本地是否有
    String fileName = getFileNameByUrl(url);
    File localFile = new File(saveDir,fileName);
    if (localFile.exists()){
        showToast(R.string.save_exist);
        return;
    }

    // 检查glide的disk是否有
    DiskCache diskCache = DiskLruCacheWrapper.get(cacheDir, App.DEFAULT_DISK_CACHE_SIZE);
    File diskTempFile = diskCache.get(new StringSignature(url));
    if (diskTempFile == null || !diskTempFile.exists()){
        showToast(R.string.save_not_downloaded);
        return;
    }

    // 检查是否在队列中

    if (mUrlSet.contains(url)){
        showToast(R.string.save_saving);
        return;
    }

    mExecutorService.execute(new SaveImgRunnable(url,diskTempFile.getAbsolutePath(),localFile.getAbsolutePath()));
    mUrlSet.add(url);
    showToast(R.string.save_start);
}
项目:KwPresent    文件:KwGlideModule.java   
@Override
public void applyOptions(Context context, GlideBuilder builder) {
    builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
    builder.setDiskCache(new DiskCache.Factory() {

        @Override
        public DiskCache build() {
            return DiskLruCacheWrapper.get(new File(FileUtil.getAppCachePath()), LibConfig
                    .DISK_CACHE_CAPACITY);
        }
    });
}