Search in sources :

Example 6 with ImageOptions

use of com.facebook.fresco.vito.options.ImageOptions in project fresco by facebook.

the class HierarcherImplTest method testBuildErrorDrawable_whenNoScaleTypeSet_thenUseDefaultScaleType.

@Test
public void testBuildErrorDrawable_whenNoScaleTypeSet_thenUseDefaultScaleType() {
    ImageOptions options = ImageOptions.create().errorRes(RES_ID).build();
    Drawable errorDrawable = mHierarcher.buildErrorDrawable(mResources, options);
    assertThat(errorDrawable).isNotNull();
    assertThat(errorDrawable).isInstanceOf(ScaleTypeDrawable.class);
    ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) errorDrawable;
    assertThat(scaleTypeDrawable.getScaleType()).isEqualTo(ImageOptions.defaults().getErrorScaleType());
    assertThat(scaleTypeDrawable.getFocusPoint()).isEqualTo(ImageOptions.defaults().getErrorFocusPoint());
    assertThat(scaleTypeDrawable.getCurrent()).isEqualTo(mDrawable);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Test(org.junit.Test)

Example 7 with ImageOptions

use of com.facebook.fresco.vito.options.ImageOptions in project fresco by facebook.

the class HierarcherImplTest method testBuildProgressDrawable.

@Test
public void testBuildProgressDrawable() {
    final Drawable drawable = new ColorDrawable(0x0);
    final ImageOptions imageOptions = ImageOptions.create().progress(drawable).progressScaleType(ScalingUtils.ScaleType.FIT_CENTER).build();
    final Drawable actual = mHierarcher.buildProgressDrawable(mResources, imageOptions);
    assertThat(actual).isInstanceOf(ScaleTypeDrawable.class);
    final ScaleTypeDrawable scaleTypeActual = (ScaleTypeDrawable) actual;
    assertThat(scaleTypeActual.getScaleType()).isEqualTo(ScalingUtils.ScaleType.FIT_CENTER);
    assertThat(scaleTypeActual.getCurrent()).isEqualTo(drawable);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Test(org.junit.Test)

Example 8 with ImageOptions

use of com.facebook.fresco.vito.options.ImageOptions in project fresco by facebook.

the class HierarcherImplTest method testApplyRoundingOptions_whenRoundWithCornerRadius_thenReturnDrawable.

@Test
public void testApplyRoundingOptions_whenRoundWithCornerRadius_thenReturnDrawable() {
    final BitmapDrawable drawable = mock(BitmapDrawable.class);
    final Bitmap bitmap = mock(Bitmap.class);
    when(drawable.getBitmap()).thenReturn(bitmap);
    ImageOptions options = mock(ImageOptions.class);
    when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadiusPx(123));
    when(options.getPlaceholderDrawable()).thenReturn(drawable);
    when(options.getPlaceholderApplyRoundingOptions()).thenReturn(true);
    Drawable result = mHierarcher.buildPlaceholderDrawable(mResources, options);
    assertThat(result).isNotNull();
    assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
    assertThat(((RoundedBitmapDrawable) result).getRadii()).isEqualTo(new float[] { 123, 123, 123, 123, 123, 123, 123, 123 });
}
Also used : RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) Test(org.junit.Test)

Example 9 with ImageOptions

use of com.facebook.fresco.vito.options.ImageOptions in project fresco by facebook.

the class HierarcherImplTest method testApplyRoundingOptions_whenRoundWithCornerRadii_thenReturnDrawable.

@Test
public void testApplyRoundingOptions_whenRoundWithCornerRadii_thenReturnDrawable() {
    final BitmapDrawable drawable = mock(BitmapDrawable.class);
    final Bitmap bitmap = mock(Bitmap.class);
    when(drawable.getBitmap()).thenReturn(bitmap);
    ImageOptions options = mock(ImageOptions.class);
    when(options.getRoundingOptions()).thenReturn(RoundingOptions.forCornerRadii(1, 2, 3, 4));
    when(options.getPlaceholderDrawable()).thenReturn(drawable);
    when(options.getPlaceholderApplyRoundingOptions()).thenReturn(true);
    Drawable result = mHierarcher.buildPlaceholderDrawable(mResources, options);
    assertThat(result).isNotNull();
    assertThat(result).isInstanceOf(RoundedBitmapDrawable.class);
    assertThat(((RoundedBitmapDrawable) result).getRadii()).isEqualTo(new float[] { 1, 1, 2, 2, 3, 3, 4, 4 });
}
Also used : RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ImageOptions(com.facebook.fresco.vito.options.ImageOptions) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) Test(org.junit.Test)

Example 10 with ImageOptions

use of com.facebook.fresco.vito.options.ImageOptions in project fresco by facebook.

the class HierarcherImplTest method testBuildErrorDrawable_whenInvalidResId_thenThrowNotFoundException.

@Test(expected = Resources.NotFoundException.class)
public void testBuildErrorDrawable_whenInvalidResId_thenThrowNotFoundException() {
    ImageOptions options = ImageOptions.create().errorRes(INVALID_RES_ID).build();
    mHierarcher.buildErrorDrawable(mResources, options);
}
Also used : ImageOptions(com.facebook.fresco.vito.options.ImageOptions) Test(org.junit.Test)

Aggregations

ImageOptions (com.facebook.fresco.vito.options.ImageOptions)32 Test (org.junit.Test)32 BitmapDrawable (android.graphics.drawable.BitmapDrawable)21 Drawable (android.graphics.drawable.Drawable)21 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)21 ColorDrawable (android.graphics.drawable.ColorDrawable)14 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)14 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)14 Bitmap (android.graphics.Bitmap)8 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)7 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)6 ImageDecodeOptions (com.facebook.imagepipeline.common.ImageDecodeOptions)4 Resources (android.content.res.Resources)2 PointF (android.graphics.PointF)2 ImageSource (com.facebook.fresco.vito.source.ImageSource)2 BorderOptions (com.facebook.fresco.vito.options.BorderOptions)1 ImageOptionsDrawableFactory (com.facebook.fresco.vito.options.ImageOptionsDrawableFactory)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 RotationOptions (com.facebook.imagepipeline.common.RotationOptions)1 CloseableImage (com.facebook.imagepipeline.image.CloseableImage)1