@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)); }
@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)); }
@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); // 默认 }
@Override public void applyOptions(Context context, GlideBuilder builder) { MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context) .setMemoryCacheScreens(2) .build(); // default // builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize())); Integer m = new SharedPreferencesUtils().getIntValue(mPref, mCacheMemory); if (m == 0){ m = 256; } int memoryCacheSizeBytes = 1024 * 1024 * m; builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes)); Integer d = new SharedPreferencesUtils().getIntValue(mPref, mCacheDisk); if (d == 0){ d = 256; } int diskCacheSizeBytes = 1024 * 1024 * d; builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); builder.setDefaultRequestOptions( new RequestOptions() .diskCacheStrategy(DiskCacheStrategy.ALL)); }
@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)); }
@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)); }
@RequiresApi(api = Build.VERSION_CODES.KITKAT) @Override public void applyOptions(Context context, GlideBuilder builder) { MemorySizeCalculator calculator = new MemorySizeCalculator(context); // Get default memory cache size int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // Set custom memory cache size int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize); int customBitmapPoolSize = (int) (1.5 * defaultBitmapPoolSize); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); // Set disk cache size int diskCacheSize = 1024 * 1024 * 100; builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide", diskCacheSize)); // Prefer higher quality images unless we're on a low RAM device ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); builder.setDecodeFormat(activityManager.isLowRamDevice() ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888); }
/** * 设置缓存设置 */ private void customCacheOptions(Context context, GlideBuilder builder) { //设置内存缓存大小和bitmap池大小 MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context) .setMemoryCacheScreens(2) .build(); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapCacheSize = calculator.getBitmapPoolSize(); //比默认的内存分配大20% int customMemoryCacheSize = (int) (4 * defaultMemoryCacheSize); int customBitmapPoolSize = (int) (4 * defaultBitmapCacheSize); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); //设置磁盘缓存 int cacheSize100MegaBytes = 1024 * 1024 * 100;//200M //外部磁盘缓存 builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); }
/** * Lazily apply options to a {@link GlideBuilder} immediately before the Glide singleton is * created. * <p> * <p> * This method will be called once and only once per implementation. * </p> * * @param context An Application {@link Context}. * @param builder The {@link GlideBuilder} that will be used to create Glide. */ @Override public void applyOptions(Context context, GlideBuilder builder) { ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); MemorySizeCalculator calculator = new MemorySizeCalculator(context); // 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().getUsableSpace(); storageCacheSize = (int) (total*0.14); } builder.setMemoryCache(new LruResourceCache(memoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(bitmapPoolSize)); builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, storageCacheSize)); builder.setDecodeFormat(ActivityManagerCompat.isLowRamDevice(activityManager) ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888); }
@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)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // disk cache config //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); // using defaults MemorySizeCalculator calculator = new MemorySizeCalculator(context); // size for memory cache int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // size for bitmap pool int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize)); }
@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)); }
@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); } }); }
@Override public void applyOptions(Context context, GlideBuilder builder) { //解决setTag问题 ViewTarget.setTagId(R.id.glide_tag_id); //磁盘缓存 builder.setDiskCache(new DiskLruCacheFactory(AppFileHelper.getAppCachePath(), 50 * 1024 * 1024)); builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); //内存缓存 MemorySizeCalculator calculator = new MemorySizeCalculator(context); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); //设置比默认大小大1.5倍的缓存和图片池大小 int customMemoryCacheSize = (int) (1.5 * defaultMemoryCacheSize); int customBitmapPoolSize = defaultBitmapPoolSize; KLog.i("poolSize", "bitmapPoolSize >>>>> " + android.text.format.Formatter.formatFileSize(context, customBitmapPoolSize) + " memorySize>>>>>>>> " + android.text.format.Formatter.formatFileSize(context, customMemoryCacheSize)); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { 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 cacheSize50MegaBytes = 52428800; /*builder.setDiskCache( new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes) );*/ /*builder.setDiskCache( new ExternalCacheDiskCacheFactory());*/ builder.setDiskCache(new DiskLruCacheFactory(Constants.OwnCacheDirectory,"Cache",cacheSize50MegaBytes)) ; builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); //PREFER_RGB_565 }
@Override public void applyOptions(Context context, GlideBuilder builder) { // Apply options to the builder here. builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); 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; String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath(); builder.setDiskCache( new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes) ); }
public GifFrameManager(Context context, GifDecoder decoder, Handler mainHandler, Transformation<Bitmap> transformation) { this.context = context; this.decoder = decoder; this.mainHandler = mainHandler; this.transformation = transformation; calculator = new MemorySizeCalculator(context); frameLoader = new GifFrameModelLoader(); frameResourceDecoder = new GifFrameResourceDecoder(); if (!decoder.isTransparent()) { // For non transparent gifs, we can beat the performance of our gif decoder for each frame by decoding jpegs // from disk. cacheDecoder = new StreamBitmapDecoder(context); encoder = new BitmapEncoder(Bitmap.CompressFormat.JPEG, 70); } else { // For transparent gifs, we would have to encode as pngs which is actually slower than our gif decoder so we // avoid writing frames to the disk cache entirely. cacheDecoder = NullCacheDecoder.get(); encoder = SkipCache.get(); } }
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 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)); builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); }
@Override public void applyOptions(Context context, GlideBuilder builder) { MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context) .setMemoryCacheScreens(2) .build(); //设置手机默认推荐缓存大小 builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize())); // 自定义缓存大小. int memoryCacheSizeBytes = 1024 * 1024 * 20; // 20mb builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes)); //自定义内置磁盘缓存大小(可以指明路径) int diskCacheSizeBytes = 1024 * 1024 * 100; // 100 MB builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); }
@Override public void applyOptions(Context context, GlideBuilder builder) { 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)); }
@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); } }
@Override public void applyOptions(final Context context, final GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500)); 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)); }
@Override public void applyOptions(final Context context, GlideBuilder builder) { ViewTarget.setTagId(R.id.glide_tag_id); 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)); builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); }
@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); } }
@Override public void applyOptions(Context context, GlideBuilder builder) { super.applyOptions(context, builder); builder.setDiskCache(() -> { // 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)); //Will transfer the opportunity to transfer Glide to GlideImageLoaderStrategy, as you think the framework provides GlideImageLoaderStrategy //And can not meet their own needs, would like to customize BaseImageLoaderStrategy, then you'd better achieve GlideAppliesOptions //Because only to become GlideAppliesOptions implementation class, where to call applyGlideOptions (), so you have the right to configure Glide BaseImageLoaderStrategy imageLoaderStrategy = GmUtils.INSTANCE.obtainGmComponent(context).imageLoader().getStrategy(); if (imageLoaderStrategy instanceof GlideAppliesOptions) { ((GlideAppliesOptions) imageLoaderStrategy).applyGlideOptions(context, builder); } }
@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); } }
@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)); }
private void setupGlide() { MemorySizeCalculator calculator = new MemorySizeCalculator(this); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // disable the disk cache because all of our images are already cached on the sd card Glide.setup(new GlideBuilder(this) .setDiskCache(new DiskCacheAdapter()) .setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize)) .setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)) ); }
@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); } }
@Override public void applyOptions(Context context, GlideBuilder builder) { MemorySizeCalculator calculator = new MemorySizeCalculator(context); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); Log.i("vipin_apply", String.valueOf(defaultMemoryCacheSize)); builder.setMemoryCache(new LruResourceCacheInternal(defaultMemoryCacheSize / 2)); builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize / 2)); }