com.facebook.drawee.drawable.RoundedColorDrawable Java Examples

The following examples show how to use com.facebook.drawee.drawable.RoundedColorDrawable. 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: HierarcherImplTest.java    From fresco with MIT License 6 votes vote down vote up
@Test
public void testApplyRoundingOptions_whenRoundAsCircle_thenReturnDrawable() {
  final Drawable drawable = new ColorDrawable(Color.YELLOW);
  when(mResources.getDrawable(RES_ID)).thenReturn(drawable);

  ImageOptions options = mock(ImageOptions.class);
  when(options.getRoundingOptions()).thenReturn(RoundingOptions.asCircle());
  when(options.getPlaceholderDrawable()).thenReturn(drawable);
  when(options.getPlaceholderApplyRoundingOptions()).thenReturn(true);

  Drawable result = mHierarcher.buildPlaceholderDrawable(mResources, options);

  assertThat(result).isExactlyInstanceOf(RoundedColorDrawable.class);

  when(options.getPlaceholderDrawable()).thenReturn(null);
  when(options.getPlaceholderRes()).thenReturn(RES_ID);

  result = mHierarcher.buildPlaceholderDrawable(mResources, options);

  assertThat(result).isExactlyInstanceOf(RoundedColorDrawable.class);
}
 
Example #2
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void setBackgroundColor(int backgroundColor) {
  if(mBackgroundColor != backgroundColor) {
    mBackgroundColor = backgroundColor;
    mBackgroundImageDrawable = new RoundedColorDrawable(backgroundColor);
    mIsDirty = true;
  }
}
 
Example #3
Source File: GenericDraweeHierarchy.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private static Drawable maybeApplyRounding(
    @Nullable RoundingParams roundingParams,
    Resources resources,
    Drawable drawable) {
  if (roundingParams != null &&
      roundingParams.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) {
    if (drawable instanceof BitmapDrawable) {
      RoundedBitmapDrawable roundedBitmapDrawable =
          RoundedBitmapDrawable.fromBitmapDrawable(resources, (BitmapDrawable) drawable);
      roundedBitmapDrawable.setCircle(roundingParams.getRoundAsCircle());
      roundedBitmapDrawable.setCornerRadii(roundingParams.getCornersRadii());
      roundedBitmapDrawable.setBorder(
          roundingParams.getBorderColor(),
          roundingParams.getBorderWidth());
      return roundedBitmapDrawable;
    }
    if (drawable instanceof ColorDrawable &&
        Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      RoundedColorDrawable roundedColorDrawable =
          RoundedColorDrawable.fromColorDrawable((ColorDrawable) drawable);
      roundedColorDrawable.setCircle(roundingParams.getRoundAsCircle());
      roundedColorDrawable.setRadii(roundingParams.getCornersRadii());
      roundedColorDrawable.setBorder(
          roundingParams.getBorderColor(),
          roundingParams.getBorderWidth());
      return roundedColorDrawable;
    }
  }
  return drawable;
}
 
Example #4
Source File: RoundingUtils.java    From fresco with MIT License 5 votes vote down vote up
private <T extends Drawable & Rounded> T getRoundedDrawable(
    Resources resources, Drawable drawable) {
  T roundingDrawable;
  if (drawable instanceof BitmapDrawable) {
    roundingDrawable = getRoundedDrawable(resources, ((BitmapDrawable) drawable).getBitmap());
  } else if (drawable instanceof NinePatchDrawable) {
    roundingDrawable = (T) new RoundedNinePatchDrawable((NinePatchDrawable) drawable);
  } else if (drawable instanceof ColorDrawable) {
    roundingDrawable = (T) RoundedColorDrawable.fromColorDrawable((ColorDrawable) drawable);
  } else {
    throw new UnsupportedOperationException(
        "Rounding of the drawable type not supported: " + drawable);
  }
  return roundingDrawable;
}
 
Example #5
Source File: RoundingUtilsTest.java    From fresco with MIT License 5 votes vote down vote up
@Test
public void testRoundedDrawablesWithoutBorder_withDrawable_thenReturnBitmapDrawable() {
  RoundingUtils roundingUtils = new RoundingUtils();
  RoundingOptions roundingOptions = RoundingOptions.asCircle();
  Drawable drawable = mock(BitmapDrawable.class);

  Drawable result = roundingUtils.roundedDrawable(mResources, drawable, null, roundingOptions);

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
  assertThat(((RoundedBitmapDrawable) result).isCircle()).isTrue();

  drawable = mock(ColorDrawable.class);

  result = roundingUtils.roundedDrawable(mResources, drawable, null, roundingOptions);

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedColorDrawable.class);
  assertThat(((RoundedColorDrawable) result).isCircle()).isTrue();

  drawable = mock(NinePatchDrawable.class);

  result = roundingUtils.roundedDrawable(mResources, drawable, null, roundingOptions);

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedNinePatchDrawable.class);
  assertThat(((RoundedNinePatchDrawable) result).isCircle()).isTrue();
}
 
Example #6
Source File: WrappingUtils.java    From fresco with MIT License 5 votes vote down vote up
/**
 * Rounds the given drawable with a {@link RoundedBitmapDrawable} or {@link RoundedColorDrawable}.
 *
 * <p>If the given drawable is not a {@link BitmapDrawable} or a {@link ColorDrawable}, it is
 * returned without being rounded.
 *
 * @return the rounded drawable, or the original drawable if rounding didn't take place
 */
private static Drawable applyLeafRounding(
    Drawable drawable, RoundingParams roundingParams, Resources resources) {
  if (drawable instanceof BitmapDrawable) {
    final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    RoundedBitmapDrawable roundedBitmapDrawable =
        new RoundedBitmapDrawable(
            resources, bitmapDrawable.getBitmap(), bitmapDrawable.getPaint());
    applyRoundingParams(roundedBitmapDrawable, roundingParams);
    return roundedBitmapDrawable;
  } else if (drawable instanceof NinePatchDrawable) {
    final NinePatchDrawable ninePatchDrawableDrawable = (NinePatchDrawable) drawable;
    RoundedNinePatchDrawable roundedNinePatchDrawable =
        new RoundedNinePatchDrawable(ninePatchDrawableDrawable);
    applyRoundingParams(roundedNinePatchDrawable, roundingParams);
    return roundedNinePatchDrawable;
  } else if (drawable instanceof ColorDrawable
      && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    RoundedColorDrawable roundedColorDrawable =
        RoundedColorDrawable.fromColorDrawable((ColorDrawable) drawable);
    applyRoundingParams(roundedColorDrawable, roundingParams);
    return roundedColorDrawable;
  } else {
    FLog.w(TAG, "Don't know how to round that drawable: %s", drawable);
  }
  return drawable;
}
 
Example #7
Source File: RoundingUtilsTest.java    From fresco with MIT License 4 votes vote down vote up
@Test
public void testRoundedDrawablesWithBorder_withDrawable_thenReturnBitmapDrawable() {
  RoundingUtils roundingUtils = new RoundingUtils();
  Drawable drawable = mock(BitmapDrawable.class);
  RoundingOptions roundingOptions = RoundingOptions.asCircle();
  BorderOptions borderOptions = BorderOptions.create(Color.YELLOW, 10);

  Drawable result =
      roundingUtils.roundedDrawable(
          mResources, drawable, borderOptions, RoundingOptions.asCircle());

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
  assertThat(((RoundedBitmapDrawable) result).getBorderWidth()).isEqualTo(borderOptions.width);
  assertThat(((RoundedBitmapDrawable) result).getBorderColor()).isEqualTo(borderOptions.color);
  assertThat(((RoundedBitmapDrawable) result).isCircle()).isTrue();

  drawable = mock(ColorDrawable.class);

  result =
      roundingUtils.roundedDrawable(
          mResources, drawable, borderOptions, RoundingOptions.asCircle());

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedColorDrawable.class);
  assertThat(((RoundedColorDrawable) result).getBorderWidth()).isEqualTo(borderOptions.width);
  assertThat(((RoundedColorDrawable) result).getBorderColor()).isEqualTo(borderOptions.color);
  assertThat(((RoundedColorDrawable) result).isCircle()).isTrue();

  drawable = mock(NinePatchDrawable.class);

  result =
      roundingUtils.roundedDrawable(
          mResources, drawable, borderOptions, RoundingOptions.asCircle());

  assertThat(result).isNotNull();
  assertThat(result).isInstanceOf(RoundedNinePatchDrawable.class);
  assertThat(((RoundedNinePatchDrawable) result).getBorderWidth()).isEqualTo(borderOptions.width);
  assertThat(((RoundedNinePatchDrawable) result).getBorderColor()).isEqualTo(borderOptions.color);
  assertThat(((RoundedNinePatchDrawable) result).isCircle()).isTrue();
}