Java Code Examples for com.facebook.imagepipeline.request.ImageRequest

The following examples show how to use com.facebook.imagepipeline.request.ImageRequest. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: fresco   Source File: ImagePipeline.java    License: MIT License 6 votes vote down vote up
/** @return {@link CacheKey} for doing bitmap cache lookups in the pipeline. */
@Nullable
public CacheKey getCacheKey(@Nullable ImageRequest imageRequest, @Nullable Object callerContext) {
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.beginSection("ImagePipeline#getCacheKey");
  }
  final CacheKeyFactory cacheKeyFactory = mCacheKeyFactory;
  CacheKey cacheKey = null;
  if (cacheKeyFactory != null && imageRequest != null) {
    if (imageRequest.getPostprocessor() != null) {
      cacheKey = cacheKeyFactory.getPostprocessedBitmapCacheKey(imageRequest, callerContext);
    } else {
      cacheKey = cacheKeyFactory.getBitmapCacheKey(imageRequest, callerContext);
    }
  }
  if (FrescoSystrace.isTracing()) {
    FrescoSystrace.endSection();
  }
  return cacheKey;
}
 
Example 2
@Override
protected int getLength(ImageRequest imageRequest) {
  AssetFileDescriptor fd = null;
  try {
    fd = mAssetManager.openFd(getAssetName(imageRequest));
    return (int) fd.getLength();
  } catch (IOException e) {
    return -1;
  } finally {
    try {
      if (fd != null) {
        fd.close();
      }
    } catch (IOException ignored) {
      // There's nothing we can do with the exception when closing descriptor.
    }
  }
}
 
Example 3
Source Project: imsdk-android   Source File: PersonalInfoPresenter.java    License: MIT License 6 votes vote down vote up
@Override
public void getVCard(boolean isForce) {
    UserVCard vCard = ProfileUtils.getLocalVCard(personalInfoView.getJid());
    if (!TextUtils.isEmpty(vCard.gravantarUrl)) {
        String url = QtalkStringUtils.getGravatar(vCard.gravantarUrl, true);
        FacebookImageUtil.loadWithCache(url, personalInfoView.getImagetView(),
                ImageRequest.CacheChoice.SMALL, CurrentPreference.getInstance().isSupportGifGravantar());
    }
    if (isForce) {
        ProfileUtils.loadVCard4mNet(personalInfoView.getImagetView(), personalInfoView.getJid(), commentView, false,
                new BasicCallback<UserVCard>() {
                    @Override
                    public void onSuccess(UserVCard userVCard) {
                        CurrentPreference.getInstance().setPreferenceUserId(userVCard.nickname);
                    }

                    @Override
                    public void onError() {

                    }
                });
    }
}
 
Example 4
Source Project: fresco   Source File: ImagePipeline.java    License: MIT License 6 votes vote down vote up
private DataSource<Void> prefetchToBitmapCache(
    ImageRequest imageRequest, Object callerContext, Priority priority) {
  if (!mIsPrefetchEnabledSupplier.get()) {
    return DataSources.immediateFailedDataSource(PREFETCH_EXCEPTION);
  }
  try {
    final Boolean shouldDecodePrefetches = imageRequest.shouldDecodePrefetches();
    final boolean skipBitmapCache =
        shouldDecodePrefetches != null
            ? !shouldDecodePrefetches // use imagerequest param if specified
            : mSuppressBitmapPrefetchingSupplier
                .get(); // otherwise fall back to pipeline's default
    Producer<Void> producerSequence =
        skipBitmapCache
            ? mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(imageRequest)
            : mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(imageRequest);
    return submitPrefetchRequest(
        producerSequence,
        imageRequest,
        ImageRequest.RequestLevel.FULL_FETCH,
        callerContext,
        priority);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example 5
Source Project: fresco   Source File: PriorityNetworkFetcherTest.java    License: MIT License 6 votes vote down vote up
private PriorityFetchState<FetchState> fetch(
    PriorityNetworkFetcher<FetchState> fetcher,
    String uri,
    NetworkFetcher.Callback callback,
    boolean isHiPri) {
  Consumer<EncodedImage> consumer = mock(Consumer.class);
  SettableProducerContext context =
      new SettableProducerContext(
          ImageRequest.fromUri(uri),
          "dontcare",
          null,
          null,
          null,
          !isHiPri,
          false,
          isHiPri ? HIGH : LOW,
          null);
  FetchState delegateFetchState = new FetchState(consumer, context);
  when(delegate.createFetchState(eq(consumer), eq(context))).thenReturn(delegateFetchState);
  PriorityFetchState<FetchState> fetchState = fetcher.createFetchState(consumer, context);
  fetcher.fetch(fetchState, callback);
  return fetchState;
}
 
Example 6
Source Project: droidddle   Source File: FrescoUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static final void setShotUrl(DraweeView view, String url, String thumbnail/*, BaseControllerListener listener*/) {
        ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
//                .setResizeOptions(
//                        new ResizeOptions(300, 400))
                .setProgressiveRenderingEnabled(true)
                .build();
        ImageRequest lowRequest = null;
        if (!TextUtils.isEmpty(thumbnail)) {
            lowRequest = ImageRequest.fromUri(thumbnail);
        }
        DraweeController draweeController = Fresco.newDraweeControllerBuilder()
                .setImageRequest(imageRequest)
                .setLowResImageRequest(lowRequest)
                .setOldController(view.getController())
                .setAutoPlayAnimations(true)
//                .setControllerListener(listener)
                .build();
        view.setController(draweeController);
    }
 
Example 7
Source Project: imsdk-android   Source File: FacebookImageUtil.java    License: MIT License 6 votes vote down vote up
public static void loadWithCache(String url, final SimpleDraweeView target,ImageRequest.CacheChoice type,boolean playAnim)
{
    if (target == null) return;

    Uri uri = Uri.parse(url);
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    ImageRequest request = builder
            .setCacheChoice(type)
            .build();
    final PipelineDraweeControllerBuilder pipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setAutoPlayAnimations(playAnim)
            .setOldController(target.getController());
    handler.post(new Runnable() {
        @Override
        public void run() {
            DraweeController controller = pipelineDraweeControllerBuilder.build();
            target.setController(controller);
        }
    });

}
 
Example 8
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener producerListener,
    Object callerContext,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority) {
  mImageRequest = Preconditions.checkNotNull(imageRequest);
  mId = Preconditions.checkNotNull(id);
  mProducerListener = Preconditions.checkNotNull(producerListener);
  mCallerContext = callerContext;
  mIsPrefetch = isPrefetch;
  mIsIntermediateResultExpected = isIntermediateResultExpected;
  mPriority = priority;
  mIsCancelled = false;
  mCallbacks = Lists.newArrayList();
}
 
Example 9
Source Project: TLint   Source File: ImageAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Image image = images.get(position);
    holder.image = image;
    if (image == null) {
        return;
    }
    holder.ivCheck.setVisibility(View.VISIBLE);
    holder.ivCheck.setImageResource(selectedImages.contains(image) ? R.drawable.ap_gallery_checked
            : R.drawable.ap_gallery_normal);
    int width = 100, height = 100;
    ImageRequest request =
            ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(new File(image.path)))
                    .setResizeOptions(new ResizeOptions(width, height))
                    .build();
    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setOldController(holder.ivPhoto.getController())
                    .setImageRequest(request)
                    .build();
    holder.ivPhoto.setController(controller);
}
 
Example 10
@Override
protected TriState shouldTransform(
    final CloseableReference<PooledByteBuffer> imageRef,
    final ImageRequest imageRequest,
    boolean isLast) {
  InputStream imageInputStream = imageRef.get().getStream();
  ImageFormat imageFormat = ImageFormatChecker.getImageFormat_WrapIOException(imageInputStream);

  switch (imageFormat) {
    case WEBP_SIMPLE:
    case WEBP_LOSSLESS:
    case WEBP_EXTENDED:
    case WEBP_EXTENDED_WITH_ALPHA:
      return TriState.valueOf(!WebpTranscoder.isWebpNativelySupported(imageFormat));
    case UNKNOWN:
      return isLast ? TriState.NO : TriState.UNSET;
    default:
      return TriState.NO;
  }
}
 
Example 11
Source Project: react-native-GPay   Source File: SystraceRequestListener.java    License: MIT License 6 votes vote down vote up
@Override
public void onRequestStart(
    ImageRequest request,
    Object callerContext,
    String requestId,
    boolean isPrefetch) {
  if (!Systrace.isTracing(Systrace.TRACE_TAG_REACT_FRESCO)) {
    return;
  }

  StringBuilder entryName = new StringBuilder();
  entryName.append("FRESCO_REQUEST_");
  entryName.append(request.getSourceUri().toString().replace(':', '_'));

  Pair<Integer,String> requestPair = Pair.create(mCurrentID, entryName.toString());
  Systrace.beginAsyncSection(
      Systrace.TRACE_TAG_REACT_FRESCO,
      requestPair.second,
      mCurrentID);
  mRequestsID.put(requestId, requestPair);
  mCurrentID++;
}
 
