Search in sources :

Example 1 with BorderOptions

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);
}
Also used : RoundingOptions(com.facebook.fresco.vito.options.RoundingOptions) BorderOptions(com.facebook.fresco.vito.options.BorderOptions)

Example 2 with BorderOptions

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();
}
Also used : RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) BorderOptions(com.facebook.fresco.vito.options.BorderOptions) Test(org.junit.Test)

Example 3 with BorderOptions

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);
}
Also used : RoundingOptions(com.facebook.fresco.vito.options.RoundingOptions) OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BorderOptions(com.facebook.fresco.vito.options.BorderOptions) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 4 with BorderOptions

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();
}
Also used : RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) RoundingOptions(com.facebook.fresco.vito.options.RoundingOptions) ColorDrawable(android.graphics.drawable.ColorDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) BorderOptions(com.facebook.fresco.vito.options.BorderOptions) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) Test(org.junit.Test)

Example 5 with BorderOptions

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);
}
Also used : Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) BorderOptions(com.facebook.fresco.vito.options.BorderOptions) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) Test(org.junit.Test)

Aggregations

BorderOptions (com.facebook.fresco.vito.options.BorderOptions)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 Drawable (android.graphics.drawable.Drawable)4 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)3 RoundingOptions (com.facebook.fresco.vito.options.RoundingOptions)3 Test (org.junit.Test)3 Bitmap (android.graphics.Bitmap)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)2 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)2 RoundedNinePatchDrawable (com.facebook.drawee.drawable.RoundedNinePatchDrawable)2 OrientedDrawable (com.facebook.drawee.drawable.OrientedDrawable)1 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)1 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)1