com.facebook.imagepipeline.cache.DefaultBitmapMemoryCacheParamsSupplier Java Examples
The following examples show how to use
com.facebook.imagepipeline.cache.DefaultBitmapMemoryCacheParamsSupplier.
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: MainReactPackageWithFrescoCache.java From react-native-image-filter-kit with MIT License | 5 votes |
private Supplier<MemoryCacheParams> createCacheParamsSupplier( final ReactApplicationContext context ) { ActivityManager manager = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); final Supplier<MemoryCacheParams> cacheParamsSupplier = new DefaultBitmapMemoryCacheParamsSupplier(manager) { @Override public MemoryCacheParams get() { MemoryCacheParams params = super.get(); return new MemoryCacheParams( mMaxCacheSizeInBytes == null ? params.maxCacheSize : mMaxCacheSizeInBytes, mMaxCacheEntries == null ? params.maxCacheEntries : mMaxCacheEntries, params.maxEvictionQueueSize, params.maxEvictionQueueEntries, params.maxCacheEntrySize ); } }; String size = String.valueOf(cacheParamsSupplier.get().maxCacheSize / 1024 / 1024); String entries = String.valueOf(cacheParamsSupplier.get().maxCacheEntries); FLog.d( ReactConstants.TAG, "ImageFilterKit: Fresco cache size - " + entries + " entries, " + size + " MB overall" ); return cacheParamsSupplier; }
Example #2
Source File: FrescoManager.java From JianshuApp with GNU General Public License v3.0 | 5 votes |
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()); }
Example #3
Source File: ImagePipelineConfig.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
private ImagePipelineConfig(Builder builder) { mBitmapMemoryCacheParamsSupplier = builder.mBitmapMemoryCacheParamsSupplier == null ? new DefaultBitmapMemoryCacheParamsSupplier( (ActivityManager) builder.mContext.getSystemService(Context.ACTIVITY_SERVICE)) : builder.mBitmapMemoryCacheParamsSupplier; mCacheKeyFactory = builder.mCacheKeyFactory == null ? DefaultCacheKeyFactory.getInstance() : builder.mCacheKeyFactory; mContext = Preconditions.checkNotNull(builder.mContext); mEncodedMemoryCacheParamsSupplier = builder.mEncodedMemoryCacheParamsSupplier == null ? new DefaultEncodedMemoryCacheParamsSupplier() : builder.mEncodedMemoryCacheParamsSupplier; mExecutorSupplier = builder.mExecutorSupplier == null ? new DefaultExecutorSupplier() : builder.mExecutorSupplier; mImageCacheStatsTracker = builder.mImageCacheStatsTracker == null ? NoOpImageCacheStatsTracker.getInstance() : builder.mImageCacheStatsTracker; mIsPrefetchEnabledSupplier = builder.mIsPrefetchEnabledSupplier == null ? new Supplier<Boolean>() { @Override public Boolean get() { return true; } } : builder.mIsPrefetchEnabledSupplier; mMainDiskCacheConfig = builder.mMainDiskCacheConfig == null ? getDefaultMainDiskCacheConfig(builder.mContext) : builder.mMainDiskCacheConfig; mMemoryTrimmableRegistry = builder.mMemoryTrimmableRegistry == null ? NoOpMemoryTrimmableRegistry.getInstance() : builder.mMemoryTrimmableRegistry; mPoolFactory = builder.mPoolFactory == null ? new PoolFactory(PoolConfig.newBuilder().build()) : builder.mPoolFactory; mProgressiveJpegConfig = builder.mProgressiveJpegConfig == null ? getDefaultProgressiveJpegConfig() : builder.mProgressiveJpegConfig; mRequestListeners = builder.mRequestListeners == null ? new HashSet<RequestListener>() : builder.mRequestListeners; mResizeAndRotateEnabledForNetwork = builder.mResizeAndRotateEnabledForNetwork; mSmallImageDiskCacheConfig = builder.mSmallImageDiskCacheConfig == null ? mMainDiskCacheConfig : builder.mSmallImageDiskCacheConfig; mAnimatedDrawableUtil = new AnimatedDrawableUtil(); AnimatedDrawableBackendProvider animatedDrawableBackendProvider = new AnimatedDrawableBackendProvider() { @Override public AnimatedDrawableBackend get(AnimatedImageResult imageResult, Rect bounds) { return new AnimatedDrawableBackendImpl(mAnimatedDrawableUtil, imageResult, bounds); } }; mAnimatedImageFactory = builder.mAnimatedImageFactory == null ? new AnimatedImageFactory(animatedDrawableBackendProvider) : builder.mAnimatedImageFactory; GingerbreadBitmapFactory factoryGingerbread = new GingerbreadBitmapFactory(); DalvikBitmapFactory factoryICS = new DalvikBitmapFactory( new EmptyJpegGenerator(mPoolFactory.getPooledByteBufferFactory()), mPoolFactory.getSingleByteArrayPool()); ArtBitmapFactory factoryLollipop = new ArtBitmapFactory(mPoolFactory.getBitmapPool()); mPlatformBitmapFactory = new PlatformBitmapFactory( factoryGingerbread, factoryICS, factoryLollipop); mImageDecoder = builder.mImageDecoder == null ? new ImageDecoder(mAnimatedImageFactory, mPlatformBitmapFactory) : builder.mImageDecoder; mNetworkFetchProducer = builder.mNetworkFetchProducer == null ? new HttpURLConnectionNetworkFetchProducer( mPoolFactory.getPooledByteBufferFactory(), mPoolFactory.getCommonByteArrayPool()) : builder.mNetworkFetchProducer; }