com.facebook.imagepipeline.listener.RequestListener Java Examples

The following examples show how to use com.facebook.imagepipeline.listener.RequestListener. 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: FrescoHelper.java    From base-module with Apache License 2.0 6 votes vote down vote up
public void init(Context context, ImagePipelineConfig config) {
    if(config == null) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

        ImagePipelineConfig.Builder builder = ImagePipelineConfig.newBuilder(context)
                .setResizeAndRotateEnabledForNetwork(true)
                .setBitmapsConfig(Bitmap.Config.ARGB_8888)
                .setBitmapMemoryCacheParamsSupplier(new MyBitmapMemoryCacheParamsSupplier(activityManager))
                .setDownsampleEnabled(true);

        if (isVLoggable || isDLoggable) {
            Set<RequestListener> requestListeners = new HashSet<>();
            requestListeners.add(new RequestLoggingListener());
            builder.setRequestListeners(requestListeners);
            int level = isVLoggable ? FLog.VERBOSE : FLog.DEBUG;
            FLog.setMinimumLoggingLevel(level);
        }

        config = builder.build();
    }

    context.getApplicationContext().registerComponentCallbacks(this);
    Fresco.initialize(context, config);
}
 
Example #2
Source File: FrescoModule.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 6 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final ImageRequest.RequestLevel requestLevel,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return getImageRequestDataSource(
          imagePipeline, imageRequest, callerContext, requestListener, uiComponentId);
    }
  };
}
 
Example #4
Source File: VitoImagePipelineImpl.java    From fresco with MIT License 6 votes vote down vote up
@Override
public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
    final VitoImageRequest imageRequest,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final long uiComponentId) {
  if (!(imageRequest.imageSource instanceof VitoImageSource)) {
    return DataSources.immediateFailedDataSource(
        new IllegalArgumentException("Unknown ImageSource " + imageRequest.imageSource));
  }
  VitoImageSource vitoImageSource = (VitoImageSource) imageRequest.imageSource;
  final String stringId = VitoUtils.getStringId(uiComponentId);
  return vitoImageSource
      .createDataSourceSupplier(
          mImagePipeline,
          mImagePipelineUtils,
          imageRequest.imageOptions,
          callerContext,
          requestListener,
          stringId)
      .get();
}
 
Example #5
Source File: FrescoControllerImplTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testListenersPrepPipelineComponents() {
  SettableProducerContext settableProducerContext = mock(SettableProducerContext.class);
  Producer producerSequence = mock(Producer.class);

  when(mFrescoState.getProducerSequence()).thenReturn(producerSequence);
  when(mFrescoState.getSettableProducerContext()).thenReturn(settableProducerContext);
  when(mFrescoContext.getExperiments())
      .thenReturn(
          new FrescoExperiments() {
            @Override
            public boolean prepareImagePipelineComponents() {
              return true;
            }
          });

  RequestListener requestListener = baseTestListeners();

  verify(mImagePipeline)
      .submitFetchRequest(eq(producerSequence), eq(settableProducerContext), eq(requestListener));
}
 
Example #6
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
public <T> DataSource<CloseableReference<T>> submitFetchRequest(
    Producer<CloseableReference<T>> producerSequence,
    SettableProducerContext settableProducerContext,
    RequestListener requestListener) {
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.beginSection("ImagePipeline#submitFetchRequest");
  }
  try {
    final RequestListener2 requestListener2 =
        new InternalRequestListener(requestListener, mRequestListener2);

    return CloseableProducerToDataSourceAdapter.create(
        producerSequence, settableProducerContext, requestListener2);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  } finally {
    if (FrescoSystrace.isTracing()) {
      FrescoSystrace.endSection();
    }
  }
}
 
Example #7
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Submits a request for execution and returns a DataSource representing the pending decoded
 * image(s).
 *
 * <p>The returned DataSource must be closed once the client has finished with it.
 *
 * @param imageRequest the request to submit
 * @param callerContext the caller context for image request
 * @param lowestPermittedRequestLevelOnSubmit the lowest request level permitted for image reques
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @param uiComponentId optional UI component ID that is requesting the image
 * @return a DataSource representing the pending decoded image(s)
 */