Example 12
Source Project: fresco   Source File: ImagePipeline.java    License: MIT License 6 votes vote down vote up
/**
 * Submits a request for prefetching to the encoded cache.
 *
 * <p>Beware that if your network fetcher doesn't support priorities prefetch requests may slow
 * down images which are immediately required on screen.
 *
 * @param imageRequest the request to submit
 * @param priority custom priority for the fetch
 * @return a DataSource that can safely be ignored.
 */
public DataSource<Void> prefetchToEncodedCache(
    ImageRequest imageRequest, Object callerContext, Priority priority) {
  if (!mIsPrefetchEnabledSupplier.get()) {
    return DataSources.immediateFailedDataSource(PREFETCH_EXCEPTION);
  }
  try {
    Producer<Void> producerSequence =
        mProducerSequenceFactory.getEncodedImagePrefetchProducerSequence(imageRequest);
    return submitPrefetchRequest(
        producerSequence,
        imageRequest,
        ImageRequest.RequestLevel.FULL_FETCH,
        callerContext,
        priority);
  } catch (Exception exception) {
    return DataSources.immediateFailedDataSource(exception);
  }
}
 
Example 13
Source Project: fresco   Source File: ImagePipelineMultiUriHelper.java    License: MIT License 6 votes vote down vote up
private static Supplier<DataSource<CloseableReference<CloseableImage>>>
    getImageRequestDataSourceSupplier(
        final ImagePipeline imagePipeline,
        final ImageRequest imageRequest,
        final Object callerContext,
        final ImageRequest.RequestLevel requestLevel,
        final RequestListener requestListener,
        final @Nullable String uiComponentId) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return getImageRequestDataSource(
          imagePipeline, imageRequest, callerContext, requestListener, uiComponentId);
    }
  };
}
 
Example 14
Source Project: fresco   Source File: ImagePipelineTest.java    License: MIT License 6 votes vote down vote up
@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 15
Source Project: fresco   Source File: ImagePipeline.java    License: MIT License 6 votes vote down vote up
/**
 * Returns a DataSource supplier that will on get submit the request for execution and return a
 * DataSource representing the pending results of the task.
 *
 * @param imageRequest the request to submit (what to execute).
 * @param callerContext the caller context of the caller of data source supplier
 * @param requestLevel which level to look down until for the image
 * @param requestListener additional image request listener independent of ImageRequest listeners
 * @return a DataSource representing pending results and completion of the request
 */
public Supplier<DataSource<CloseableReference<CloseableImage>>> getDataSourceSupplier(
    final ImageRequest imageRequest,
    final Object callerContext,
    final ImageRequest.RequestLevel requestLevel,
    final @Nullable RequestListener requestListener) {
  return new Supplier<DataSource<CloseableReference<CloseableImage>>>() {
    @Override
    public DataSource<CloseableReference<CloseableImage>> get() {
      return fetchDecodedImage(imageRequest, callerContext, requestLevel, requestListener);
    }

    @Override
    public String toString() {
      return Objects.toStringHelper(this).add("uri", imageRequest.getSourceUri()).toString();
    }
  };
}
 
Example 16
private static int getScaleNumerator(
    final ImageRequest imageRequest,
    final ImageTransformMetaData metaData) {
  final ResizeOptions resizeOptions = imageRequest.getResizeOptions();
  if (resizeOptions == null) {
    return JpegTranscoder.SCALE_DENOMINATOR;
  }

  final int rotationAngle = getRotationAngle(imageRequest, metaData);
  final boolean swapDimensions = rotationAngle == 90 || rotationAngle == 270;
  final int widthAfterRotation = swapDimensions ? metaData.getHeight() : metaData.getWidth();
  final int heightAfterRotation = swapDimensions ? metaData.getWidth() : metaData.getHeight();

  final float widthRatio = ((float) resizeOptions.width) / widthAfterRotation;
  final float heightRatio = ((float) resizeOptions.height) / heightAfterRotation;
  final int numerator =
      (int) Math.ceil(Math.max(widthRatio, heightRatio) * JpegTranscoder.SCALE_DENOMINATOR);

  if (numerator > MAX_JPEG_SCALE_NUMERATOR) {
    return JpegTranscoder.SCALE_DENOMINATOR;
  }
  if (numerator < 1) {
    return 1;
  }
  return numerator;
}
 
