예제 #1
0
 /**
  * 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
  * @return a DataSource representing the pending decoded image(s)
  */
 public DataSource<CloseableReference<CloseableImage>> fetchDecodedImage(
     ImageRequest imageRequest, Object callerContext) {
   try {
     Producer<CloseableReference<CloseableImage>> producerSequence =
         mProducerSequenceFactory.getDecodedImageProducerSequence(imageRequest);
     return submitFetchRequest(
         producerSequence, imageRequest, ImageRequest.RequestLevel.FULL_FETCH, callerContext);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }
예제 #2
0
 /**
  * Submits a request for bitmap cache lookup.
  *
  * @param imageRequest the request to submit
  * @return a DataSource representing the image
  */
 public DataSource<CloseableReference<CloseableImage>> fetchImageFromBitmapCache(
     ImageRequest imageRequest, Object callerContext) {
   try {
     Producer<CloseableReference<CloseableImage>> producerSequence =
         mProducerSequenceFactory.getDecodedImageProducerSequence(imageRequest);
     return submitFetchRequest(
         producerSequence,
         imageRequest,
         ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE,
         callerContext);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }
예제 #3
0
 /**
  * Submits a request for prefetching to the bitmap cache.
  *
  * @param imageRequest the request to submit
  * @return a DataSource that can safely be ignored.
  */
 public DataSource<Void> prefetchToBitmapCache(ImageRequest imageRequest, Object callerContext) {
   if (!mIsPrefetchEnabledSupplier.get()) {
     return DataSources.immediateFailedDataSource(PREFETCH_EXCEPTION);
   }
   try {
     Producer<Void> producerSequence =
         mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(imageRequest);
     return submitPrefetchRequest(
         producerSequence,
         imageRequest,
         ImageRequest.RequestLevel.FULL_FETCH,
         callerContext,
         Priority.MEDIUM);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }
예제 #4
0
 /**
  * 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) {
   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);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }