use of com.facebook.drawee.drawable.RoundedBitmapDrawable 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.RoundedBitmapDrawable in project fresco by facebook.
the class BitmapDrawableFactoryTest method testCreateDrawable_whenRoundWithCornerRadius_thenReturnBitmapDrawable.
@Test
public void testCreateDrawable_whenRoundWithCornerRadius_thenReturnBitmapDrawable() {
final CloseableStaticBitmap closeableImage = mock(CloseableStaticBitmap.class);
final Bitmap bitmap = mock(Bitmap.class);
when(closeableImage.getUnderlyingBitmap()).thenReturn(bitmap);
final ImageOptions options = mock(ImageOptions.class);
when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadiusPx(123));
when(closeableImage.getExtras()).thenReturn(mImageExtrasNotRounded);
Drawable drawable = mDrawableFactory.createDrawable(closeableImage, options);
assertThat(drawable).isNotNull();
assertThat(drawable).isInstanceOf(RoundedBitmapDrawable.class);
assertThat(((RoundedBitmapDrawable) drawable).getRadii()).isEqualTo(new float[] { 123, 123, 123, 123, 123, 123, 123, 123 });
}
use of com.facebook.drawee.drawable.RoundedBitmapDrawable in project fresco by facebook.
the class RoundingUtilsTest method testRoundedDrawablesWithBorder_withBitmap_withNotAlreadyRounded_thenReturnBitmapDrawable.
@Test
public void testRoundedDrawablesWithBorder_withBitmap_withNotAlreadyRounded_thenReturnBitmapDrawable() {
RoundingUtils roundingUtils = new RoundingUtils();
final Bitmap bitmap = mock(Bitmap.class);
BorderOptions borderOptions = BorderOptions.create(Color.YELLOW, 10);
Drawable drawable = roundingUtils.roundedDrawable(mResources, bitmap, borderOptions, RoundingOptions.asCircle());
assertThat(drawable).isNotNull();
assertThat(drawable).isInstanceOf(RoundedBitmapDrawable.class);
assertThat(((RoundedBitmapDrawable) drawable).getBorderWidth()).isEqualTo(borderOptions.width);
assertThat(((RoundedBitmapDrawable) drawable).getBorderColor()).isEqualTo(borderOptions.color);
assertThat(((RoundedBitmapDrawable) drawable).isCircle()).isTrue();
}
use of com.facebook.drawee.drawable.RoundedBitmapDrawable in project fresco by facebook.
the class HierarcherImplTest method testApplyRoundingOptions_whenRoundWithCornerRadius_thenReturnDrawable.
@Test
public void testApplyRoundingOptions_whenRoundWithCornerRadius_thenReturnDrawable() {
final BitmapDrawable drawable = mock(BitmapDrawable.class);
final Bitmap bitmap = mock(Bitmap.class);
when(drawable.getBitmap()).thenReturn(bitmap);
ImageOptions options = mock(ImageOptions.class);
when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadiusPx(123));
when(options.getPlaceholderDrawable()).thenReturn(drawable);
when(options.getPlaceholderApplyRoundingOptions()).thenReturn(true);
Drawable result = mHierarcher.buildPlaceholderDrawable(mResources, options);
assertThat(result).isNotNull();
assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
assertThat(((RoundedBitmapDrawable) result).getRadii()).isEqualTo(new float[] { 123, 123, 123, 123, 123, 123, 123, 123 });
}
use of com.facebook.drawee.drawable.RoundedBitmapDrawable in project fresco by facebook.
the class HierarcherImplTest method testApplyRoundingOptions_whenRoundWithCornerRadii_thenReturnDrawable.
@Test
public void testApplyRoundingOptions_whenRoundWithCornerRadii_thenReturnDrawable() {
final BitmapDrawable drawable = mock(BitmapDrawable.class);
final Bitmap bitmap = mock(Bitmap.class);
when(drawable.getBitmap()).thenReturn(bitmap);
ImageOptions options = mock(ImageOptions.class);
when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadii(1, 2, 3, 4));
when(options.getPlaceholderDrawable()).thenReturn(drawable);
when(options.getPlaceholderApplyRoundingOptions()).thenReturn(true);
Drawable result = mHierarcher.buildPlaceholderDrawable(mResources, options);
assertThat(result).isNotNull();
assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
assertThat(((RoundedBitmapDrawable) result).getRadii()).isEqualTo(new float[] { 1, 1, 2, 2, 3, 3, 4, 4 });
}
Aggregations