Example 17
Source Project: fresco   Source File: SettableProducerContext.java    License: MIT License 6 votes vote down vote up
public SettableProducerContext(
    ImageRequest imageRequest,
    String id,
    ProducerListener2 producerListener,
    Object callerContext,
    ImageRequest.RequestLevel lowestPermittedRequestLevel,
    boolean isPrefetch,
    boolean isIntermediateResultExpected,
    Priority priority,
    ImagePipelineConfig imagePipelineConfig) {
  super(
      imageRequest,
      id,
      producerListener,
      callerContext,
      lowestPermittedRequestLevel,
      isPrefetch,
      isIntermediateResultExpected,
      priority,
      imagePipelineConfig);
}
 
Example 18
protected void onPostExecute(File result) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.fromFile(result))
            .setResizeOptions(new ResizeOptions(previewView.getLayoutParams().width,
                    previewView.getLayoutParams().height))
            .build();
    PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
            .setOldController(previewView.getController())
            .setImageRequest(request)
            .build();
    previewView.setController(controller);
}
 
Example 19
Source Project: TLint   Source File: OffLineService.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isImageDownloaded(Uri loadUri) {
    if (loadUri == null) {
        return false;
    }
    CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
            .getEncodedCacheKey(ImageRequest.fromUri(loadUri), null);
    return ImagePipelineFactory.getInstance().getMainFileCache().hasKey(cacheKey)
            || ImagePipelineFactory.getInstance().getSmallImageFileCache().hasKey(cacheKey);
}
 
Example 20
public SingleImageBuilder setThumbnail(String url){
    Uri thumbnailUri = Uri.parse(url);
    ImageRequest request = getRequest(thumbnailUri, false);
    lowResImageRequest = request;
    controllerBuilder.setImageRequest(request);
    return this;
}
 
Example 21
Source Project: imsdk-android   Source File: GalleryFragment.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case SAVE_TO_GALLERY:
            DownloadPictureUtil.downloadPicture(getActivity(), mImageUrl, new DownloadPictureUtil.PicCallBack() {
                @Override
                public void onDownLoadSuccess(String str) {

                }
            }, true);
            break;
        case SIGNOTIFICATE_QR_CODE:
            FacebookImageUtil.getBitmapByUrl(mImageUrl, ImageRequest.CacheChoice.DEFAULT, getContext(), new FacebookImageUtil.GetBitampCallback() {
                @Override
                public void onSuccess(Bitmap bitmap) {
                    String decode = QRUtil.cognitiveQR(bitmap);
                    if (TextUtils.isEmpty(decode)) {
                        Toast.makeText(getContext(), R.string.atom_ui_tip_parse_failed, Toast.LENGTH_SHORT).show();
                    } else {
                        QRRouter.handleQRCode(decode, getContext());
                        getActivity().finish();
                    }
                }

                @Override
                public void onFailure() {
                    Toast.makeText(getContext(), R.string.atom_ui_tip_parse_failed, Toast.LENGTH_SHORT).show();
                }
            });
            break;
    }
    return true;
}
 
Example 22
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL, Context context, BaseBitmapDataSubscriber bbds
, BasePostprocessor postprocessor)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
            .setResizeOptions(new ResizeOptions(w,h))
            .setProgressiveRenderingEnabled(true);
    if(postprocessor!=null){
        builder.setPostprocessor(postprocessor);
    }
    ImageRequest imageRequest =
            builder
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
 
Example 23
Source Project: imsdk-android   Source File: QchatPersonalInfoPresenter.java    License: MIT License 5 votes vote down vote up
/**
 * 加载头像
 * @param forceUpdate  是否去服务器上更新图片
 */
@Override
public void loadGravatar(final boolean forceUpdate) {
    UserVCard vCard = ProfileUtils.getLocalVCard(personalInfoView.getJid());
    if (vCard.gravantarVersion > -1) {
        if (!TextUtils.isEmpty(vCard.gravantarUrl)) {
            FacebookImageUtil.loadWithCache(QtalkStringUtils.getGravatar(vCard.gravantarUrl,true)
                    , personalInfoView.getImagetView(), ImageRequest.CacheChoice.SMALL,
                    CurrentPreference.getInstance().isSupportGifGravantar());
        }
    } else {
        if (forceUpdate)
            load4mNet();
    }
}
 
Example 24
Source Project: TLint   Source File: ThreadListFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void renderThreadInfo(Forum forum) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(forum.getBackImg()))
            .setResizeOptions(new ResizeOptions(500, 500))
            .build();
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(request)
            .setOldController(backdrop.getController())
            .setAutoPlayAnimations(true)
            .build();
    backdrop.setController(draweeController);
    collapsingToolbar.setTitle(forum.getName());
    tvSubTitle.setText(forum.getDescription());
}
 
