本文整理汇总了Java中com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory类的典型用法代码示例。如果您正苦于以下问题:Java InternalCacheDiskCacheFactory类的具体用法?Java InternalCacheDiskCacheFactory怎么用?Java InternalCacheDiskCacheFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InternalCacheDiskCacheFactory类属于com.bumptech.glide.load.engine.cache包,在下文中一共展示了InternalCacheDiskCacheFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@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));
}
示例2: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@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);
}
示例3: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的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);
}
示例4: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@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));
}
示例5: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@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);
}
});
}
示例6: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// 指定位置在packageName/cache/glide_cache,大小为MAX_CACHE_DISK_SIZE的磁盘缓存
// 设置一个用来创建DiskCache的工厂。默认情况下Glide使用InternalCacheDiskCacheFactory内部工厂类创建DiskCache,
// 缓存目录为程序内部缓存目录/data/data/your_package_name/image_manager_disk_cache/(不能被其它应用访问)且缓存最大为250MB。
// 当然,可以通过InternalCacheDiskCacheFactory构造器更改缓存的目录和最大缓存大小
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "glide_cache", ConfigConstants.MAX_CACHE_DISK_SIZE));
// 指定内存缓存大小
// MemoryCache用来把resources 缓存在内存里,以便能马上能拿出来显示。
// 默认情况下Glide使用LruResourceCache,我们可以通过它的构造器设置最大缓存内存大小。
builder.setMemoryCache(new LruResourceCache(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
// 全部的内存缓存用来作为图片缓存
// Bitmap池用来允许不同尺寸的Bitmap被重用,这可以显著地减少因为图片解码像素数组分配内存而引发的垃圾回收。
// 默认情况下Glide使用LruBitmapPool作为Bitmap池,LruBitmapPool采用LRU算法保存最近使用的尺寸的Bitmap。
// 我们可以通过它的构造器设置最大缓存内存大小。
builder.setBitmapPool(new LruBitmapPool(ConfigConstants.MAX_CACHE_MEMORY_SIZE));
// 为所有的默认解码器设置解码格式。如DecodeFormat.PREFER_ARGB_8888。
// 默认是DecodeFormat.PREFER_RGB_565,因为相对于ARGB_8888的4字节/像素可以节省一半的内存,但不支持透明度且某些图片会出现条带。
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);//和Picasso配置一样
}
示例7: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的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);
}
示例8: getCacheSize
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
/**
* 获取Glide造成的缓存大小
*
* @return CacheSize
*/
public String getCacheSize(Context context) {
try {
return getFormatSize(getFolderSize(new File(context.getCacheDir() + "/"+ InternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR)));
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例9: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
builder
// 下面三项都是默认的, 不必设置
// .setMemoryCache(new LruResourceCache(MEMORY_CACHE_SIZE))
// .setBitmapPool(new LruBitmapPool(MEMORY_CACHE_SIZE))
// 默认 rgb565
.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888)
.setDiskCache(new InternalCacheDiskCacheFactory(context, DISK_CACHE_SIZE));
}
示例10: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@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));
}
示例11: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
if (AppUtil.hasSDCard()) {
builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "GlideCache", 500 * 1024 * 1024));
LogUtil.e("Glide使用SD卡缓存");
} else {
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, "GlideCache", 250 * 1024 * 1024));
LogUtil.e("Glide使用内部缓存");
}
builder.setMemoryCache(new LruResourceCache(100 * 1024 * 1024));
}
示例12: getCacheSize
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
/**
* 获取Glide造成的缓存大小
*
* @return CacheSize
*/
public String getCacheSize(Context context) {
try {
return getFormatSize(getFolderSize(new File(context.getCacheDir() + "/"+InternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR)));
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
示例13: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// 定义缓存大小和位置
builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskSize)); // 内存中
builder.setDiskCache(new ExternalCacheDiskCacheFactory(context, "cache", diskSize)); // sd卡中
// 自定义内存和图片池大小
builder.setMemoryCache(new LruResourceCache(memorySize)); // 自定义内存大小
builder.setBitmapPool(new LruBitmapPool(memorySize)); // 自定义图片池大小
// 定义图片格式
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); // 高质量
// builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565); // 默认(中等质量)
}
示例14: applyOptions
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的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));
}
示例15: getCacheSize
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory; //导入依赖的package包/类
/**
* 获取Glide造成的缓存大小
*
* @return CacheSize
*/
public String getCacheSize(Context context) {
try {
return getFormatSize(getFolderSize(new File(context.getCacheDir() + "/" + InternalCacheDiskCacheFactory.DEFAULT_DISK_CACHE_DIR)));
} catch (Exception e) {
e.printStackTrace();
}
return "";
}