com.facebook.imagepipeline.request.ImageRequest Java Examples

The following examples show how to use com.facebook.imagepipeline.request.ImageRequest. 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: ImagePipeline.java    From fresco with 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 #2
Source File: PersonalInfoPresenter.java    From imsdk-android with 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 #3
Source File: FrescoUtils.java    From droidddle with 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 #4
Source File: ImagePipeline.java    From fresco with 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 File: PriorityNetworkFetcherTest.java    From fresco with 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 File: LocalAssetFetchProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@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 #7
Source File: FacebookImageUtil.java    From imsdk-android with 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
Source File: SettableProducerContext.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
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 File: SettableProducerContext.java    From fresco with 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 #10
Source File: WebpTranscodeProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@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 File: SystraceRequestListener.java    From react-native-GPay with 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 File: ImageAdapter.java    From TLint with 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 #13
Source File: ImagePipeline.java    From fresco with 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 #14
Source File: ImagePipelineMultiUriHelper.java    From fresco with 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 #15
Source File: ImagePipelineTest.java    From fresco with 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 #16
Source File: ResizeAndRotateProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
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 File: ImagePipeline.java    From fresco with 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 #18
Source File: GalleryFragment.java    From imsdk-android with 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 #19
Source File: ForwardingRequestListener.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void onRequestSuccess(ImageRequest request, String requestId, boolean isPrefetch) {
  final int numberOfListeners = mRequestListeners.size();
  for (int i = 0; i < numberOfListeners; ++i) {
    RequestListener listener = mRequestListeners.get(i);
    try {
      listener.onRequestSuccess(request, requestId, isPrefetch);
    } catch (Exception exception) {
      // Don't punish the other listeners if we're given a bad one.
      onException("InternalListener exception in onRequestSuccess", exception);
    }
  }
}
 
Example #20
Source File: ProducerSequenceFactory.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Returns a sequence that can be used for a prefetch request for a decoded image.
 *
 * @param imageRequest the request that will be submitted
 * @return the sequence that should be used to process the request
 */
public Producer<Void> getDecodedImagePrefetchProducerSequence(ImageRequest imageRequest) {
  Producer<CloseableReference<CloseableImage>> inputProducer =
      getBasicDecodedImageSequence(imageRequest);

  if (mUseBitmapPrepareToDraw) {
    inputProducer = getBitmapPrepareSequence(inputProducer);
  }

  return getDecodedImagePrefetchSequence(inputProducer);
}
 
Example #21
Source File: ImagePipelineUtilsImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Nullable
public ImageRequest wrapDecodedImageRequest(
    ImageRequest imageRequest, DecodedImageOptions imageOptions) {
  ImageRequestBuilder builder =
      createDecodedImageRequestBuilder(
          createEncodedImageRequestBuilder(imageRequest, imageOptions), imageOptions);
  return builder != null ? builder.build() : null;
}
 
Example #22
Source File: CommentImageGrid.java    From CommentGallery with Apache License 2.0 5 votes vote down vote up
private void layoutChildrenView() {
    int childrenCount = getChildCount();

    for (int i = 0; i < childrenCount; i++) {
        ViewGroup childImageLayout = (ViewGroup) getChildAt(i);
        SimpleDraweeView childImageView = (SimpleDraweeView) childImageLayout.getChildAt(0);
        if (mOnItemClickListener != null) {
            final int finalI = i;
            childImageLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItemClick(finalI);
                }
            });
        }
        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(mImageUrls.get(i)))
                .setProgressiveRenderingEnabled(true)
                .setResizeOptions(new ResizeOptions(mItemWidth, mItemWidth))
                .build();
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(childImageView.getController())
                .build();
        childImageView.setController(controller);

        int[] position = findPosition(i);
        int itemHeight = mItemWidth;
        int left = (int) (mItemWidth + mHorizontalSpace) * position[1];
        int top = (int) (itemHeight + mVerticalSpace) * position[0];
        int right = left + mItemWidth;
        int bottom = top + itemHeight;

        childImageLayout.layout(left, top, right, bottom);
    }
}
 
Example #23
Source File: PostItemGalleryView.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
private DraweeController getDraweeController(PostItem item) {
    Uri thumbnailUri = Uri.parse(item.getThumbnail());
    ImageRequest thumbnail = ImageRequestBuilder.newBuilderWithSource(thumbnailUri)
            .build();

    PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder()
            .setImageRequest(thumbnail)
            .setOldController(thumbnailView.getController());
    return builder.build();
}
 