Example 25
Source Project: fresco   Source File: FrescoControllerImplTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testListeners() {
  RequestListener requestListener = baseTestListeners();
  verify(mImagePipeline)
      .fetchDecodedImage(
          any(ImageRequest.class),
          any(Object.class),
          any(ImageRequest.RequestLevel.class),
          eq(requestListener),
          eq(IMAGE_ID_STRING));
}
 
Example 26
Source Project: fresco   Source File: FrescoControllerImplTest.java    License: MIT License 5 votes vote down vote up
@Test
public void testPrepareImagePipelineComponents_whenNullRequest_thenDoNotPrepareComponents() {
  ProducerSequenceFactory producerSequenceFactory = mock(ProducerSequenceFactory.class);

  when(mImagePipeline.getProducerSequenceFactory()).thenReturn(producerSequenceFactory);
  when(producerSequenceFactory.getDecodedImageProducerSequence(isNull(ImageRequest.class)))
      .thenThrow(new NullPointerException());

  mFrescoController.prepareImagePipelineComponents(mFrescoState, null, CALLER_CONTEXT);

  verifyNoMoreInteractions(mFrescoState);
}
 
Example 27
Source Project: fresco   Source File: EncodedMemoryCacheProducerTest.java    License: MIT License 5 votes vote down vote up
@Before
public void setUp() {
  MockitoAnnotations.initMocks(this);
  mEncodedMemoryCacheProducer =
      new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
  mPooledByteBuffer1 = mock(PooledByteBuffer.class);
  mPooledByteBuffer2 = mock(PooledByteBuffer.class);
  mFinalImageReference = CloseableReference.of(mPooledByteBuffer1);
  mIntermediateImageReference = CloseableReference.of(mPooledByteBuffer2);
  mFinalImageReferenceClone = mFinalImageReference.clone();
  mFinalEncodedImage = new EncodedImage(mFinalImageReference);
  mFinalEncodedImage.setImageFormat(new ImageFormat("jpeg", null));
  mFinalEncodedImage.setWidth(100);
  mFinalEncodedImage.setHeight(100);
  mImagePipelineConfig = mock(ImagePipelineConfig.class);
  mImagePipelineExperiments = mock(ImagePipelineExperiments.class);

  mFinalEncodedImageFormatUnknown = new EncodedImage(mFinalImageReference);
  mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
  mFinalEncodedImageClone = new EncodedImage(mFinalImageReferenceClone);
  List<CacheKey> list = new ArrayList<>();
  list.add(new SimpleCacheKey("http://dummy.uri"));
  mCacheKey = new MultiCacheKey(list);
  when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);

  when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
  when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
  when(mProducerContext.getCallerContext()).thenReturn(mCallerContext);
  when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
  when(mProducerListener.requiresExtraMap(mProducerContext, PRODUCER_NAME)).thenReturn(true);
  when(mProducerContext.getLowestPermittedRequestLevel())
      .thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
  when(mProducerContext.getImagePipelineConfig()).thenReturn(mImagePipelineConfig);
  when(mImagePipelineConfig.getExperiments()).thenReturn(mImagePipelineExperiments);
  when(mImagePipelineExperiments.isEncodedCacheEnabled()).thenReturn(true);

  when(mImageRequest.isMemoryCacheEnabled()).thenReturn(true);
}
 
Example 28
Source Project: RecyclerRenderers   Source File: ViewUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void bind(final SimpleDraweeView view, String uri) {
  ImageRequest imageRequest =
      ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri))
          .build();
  DraweeController draweeController = Fresco.newDraweeControllerBuilder()
      .setImageRequest(imageRequest)
      .setOldController(view.getController())
      .setAutoPlayAnimations(true)
      .build();
  view.setController(draweeController);
}
 
Example 29
Source Project: fresco   Source File: SimpleDraweeView.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the image request
 *
 * @param request Image Request
 */
public void setImageRequest(ImageRequest request) {
  AbstractDraweeControllerBuilder controllerBuilder = mControllerBuilder;
  DraweeController controller =
      controllerBuilder.setImageRequest(request).setOldController(getController()).build();
  setController(controller);
}
 
Example 30
Source Project: Flora   Source File: MultiImageInterceptor.java    License: MIT License 5 votes vote down vote up
private void load(Uri uri, SimpleDraweeView draweeView, int width, int height) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
            .setResizeOptions(new ResizeOptions(width, height))
            .setProgressiveRenderingEnabled(true)
            .setAutoRotateEnabled(true)
            .build();

    PipelineDraweeController controller =
            (PipelineDraweeController) Fresco.newDraweeControllerBuilder()
                    .setImageRequest(request)
                    .setOldController(draweeView.getController())
                    .setAutoPlayAnimations(true)
                    .build();
    draweeView.setController(controller);
}