Java Code Examples for com.facebook.imagepipeline.request.ImageRequestBuilder#newBuilderWithSource()

The following examples show how to use com.facebook.imagepipeline.request.ImageRequestBuilder#newBuilderWithSource() . 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: 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 2
Source File: ImageViewerAdapter.java    From photo-viewer with Apache License 2.0 6 votes vote down vote up
private void setController(String url, ReadableMap headers) {
			PipelineDraweeControllerBuilder controllerBuilder = Fresco.newDraweeControllerBuilder();
//			controllerBuilder.setUri(url);
			controllerBuilder.setOldController(drawee.getController());
			controllerBuilder.setControllerListener(getDraweeControllerListener(drawee));
			controllerBuilder.setAutoPlayAnimations(true);
			if (imageRequestBuilder != null) {
				imageRequestBuilder.setSource(Uri.parse(url));
				controllerBuilder.setImageRequest(imageRequestBuilder.build());
			}
//			support load local image just like React Native do

			ImageSource imageSource = new ImageSource(getContext(), url);
			ImageRequestBuilder imageRequestBuilder1 = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri());
//			support headers
			ImageRequest imageRequest = ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder1, headers);

			controllerBuilder.setImageRequest(imageRequest);


			drawee.setController(controllerBuilder.build());
		}
 
Example 3
Source File: FrescoHolder.java    From fresco with MIT License 6 votes vote down vote up
@Override
protected void onBind(String uriString) {
  Uri uri = Uri.parse(uriString);
  ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
  if (UriUtil.isNetworkUri(uri)) {
    imageRequestBuilder.setProgressiveRenderingEnabled(true);
  } else {
    imageRequestBuilder.setResizeOptions(
        new ResizeOptions(
            mImageView.getLayoutParams().width, mImageView.getLayoutParams().height));
  }
  DraweeController draweeController =
      Fresco.newDraweeControllerBuilder()
          .setImageRequest(imageRequestBuilder.build())
          .setOldController(mImageView.getController())
          .setControllerListener(mImageView.getListener())
          .setAutoPlayAnimations(true)
          .build();
  mImageView.setController(draweeController);
}
 
Example 4
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 5
Source File: FrescoUtils.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void displayPhoto(SimpleDraweeView mSimpleDraweeView, String path, int width, int height, ControllerListener mControllerListener) {
    if (!TextUtils.isEmpty(path)) {
        PipelineDraweeControllerBuilder mPipelineDraweeControllerBuilder = Fresco.newDraweeControllerBuilder();
        ImageRequestBuilder mImageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path));
        mImageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
        mPipelineDraweeControllerBuilder.setOldController(mSimpleDraweeView.getController());
        mPipelineDraweeControllerBuilder.setImageRequest(mImageRequestBuilder.build());
        mPipelineDraweeControllerBuilder.setControllerListener(mControllerListener);
        mSimpleDraweeView.setController(mPipelineDraweeControllerBuilder.build());
    }
}
 
Example 6
Source File: FrescoImageLoader.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void display(SimpleDraweeView view, String lowUri, String uri, ControllerListener listener) {
    if (uri != null) {
        ImageRequestBuilder imageRequest;
        int w = view.getLayoutParams().width;
        int h = view.getLayoutParams().height;
        PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        if (!lowUri.startsWith("file:///")) {
            lowUri = "file://" + lowUri;
        }
        if (lowUri != null && lowUri.length() > 0) {
            controller.setLowResImageRequest(ImageRequest.fromUri(lowUri));
        }
        controller.setOldController(view.getController());
        controller.setAutoPlayAnimations(true);
        if (uri.endsWith(".MP4")) {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(lowUri));
        } else {
            imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(uri));
        }
        if (w > 0 && h > 0) {
            imageRequest.setResizeOptions(new ResizeOptions(w, h));
        }
        controller.setImageRequest(imageRequest.build());
        controller.setControllerListener(listener);
        view.setController(controller.build());
    }
}
 
