use of com.facebook.drawee.drawable.RoundedNinePatchDrawable in project fresco by facebook.
the class WrappingUtils method applyLeafRounding.
/**
* 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(), roundingParams.getRepeatEdgePixels());
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) {
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;
}
use of com.facebook.drawee.drawable.RoundedNinePatchDrawable in project fresco by facebook.
the class RoundingUtilsTest method testRoundedDrawablesWithBorder_withDrawable_thenReturnBitmapDrawable.
@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();
}
use of com.facebook.drawee.drawable.RoundedNinePatchDrawable in project fresco by facebook.
the class RoundingUtilsTest method testRoundedDrawablesWithoutBorder_withDrawable_thenReturnBitmapDrawable.
@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();
}
Aggregations