public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
    ImageRequest imageRequest,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
    @Nullable RequestListener requestListener,
    @Nullable String uiComponentId) {
  try {
    Producer<CloseableReference<CloseableImage>> producerSequence =
        mProducerSequenceFactory.getDecodedImageProducerSequence(imageRequest);
    return submitFetchRequest(
        producerSequence,
        imageRequest,
        lowestPermittedRequestLevelOnSubmit,
        callerContext,
        requestListener,
        uiComponentId);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example #8
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * 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
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @param uiComponentId optional UI component ID requesting 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,
    final @Nullable RequestListener requestListener,
    final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(
          imageRequest, callerContext, requestLevel, requestListener, uiComponentId);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example #9
Source File: ImagePipeline.java    From fresco with MIT License 6 votes vote down vote up
/**
 * 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
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @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,
    final @Nullable RequestListener requestListener) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(imageRequest, callerContext, requestLevel, requestListener);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example #10
Source File: InitFrescoTask.java    From android-performance with MIT License 5 votes vote down vote up
@Override
public void run() {
    Set<RequestListener> listenerset = new HashSet<>();
    listenerset.add(new FrescoTraceListener());
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(mContext).setRequestListeners(listenerset)
            .build();
    Fresco.initialize(mContext,config);
}
 
Example #11
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Submits a request for execution and returns a DataSource representing the pending encoded
 * image(s).
 *
 * <p>The ResizeOptions in the imageRequest will be ignored for this fetch
 *
 * <p>The returned DataSource must be closed once the client has finished with it.
 *
 * @param imageRequest the request to submit
 * @return a DataSource representing the pending encoded image(s)
 */
public DataSource<CloseableReference<PooledByteBuffer>> fetchEncodedImage(
    ImageRequest imageRequest, Object callerContext, @Nullable RequestListener requestListener) {
  Preconditions.checkNotNull(imageRequest.getSourceUri());
  try {
    Producer<CloseableReference<PooledByteBuffer>> producerSequence =
        mProducerSequenceFactory.getEncodedImageProducerSequence(imageRequest);
    // The resize options are used to determine whether images are going to be downsampled during
    // decode or not. For the case where the image has to be downsampled and it's a local image it
    // will be kept as a FileInputStream until decoding instead of reading it in memory. Since
    // this method returns an encoded image, it should always be read into memory. Therefore, the
    // resize options are ignored to avoid treating the image as if it was to be downsampled
    // during decode.
    if (imageRequest.getResizeOptions() != null) {
      imageRequest = ImageRequestBuilder.fromRequest(imageRequest).setResizeOptions(null).build();
    }
    return submitFetchRequest(
        producerSequence,
        imageRequest,
        ImageRequest.RequestLevel.FULL_FETCH,
        callerContext,
        requestListener,
        null);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example #12
Source File: AnimationApplication.java    From fresco with MIT License 5 votes vote down vote up
@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);
}
 
Example #13
Source File: ImagePipelineTest.java    From fresco with MIT License 5 votes vote down vote up
@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);
}
 
Example #14
Source File: ImagePipelineTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  mPrefetchEnabledSupplier = mock(Supplier.class);
  mSuppressBitmapPrefetchingSupplier = mock(Supplier.class);
  mLazyDataSourceSupplier = mock(Supplier.class);
  when(mPrefetchEnabledSupplier.get()).thenReturn(true);
  when(mSuppressBitmapPrefetchingSupplier.get()).thenReturn(false);
  when(mLazyDataSourceSupplier.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),
          Sets.newHashSet(mock(RequestListener2.class)),
          mPrefetchEnabledSupplier,
          mBitmapMemoryCache,
          mEncodedMemoryCache,
          mMainDiskStorageCache,
          mSmallImageDiskStorageCache,
          mCacheKeyFactory,
          mThreadHandoffProducerQueue,
          mSuppressBitmapPrefetchingSupplier,
          mLazyDataSourceSupplier,
          null,
          mConfig);

  when(mImageRequest.getProgressiveRenderingEnabled()).thenReturn(true);
  when(mImageRequest.getPriority()).thenReturn(Priority.HIGH);
  when(mImageRequest.getLowestPermittedRequestLevel())
      .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
  when(mImageRequest.shouldDecodePrefetches()).thenReturn(null);
}
 
