Java Code Examples for com.facebook.drawee.generic.GenericDraweeHierarchyBuilder#setRoundingParams()

The following examples show how to use com.facebook.drawee.generic.GenericDraweeHierarchyBuilder#setRoundingParams() . 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: DraweeUtil.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Creates the Hierarchy using the information into the Config
 *
 * @param context The Context
 * @param config The Config object
 * @return The Hierarchy to use
 */
public static GenericDraweeHierarchy createDraweeHierarchy(
    final Context context, final Config config) {
  FrescoSystrace.beginSection("DraweeUtil#createDraweeHierarchy");
  GenericDraweeHierarchyBuilder builder =
      new GenericDraweeHierarchyBuilder(context.getResources())
          .setFadeDuration(config.fadeDurationMs)
          .setPlaceholderImage(Const.PLACEHOLDER)
          .setFailureImage(Const.FAILURE)
          .setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER);
  applyScaleType(builder, config);

  if (config.useRoundedCorners || config.drawBorder) {
    final Resources res = context.getResources();
    final RoundingParams roundingParams = new RoundingParams();

    if (config.useRoundedCorners) {
      roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY);
      roundingParams.setCornersRadius(res.getDimensionPixelSize(R.dimen.drawee_corner_radius));
      roundingParams.setRoundAsCircle(config.useRoundedAsCircle);
    }

    if (config.drawBorder) {
      //noinspection deprecation
      roundingParams.setBorderColor(res.getColor(R.color.colorPrimary));
      roundingParams.setBorderWidth(res.getDimensionPixelSize(R.dimen.drawee_border_width));
    }

    builder.setRoundingParams(roundingParams);
  }
  GenericDraweeHierarchy result = builder.build();
  FrescoSystrace.endSection();
  return result;
}
 
Example 2
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);
}