本文整理匯總了Java中com.facebook.common.memory.NoOpMemoryTrimmableRegistry類的典型用法代碼示例。如果您正苦於以下問題:Java NoOpMemoryTrimmableRegistry類的具體用法?Java NoOpMemoryTrimmableRegistry怎麽用?Java NoOpMemoryTrimmableRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NoOpMemoryTrimmableRegistry類屬於com.facebook.common.memory包,在下文中一共展示了NoOpMemoryTrimmableRegistry類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: PoolConfig
import com.facebook.common.memory.NoOpMemoryTrimmableRegistry; //導入依賴的package包/類
private PoolConfig(Builder builder) {
mBitmapPoolParams =
builder.mBitmapPoolParams == null ?
DefaultBitmapPoolParams.get() :
builder.mBitmapPoolParams;
mBitmapPoolStatsTracker =
builder.mBitmapPoolStatsTracker == null ?
NoOpPoolStatsTracker.getInstance() :
builder.mBitmapPoolStatsTracker;
mFlexByteArrayPoolParams =
builder.mFlexByteArrayPoolParams == null ?
DefaultFlexByteArrayPoolParams.get() :
builder.mFlexByteArrayPoolParams;
mMemoryTrimmableRegistry =
builder.mMemoryTrimmableRegistry == null ?
NoOpMemoryTrimmableRegistry.getInstance() :
builder.mMemoryTrimmableRegistry;
mNativeMemoryChunkPoolParams =
builder.mNativeMemoryChunkPoolParams == null ?
DefaultNativeMemoryChunkPoolParams.get() :
builder.mNativeMemoryChunkPoolParams;
mNativeMemoryChunkPoolStatsTracker =
builder.mNativeMemoryChunkPoolStatsTracker == null ?
NoOpPoolStatsTracker.getInstance() :
builder.mNativeMemoryChunkPoolStatsTracker;
mSmallByteArrayPoolParams =
builder.mSmallByteArrayPoolParams == null ?
DefaultByteArrayPoolParams.get() :
builder.mSmallByteArrayPoolParams;
mSmallByteArrayPoolStatsTracker =
builder.mSmallByteArrayPoolStatsTracker == null ?
NoOpPoolStatsTracker.getInstance() :
builder.mSmallByteArrayPoolStatsTracker;
}
示例2: getDefaultImagePipelineConfig
import com.facebook.common.memory.NoOpMemoryTrimmableRegistry; //導入依賴的package包/類
public static ImagePipelineConfig getDefaultImagePipelineConfig(Context context) {
final int cacheSize = (int) SharedPreferencesUtil.getData(HViewerApplication.mContext,
SettingFragment.KEY_PREF_CACHE_SIZE, 300);
MAX_DISK_CACHE_VERYLOW_SIZE = cacheSize / 5 * ByteConstants.MB;
MAX_DISK_CACHE_LOW_SIZE = cacheSize * 3 / 5 * ByteConstants.MB;
MAX_DISK_CACHE_SIZE = cacheSize * ByteConstants.MB;
//內存配置
final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(
MAX_MEMORY_CACHE_SIZE, // 內存緩存中總圖片的最大大小,以字節為單位。
Integer.MAX_VALUE, // 內存緩存中圖片的最大數量。
MAX_MEMORY_CACHE_SIZE, // 內存緩存中準備清除但尚未被刪除的總圖片的最大大小,以字節為單位。
Integer.MAX_VALUE, // 內存緩存中準備清除的總圖片的最大數量。
Integer.MAX_VALUE); // 內存緩存中單個圖片的最大大小。
//修改內存圖片緩存數量,空間策略(這個方式有點惡心)
Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() {
@Override
public MemoryCacheParams get() {
return bitmapCacheParams;
}
};
//小圖片的磁盤配置
DiskCacheConfig diskSmallCacheConfig = DiskCacheConfig.newBuilder(context)
.setBaseDirectoryPath(getDiskCacheDir(context)) //緩存圖片基路徑
.setBaseDirectoryName(IMAGE_PIPELINE_SMALL_CACHE_DIR) //文件夾名
.setMaxCacheSize(MAX_DISK_CACHE_SIZE) //默認緩存的最大大小。
.setMaxCacheSizeOnLowDiskSpace(MAX_SMALL_DISK_LOW_CACHE_SIZE) //緩存的最大大小,使用設備時低磁盤空間。
.setMaxCacheSizeOnVeryLowDiskSpace(MAX_SMALL_DISK_VERYLOW_CACHE_SIZE) //緩存的最大大小,當設備極低磁盤空間
.setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
.build();
//默認圖片的磁盤配置
DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context)
.setBaseDirectoryPath(getDiskCacheDir(context))//緩存圖片基路徑
.setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) //文件夾名
.setMaxCacheSize(MAX_DISK_CACHE_SIZE) //默認緩存的最大大小。
.setMaxCacheSizeOnLowDiskSpace(MAX_DISK_CACHE_LOW_SIZE) //緩存的最大大小,使用設備時低磁盤空間。
.setMaxCacheSizeOnVeryLowDiskSpace(MAX_DISK_CACHE_VERYLOW_SIZE) //緩存的最大大小,當設備極低磁盤空間
.setDiskTrimmableRegistry(NoOpDiskTrimmableRegistry.getInstance())
.build();
// 自定義使用okhttp進行請求
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.dns(new HttpDns())
.build();
//緩存圖片配置
ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(context)
.setBitmapsConfig(Bitmap.Config.RGB_565)
.setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams)
.setSmallImageDiskCacheConfig(diskSmallCacheConfig)
.setMainDiskCacheConfig(diskCacheConfig)
.setMemoryTrimmableRegistry(NoOpMemoryTrimmableRegistry.getInstance())
.setResizeAndRotateEnabledForNetwork(true)
.setNetworkFetcher(new MyOkHttpNetworkFetcher(okHttpClient));
// 這段代碼用於清理緩存
NoOpMemoryTrimmableRegistry.getInstance().registerMemoryTrimmable(new MemoryTrimmable() {
@Override
public void trim(MemoryTrimType trimType) {
final double suggestedTrimRatio = trimType.getSuggestedTrimRatio();
Logger.d("ImagePipeline", String.format("onCreate suggestedTrimRatio : %d", suggestedTrimRatio));
if (MemoryTrimType.OnCloseToDalvikHeapLimit.getSuggestedTrimRatio() == suggestedTrimRatio
|| MemoryTrimType.OnSystemLowMemoryWhileAppInBackground.getSuggestedTrimRatio() == suggestedTrimRatio
|| MemoryTrimType.OnSystemLowMemoryWhileAppInForeground.getSuggestedTrimRatio() == suggestedTrimRatio
) {
ImagePipelineFactory.getInstance().getImagePipeline().clearMemoryCaches();
}
}
});
return configBuilder.build();
}