Example #15
Source File: ForwardingRequestListenerTest.java    From fresco with MIT License 5 votes vote down vote up
@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));
}
 
Example #16
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
public ImagePipeline(
    ProducerSequenceFactory producerSequenceFactory,
    Set<RequestListener> requestListeners,
    Set<RequestListener2> requestListener2s,
    Supplier<Boolean> isPrefetchEnabledSupplier,
    MemoryCache<CacheKey, CloseableImage> bitmapMemoryCache,
    MemoryCache<CacheKey, PooledByteBuffer> encodedMemoryCache,
    BufferedDiskCache mainBufferedDiskCache,
    BufferedDiskCache smallImageBufferedDiskCache,
    CacheKeyFactory cacheKeyFactory,
    ThreadHandoffProducerQueue threadHandoffProducerQueue,
    Supplier<Boolean> suppressBitmapPrefetchingSupplier,
    Supplier<Boolean> lazyDataSource,
    @Nullable CallerContextVerifier callerContextVerifier,
    ImagePipelineConfig config) {
  mIdCounter = new AtomicLong();
  mProducerSequenceFactory = producerSequenceFactory;
  mRequestListener = new ForwardingRequestListener(requestListeners);
  mRequestListener2 = new ForwardingRequestListener2(requestListener2s);
  mIsPrefetchEnabledSupplier = isPrefetchEnabledSupplier;
  mBitmapMemoryCache = bitmapMemoryCache;
  mEncodedMemoryCache = encodedMemoryCache;
  mMainBufferedDiskCache = mainBufferedDiskCache;
  mSmallImageBufferedDiskCache = smallImageBufferedDiskCache;
  mCacheKeyFactory = cacheKeyFactory;
  mThreadHandoffProducerQueue = threadHandoffProducerQueue;
  mSuppressBitmapPrefetchingSupplier = suppressBitmapPrefetchingSupplier;
  mLazyDataSource = lazyDataSource;
  mCallerContextVerifier = callerContextVerifier;
  mConfig = config;
}
 
Example #17
Source File: FrescoControllerImplTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testListeners() {
  RequestListener requestListener = baseTestListeners();
  verify(mImagePipeline)
      .fetchDecodedImage(
          any(ImageRequest.class),
          any(Object.class),
          any(ImageRequest.RequestLevel.class),
          eq(requestListener),
          eq(IMAGE_ID_STRING));
}
 
Example #18
Source File: FrescoControllerImplTest.java    From fresco with MIT License 5 votes vote down vote up
private RequestListener baseTestListeners() {
  ImageOptions imageOptions = ImageOptions.create().build();
  RequestListener requestListener = mock(BaseRequestListener.class);

  when(mFrescoContext.getUiThreadExecutorService())
      .thenReturn(UiThreadImmediateExecutorService.getInstance());

  final Uri uri = Uri.parse("http://fresco");
  ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).build();
  when(mFrescoState.getImageRequest()).thenReturn(imageRequest);

  when(mFrescoState.getImageOptions()).thenReturn(imageOptions);
  when(mFrescoState.getRequestListener()).thenReturn(requestListener);

  when(mFrescoState.getUri()).thenReturn(uri);

  SimpleDataSource dataSource = SimpleDataSource.create();

  when(mImagePipeline.submitFetchRequest(
          any(Producer.class),
          any(com.facebook.imagepipeline.producers.SettableProducerContext.class),
          eq(requestListener)))
      .thenReturn(dataSource);
  when(mImagePipeline.fetchDecodedImage(
          any(ImageRequest.class),
          any(Object.class),
          any(ImageRequest.RequestLevel.class),
          eq(requestListener),
          eq(IMAGE_ID_STRING)))
      .thenReturn(dataSource);

  mFrescoController.onAttach(mFrescoState, null);

  verify(mFrescoContext, atLeast(1)).getImagePipeline();
  verify(mFrescoState, atLeast(1)).getCachedImage();
  verify(mFrescoState).onSubmit(eq(IMAGE_ID), eq(CALLER_CONTEXT));
  verify(mFrescoState, atLeast(1)).getImageRequest();
  return requestListener;
}
 
