@Test
 public void testLocalVideoMiniThumbnailSuccess() throws Exception {
   when(mImageRequest.getPreferredWidth()).thenReturn(100);
   when(mImageRequest.getPreferredHeight()).thenReturn(100);
   when(android.media.ThumbnailUtils.createVideoThumbnail(
           mFile.getPath(), MediaStore.Images.Thumbnails.MINI_KIND))
       .thenReturn(mBitmap);
   doAnswer(
           new Answer() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Throwable {
               mCloseableReference = ((CloseableReference) invocation.getArguments()[0]).clone();
               return null;
             }
           })
       .when(mConsumer)
       .onNewResult(any(CloseableReference.class), eq(true));
   mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext);
   mExecutor.runUntilIdle();
   assertEquals(1, mCloseableReference.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
   assertEquals(
       mBitmap, mCloseableReference.getUnderlyingReferenceTestOnly().get().getUnderlyingBitmap());
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, null);
 }
예제 #2
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);
   }
 }
 private boolean isResultGoodEnough(EncodedImage encodedimage, ImageRequest imagerequest) {
   while (encodedimage == null
       || encodedimage.getWidth() < imagerequest.getPreferredWidth()
       || encodedimage.getHeight() < imagerequest.getPreferredHeight()) {
     return false;
   }
   return true;
 }
 private CacheKey getCacheKey() {
   final ImageRequest imageRequest = getImageRequest();
   final CacheKeyFactory cacheKeyFactory = mImagePipeline.getCacheKeyFactory();
   CacheKey cacheKey = null;
   if (cacheKeyFactory != null && imageRequest != null) {
     if (imageRequest.getPostprocessor() != null) {
       cacheKey = cacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, getCallerContext());
     } else {
       cacheKey = cacheKeyFactory.getBitmapCacheKey(imageRequest, getCallerContext());
     }
   }
   return cacheKey;
 }
예제 #5
0
 @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);
 }
예제 #6
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);
   }
 }
 protected void onNewResultImpl(EncodedImage encodedimage, boolean flag) {
   ImageRequest imagerequest = mProducerContext.getImageRequest();
   boolean flag2 = isResultGoodEnough(encodedimage, imagerequest);
   if (encodedimage != null && (flag2 || imagerequest.getLocalThumbnailPreviewsEnabled())) {
     Consumer consumer = getConsumer();
     boolean flag1;
     if (flag && flag2) {
       flag1 = true;
     } else {
       flag1 = false;
     }
     consumer.onNewResult(encodedimage, flag1);
   }
   if (flag && !flag2) {
     mNextProducer2.produceResults(getConsumer(), mProducerContext);
   }
 }
예제 #8
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);
   }
 }
  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalVideoThumbnailProducer = new LocalVideoThumbnailProducer(mExecutor);
    mFile = new File(Robolectric.application.getExternalFilesDir(null), TEST_FILENAME);

    mockStatic(ThumbnailUtils.class);
    mProducerContext =
        new SettableProducerContext(
            mImageRequest,
            mRequestId,
            mProducerListener,
            mock(Object.class),
            ImageRequest.RequestLevel.FULL_FETCH,
            false,
            false,
            Priority.MEDIUM);
    when(mImageRequest.getSourceFile()).thenReturn(mFile);
  }
예제 #10
0
 /**
  * Returns whether the image is stored in the disk cache.
  *
  * <p>If you have supplied your own cache key factory when configuring the pipeline, this method
  * may not work correctly. It will only work if the custom factory builds the cache key entirely
  * from the URI. If that is not the case, use {@link #isInDiskCache(ImageRequest)}.
  *
  * @param uri the uri for the image to be looked up.
  * @return true if the image was found in the disk cache, false otherwise.
  */
 public DataSource<Boolean> isInDiskCache(final Uri uri) {
   return isInDiskCache(ImageRequest.fromUri(uri));
 }
예제 #11
0
 /**
  * Returns whether the image is stored in the disk cache. Performs disk cache check synchronously.
  * It is not recommended to use this unless you know what exactly you are doing. Disk cache check
  * is a costly operation, the call will block the caller thread until the cache check is
  * completed.
  *
  * @param uri the uri for the image to be looked up.
  * @return true if the image was found in the disk cache, false otherwise.
  */
 public boolean isInDiskCacheSync(final Uri uri) {
   return isInDiskCacheSync(ImageRequest.fromUri(uri));
 }
예제 #12
0
 /**
  * If you have supplied your own cache key factory when configuring the pipeline, this method may
  * not work correctly. It will only work if the custom factory builds the cache key entirely from
  * the URI. If that is not the case, use {@link #evictFromDiskCache(ImageRequest)}.
  *
  * @param uri The uri of the image to evict
  */
 public void evictFromDiskCache(final Uri uri) {
   evictFromDiskCache(ImageRequest.fromUri(uri));
 }
 @Override
 public PipelineDraweeControllerBuilder setUri(@Nullable String uriString) {
   return super.setImageRequest(ImageRequest.fromUri(uriString));
 }
 @Override
 public PipelineDraweeControllerBuilder setUri(Uri uri) {
   return super.setImageRequest(ImageRequest.fromUri(uri));
 }