Search in sources :

Example 1 with RoundedNinePatchDrawable

use of com.facebook.drawee.drawable.RoundedNinePatchDrawable 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;
}
Also used : RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) RoundedNinePatchDrawable(com.facebook.drawee.drawable.RoundedNinePatchDrawable)

Example 2 with RoundedNinePatchDrawable

use of com.facebook.drawee.drawable.RoundedNinePatchDrawable 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 3 with RoundedNinePatchDrawable

use of com.facebook.drawee.drawable.RoundedNinePatchDrawable 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

BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 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 Drawable (android.graphics.drawable.Drawable)2 RoundingOptions (com.facebook.fresco.vito.options.RoundingOptions)2 Test (org.junit.Test)2 BorderOptions (com.facebook.fresco.vito.options.BorderOptions)1