use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class ImagePipelineTest method testFetchNetworkEncodedImage.
@Test
public void testFetchNetworkEncodedImage() {
Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class);
when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)).thenReturn(encodedSequence);
when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("http://test"));
DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext);
assertFalse(dataSource.isFinished());
ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class);
verify(mRequestListener1).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
ImageRequest capturedImageRequest = argumentCaptor.getValue();
assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
verify(mRequestListener2).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
capturedImageRequest = argumentCaptor.getValue();
assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class);
verify(encodedSequence).produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class ImagePipelineTest method testFetchLocalEncodedImage.
@Test
public void testFetchLocalEncodedImage() {
Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class);
when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)).thenReturn(encodedSequence);
when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("file:///local/file"));
DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext);
assertFalse(dataSource.isFinished());
ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class);
verify(mRequestListener1).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
ImageRequest capturedImageRequest = argumentCaptor.getValue();
assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
verify(mRequestListener2).onRequestStart(argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false));
capturedImageRequest = argumentCaptor.getValue();
assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri());
ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class);
verify(encodedSequence).produceResults(any(Consumer.class), producerContextArgumentCaptor.capture());
assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected());
assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH);
}
use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class ImagePipeline method submitFetchRequest.
private <T> DataSource<CloseableReference<T>> submitFetchRequest(Producer<CloseableReference<T>> producerSequence, ImageRequest imageRequest, ImageRequest.RequestLevel lowestPermittedRequestLevelOnSubmit, Object callerContext) {
final RequestListener requestListener = getRequestListenerForRequest(imageRequest);
try {
ImageRequest.RequestLevel lowestPermittedRequestLevel = ImageRequest.RequestLevel.getMax(imageRequest.getLowestPermittedRequestLevel(), lowestPermittedRequestLevelOnSubmit);
SettableProducerContext settableProducerContext = new SettableProducerContext(imageRequest, generateUniqueFutureId(), requestListener, callerContext, lowestPermittedRequestLevel, /* isPrefetch */
false, imageRequest.getProgressiveRenderingEnabled() || imageRequest.getMediaVariations() != null || !UriUtil.isNetworkUri(imageRequest.getSourceUri()), imageRequest.getPriority());
return CloseableProducerToDataSourceAdapter.create(producerSequence, settableProducerContext, requestListener);
} catch (Exception exception) {
return DataSources.immediateFailedDataSource(exception);
}
}
use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class ImagePipeline method isInDiskCacheSync.
/**
* 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 imageRequest the imageRequest for the image to be looked up.
* @return true if the image was found in the disk cache, false otherwise.
*/
public boolean isInDiskCacheSync(final ImageRequest imageRequest) {
final CacheKey cacheKey = mCacheKeyFactory.getEncodedCacheKey(imageRequest, null);
final ImageRequest.CacheChoice cacheChoice = imageRequest.getCacheChoice();
switch(cacheChoice) {
case DEFAULT:
return mMainBufferedDiskCache.diskCheckSync(cacheKey);
case SMALL:
return mSmallImageBufferedDiskCache.diskCheckSync(cacheKey);
default:
return false;
}
}
use of com.facebook.imagepipeline.request.ImageRequest in project fresco by facebook.
the class DecodeProducer method produceResults.
@Override
public void produceResults(final Consumer<CloseableReference<CloseableImage>> consumer, final ProducerContext producerContext) {
final ImageRequest imageRequest = producerContext.getImageRequest();
ProgressiveDecoder progressiveDecoder;
if (!UriUtil.isNetworkUri(imageRequest.getSourceUri())) {
progressiveDecoder = new LocalImagesProgressiveDecoder(consumer, producerContext, mDecodeCancellationEnabled);
} else {
ProgressiveJpegParser jpegParser = new ProgressiveJpegParser(mByteArrayPool);
progressiveDecoder = new NetworkImagesProgressiveDecoder(consumer, producerContext, jpegParser, mProgressiveJpegConfig, mDecodeCancellationEnabled);
}
mInputProducer.produceResults(progressiveDecoder, producerContext);
}
Aggregations