Example #19
Source File: FrescoControllerImplTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testPrepareImagePipelineComponents_whenValidRequest_thenPrepareComponents() {
  final String imageId = "ID 123";
  ImageRequest request = mock(ImageRequest.class);
  ProducerSequenceFactory producerSequenceFactory = mock(ProducerSequenceFactory.class);
  Producer<CloseableReference<CloseableImage>> producerSequence = mock(MockProducer.class);
  RequestListener requestListener = mock(RequestListener.class);
  ArgumentCaptor<SettableProducerContext> producerContextCaptor =
      ArgumentCaptor.forClass(SettableProducerContext.class);

  when(request.getLowestPermittedRequestLevel()).thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
  when(mImagePipeline.generateUniqueFutureId()).thenReturn(imageId);
  when(mImagePipeline.getProducerSequenceFactory()).thenReturn(producerSequenceFactory);
  when(mImagePipeline.getRequestListenerForRequest(eq(request), nullable(RequestListener.class)))
      .thenReturn(requestListener);
  when(producerSequenceFactory.getDecodedImageProducerSequence(eq(request)))
      .thenReturn(producerSequence);

  mFrescoController.prepareImagePipelineComponents(mFrescoState, request, CALLER_CONTEXT);

  verify(mFrescoState).setProducerSequence(eq(producerSequence));
  verify(mFrescoState).setRequestListener(eq(requestListener));
  verify(mFrescoState).setSettableProducerContext(producerContextCaptor.capture());

  SettableProducerContext producerContext = producerContextCaptor.getValue();
  assertThat(producerContext).isNotNull();
  assertThat(producerContext.getImageRequest()).isEqualTo(request);
  assertThat(producerContext.getId()).isEqualTo(imageId);
}
 
Example #20
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
public static DataSource<CloseableReference<CloseableImage>> getImageRequestDataSource(
    ImagePipeline imagePipeline,
    ImageRequest imageRequest,
    Object callerContext,
    @Nullable RequestListener requestListener,
    @Nullable String uiComponentId) {
  return imagePipeline.fetchDecodedImage(
      imageRequest,
      callerContext,
      ImageRequest.RequestLevel.FULL_FETCH,
      requestListener,
      uiComponentId);
}
 
Example #21
Source File: ImagePipeline.java    From fresco with MIT License 5 votes vote down vote up
public RequestListener getRequestListenerForRequest(
    ImageRequest imageRequest, @Nullable RequestListener requestListener) {
  if (requestListener == null) {
    if (imageRequest.getRequestListener() == null) {
      return mRequestListener;
    }
    return new ForwardingRequestListener(mRequestListener, imageRequest.getRequestListener());
  } else {
    if (imageRequest.getRequestListener() == null) {
      return new ForwardingRequestListener(mRequestListener, requestListener);
    }
    return new ForwardingRequestListener(
        mRequestListener, requestListener, imageRequest.getRequestListener());
  }
}
 
Example #22
Source File: VitoImageSource.java    From fresco with MIT License 5 votes vote down vote up
Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
final ImagePipeline imagePipeline,
final ImagePipelineUtils imagePipelineUtils,
final ImageOptions imageOptions,
final @Nullable Object callerContext,
final @Nullable RequestListener requestListener,
final String uiComponentId);
 
Example #23
Source File: EmptyImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return DataSources.immediateFailedDataSource(NO_REQUEST_EXCEPTION);
    }
  };
}
 
