public void init( Resources resources, DeferredReleaser deferredReleaser, DrawableFactory animatedDrawableFactory, Executor uiThreadExecutor, MemoryCache<CacheKey, CloseableImage> memoryCache, @Nullable ImmutableList<DrawableFactory> drawableFactories, @Nullable Supplier<Boolean> debugOverlayEnabledSupplier) { mResources = resources; mDeferredReleaser = deferredReleaser; mAnimatedDrawableFactory = animatedDrawableFactory; mUiThreadExecutor = uiThreadExecutor; mMemoryCache = memoryCache; mDrawableFactories = drawableFactories; mDebugOverlayEnabledSupplier = debugOverlayEnabledSupplier; }
public PipelineDraweeController newController( Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier, String id, CacheKey cacheKey, Object callerContext, @Nullable ImmutableList<DrawableFactory> customDrawableFactories) { Preconditions.checkState(mResources != null, "init() not called"); // Field values passed as arguments so that any subclass of PipelineDraweeControllerFactory // can simply override internalCreateController() and return a custom Drawee controller PipelineDraweeController controller = internalCreateController( mResources, mDeferredReleaser, mAnimatedDrawableFactory, mUiThreadExecutor, mMemoryCache, mDrawableFactories, customDrawableFactories, dataSourceSupplier, id, cacheKey, callerContext); if (mDebugOverlayEnabledSupplier != null) { controller.setDrawDebugOverlay(mDebugOverlayEnabledSupplier.get()); } return controller; }
protected PipelineDraweeController internalCreateController( Resources resources, DeferredReleaser deferredReleaser, DrawableFactory animatedDrawableFactory, Executor uiThreadExecutor, MemoryCache<CacheKey, CloseableImage> memoryCache, @Nullable ImmutableList<DrawableFactory> globalDrawableFactories, @Nullable ImmutableList<DrawableFactory> customDrawableFactories, Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier, String id, CacheKey cacheKey, Object callerContext) { PipelineDraweeController controller = new PipelineDraweeController( resources, deferredReleaser, animatedDrawableFactory, uiThreadExecutor, memoryCache, dataSourceSupplier, id, cacheKey, callerContext, globalDrawableFactories); controller.setCustomDrawableFactories(customDrawableFactories); return controller; }
public PipelineDraweeController( Resources resources, DeferredReleaser deferredReleaser, DrawableFactory animatedDrawableFactory, Executor uiThreadExecutor, MemoryCache<CacheKey, CloseableImage> memoryCache, Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier, String id, CacheKey cacheKey, Object callerContext) { this( resources, deferredReleaser, animatedDrawableFactory, uiThreadExecutor, memoryCache, dataSourceSupplier, id, cacheKey, callerContext, null); }
public PipelineDraweeController( Resources resources, DeferredReleaser deferredReleaser, DrawableFactory animatedDrawableFactory, Executor uiThreadExecutor, MemoryCache<CacheKey, CloseableImage> memoryCache, Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier, String id, CacheKey cacheKey, Object callerContext, @Nullable ImmutableList<DrawableFactory> globalDrawableFactories) { super(deferredReleaser, uiThreadExecutor, id, callerContext); mResources = resources; mAnimatedDrawableFactory = animatedDrawableFactory; mMemoryCache = memoryCache; mCacheKey = cacheKey; mGlobalDrawableFactories = globalDrawableFactories; init(dataSourceSupplier); }
public ExperimentalBitmapAnimationDrawableFactory( AnimatedDrawableBackendProvider animatedDrawableBackendProvider, ScheduledExecutorService scheduledExecutorServiceForUiThread, ExecutorService executorServiceForFramePreparing, MonotonicClock monotonicClock, PlatformBitmapFactory platformBitmapFactory, CountingMemoryCache<CacheKey, CloseableImage> backingCache, Supplier<Integer> cachingStrategySupplier, Supplier<Integer> numberOfFramesToPrepareSupplier) { mAnimatedDrawableBackendProvider = animatedDrawableBackendProvider; mScheduledExecutorServiceForUiThread = scheduledExecutorServiceForUiThread; mExecutorServiceForFramePreparing = executorServiceForFramePreparing; mMonotonicClock = monotonicClock; mPlatformBitmapFactory = platformBitmapFactory; mBackingCache = backingCache; mCachingStrategySupplier = cachingStrategySupplier; mNumberOfFramesToPrepareSupplier = numberOfFramesToPrepareSupplier; }
public void setUp() { mSrc1 = mock(DataSource.class); mSrc2 = mock(DataSource.class); mSrc3 = mock(DataSource.class); mDataSourceSupplier1 = mock(Supplier.class); mDataSourceSupplier2 = mock(Supplier.class); mDataSourceSupplier3 = mock(Supplier.class); when(mDataSourceSupplier1.get()).thenReturn(mSrc1); when(mDataSourceSupplier2.get()).thenReturn(mSrc2); when(mDataSourceSupplier3.get()).thenReturn(mSrc3); mDataSubscriber = mock(DataSubscriber.class); mExecutor = CallerThreadExecutor.getInstance(); mInOrder = inOrder( mSrc1, mSrc2, mSrc3, mDataSourceSupplier1, mDataSourceSupplier2, mDataSourceSupplier3, mDataSubscriber); mSuppliers = Arrays.asList( mDataSourceSupplier1, mDataSourceSupplier2, mDataSourceSupplier3); }
public CountingMemoryCache( ValueDescriptor<V> valueDescriptor, CacheTrimStrategy cacheTrimStrategy, Supplier<MemoryCacheParams> memoryCacheParamsSupplier, PlatformBitmapFactory platformBitmapFactory, boolean isExternalCreatedBitmapLogEnabled) { mValueDescriptor = valueDescriptor; mExclusiveEntries = new CountingLruMap<>(wrapValueDescriptor(valueDescriptor)); mCachedEntries = new CountingLruMap<>(wrapValueDescriptor(valueDescriptor)); mCacheTrimStrategy = cacheTrimStrategy; mMemoryCacheParamsSupplier = memoryCacheParamsSupplier; mMemoryCacheParams = mMemoryCacheParamsSupplier.get(); mLastCacheParamsCheck = SystemClock.uptimeMillis(); if (isExternalCreatedBitmapLogEnabled) { platformBitmapFactory.setCreationListener( new PlatformBitmapFactory.BitmapCreationObserver() { @Override public void onBitmapCreated( Bitmap bitmap, Object callerContext) { mOtherEntries.put(bitmap, callerContext); } }); } }
public DecodeProducer( final ByteArrayPool byteArrayPool, final Executor executor, final ImageDecoder imageDecoder, final ProgressiveJpegConfig progressiveJpegConfig, final boolean downsampleEnabled, final boolean downsampleEnabledForNetwork, final boolean decodeCancellationEnabled, final Producer<EncodedImage> inputProducer, final Supplier<Boolean> experimentalSmartResizingEnabled) { mByteArrayPool = Preconditions.checkNotNull(byteArrayPool); mExecutor = Preconditions.checkNotNull(executor); mImageDecoder = Preconditions.checkNotNull(imageDecoder); mProgressiveJpegConfig = Preconditions.checkNotNull(progressiveJpegConfig); mDownsampleEnabled = downsampleEnabled; mDownsampleEnabledForNetwork = downsampleEnabledForNetwork; mInputProducer = Preconditions.checkNotNull(inputProducer); mDecodeCancellationEnabled = decodeCancellationEnabled; mExperimentalSmartResizingEnabled = experimentalSmartResizingEnabled; }
ProducerFactory createProducerFactory( Context context, ByteArrayPool byteArrayPool, ImageDecoder imageDecoder, ProgressiveJpegConfig progressiveJpegConfig, boolean downsampleEnabled, boolean resizeAndRotateEnabledForNetwork, boolean decodeCancellationEnabled, Supplier<Boolean> experimentalSmartResizingEnabled, ExecutorSupplier executorSupplier, PooledByteBufferFactory pooledByteBufferFactory, MemoryCache<CacheKey, CloseableImage> bitmapMemoryCache, MemoryCache<CacheKey, PooledByteBuffer> encodedMemoryCache, BufferedDiskCache defaultBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, MediaVariationsIndex mediaVariationsIndex, CacheKeyFactory cacheKeyFactory, PlatformBitmapFactory platformBitmapFactory, int bitmapPrepareToDrawMinSizeBytes, int bitmapPrepareToDrawMaxSizeBytes, boolean bitmapPrepareToDrawForPrefetch);
public ImagePipeline( ProducerSequenceFactory producerSequenceFactory, Set<RequestListener> requestListeners, Supplier<Boolean> isPrefetchEnabledSupplier, MemoryCache<CacheKey, CloseableImage> bitmapMemoryCache, MemoryCache<CacheKey, PooledByteBuffer> encodedMemoryCache, BufferedDiskCache mainBufferedDiskCache, BufferedDiskCache smallImageBufferedDiskCache, CacheKeyFactory cacheKeyFactory, ThreadHandoffProducerQueue threadHandoffProducerQueue, Supplier<Boolean> suppressBitmapPrefetchingSupplier) { mIdCounter = new AtomicLong(); mProducerSequenceFactory = producerSequenceFactory; mRequestListener = new ForwardingRequestListener(requestListeners); mIsPrefetchEnabledSupplier = isPrefetchEnabledSupplier; mBitmapMemoryCache = bitmapMemoryCache; mEncodedMemoryCache = encodedMemoryCache; mMainBufferedDiskCache = mainBufferedDiskCache; mSmallImageBufferedDiskCache = smallImageBufferedDiskCache; mCacheKeyFactory = cacheKeyFactory; mThreadHandoffProducerQueue = threadHandoffProducerQueue; mSuppressBitmapPrefetchingSupplier = suppressBitmapPrefetchingSupplier; }
/** * Returns a DataSource supplier that will on get submit the request for execution and return a * DataSource representing the pending results of the task. * * @param imageRequest the request to submit (what to execute). * @param callerContext the caller context of the caller of data source supplier * @param requestLevel which level to look down until for the image * @return a DataSource representing pending results and completion of the request */ public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier( final ImageRequest imageRequest, final Object callerContext, final ImageRequest.RequestLevel requestLevel) { return new Supplier<DataSource<CloseableReference<CloseableImage>>>() { @Override public DataSource<CloseableReference<CloseableImage>> get() { return fetchDecodedImage(imageRequest, callerContext, requestLevel); } @Override public String toString() { return Objects.toStringHelper(this) .add("uri", imageRequest.getSourceUri()) .toString(); } }; }
/** * Returns a DataSource supplier that will on get submit the request for execution and return a * DataSource representing the pending results of the task. * * @param imageRequest the request to submit (what to execute). * @return a DataSource representing pending results and completion of the request */ public Supplier<DataSource<CloseableReference<PooledByteBuffer>>> getEncodedImageDataSourceSupplier( final ImageRequest imageRequest, final Object callerContext) { return new Supplier<DataSource<CloseableReference<PooledByteBuffer>>>() { @Override public DataSource<CloseableReference<PooledByteBuffer>> get() { return fetchEncodedImage(imageRequest, callerContext); } @Override public String toString() { return Objects.toStringHelper(this) .add("uri", imageRequest.getSourceUri()) .toString(); } }; }
@Test public void testGetBitmapCacheGetSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline.getDataSourceSupplier( mImageRequest, mCallerContext, ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); dataSourceSupplier.get(); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
@Test public void testGetFullFetchSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline .getDataSourceSupplier(mImageRequest, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH); Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = dataSourceSupplier.get(); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
protected Supplier<DataSource<IMAGE>> getFirstAvailableDataSourceSupplier( REQUEST[] imageRequests, boolean tryBitmapCacheOnlyFirst) { List<Supplier<DataSource<IMAGE>>> suppliers = new ArrayList<>(imageRequests.length * 2); if (tryBitmapCacheOnlyFirst) { // we first add bitmap-cache-only suppliers, then the full-fetch ones for (int i = 0; i < imageRequests.length; i++) { suppliers.add( getDataSourceSupplierForRequest(imageRequests[i], CacheLevel.BITMAP_MEMORY_CACHE)); } } for (int i = 0; i < imageRequests.length; i++) { suppliers.add(getDataSourceSupplierForRequest(imageRequests[i])); } return FirstAvailableDataSourceSupplier.create(suppliers); }
/** Creates a data source supplier for the given image request. */ protected Supplier<DataSource<IMAGE>> getDataSourceSupplierForRequest( final REQUEST imageRequest, final CacheLevel cacheLevel) { final Object callerContext = getCallerContext(); return new Supplier<DataSource<IMAGE>>() { @Override public DataSource<IMAGE> get() { return getDataSourceForRequest(imageRequest, callerContext, cacheLevel); } @Override public String toString() { return Objects.toStringHelper(this) .add("request", imageRequest.toString()) .toString(); } }; }
@Before public void setUp() { mDeferredReleaser = mock(DeferredReleaser.class); mCallerContext = mock(Object.class); mDataSourceSupplier = mock(Supplier.class); mDraweeHierarchy = mock(SettableDraweeHierarchy.class); mUiThreadExecutor = CallerThreadExecutor.getInstance(); mController = new FakeDraweeController( mDeferredReleaser, mUiThreadExecutor, mDataSourceSupplier, "id", mCallerContext); doAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { ((DeferredReleaser.Releasable) invocation.getArguments()[0]).release(); return null; } }).when(mDeferredReleaser).scheduleDeferredRelease(any(DeferredReleaser.Releasable.class)); when(mDataSourceSupplier.get()).thenReturn(SimpleDataSource.<FakeImage>create()); }
@Test public void testMockProviderOf() { Object obj = mock(Object.class); Supplier<Object> provider = DraweeMocks.supplierOf(obj); assertEquals(obj, provider.get()); assertEquals(obj, provider.get()); assertEquals(obj, provider.get()); assertEquals(obj, provider.get()); assertEquals(obj, provider.get()); Object obj1 = mock(Object.class); Object obj2 = mock(Object.class); Object obj3 = mock(Object.class); Supplier<Object> multiProvider = DraweeMocks.supplierOf(obj1, obj2, obj3); assertEquals(obj1, multiProvider.get()); assertEquals(obj2, multiProvider.get()); assertEquals(obj3, multiProvider.get()); assertEquals(obj3, multiProvider.get()); assertEquals(obj3, multiProvider.get()); }
/** * Configures disk and memory cache not to exceed common limits */ private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE); // Max cache entry size configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(getExternalCacheDir(context)) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(MAX_DISK_CACHE_SIZE) .build()); }
/** * Configures disk and memory cache not to exceed common limits */ private static void configureCaches( ImagePipelineConfig.Builder configBuilder, Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE); // Max cache entry size configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(context.getApplicationContext().getCacheDir()) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(MAX_DISK_CACHE_SIZE) .build()); }
private void FrescoInit() { DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this) .setMaxCacheSize(40 * ByteConstants.MB) .setBaseDirectoryPathSupplier(new Supplier<File>() { @Override public File get() { return getCacheDir(); } }) .build(); final FrescoCacheParams bitmapCacheParams = new FrescoCacheParams(activityManager); //Set<RequestListener> listeners = new HashSet<>(); ImagePipelineConfig imagePipelineConfig = OkHttpImagePipelineConfigFactory.newBuilder(this, RetrofitClient.getInstance().getOkHttpClient()) .setMainDiskCacheConfig(diskCacheConfig) .setBitmapMemoryCacheParamsSupplier(bitmapCacheParams) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, imagePipelineConfig); }
/** * 初始化操作,建议在子线程中进行 * 添加的依赖: * compile 'com.facebook.fresco:fresco:0.10.0+' compile 'com.facebook.fresco:animated-webp:0.10.0' compile 'com.facebook.fresco:animated-gif:0.10.0' * @param context * @param cacheSizeInM 磁盘缓存的大小,以M为单位 */ public static void init(final Context context,int cacheSizeInM){ DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(context) .setMaxCacheSize(cacheSizeInM*1024*1024) .setBaseDirectoryName(PHOTO_FRESCO) .setBaseDirectoryPathSupplier(new Supplier<File>() { @Override public File get() { return context.getCacheDir(); } }) .build(); MyImageCacheStatsTracker imageCacheStatsTracker = new MyImageCacheStatsTracker(); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(context) .setMainDiskCacheConfig(diskCacheConfig) .setImageCacheStatsTracker(imageCacheStatsTracker) .setDownsampleEnabled(true)//Downsampling,它处理图片的速度比常规的裁剪更快, // 并且同时支持PNG,JPG以及WEP格式的图片,非常强大,与ResizeOptions配合使用 .setBitmapsConfig(Bitmap.Config.RGB_565) .build(); Fresco.initialize(context, config); }
public void setSupplier(@Nullable Supplier<DataSource<T>> supplier) { // early return without calling {@code supplier.get()} in case we are closed if (isClosed()) { return; } DataSource<T> oldDataSource; DataSource<T> newDataSource = (supplier != null) ? supplier.get() : null; synchronized (RetainingDataSource.this) { if (isClosed()) { oldDataSource = newDataSource; newDataSource = null; } else { oldDataSource = mDataSource; mDataSource = newDataSource; } } if (newDataSource != null) { newDataSource.subscribe(new InternalDataSubscriber(), CallerThreadExecutor.getInstance()); } closeSafely(oldDataSource); }
private ImagePipelineConfig getConfigureCaches(Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( MAX_MEM,// 内存缓存中总图片的最大大小,以字节为单位。 Integer.MAX_VALUE,// 内存缓存中图片的最大数量。 MAX_MEM,// 内存缓存中准备清除但尚未被删除的总图片的最大大小,以字节为单位。 Integer.MAX_VALUE,// 内存缓存中准备清除的总图片的最大数量。 Integer.MAX_VALUE / 10);// 内存缓存中单个图片的最大大小。 Supplier<MemoryCacheParams> mSupplierMemoryCacheParams = new Supplier<MemoryCacheParams>() { @Override public MemoryCacheParams get() { return bitmapCacheParams; } }; ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context) .setDownsampleEnabled(true); builder.setBitmapMemoryCacheParamsSupplier(mSupplierMemoryCacheParams); return builder.build(); }
public static ImagePipelineConfig getImagePipelineConfig(Context context) { if (sImagePipelineConfig == null) { sImagePipelineConfig = ImagePipelineConfig.newBuilder(context) .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(context) .setMaxCacheSize(ConfigConstants.MAX_CACHE_DISK_SIZE) .build()) .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { @Override public MemoryCacheParams get() { return new MemoryCacheParams(ConfigConstants.MAX_CACHE_MEMORY_SIZE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); } } ) .build(); } return sImagePipelineConfig; }
/** * Configures disk and memory cache not to exceed common limits */ private static void configureCaches( ImagePipelineConfig.Builder configBuilder, Context context) { FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR); final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache ConfigConstants.MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE); // Max cache entry size configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(context) .setBaseDirectoryPath(FileUtils.createDirs(ConfigConstants.IMAGE_PIPELINE_BASE_DIR)) .setBaseDirectoryName(ConfigConstants.IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(ConfigConstants.MAX_DISK_CACHE_SIZE) .build()); }
private void initFrescoConfig() { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams(MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE); ImagePipelineConfig config = OkHttpImagePipelineConfigFactory.newBuilder(this, mOkHttpClient) .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig()) .setBitmapMemoryCacheParamsSupplier(new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig( DiskCacheConfig.newBuilder(this).setMaxCacheSize(MAX_DISK_CACHE_SIZE).build()) .setDownsampleEnabled(true) .build(); Fresco.initialize(this, config); }
/** * Configures disk and memory cache not to exceed common limits */ private static void configureCaches(ImagePipelineConfig.Builder configBuilder, Context context) { final MemoryCacheParams bitmapCacheParams = new MemoryCacheParams( MAX_MEMORY_CACHE_SIZE, // Max total size of elements in the cache Integer.MAX_VALUE, // Max entries in the cache MAX_MEMORY_CACHE_SIZE, // Max total size of elements in eviction queue Integer.MAX_VALUE, // Max length of eviction queue Integer.MAX_VALUE); // Max cache entry size configBuilder .setBitmapMemoryCacheParamsSupplier( new Supplier<MemoryCacheParams>() { public MemoryCacheParams get() { return bitmapCacheParams; } }) .setMainDiskCacheConfig(DiskCacheConfig.newBuilder() .setBaseDirectoryPath(getExternalCacheDir(context)) .setBaseDirectoryName(IMAGE_PIPELINE_CACHE_DIR) .setMaxCacheSize(MAX_DISK_CACHE_SIZE) .build()); }