Search in sources :

Example 1 with RoundingOptions

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

Example 2 with 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);
}
Also used : RoundingOptions(com.facebook.fresco.vito.options.RoundingOptions) 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) Test(org.junit.Test)

Example 3 with 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);
}
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 RoundingOptions

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();
}
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 RoundingOptions

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();
}
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) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) Test(org.junit.Test)

Aggregations

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