Beispiel #1
0
 private <T> DataSource<CloseableReference<T>> submitFetchRequest(
     Producer<CloseableReference<T>> producerSequence,
     ImageRequest imageRequest,
     ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
     Object callerContext) {
   try {
     ImageRequest.RequestLevel lowestPermittedRequestLevel =
         ImageRequest.RequestLevel.getMax(
             imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
     SettableProducerContext settableProducerContext =
         new SettableProducerContext(
             imageRequest,
             generateUniqueFutureId(),
             mRequestListener,
             callerContext,
             lowestPermittedRequestLevel,
             /* isPrefetch */ false,
             imageRequest.getProgressiveRenderingEnabled()
                 || !UriUtil.isNetworkUri(imageRequest.getSourceUri()),
             imageRequest.getPriority());
     return CloseableProducerToDataSourceAdapter.create(
         producerSequence, settableProducerContext, mRequestListener);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }
Beispiel #2
0
 private DataSource<Void> submitPrefetchRequest(
     Producer<Void> producerSequence,
     ImageRequest imageRequest,
     ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit,
     Object callerContext,
     Priority priority) {
   try {
     ImageRequest.RequestLevel lowestPermittedRequestLevel =
         ImageRequest.RequestLevel.getMax(
             imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
     SettableProducerContext settableProducerContext =
         new SettableProducerContext(
             imageRequest,
             generateUniqueFutureId(),
             mRequestListener,
             callerContext,
             lowestPermittedRequestLevel,
             /* isPrefetch */ true,
             /* isIntermediateResultExpected */ false,
             priority);
     return ProducerToDataSourceAdapter.create(
         producerSequence, settableProducerContext, mRequestListener);
   } catch (Exception exception) {
     return DataSources.immediateFailedDataSource(exception);
   }
 }
  /** Gets the top-level data source supplier to be used by a controller. */
  protected Supplier<DataSource<IMAGE>> obtainDataSourceSupplier() {
    if (mDataSourceSupplier != null) {
      return mDataSourceSupplier;
    }

    Supplier<DataSource<IMAGE>> supplier = null;

    // final image supplier;
    if (mImageRequest != null) {
      supplier = getDataSourceSupplierForRequest(mImageRequest);
    } else if (mMultiImageRequests != null) {
      supplier = getFirstAvailableDataSourceSupplier(mMultiImageRequests);
    }

    // increasing-quality supplier; highest-quality supplier goes first
    if (supplier != null && mLowResImageRequest != null) {
      List<Supplier<DataSource<IMAGE>>> suppliers = new ArrayList<Supplier<DataSource<IMAGE>>>(2);
      suppliers.add(supplier);
      suppliers.add(getDataSourceSupplierForRequest(mLowResImageRequest));
      supplier = IncreasingQualityDataSourceSupplier.create(suppliers);
    }

    // no image requests; use null data source supplier
    if (supplier == null) {
      supplier = DataSources.getFailedDataSourceSupplier(NO_REQUEST_EXCEPTION);
    }

    return supplier;
  }
Beispiel #4
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);
   }
 }
Beispiel #5
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);
   }
 }
Beispiel #6
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);
   }
 }
Beispiel #7
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);
   }
 }