示例#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);
   }
 }
 @Override
 public void produceResults(
     final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext context) {
   final ImageRequest imageRequest = context.getImageRequest();
   ProgressiveDecoder progressiveDecoder;
   if (!UriUtil.isNetworkUri(imageRequest.getSourceUri())) {
     progressiveDecoder = new LocalImagesProgressiveDecoder(consumer, context);
   } else {
     ProgressiveJpegParser jpegParser = new ProgressiveJpegParser(mByteArrayPool);
     progressiveDecoder =
         new NetworkImagesProgressiveDecoder(
             consumer, context, jpegParser, mProgressiveJpegConfig);
   }
   mNextProducer.produceResults(progressiveDecoder, context);
 }
示例#3
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);
   }
 }