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

The following examples show how to use com.facebook.imagepipeline.request.ImageRequestBuilder#build() . 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: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片到 View 上,可设置回调监听
 * @param draweeView
 * @param listener
 */
public void intoTarget(SimpleDraweeView draweeView, ControllerListener listener) {
    if ((mImageConfig != null && mImageConfig.useNewHierarchy) || !draweeView.hasHierarchy()) {
        GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder
                .newInstance(draweeView.getResources()).build();
        draweeView.setHierarchy(hierarchy);
    }
    parseImageConfig(draweeView.getHierarchy());
    if (mUri != null) {
        ImageDecodeOptions imageDecodeOptions = ImageDecodeOptions.newBuilder()
                .setDecodePreviewFrame(true)
                .build();
        ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
                .setProgressiveRenderingEnabled(true)
                .setImageDecodeOptions(imageDecodeOptions);
        if (mWidth > 0 && mHeight > 0) {
            builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
        } else {
            int width = draweeView.getMeasuredWidth();
            int height = draweeView.getMeasuredHeight();
            if(width > 0 && height > 0){
                builder.setResizeOptions(new ResizeOptions(width, height));
            }
        }

        ImageRequest request = builder.build();
        AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setControllerListener(listener)
                .setOldController(draweeView.getController())
                .setAutoPlayAnimations(true)
                .build();
        draweeView.setController(controller);
    } else {
        draweeView.setImageURI("");
    }
}
 
Example 2
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片获取 Bitmap 对象
 * @param subscriber
 */
public void intoTarget(BaseBitmapDataSubscriber subscriber) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
            .setProgressiveRenderingEnabled(true);

    if (mWidth > 0 && mHeight > 0) {
        builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
    }

    ImageRequest imageRequest = builder.build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example 3
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 4
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
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 5
Source File: ImagePipelineUtilsImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Nullable
public ImageRequest buildImageRequest(@Nullable Uri uri, DecodedImageOptions imageOptions) {
  if (uri == null) {
    return null;
  }
  final ImageRequestBuilder imageRequestBuilder =
      createEncodedImageRequestBuilder(uri, imageOptions);
  ImageRequestBuilder builder =
      createDecodedImageRequestBuilder(imageRequestBuilder, imageOptions);
  return builder != null ? builder.build() : null;
}
 
Example 6
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 7
Source File: ImagePipelineUtilsImpl.java    From fresco with MIT License 5 votes vote down vote up
@Override
@Nullable
public ImageRequest buildEncodedImageRequest(
    @Nullable Uri uri, EncodedImageOptions imageOptions) {
  ImageRequestBuilder builder = createEncodedImageRequestBuilder(uri, imageOptions);
  return builder != null ? builder.build() : null;
}
 
Example 8
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 9
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();
}