Search in sources :

Example 51 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class BranchOnSeparateImagesProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mInputProducer1 = mock(Producer.class);
    mInputProducer2 = mock(Producer.class);
    BranchOnSeparateImagesProducer branchOnSeparateImagesProducer = new BranchOnSeparateImagesProducer(mInputProducer1, mInputProducer2);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mImageRequest.getPreferredWidth()).thenReturn(WIDTH);
    when(mImageRequest.getPreferredHeight()).thenReturn(HEIGHT);
    when(mImageRequest.getResizeOptions()).thenReturn(new ResizeOptions(WIDTH, HEIGHT));
    when(mImageRequest.getLocalThumbnailPreviewsEnabled()).thenReturn(true);
    mIntermediateResult = mock(EncodedImage.class);
    mFirstProducerFinalResult = mock(EncodedImage.class);
    mSecondProducerFinalResult = mock(EncodedImage.class);
    PooledByteBuffer mockByteBuffer = mock(PooledByteBuffer.class);
    when(mIntermediateResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
    when(mFirstProducerFinalResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
    when(mSecondProducerFinalResult.getByteBufferRef()).thenReturn(CloseableReference.of(mockByteBuffer));
    mFirstProducerConsumer = null;
    mSecondProducerConsumer = null;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mFirstProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
            return null;
        }
    }).when(mInputProducer1).produceResults(any(Consumer.class), any(ProducerContext.class));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mSecondProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
            return null;
        }
    }).when(mInputProducer2).produceResults(any(Consumer.class), any(ProducerContext.class));
    branchOnSeparateImagesProducer.produceResults(mConsumer, mProducerContext);
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PooledByteBuffer(com.facebook.common.memory.PooledByteBuffer) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Before(org.junit.Before)

Example 52 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class DraweeViewHolder method bind.

/**
 * @param uri The Uri to show into the DraweeView for this Holder
 */
public void bind(Uri uri) {
    mDraweeView.initInstrumentation(uri.toString(), mPerfListener);
    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(mDraweeView.getLayoutParams().width, mDraweeView.getLayoutParams().height));
    PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
    // Create the Builder
    PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
    if (mConfig.reuseOldController) {
        builder.setOldController(mDraweeView.getController());
    }
    mDraweeView.setListener(builder);
    mDraweeView.setController(builder.build());
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)

Example 53 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class DraweeViewListAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    InstrumentedDraweeView draweeView;
    if (convertView == null) {
        final Context context = parent.getContext();
        GenericDraweeHierarchy gdh = DraweeUtil.createDraweeHierarchy(context, mConfig);
        draweeView = new InstrumentedDraweeView(context, gdh, mConfig);
        SizeUtil.setConfiguredSize(parent, draweeView, mConfig);
        draweeView.setPadding(mPaddingPx, mPaddingPx, mPaddingPx, mPaddingPx);
    } else {
        draweeView = (InstrumentedDraweeView) convertView;
    }
    final Uri uri = getItem(position);
    draweeView.initInstrumentation(uri.toString(), mPerfListener);
    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(draweeView.getLayoutParams().width, draweeView.getLayoutParams().height));
    PipelineUtil.addOptionalFeatures(imageRequestBuilder, mConfig);
    // Create the Builder
    PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder().setImageRequest(imageRequestBuilder.build());
    if (mConfig.reuseOldController) {
        builder.setOldController(draweeView.getController());
    }
    if (mConfig.instrumentationEnabled) {
        draweeView.setListener(builder);
    }
    draweeView.setController(builder.build());
    return draweeView;
}
Also used : Context(android.content.Context) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) InstrumentedDraweeView(com.facebook.samples.scrollperf.instrumentation.InstrumentedDraweeView) Uri(android.net.Uri) ImageRequestBuilder(com.facebook.imagepipeline.request.ImageRequestBuilder) PipelineDraweeControllerBuilder(com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)

Example 54 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class ResizeAndRotateProducerTest method whenRequestWidthAndHeight.

private void whenRequestWidthAndHeight(int preferredWidth, int preferredHeight) {
    when(mImageRequest.getPreferredWidth()).thenReturn(preferredWidth);
    when(mImageRequest.getPreferredHeight()).thenReturn(preferredHeight);
    ResizeOptions resizeOptions = null;
    if (preferredWidth > 0 || preferredHeight > 0) {
        resizeOptions = new ResizeOptions(preferredWidth, preferredHeight);
    }
    when(mImageRequest.getResizeOptions()).thenReturn(resizeOptions);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions)

Example 55 with ResizeOptions

use of com.facebook.imagepipeline.common.ResizeOptions in project fresco by facebook.

the class ThumbnailBranchProducerTest method testNullReturnedIfNoProducerSufficientForResizeOptions.

@Test
public void testNullReturnedIfNoProducerSufficientForResizeOptions() {
    int width = THUMBNAIL_WIDTHS[2] + 50;
    int height = THUMBNAIL_HEIGHTS[2] + 50;
    mockRequestWithResizeOptions(width, height);
    mProducer.produceResults(mImageConsumer, mProducerContext);
    verify(mImageConsumer).onNewResult(null, Consumer.IS_LAST);
    ResizeOptions resizeOptions = new ResizeOptions(width, height);
    verify(mThumbnailProducers[0]).canProvideImageForSize(resizeOptions);
    verify(mThumbnailProducers[1]).canProvideImageForSize(resizeOptions);
    verify(mThumbnailProducers[2]).canProvideImageForSize(resizeOptions);
    verifyNoMoreInteractions((Object[]) mThumbnailProducers);
}
Also used : ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) Test(org.junit.Test)

Aggregations

ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)63 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)31 Uri (android.net.Uri)12 Test (org.junit.Test)11 DraweeController (com.facebook.drawee.interfaces.DraweeController)10 PipelineDraweeController (com.facebook.drawee.backends.pipeline.PipelineDraweeController)9 ImageRequestBuilder (com.facebook.imagepipeline.request.ImageRequestBuilder)7 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)6 File (java.io.File)5 PipelineDraweeControllerBuilder (com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 CloseableReference (com.facebook.common.references.CloseableReference)3 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)3 FileSystemReference (im.actor.runtime.files.FileSystemReference)3 Context (android.content.Context)2 Canvas (android.graphics.Canvas)2 Point (android.graphics.Point)2 Animatable (android.graphics.drawable.Animatable)2 View (android.view.View)2