use of com.facebook.fresco.vito.options.RoundingOptions in project fresco by facebook.
the class HierarcherImpl method applyRoundingOptions.
protected Drawable applyRoundingOptions(Resources resources, Drawable placeholderDrawable, ImageOptions imageOptions) {
RoundingOptions roundingOptions = imageOptions.getRoundingOptions();
BorderOptions borderOptions = imageOptions.getBorderOptions();
return mRoundingUtils.roundedDrawable(resources, placeholderDrawable, borderOptions, roundingOptions);
}
use of com.facebook.fresco.vito.options.RoundingOptions in project fresco by facebook.
the class RoundingUtilsTest method testBuildOverlayDrawable_whenInvalidResId_thenThrowNotFoundException.
@Test(expected = UnsupportedOperationException.class)
public void testBuildOverlayDrawable_whenInvalidResId_thenThrowNotFoundException() {
RoundingUtils roundingUtils = new RoundingUtils();
Drawable drawable = mock(Drawable.class);
RoundingOptions roundingOptions = mock(RoundingOptions.class);
roundingUtils.roundedDrawable(mResources, drawable, null, roundingOptions);
}
use of com.facebook.fresco.vito.options.RoundingOptions in project fresco by facebook.
the class BitmapDrawableFactory method handleCloseableStaticBitmap.
/**
* We handle the given bitmap and return a Drawable ready for being displayed: If rounding is set,
* the image will be rounded, if a border if set, the border will be applied and finally, the
* image will be rotated if required.
*
* <p>Bitmap -> border -> rounded corners -> RoundedBitmapDrawable (since bitmap is square) ->
* fully circular -> CircularBorderBitmapDrawable (bitmap is circular) -> square image ->
* RoundedBitmapDrawable (for border support) -> no border -> rounded corners ->
* RoundedBitmapDrawable (since bitmap is square) -> fully circular -> BitmapDrawable (since
* bitmap is circular) -> square image -> BitmapDrawable
*
* <p>If needed, the resulting drawable is rotated using OrientedDrawable.
*
* @param closeableStaticBitmap the image to handle
* @param imageOptions display options for the given image
* @return the drawable to display
*/
protected Drawable handleCloseableStaticBitmap(CloseableStaticBitmap closeableStaticBitmap, ImageOptions imageOptions) {
RoundingOptions roundingOptions = imageOptions.getRoundingOptions();
BorderOptions borderOptions = imageOptions.getBorderOptions();
boolean isBitmapRounded = Boolean.TRUE.equals(closeableStaticBitmap.getExtras().get("is_rounded"));
Drawable drawable;
if (isBitmapRounded && roundingOptions != null && roundingOptions.isCircular()) {
if (borderOptions != null && borderOptions.width > 0) {
CircularBorderBitmapDrawable circularBorderDrawable = new CircularBorderBitmapDrawable(mResources, closeableStaticBitmap.getUnderlyingBitmap());
circularBorderDrawable.setBorder(borderOptions);
drawable = circularBorderDrawable;
} else {
drawable = new BitmapDrawable(mResources, closeableStaticBitmap.getUnderlyingBitmap());
}
} else {
drawable = mRoundingUtils.roundedDrawable(mResources, closeableStaticBitmap.getUnderlyingBitmap(), borderOptions, roundingOptions);
}
return rotatedDrawable(closeableStaticBitmap, drawable);
}
use of com.facebook.fresco.vito.options.RoundingOptions 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.fresco.vito.options.RoundingOptions 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