Java Code Examples for com.bumptech.glide.GlideBuilder#setDiskCache()
The following examples show how to use
com.bumptech.glide.GlideBuilder#setDiskCache() .
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 AcgClub with MIT License | 6 votes |
@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 2
Source File: FCGlideModules.java From FamilyChat with Apache License 2.0 | 6 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { //修改内存容量和位图缓存池大小 MemorySizeCalculator calculator = new MemorySizeCalculator(context); int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); int customMemoryCacheSize = (int) (MEMORY_CACHE_COUNT * defaultMemoryCacheSize); int customBitmapPoolSize = (int) (MEMORY_CACHE_COUNT * defaultBitmapPoolSize); builder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); builder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); //设置磁盘缓存 String diskCachePath = FCCache.getInstance().getImageCachePath(); int cacheSize = 0; long availableSize = SdUtils.getAvailableExternalMemorySize(); if (availableSize < MAX_DISK_CACHE_SIZE) cacheSize = (int) availableSize; else cacheSize = MAX_DISK_CACHE_SIZE; builder.setDiskCache(new DiskLruCacheFactory(diskCachePath, cacheSize)); }
Example 3
Source File: MyGlideModule.java From Simpler with Apache License 2.0 | 6 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { ViewTarget.setTagId(R.id.glide_tag_id); // Apply options to the builder here. // 默认内存和图片池大小 // MemorySizeCalculator calculator = new MemorySizeCalculator(context); // int defaultMemoryCacheSize = calculator.getMemoryCacheSize(); // 默认内存大小 // int defaultBitmapPoolSize = calculator.getBitmapPoolSize(); // 默认图片池大小 // builder.setMemoryCache(new LruResourceCache(defaultMemoryCacheSize)); // 该两句无需设置,是默认的 // builder.setBitmapPool(new LruBitmapPool(defaultBitmapPoolSize)); //定义图片的本地磁盘缓存 // File cacheDir = context.getExternalCacheDir();//指定的是数据的缓存地址 // int diskCacheSize = 1024 * 1024 * 1024;//最多可以缓存多少字节的数据 //设置磁盘缓存大小 // builder.setDiskCache(new DiskLruCacheFactory(cacheDir.getPath(), "glide", diskCacheSize)); // 定义缓存大小和位置 if (BaseConfig.sSDCardExist) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, extDiskSize)); //外部存储 } else { builder.setDiskCache(new InternalCacheDiskCacheFactory(context, Constants.Dir.IMAGE_CACHE_DIR, intDiskSize)); //内部存储 } // 自定义内存和图片池大小 // builder.setMemoryCache(new LruResourceCache(memorySize)); // builder.setBitmapPool(new LruBitmapPool(memorySize)); // builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); }
Example 4
Source File: GlideConfiguration.java From MVPArms with Apache License 2.0 | 6 votes |
@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); } }
Example 5
Source File: GlideModelConfig.java From Android with MIT License | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { // Define cache size and location builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskSize)); //Mobile disk //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", diskSize)); //sdcard disk // The custom memory pool size and pictures builder.setMemoryCache(new LruResourceCache(memorySize)); builder.setBitmapPool(new LruBitmapPool(memorySize)); // Define the image format //builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); }
Example 6
Source File: MyAppGlideModule.java From nativescript-image-cache-it with Apache License 2.0 | 5 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { int diskCacheSizeBytes = 1024 * 1024 * 1000; // 1GB builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); /*MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context) .setMemoryCacheScreens(4) .build(); builder.setMemoryCache(new LruResourceCache(calculator.getMemoryCacheSize())); MemorySizeCalculator bpCalculator = new MemorySizeCalculator.Builder(context) .setBitmapPoolScreens(3) .build(); builder.setBitmapPool(new LruBitmapPool(bpCalculator.getBitmapPoolSize())); */ }
Example 7
Source File: CustomGlideModule.java From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { int MEM_CACHE_SIZE = 1024 * 1024 * ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass() / 3; builder.setMemoryCache(new LruResourceCache(MEM_CACHE_SIZE)); RequestOptions requestOptions = new RequestOptions(); requestOptions = requestOptions.format(DecodeFormat.PREFER_ARGB_8888); builder.setDefaultRequestOptions(requestOptions); builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); }
Example 8
Source File: GlideConfiguration.java From MVVMArms with Apache License 2.0 | 5 votes |
@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 9
Source File: VideoListGlideModule.java From VideoListPlayer with MIT License | 5 votes |
@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 10
Source File: MyGlideModule.java From ZoomPreviewPicture with Apache License 2.0 | 5 votes |
@Override public void applyOptions(final 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)); builder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); ViewTarget.setTagId(R.id.glide_tag_id); }
Example 11
Source File: GlideConfiguration.java From Aurora with Apache License 2.0 | 5 votes |
@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 12
Source File: GlideSetup.java From MoeGallery with GNU General Public License v3.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { //builder.setMemoryCache(new LruResourceCache(64 * 1024 * 1024)); //builder.setBitmapPool(new LruBitmapPool(32 * 1024 * 1024)); builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); builder.setDiskCache(new InternalCacheDiskCacheFactory(context, 2147483647)); builder.setResizeService(new FifoPriorityThreadPoolExecutor(2)); }
Example 13
Source File: GlideConfig.java From AndroidProject with Apache License 2.0 | 5 votes |
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { // 读写外部缓存目录不需要申请存储权限 File diskCacheFile = new File(context.getCacheDir(), "glide"); // 如果这个路径是一个文件 if (diskCacheFile.exists() && diskCacheFile.isFile()) { // 执行删除操作 diskCacheFile.delete(); } // 如果这个路径不存在 if (!diskCacheFile.exists()) { // 创建多级目录 diskCacheFile.mkdirs(); } builder.setDiskCache(() -> DiskLruCacheWrapper.create(diskCacheFile, 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)); // 设置默认的加载占位图和加载出错图 builder.setDefaultRequestOptions(new RequestOptions().placeholder(R.drawable.image_loading).error(R.drawable.image_load_err)); }
Example 14
Source File: QtalkGlideModule.java From imsdk-android with MIT License | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { final String dir = "/files/glide"; int diskCacheSize = 1024 * 1024 * 1024;//最多可以缓存多少字节的数据 // builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, dir, diskCacheSize)); builder.setDiskCache(new DiskLruCacheFactory(new DiskLruCacheFactory.CacheDirectoryGetter() { @Override public File getCacheDirectory() { return new File(MyDiskCache.getDirectory().getAbsolutePath() + "/files/glide"); } }, diskCacheSize)); }
Example 15
Source File: OkHttpProgressGlideModule.java From imsdk-android with MIT License | 5 votes |
@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 16
Source File: SilenceGlideModule.java From Silence with GNU General Public License v3.0 | 4 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDiskCache(new NoopDiskCacheFactory()); }
Example 17
Source File: GlideConfig.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public void applyOptions(final Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500)); }
Example 18
Source File: GlideConfig.java From iBeebo with GNU General Public License v3.0 | 4 votes |
@Override public void applyOptions(final Context context, GlideBuilder builder) { builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, 1024 * 1024 * 500)); }
Example 19
Source File: MyAppGlideModule.java From v9porn with MIT License | 4 votes |
@Override public void applyOptions(@NonNull Context context, GlideBuilder builder) { int diskCacheSizeBytes = 1024 * 1024 * 250; builder.setDiskCache(new DiskLruCacheFactory(AppCacheUtils.getGlideDiskCacheDir(context).getAbsolutePath(), diskCacheSizeBytes)); }
Example 20
Source File: GustomCachingGlideModule.java From Android-Tech with Apache License 2.0 | 3 votes |
@Override public void applyOptions(Context context, GlideBuilder glideBuilder) { // 自定义内存缓存 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); glideBuilder.setMemoryCache(new LruResourceCache(customMemoryCacheSize)); glideBuilder.setBitmapPool(new LruBitmapPool(customBitmapPoolSize)); // 自定义磁盘缓存 // set size & external vs. internal int cacheSize100MegaBytes = 104857600; glideBuilder.setDiskCache(new InternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); // glideBuilder.setDiskCache(new ExternalCacheDiskCacheFactory(context, cacheSize100MegaBytes)); // 选一个特定的存储目录 // String downloadDirectoryPath = Environment.getDownloadCacheDirectory().getPath(); // glideBuilder.setDiskCache(new DiskLruCacheFactory(downloadDirectoryPath, cacheSize100MegaBytes)); }