use of com.facebook.fresco.vito.options.BorderOptions 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.BorderOptions 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.fresco.vito.options.BorderOptions 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.BorderOptions 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.BorderOptions in project fresco by facebook.
the class BitmapDrawableFactoryTest method testCreateDrawable_whenAlreadyRoundedWithBorder_thenReturnBitmapDrawable.
@Test
public void testCreateDrawable_whenAlreadyRoundedWithBorder_thenReturnBitmapDrawable() {
final CloseableStaticBitmap closeableImage = mock(CloseableStaticBitmap.class);
final Bitmap bitmap = mock(Bitmap.class);
when(closeableImage.getUnderlyingBitmap()).thenReturn(bitmap);
when(closeableImage.getExtras()).thenReturn(mImageExtrasRounded);
final ImageOptions options = mock(ImageOptions.class);
BorderOptions borderOptions = BorderOptions.create(Color.YELLOW, 10);
when(options.getBorderOptions()).thenReturn(borderOptions);
when(options.getRoundingOptions()).thenReturn(RoundingOptions.asCircle(false, false));
Drawable drawable = mDrawableFactory.createDrawable(closeableImage, options);
assertThat(drawable).isNotNull();
assertThat(drawable).isInstanceOf(CircularBorderBitmapDrawable.class);
assertThat(((CircularBorderBitmapDrawable) drawable).getBorder()).isEqualTo(borderOptions);
}
Aggregations