com.facebook.imagepipeline.producers.ProducerContext Java Examples
The following examples show how to use
com.facebook.imagepipeline.producers.ProducerContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testGetFullFetchSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline.getDataSourceSupplier( mImageRequest, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH); Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = dataSourceSupplier.get(); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
Example #2
Source File: ForwardingRequestListener2.java From fresco with MIT License | 6 votes |
@Override public void onProducerFinishWithCancellation( ProducerContext producerContext, String producerName, @Nullable Map<String, String> extraMap) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onProducerFinishWithCancellation(producerContext, producerName, extraMap); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onProducerFinishWithCancellation", exception); } } }
Example #3
Source File: ForwardingRequestListener2.java From fresco with MIT License | 6 votes |
@Override public void onProducerFinishWithFailure( ProducerContext producerContext, String producerName, Throwable t, @Nullable Map<String, String> extraMap) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onProducerFinishWithFailure(producerContext, producerName, t, extraMap); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onProducerFinishWithFailure", exception); } } }
Example #4
Source File: ForwardingRequestListener2.java From fresco with MIT License | 6 votes |
@Override public void onProducerFinishWithSuccess( ProducerContext producerContext, String producerName, @Nullable Map<String, String> extraMap) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onProducerFinishWithSuccess(producerContext, producerName, extraMap); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onProducerFinishWithSuccess", exception); } } }
Example #5
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testPrefetchToEncodedCacheDefaultPriority() { Producer<Void> prefetchProducerSequence = mock(Producer.class); when(mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(mImageRequest)) .thenReturn(prefetchProducerSequence); DataSource<Void> dataSource = mImagePipeline.prefetchToEncodedCache(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.MEDIUM); }
Example #6
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testPrefetchToEncodedCacheCustomPriority() { Producer<Void> prefetchProducerSequence = mock(Producer.class); when(mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(mImageRequest)) .thenReturn(prefetchProducerSequence); DataSource<Void> dataSource = mImagePipeline.prefetchToEncodedCache(mImageRequest, mCallerContext, Priority.MEDIUM); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.MEDIUM); }
Example #7
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testPrefetchToBitmapCache() { Producer<Void> prefetchProducerSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(mImageRequest)) .thenReturn(prefetchProducerSequence); DataSource<Void> dataSource = mImagePipeline.prefetchToBitmapCache(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.MEDIUM); }
Example #8
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@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); }
Example #9
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@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); }
Example #10
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testFetchDecodedImage() { Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = mImagePipeline.fetchDecodedImage(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
Example #11
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testFetchDecodedImageWithRequestLevel() { Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = mImagePipeline.fetchDecodedImage( mImageRequest, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.DISK_CACHE); }
Example #12
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testFetchFromBitmapCacheDueToMethodCall() { Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); mImagePipeline.fetchImageFromBitmapCache(mImageRequest, mCallerContext); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); }
Example #13
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testFetchFromBitmapCacheDueToImageRequest() { Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mImageRequest.getLowestPermittedRequestLevel()) .thenReturn(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); mImagePipeline.fetchDecodedImage(mImageRequest, mCallerContext); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); }
Example #14
Source File: ImagePipelineTest.java From fresco with MIT License | 6 votes |
@Test public void testGetBitmapCacheGetSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline.getDataSourceSupplier( mImageRequest, mCallerContext, ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); dataSourceSupplier.get(); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
Example #15
Source File: ImagePipelineTest.java From fresco with MIT License | 5 votes |
private void verifyPrefetchToDiskCache( DataSource<Void> dataSource, Producer<Void> prefetchProducerSequence, Priority priority) { assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(priority, producerContextArgumentCaptor.getValue().getPriority()); }
Example #16
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onRequestCancellation(ProducerContext producerContext) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onRequestCancellation(producerContext); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onRequestCancellation", exception); } } }
Example #17
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onRequestFailure(ProducerContext producerContext, Throwable throwable) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onRequestFailure(producerContext, throwable); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onRequestFailure", exception); } } }
Example #18
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onRequestSuccess(ProducerContext producerContext) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onRequestSuccess(producerContext); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onRequestSuccess", exception); } } }
Example #19
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public boolean requiresExtraMap(ProducerContext producerContext, String producerName) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { if (mRequestListeners.get(i).requiresExtraMap(producerContext, producerName)) { return true; } } return false; }
Example #20
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onUltimateProducerReached( ProducerContext producerContext, String producerName, boolean successful) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onUltimateProducerReached(producerContext, producerName, successful); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onProducerFinishWithSuccess", exception); } } }
Example #21
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onProducerStart(ProducerContext producerContext, String producerName) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onProducerStart(producerContext, producerName); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onProducerStart", exception); } } }
Example #22
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onRequestStart(ProducerContext producerContext) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onRequestStart(producerContext); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onRequestStart", exception); } } }
Example #23
Source File: ForwardingRequestListener2.java From fresco with MIT License | 5 votes |
@Override public void onProducerEvent( ProducerContext producerContext, String producerName, String producerEventName) { final int numberOfListeners = mRequestListeners.size(); for (int i = 0; i < numberOfListeners; ++i) { RequestListener2 listener = mRequestListeners.get(i); try { listener.onProducerEvent(producerContext, producerName, producerEventName); } catch (Exception exception) { // Don't punish the other listeners if we're given a bad one. onException("InternalListener exception in onIntermediateChunkStart", exception); } } }
Example #24
Source File: AbstractProducerToDataSourceAdapter.java From fresco with MIT License | 5 votes |
protected void onNewResultImpl(@Nullable T result, int status, ProducerContext producerContext) { boolean isLast = BaseConsumer.isLast(status); if (super.setResult(result, isLast, getExtras(producerContext))) { if (isLast) { mRequestListener.onRequestSuccess(mSettableProducerContext); } } }
Example #25
Source File: OkHttpNetworkFetcher.java From PicKing with Apache License 2.0 | 4 votes |
public OkHttpNetworkFetchState( Consumer<EncodedImage> consumer, ProducerContext producerContext) { super(consumer, producerContext); }
Example #26
Source File: OkHttpNetworkFetchProducer.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 4 votes |
@Override protected NfpRequestState newRequestState( Consumer<CloseableReference<PooledByteBuffer>> consumer, ProducerContext context) { return new NfpRequestState(consumer, context); }
Example #27
Source File: VolleyNetworkFetcher.java From fresco with MIT License | 4 votes |
public VolleyNetworkFetchState( Consumer<EncodedImage> consumer, ProducerContext producerContext) { super(consumer, producerContext); }
Example #28
Source File: VolleyNetworkFetcher.java From fresco with MIT License | 4 votes |
@Override public VolleyNetworkFetchState createFetchState( Consumer<EncodedImage> consumer, ProducerContext context) { return new VolleyNetworkFetchState(consumer, context); }
Example #29
Source File: OkHttpNetworkFetcher.java From fresco with MIT License | 4 votes |
public OkHttpNetworkFetchState( Consumer<EncodedImage> consumer, ProducerContext producerContext) { super(consumer, producerContext); }
Example #30
Source File: OkHttpNetworkFetcher.java From fresco with MIT License | 4 votes |
@Override public OkHttpNetworkFetchState createFetchState( Consumer<EncodedImage> consumer, ProducerContext context) { return new OkHttpNetworkFetchState(consumer, context); }