Example #24
Source File: IncreasingQualityImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  final List<Supplier<DataSource<CloseableReference<CloseableImage>>>> suppliers =
      new ArrayList<>(2);
  suppliers.add(
      mHighResImageSource.createDataSourceSupplier(
          imagePipeline,
          imagePipelineUtils,
          imageOptions,
          callerContext,
          requestListener,
          uiComponentId));
  suppliers.add(
      mLowResImageSource.createDataSourceSupplier(
          imagePipeline,
          imagePipelineUtils,
          imageOptions,
          callerContext,
          requestListener,
          uiComponentId));
  return IncreasingQualityDataSourceSupplier.create(suppliers);
}
 
Example #25
Source File: FirstAvailableImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  final List<Supplier<DataSource<CloseableReference<CloseableImage>>>> suppliers =
      new ArrayList<>(mFirstAvailableImageSources.length);
  for (ImageSource source : mFirstAvailableImageSources) {
    if (source instanceof VitoImageSource) {
      suppliers.add(
          ((VitoImageSource) source)
              .createDataSourceSupplier(
                  imagePipeline,
                  imagePipelineUtils,
                  imageOptions,
                  callerContext,
                  requestListener,
                  uiComponentId));
    } else {
      throw new IllegalArgumentException(
          "FirstAvailableImageSource must be VitoImageSource: " + source);
    }
  }
  return FirstAvailableDataSourceSupplier.create(suppliers);
}
 
Example #26
Source File: SingleImageSource.java    From fresco with MIT License 5 votes vote down vote up
@Override
public Supplier<DataSource<CloseableReference<CloseableImage>>> createDataSourceSupplier(
    final ImagePipeline imagePipeline,
    final ImagePipelineUtils imagePipelineUtils,
    final ImageOptions imageOptions,
    final @Nullable Object callerContext,
    final @Nullable RequestListener requestListener,
    final String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      final ImageRequest imageRequest =
          maybeExtractFinalImageRequest(imagePipelineUtils, imageOptions);
      if (imageRequest != null) {
        return imagePipeline.fetchDecodedImage(
            imageRequest,
            callerContext,
            ImageRequest.RequestLevel.FULL_FETCH,
            requestListener, // TODO: Check if this is correct !!
            uiComponentId);
      } else {
        return DataSources.immediateFailedDataSource(
            new NullPointerException(
                "Could not extract image request from: " + SingleImageSource.this));
      }
    }
  };
}
 
Example #27
Source File: FrescoControllerImpl.java    From fresco with MIT License 5 votes vote down vote up
private void setupRequestListener(FrescoState frescoState, ImageRequest imageRequest) {
  // TODO(T35949558): Add support for external request listeners
  if (imageRequest == null) {
    return;
  }
  final RequestListener requestListener =
      mFrescoContext
          .getImagePipeline()
          .getRequestListenerForRequest(imageRequest, frescoState.getImageOriginListener());
  frescoState.setRequestListener(requestListener);
}
 
Example #28
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return getImageRequestDataSourceSupplier(
      imagePipeline,
      imageRequest,
      callerContext,
      ImageRequest.RequestLevel.FULL_FETCH,
      requestListener,
      uiComponentId);
}
 
Example #29
Source File: ImagePipelineMultiUriHelper.java    From fresco with MIT License 5 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getFirstAvailableDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final Object callerContext,
        final @Nullable RequestListener requestListener,
        ImageRequest[] imageRequests,
        boolean tryBitmapCacheOnlyFirst,
        final @Nullable String uiComponentId) {
  List<Supplier<DataSource<CloseableReference<CloseableImage>>>> 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(
          getImageRequestDataSourceSupplier(
              imagePipeline,
              imageRequests[i],
              callerContext,
              ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE,
              requestListener,
              uiComponentId));
    }
  }
  for (int i = 0; i < imageRequests.length; i++) {
    suppliers.add(
        getImageRequestDataSourceSupplier(
            imagePipeline, imageRequests[i], callerContext, requestListener, uiComponentId));
  }
  return FirstAvailableDataSourceSupplier.create(suppliers);
}
 
Example #30
Source File: ZoomableApplication.java    From fresco with MIT License 5 votes vote down vote up
@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);
}