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; }
/** * Get the default Fresco configuration builder. * Allows adding of configuration options in addition to the default values. * * @return {@link ImagePipelineConfig.Builder} that has been initialized with default values */ public static ImagePipelineConfig.Builder getDefaultConfigBuilder(ReactContext context) { HashSet<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new SystraceRequestListener()); OkHttpClient client = OkHttpClientProvider.createClient(); // make sure to forward cookies for any requests via the okHttpClient // so that image requests to endpoints that use cookies still work CookieJarContainer container = (CookieJarContainer) client.cookieJar(); ForwardingCookieHandler handler = new ForwardingCookieHandler(context); container.setCookieJar(new JavaNetCookieJar(handler)); return OkHttpImagePipelineConfigFactory .newBuilder(context.getApplicationContext(), client) .setNetworkFetcher(new ReactOkHttpNetworkFetcher(client)) .setDownsampleEnabled(false) .setRequestListeners(requestListeners); }
private static ImagePipelineConfig getDefaultConfig( Context context, @Nullable RequestListener listener, @Nullable DiskCacheConfig diskCacheConfig) { HashSet<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new SystraceRequestListener()); if (listener != null) { requestListeners.add(listener); } OkHttpClient okHttpClient = OkHttpClientProvider.getOkHttpClient(); ImagePipelineConfig.Builder builder = OkHttpImagePipelineConfigFactory.newBuilder(context.getApplicationContext(), okHttpClient); builder .setDownsampleEnabled(false) .setRequestListeners(requestListeners); if (diskCacheConfig != null) { builder.setMainDiskCacheConfig(diskCacheConfig); } return builder.build(); }
public static <T> DataSource<CloseableReference<T>> create( Producer<CloseableReference<T>> producer, SettableProducerContext settableProducerContext, RequestListener listener) { return new CloseableProducerToDataSourceAdapter<T>( producer, settableProducerContext, listener); }
protected AbstractProducerToDataSourceAdapter( Producer<T> producer, SettableProducerContext settableProducerContext, RequestListener requestListener) { mSettableProducerContext = settableProducerContext; mRequestListener = requestListener; mRequestListener.onRequestStart( settableProducerContext.getImageRequest(), mSettableProducerContext.getCallerContext(), mSettableProducerContext.getId(), mSettableProducerContext.isPrefetch()); producer.produceResults(createConsumer(), settableProducerContext); }
public static <T> DataSource<T> create( Producer<T> producer, SettableProducerContext settableProducerContext, RequestListener listener) { return new ProducerToDataSourceAdapter<T>( producer, settableProducerContext, listener); }
private <T> DataSource<CloseableReference<T>> submitFetchRequest( Producer<CloseableReference<T>> producerSequence, ImageRequest imageRequest, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, Object callerContext) { final RequestListener requestListener = getRequestListenerForRequest(imageRequest); try { ImageRequest.RequestLevel lowestPermittedRequestLevel = ImageRequest.RequestLevel.getMax( imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit); SettableProducerContext settableProducerContext = new SettableProducerContext( imageRequest, generateUniqueFutureId(), requestListener, callerContext, lowestPermittedRequestLevel, /* isPrefetch */ false, imageRequest.getProgressiveRenderingEnabled() || imageRequest.getMediaVariations() != null || !UriUtil.isNetworkUri(imageRequest.getSourceUri()), imageRequest.getPriority()); return CloseableProducerToDataSourceAdapter.create( producerSequence, settableProducerContext, requestListener); } catch (Exception exception) { return DataSources.immediateFailedDataSource(exception); } }
private DataSource<Void> submitPrefetchRequest( Producer<Void> producerSequence, ImageRequest imageRequest, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, Object callerContext, Priority priority) { final RequestListener requestListener = getRequestListenerForRequest(imageRequest); try { ImageRequest.RequestLevel lowestPermittedRequestLevel = ImageRequest.RequestLevel.getMax( imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit); SettableProducerContext settableProducerContext = new SettableProducerContext( imageRequest, generateUniqueFutureId(), requestListener, callerContext, lowestPermittedRequestLevel, /* isPrefetch */ true, /* isIntermediateResultExpected */ false, priority); return ProducerToDataSourceAdapter.create( producerSequence, settableProducerContext, requestListener); } catch (Exception exception) { return DataSources.immediateFailedDataSource(exception); } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); mRequestListener1 = mock(RequestListener.class); mRequestListener2 = mock(RequestListener.class); mRequestListener3 = mock(RequestListener.class); when(mRequestListener1.requiresExtraMap(mRequestId)).thenReturn(false); when(mRequestListener2.requiresExtraMap(mRequestId)).thenReturn(false); when(mRequestListener3.requiresExtraMap(mRequestId)).thenReturn(false); mListenerManager = new ForwardingRequestListener( Sets.newHashSet(mRequestListener1, mRequestListener2, mRequestListener3)); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); mPrefetchEnabledSupplier = mock(Supplier.class); mSuppressBitmapPrefetchingSupplier = mock(Supplier.class); when(mPrefetchEnabledSupplier.get()).thenReturn(true); when(mSuppressBitmapPrefetchingSupplier.get()).thenReturn(false); mRequestListener1 = mock(RequestListener.class); mRequestListener2 = mock(RequestListener.class); mBitmapMemoryCache = mock(MemoryCache.class); mEncodedMemoryCache = mock(MemoryCache.class); mMainDiskStorageCache = mock(BufferedDiskCache.class); mSmallImageDiskStorageCache = mock(BufferedDiskCache.class); mThreadHandoffProducerQueue= mock(ThreadHandoffProducerQueue.class); mImagePipeline = new ImagePipeline( mProducerSequenceFactory, Sets.newHashSet(mRequestListener1, mRequestListener2), mPrefetchEnabledSupplier, mBitmapMemoryCache, mEncodedMemoryCache, mMainDiskStorageCache, mSmallImageDiskStorageCache, mCacheKeyFactory, mThreadHandoffProducerQueue, mSuppressBitmapPrefetchingSupplier); when(mImageRequest.getProgressiveRenderingEnabled()).thenReturn(true); when(mImageRequest.getPriority()).thenReturn(Priority.HIGH); when(mImageRequest.getLowestPermittedRequestLevel()) .thenReturn(ImageRequest.RequestLevel.FULL_FETCH); }
@Test public void testLocalRequestListenerIsCalled() { RequestListener localRequestListner = mock(RequestListener.class); when(mImageRequest.getRequestListener()).thenReturn(localRequestListner); Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); mImagePipeline.fetchImageFromBitmapCache(mImageRequest, mCallerContext); verify(localRequestListner).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); }
@Override public void onCreate() { super.onCreate(); FLog.setMinimumLoggingLevel(FLog.VERBOSE); Set<RequestListener> listeners = new HashSet<>(); listeners.add(new RequestLoggingListener()); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setRequestListeners(listeners) .build(); Fresco.initialize(this, config); }
@Override public void onCreate() { super.onCreate(); Set<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new RequestLoggingListener()); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) // other setters .setRequestListeners(requestListeners) .build(); Fresco.initialize(this, config); FLog.setMinimumLoggingLevel(FLog.VERBOSE); }
private static ImagePipelineConfig getDefaultConfig(Context context) { HashSet<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new SystraceRequestListener()); return OkHttpImagePipelineConfigFactory .newBuilder(context.getApplicationContext(), OkHttpClientProvider.getOkHttpClient()) .setDownsampleEnabled(false) .setRequestListeners(requestListeners) .build(); }
private void initialize() { mApplication = this; mContext = this.getApplicationContext(); mResources = this.getResources(); Builder builder = Logcat.newBuilder(); builder.logCatLogLevel(Logcat.SHOW_VERBOSE_LOG); // builder.logCatLogLevel(Logcat.NOT_SHOW_LOG); // Logcat.initialize(this, builder.build()); Logcat.initialize(this); if (IS_DEBUG_ACTIVITYLIFE) { mActivityLifecycle = new MyActivityLifecycle(); this.registerActivityLifecycleCallbacks(mActivityLifecycle); } // Set<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new RequestLoggingListener()); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) // other setters .setRequestListeners(requestListeners) //配置图片磁盘缓存 .setMainDiskCacheConfig(DiskCacheConfig.newBuilder(this) .setBaseDirectoryName("image") //父目录下的文件夹名 .setBaseDirectoryPath(StorageUtils.getAppCacheFile(this)) //保存父目录 .build()) .build(); Fresco.initialize(this, config); FLog.setMinimumLoggingLevel(FLog.DEBUG); try { CrashHandler crashHandler = CrashHandler.getInstance(); crashHandler.init(this, Config.CARSH_LOG_PATH); } catch (Exception e) { e.printStackTrace(); } }
/** * 初始化fresco */ private void initFresco() { Set<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new RequestLoggingListener()); ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this) .setBitmapsConfig(Bitmap.Config.ARGB_8888) .setDownsampleEnabled(true) .setNetworkFetcher(new OkHttpNetworkFetcher(new OkHttpClient())) .setRequestListeners(requestListeners) .build(); Fresco.initialize(this, config); }
private void initFresco() { final ImagePipelineConfig.Builder configBuilder = ImagePipelineConfig.newBuilder(this); File cacheDir = getExternalCacheDir(); if (cacheDir == null) { cacheDir = getCacheDir(); } final DiskCacheConfig.Builder mainDiskCacheConfigBuilder = DiskCacheConfig.newBuilder(this); mainDiskCacheConfigBuilder.setBaseDirectoryName("image_cache"); mainDiskCacheConfigBuilder.setBaseDirectoryPath(cacheDir); mainDiskCacheConfigBuilder.setMaxCacheSize(100 * 1024 * 1024); mainDiskCacheConfigBuilder.setVersion(1); configBuilder.setMainDiskCacheConfig(mainDiskCacheConfigBuilder.build()); final ImagePipelineConfig.Builder config = ImagePipelineConfig.newBuilder(this); if (BuildConfig.DEBUG) { final Set<RequestListener> requestListeners = new HashSet<>(); requestListeners.add(new RequestLoggingListener()); config.setRequestListeners(requestListeners); FLog.setMinimumLoggingLevel(FLog.VERBOSE); } configBuilder.setMemoryTrimmableRegistry(frescoMemoryTrimmableRegistry); Fresco.initialize(this, config.build()); }
private CloseableProducerToDataSourceAdapter( Producer<CloseableReference<T>> producer, SettableProducerContext settableProducerContext, RequestListener listener) { super(producer, settableProducerContext, listener); }
private ProducerToDataSourceAdapter( Producer<T> producer, SettableProducerContext settableProducerContext, RequestListener listener) { super(producer, settableProducerContext, listener); }
/** * @return the additional request listener to use for this image request */ public @Nullable RequestListener getRequestListener() { return mRequestListener; }
public @Nullable RequestListener getRequestListener() { return mRequestListener; }
public Set<RequestListener> getRequestListeners() { return Collections.unmodifiableSet(mRequestListeners); }
public Builder setRequestListeners(Set<RequestListener> requestListeners) { mRequestListeners = requestListeners; return this; }
private RequestListener getRequestListenerForRequest(ImageRequest imageRequest) { if (imageRequest.getRequestListener() == null) { return mRequestListener; } return new ForwardingRequestListener(mRequestListener, imageRequest.getRequestListener()); }