Example 7
Source File: FrescoImageProvider.java    From HybridCache with MIT License 5 votes vote down vote up
private DataSource<Void> prefetchToDiskCache(String url, ImageRequestListener listener) {
    if (!TextUtils.isEmpty(url)) {
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url));
        if (listener != null) {
            builder.setRequestListener(new ImageRequestWrapper(listener));
        }
        return imagePipeline.prefetchToDiskCache(builder.build(), null);
    }
    if (listener != null) {
        listener.onFailed(null, new Exception("url is empty"));
    }

    return null;
}
 
Example 8
Source File: MerryPhotoView.java    From photo-viewer with Apache License 2.0 5 votes vote down vote up
private ImageRequestBuilder getLocalImage() {
    final Context context = getContext();

    ImageSource imageSource = new ImageSource(context, "cat-2575694_1920");

    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(imageSource.getUri());
    return imageRequestBuilder;
}
 
Example 9
Source File: BoxingFrescoLoader.java    From boxing with Apache License 2.0 5 votes vote down vote up
@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height,  IBoxingCallback callback) {
    absPath = "file://" + absPath;
    ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(absPath));
    if (width > 0 && height > 0) {
        requestBuilder.setResizeOptions(new ResizeOptions(width, height));
    }
    ImageRequest request = requestBuilder.build();
    loadImage(request, img, callback);
}
 
Example 10
Source File: UniversalDraweeView.java    From JianshuApp with GNU General Public License v3.0 5 votes vote down vote up
private void loadImageURI(Uri uri, @Nullable Object callerContext, int width, int height) {
    // 对URL做格式转换、尺寸限制等处理
    uri = Uri.parse(ImageUtils.format(uri.toString(), DisplayInfo.getWidthPixels()));

    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
    imageRequestBuilder.setProgressiveRenderingEnabled(true);

    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
    if (width > 0 && height > 0) {
        imageRequestBuilder.setResizeOptions(new ResizeOptions(width, height));
    }

    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder()
            .setCallerContext(callerContext)
            .setImageRequest(imageRequestBuilder.build())
            .setOldController(getController())
            .setAutoPlayAnimations(true)  // 自动播放动态图
            .setTapToRetryEnabled(true)  // 在加载失败时,可以点击重新加载
            .setControllerListener(new BaseControllerListener<ImageInfo>() {
                @Override
                public void onFinalImageSet(String id,
                                            ImageInfo imageInfo,
                                            Animatable animatable) {
                    super.onFinalImageSet(id, imageInfo, animatable);
                    onUpdateImage(imageInfo);
                }
            });
    if (AppUtils.isMainThread()) {
        setController(controller.build());
    } else {
        Observable.just(0)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(it -> setController(controller.build()));
    }
}
 
Example 11
Source File: FrescoBasedReactTextInlineImageSpan.java    From react-native-GPay with MIT License 4 votes vote down vote up
@Override
public void draw(
    Canvas canvas,
    CharSequence text,
    int start,
    int end,
    float x,
    int top,
    int y,
    int bottom,
    Paint paint) {
  if (mDrawable == null) {
    ImageRequestBuilder imageRequestBuilder = ImageRequestBuilder.newBuilderWithSource(mUri);
    ImageRequest imageRequest = ReactNetworkImageRequest.fromBuilderWithHeaders(imageRequestBuilder, mHeaders);

    DraweeController draweeController = mDraweeControllerBuilder
        .reset()
        .setOldController(mDraweeHolder.getController())
        .setCallerContext(mCallerContext)
        .setImageRequest(imageRequest)
        .build();
    mDraweeHolder.setController(draweeController);
    mDraweeControllerBuilder.reset();

    mDrawable = mDraweeHolder.getTopLevelDrawable();
    mDrawable.setBounds(0, 0, mWidth, mHeight);
    if(mTintColor != 0) {
      mDrawable.setColorFilter(mTintColor, PorterDuff.Mode.SRC_IN);
    }
    mDrawable.setCallback(mTextView);

  }

  // NOTE: This drawing code is copied from DynamicDrawableSpan

  canvas.save();

  // Align to center
  int fontHeight = (int)(paint.descent() - paint.ascent());
  int centerY = y + (int)paint.descent() - fontHeight / 2;
  int transY = centerY - (mDrawable.getBounds().bottom - mDrawable.getBounds().top) / 2;

  canvas.translate(x, transY);
  mDrawable.draw(canvas);
  canvas.restore();
}
 