Example #24
Source File: FrescoFactory.java    From FrescoUtils with Apache License 2.0 5 votes vote down vote up
public static ImageRequest buildImageRequestWithSource(BaseFrescoImageView fresco, Point size){
    String thumbnail = null;
    if(TextUtils.isEmpty(fresco.getThumbnailUrl())){
        thumbnail = fresco.getThumbnailPath();
    }else{
        thumbnail = fresco.getThumbnailUrl();
    }
    Uri uri = Uri.parse(thumbnail);
    return  ImageRequestBuilder.newBuilderWithSource(uri)
            .setPostprocessor(fresco.getPostProcessor())
            .setAutoRotateEnabled(fresco.getAutoRotateEnabled())
            .setResizeOptions(new ResizeOptions(size.x, size.y))
            .setLocalThumbnailPreviewsEnabled(true)
            .build();
}
 
Example #25
Source File: LocationHolder.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #26
Source File: PhotoActivity.java    From materialup with Apache License 2.0 5 votes vote down vote up
private void save() {
        try {
            ImageRequest imageRequest = ImageRequest.fromUri(mUrl);
            CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
            BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
            File file = ((FileBinaryResource) resource).getFile();

            String fileName = mUrl;
            fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
            if (mTitle != null) {
                fileName = mTitle + fileName;
            }
            File pic = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            File dir = new File(pic, "material/");
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File renamed = new File(dir, fileName);
            if (!renamed.exists()) {
                renamed.createNewFile();
                FileUtil.copy(file, renamed);
            }
            UI.showToast(this, getString(R.string.image_saved_to, renamed.getAbsolutePath()));
//            Snackbar.make(mDraweeView,R.string.image_is_saved, Snackbar.LENGTH_LONG);
        } catch (Exception ex) {
            Log.w("SHARE", "Sharing " + mUrl + " failed", ex);
        }
    }
 
Example #27
Source File: ImagePipelineResizingFragment.java    From fresco with MIT License 5 votes vote down vote up
private void reloadImage(Uri imageUri, @Nullable ResizeOptions resizeOptions) {
  final ImageRequest imageRequest =
      ImageRequestBuilder.newBuilderWithSource(imageUri)
          .setResizeOptions(resizeOptions)
          .setImageDecodeOptions(new ImageDecodeOptionsBuilder().build())
          .build();

  final DraweeController draweeController =
      Fresco.newDraweeControllerBuilder()
          .setOldController(mDraweeMain.getController())
          .setImageRequest(imageRequest)
          .build();

  mDraweeMain.setController(draweeController);
}
 
Example #28
Source File: FrescoUtils.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
public static PipelineDraweeControllerBuilder getPreController(String url, final PhotoDraweeView draweeView) {
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
            .setProgressiveRenderingEnabled(true)
            .build();

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
    controller.setImageRequest(request);
    controller.setOldController(draweeView.getController());
    controller.setAutoPlayAnimations(true);
    return controller;
}
 
Example #29
Source File: ImageManager.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public SingleImageBuilder setImageFromRes(int resId, boolean progressive){
    Uri uri = new Uri.Builder()
            .scheme(UriUtil.LOCAL_RESOURCE_SCHEME) // "res"
            .path(String.valueOf(resId))
            .build();
    ImageRequest request = getRequest(uri, progressive);
    mainImageRequest = request;
    controllerBuilder.setLowResImageRequest(request);
    return this;
}
 
Example #30
Source File: LocalResourceFetchProducerTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  when(mResources.openRawResourceFd(eq(TEST_ID))).thenReturn(mAssetFileDescriptor);
  when(mAssetFileDescriptor.getLength()).thenReturn((long) TEST_DATA_LENGTH);

  mExecutor = new TestExecutorService(new FakeClock());
  mLocalResourceFetchProducer =
      new LocalResourceFetchProducer(mExecutor, mPooledByteBufferFactory, mResources);

  mProducerContext =
      new SettableProducerContext(
          mImageRequest,
          mRequestId,
          mProducerListener,
          mock(Object.class),
          ImageRequest.RequestLevel.FULL_FETCH,
          false,
          true,
          Priority.MEDIUM,
          mConfig);
  when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("res:///" + TEST_ID));
  doAnswer(
          new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
              mCapturedEncodedImage =
                  EncodedImage.cloneOrNull(((EncodedImage) invocation.getArguments()[0]));
              return null;
            }
          })
      .when(mConsumer)
      .onNewResult(notNull(EncodedImage.class), anyInt());
}