Java Code Examples for com.bumptech.glide.GlideBuilder#setDefaultRequestOptions()
The following examples show how to use
com.bumptech.glide.GlideBuilder#setDefaultRequestOptions() .
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: GlideModifications.java From aptoide-client-v8 with GNU General Public License v3.0 | 6 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(RequestOptions.formatOf(DecodeFormat.PREFER_RGB_565)); // disk cache config //builder.setDiskCache(new ExternalCacheDiskCacheFactory(context)); // using defaults MemorySizeCalculator calculator = new MemorySizeCalculator.Builder(context).build(); // 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)); }
Example 2
Source File: MyGlideModule.java From hipda with GNU General Public License v2.0 | 6 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder gb) { String cacheSizeStr = HiSettingsHelper.getInstance().getStringValue(HiSettingsHelper.PERF_CACHE_SIZE_IN_MB, DEFAULT_CACHE_SIZE + ""); int cacheSize = DEFAULT_CACHE_SIZE; if (TextUtils.isDigitsOnly(cacheSizeStr)) { cacheSize = Integer.parseInt(cacheSizeStr); if (cacheSize < MIN_CACHE_SIZE) { cacheSize = DEFAULT_CACHE_SIZE; } } gb.setDiskCache(new ExternalPreferredCacheDiskCacheFactory(context, cacheSize * 1024 * 1024)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) gb.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); GlideHelper.initDefaultFiles(); }
Example 3
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 4
Source File: MyAppGlideModule.java From Awesome-WanAndroid with Apache License 2.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); int memoryCacheSizeBytes = 1024 * 1024 * 20; builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes)); int bitmapPoolSizeBytes = 1024 * 1024 * 30; builder.setBitmapPool(new LruBitmapPool(bitmapPoolSizeBytes)); int diskCacheSizeBytes = 1024 * 1024 * 100; builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes)); }
Example 5
Source File: MyAppGlideModel.java From OpenHub with GNU General Public License v3.0 | 5 votes |
@Override public void applyOptions(Context context, GlideBuilder builder) { super.applyOptions(context, builder); builder.setDiskCache(new InternalCacheDiskCacheFactory(context, AppConfig.IMAGE_MAX_CACHE_SIZE)); RequestOptions requestOptions = RequestOptions.placeholderOf(R.mipmap.logo); builder.setDefaultRequestOptions(requestOptions); }
Example 6
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 7
Source File: MyAppGlideModule.java From Yuan-WanAndroid with Apache License 2.0 | 4 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); }
Example 8
Source File: GlideAppModule.java From WanAndroid with Apache License 2.0 | 4 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)); }
Example 9
Source File: GlideModule.java From Android-Example with Apache License 2.0 | 4 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { builder.setDefaultRequestOptions(RequestOptions.formatOf(DecodeFormat.PREFER_ARGB_8888)); }
Example 10
Source File: HHGlideModel.java From HHComicViewer with Apache License 2.0 | 4 votes |
@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 11
Source File: EasyXkcdGlideModule.java From Easy_xkcd with Apache License 2.0 | 4 votes |
@Override public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) { builder.setDefaultRequestOptions(new RequestOptions().override(Target.SIZE_ORIGINAL)); super.applyOptions(context, builder); }