Example 12
Source File: ImageViewer.java    From photo-viewer with Apache License 2.0 4 votes vote down vote up
/**
 * Creates new {@code ImageRequestBuilder}.
 */
public static ImageRequestBuilder createImageRequestBuilder() {
    return ImageRequestBuilder.newBuilderWithSource(Uri.parse(""));
}
 
Example 13
Source File: FrescoPlusFetcher.java    From FrescoPlus with Apache License 2.0 4 votes vote down vote up
/**
 * @param frescoPlusView The draweeView is to display the bitmap
 * @param uri         The source uri
 * @param callback    Listening to the success or failure
 */
private void fetchImage(FrescoPlusView frescoPlusView, Uri uri, FPFetchCallback<ImageInfo> callback) {
    GenericDraweeHierarchyBuilder hierarchyBuilder = new GenericDraweeHierarchyBuilder(null);
    hierarchyBuilder.setFadeDuration(fadeDuration);
    hierarchyBuilder.setRoundingParams(RoundingParams.fromCornersRadius(radius));
    hierarchyBuilder.setActualImageScaleType(scaleType);
    if (defaultDrawable != null)
        hierarchyBuilder.setPlaceholderImage(defaultDrawable, scaleType);
    if (pressedDrawable != null)
        hierarchyBuilder.setPressedStateOverlay(pressedDrawable);
    if (retryDrawable != null)
        hierarchyBuilder.setRetryImage(retryDrawable);
    if (overlayDrawable != null)
        hierarchyBuilder.setOverlay(overlayDrawable);
    if (failureDrawable != null)
        hierarchyBuilder.setFailureImage(failureDrawable, scaleType);
    if (progressDrawable != null)
        hierarchyBuilder.setProgressBarImage(progressDrawable);
    GenericDraweeHierarchy hierarchy = hierarchyBuilder.build();

    ImageRequestBuilder requestBuilder = ImageRequestBuilder.newBuilderWithSource(uri);
    requestBuilder.setLowestPermittedRequestLevel(requestLevel);
    requestBuilder.setAutoRotateEnabled(autoRotateEnabled);
    if (postprocessor != null)
        requestBuilder.setPostprocessor(postprocessor);
    Priority priority = requestPriority == FrescoPriority.HIGH ? Priority.HIGH : Priority.MEDIUM;
    requestBuilder.setRequestPriority(priority);
    if (resizeWidth > 0 && resizeHeight > 0)
        requestBuilder.setResizeOptions(new ResizeOptions(resizeWidth, resizeHeight));
    ImageRequest imageRequest = requestBuilder.build();

    DraweeController draweeController = FrescoPlusCore.newDraweeControllerBuilder()
            .setOldController(frescoPlusView.getController())
            .setAutoPlayAnimations(true)
            .setRetainImageOnFailure(true)
            .setTapToRetryEnabled(true)
            .setImageRequest(imageRequest)
            .setControllerListener(FetchImageControllerListenerSupplier.newInstance(callback))
            .build();
    frescoPlusView.setHierarchy(hierarchy);
    frescoPlusView.setController(draweeController);
}
 
Example 14
Source File: FrescoImageLoader.java    From ScrollGalleryView with MIT License 4 votes vote down vote up
private ImageRequest createImageRequest(Integer thumbnailWidth, Integer thumbnailHeight) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url));
    builder.setResizeOptions(new ResizeOptions(thumbnailWidth, thumbnailHeight));

    return builder.build();
}