Search in sources :

Example 6 with RoundedBitmapDrawable

use of com.facebook.drawee.drawable.RoundedBitmapDrawable in project fresco by facebook.

the class RoundingUtilsTest method testRoundedDrawablesWithoutBorder_withBitmap_withNotAlreadyRounded_thenReturnBitmapDrawable.

@Test
public void testRoundedDrawablesWithoutBorder_withBitmap_withNotAlreadyRounded_thenReturnBitmapDrawable() {
    RoundingUtils roundingUtils = new RoundingUtils();
    final Bitmap bitmap = mock(Bitmap.class);
    Drawable drawable = roundingUtils.roundedDrawable(mResources, bitmap, null, RoundingOptions.asCircle());
    assertThat(drawable).isNotNull();
    assertThat(drawable).isInstanceOf(RoundedBitmapDrawable.class);
    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) Test(org.junit.Test)

Example 7 with RoundedBitmapDrawable

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

use of com.facebook.drawee.drawable.RoundedBitmapDrawable in project fresco by facebook.

the class BitmapDrawableFactoryTest method testCreateDrawable_whenRoundWithCornerRadii_thenReturnBitmapDrawable.

@Test
public void testCreateDrawable_whenRoundWithCornerRadii_thenReturnBitmapDrawable() {
    final CloseableStaticBitmap closeableImage = mock(CloseableStaticBitmap.class);
    final Bitmap bitmap = mock(Bitmap.class);
    when(closeableImage.getUnderlyingBitmap()).thenReturn(bitmap);
    final ImageOptions options = mock(ImageOptions.class);
    when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadii(1, 2, 3, 4));
    when(closeableImage.getExtras()).thenReturn(mImageExtrasNotRounded);
    Drawable drawable = mDrawableFactory.createDrawable(closeableImage, options);
    assertThat(drawable).isNotNull();
    assertThat(drawable).isInstanceOf(RoundedBitmapDrawable.class);
    assertThat(((RoundedBitmapDrawable) drawable).getRadii()).isEqualTo(new float[] { 1, 1, 2, 2, 3, 3, 4, 4 });
}
Also used : RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) 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) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) Test(org.junit.Test)

Example 9 with RoundedBitmapDrawable

use of com.facebook.drawee.drawable.RoundedBitmapDrawable 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)9 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)9 Drawable (android.graphics.drawable.Drawable)8 Test (org.junit.Test)8 ColorDrawable (android.graphics.drawable.ColorDrawable)7 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)7 Bitmap (android.graphics.Bitmap)6 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)5 RoundedNinePatchDrawable (com.facebook.drawee.drawable.RoundedNinePatchDrawable)5 ImageOptions (com.facebook.fresco.vito.options.ImageOptions)4 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)2 BorderOptions (com.facebook.fresco.vito.options.BorderOptions)2 RoundingOptions (com.facebook.fresco.vito.options.RoundingOptions)2 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)2