本文整理汇总了Java中com.bumptech.glide.GlideBuilder.setDiskCache方法的典型用法代码示例。如果您正苦于以下问题:Java GlideBuilder.setDiskCache方法的具体用法?Java GlideBuilder.setDiskCache怎么用?Java GlideBuilder.setDiskCache使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.bumptech.glide.GlideBuilder
的用法示例。
在下文中一共展示了GlideBuilder.setDiskCache方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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));
}
示例2: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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); // 默认
}
示例3: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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 ));
}
示例4: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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));
}
示例5: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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);
}
示例6: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
/**
* 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);
}
示例7: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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);
}
}
示例8: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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));
}
示例9: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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);
}
示例10: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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));
}
示例11: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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);
}
}
示例12: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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);
}
}
示例13: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
/**
* ************************ 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");
}
示例14: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
final int cacheSize250M = 262144000;// glide默认磁盘缓存大小为250m
builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "pic_cache", cacheSize250M));
// 默认内存缓存为两个屏幕像素字节大小w*h*4*2
// 设置默认的请求选项
}
示例15: applyOptions
import com.bumptech.glide.GlideBuilder; //导入方法依赖的package包/类
@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));
}