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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations