本文整理汇总了Java中com.facebook.imagepipeline.cache.DefaultBitmapMemoryCacheParamsSupplier类的典型用法代码示例。如果您正苦于以下问题:Java DefaultBitmapMemoryCacheParamsSupplier类的具体用法?Java DefaultBitmapMemoryCacheParamsSupplier怎么用?Java DefaultBitmapMemoryCacheParamsSupplier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultBitmapMemoryCacheParamsSupplier类属于com.facebook.imagepipeline.cache包,在下文中一共展示了DefaultBitmapMemoryCacheParamsSupplier类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.facebook.imagepipeline.cache.DefaultBitmapMemoryCacheParamsSupplier; //导入依赖的package包/类
public static void init(Context context, File baseDirectoryPath) {
ImagePipelineConfig.Builder imagePipelineConfigBuilder = ImagePipelineConfig.newBuilder(context)
.setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context)
.setBaseDirectoryPath(baseDirectoryPath)
.setBaseDirectoryName("original")
.build())
.setDownsampleEnabled(true);
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
Supplier<MemoryCacheParams> memoryCacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(activityManager) {
@Override
public MemoryCacheParams get() {
int maxCacheEntries = 256;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
maxCacheEntries = 64;
}
return new MemoryCacheParams(
getMaxCacheSize(),
maxCacheEntries,
Integer.MAX_VALUE,
Integer.MAX_VALUE,
Integer.MAX_VALUE);
}
private int getMaxCacheSize() {
final int maxMemory = Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE);
if (maxMemory < 32 * ByteConstants.MB) {
return 4 * ByteConstants.MB;
} else if (maxMemory < 64 * ByteConstants.MB) {
return 6 * ByteConstants.MB;
} else {
return maxMemory / 4;
}
}
};
imagePipelineConfigBuilder.setBitmapMemoryCacheParamsSupplier(memoryCacheParamsSupplier);
Fresco.initialize(context, imagePipelineConfigBuilder.build());
}