Search in sources :

Example 21 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testHierarchy_WithRoundedOverlayColor.

@Test
public void testHierarchy_WithRoundedOverlayColor() throws Exception {
    RoundingParams roundingParams = RoundingParams.fromCornersRadius(10).setOverlayColor(0xFFFFFFFF);
    GenericDraweeHierarchy dh = mBuilder.setRoundingParams(roundingParams).build();
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    RoundedCornersDrawable roundedDrawable = (RoundedCornersDrawable) rootDrawable.getCurrent();
    assertRoundingParams(roundingParams, roundedDrawable);
    assertEquals(roundingParams.getOverlayColor(), roundedDrawable.getOverlayColor());
    FadeDrawable fadeDrawable = (FadeDrawable) roundedDrawable.getCurrent();
    assertNotNull(fadeDrawable);
    verifyCallback(rootDrawable, fadeDrawable);
}
Also used : RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Test(org.junit.Test)

Example 22 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testSetActualImageScaleType.

@Test
public void testSetActualImageScaleType() {
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage).build();
    // actual image index in DH tree
    final int imageIndex = 2;
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) fadeDrawable.getDrawable(imageIndex);
    ScaleType scaleType1 = ScaleType.FOCUS_CROP;
    dh.setActualImageScaleType(scaleType1);
    assertEquals(scaleType1, scaleTypeDrawable.getScaleType());
    ScaleType scaleType2 = ScaleType.CENTER;
    dh.setActualImageScaleType(scaleType2);
    assertEquals(scaleType2, scaleTypeDrawable.getScaleType());
}
Also used : ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Test(org.junit.Test)

Example 23 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testHierarchy_WithRetryImage.

@Test
public void testHierarchy_WithRetryImage() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setRetryImage(mRetryImage, ScaleType.CENTER).build();
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
    assertScaleTypeAndDrawable(mRetryImage, ScaleType.CENTER, fadeDrawable.getDrawable(4));
    verifyCallback(rootDrawable, mRetryImage);
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Test(org.junit.Test)

Example 24 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testSetDrawable.

private void testSetDrawable(GenericDraweeHierarchy dh, int index, SetDrawableCallback callback) {
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    // null
    callback.setDrawable(null);
    assertNull(fadeDrawable.getDrawable(index));
    // null -> null
    callback.setDrawable(null);
    assertNull(fadeDrawable.getDrawable(index));
    // null -> drawable
    Drawable drawable1 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable1);
    assertSame(drawable1, fadeDrawable.getDrawable(index));
    // drawable -> drawable
    Drawable drawable2 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable2);
    assertSame(drawable2, fadeDrawable.getDrawable(index));
    // drawable -> null
    callback.setDrawable(null);
    assertNull(fadeDrawable.getDrawable(index));
    // null -> scaletype + drawable
    Drawable drawable3 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable3, ScaleType.FOCUS_CROP);
    assertScaleTypeAndDrawable(drawable3, ScaleType.FOCUS_CROP, fadeDrawable.getDrawable(index));
    // scaletype + drawable -> scaletype + drawable
    Drawable drawable4 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable4, ScaleType.CENTER);
    assertScaleTypeAndDrawable(drawable4, ScaleType.CENTER, fadeDrawable.getDrawable(index));
    // scaletype + drawable -> null
    callback.setDrawable(null);
    assertNull(fadeDrawable.getDrawable(index));
    // drawable -> scaletype + drawable
    callback.setDrawable(drawable1);
    Drawable drawable5 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable5, ScaleType.FIT_CENTER);
    assertScaleTypeAndDrawable(drawable5, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(index));
    // scaletype + drawable -> drawable (kep the old scaletype)
    Drawable drawable6 = DrawableTestUtils.mockDrawable();
    callback.setDrawable(drawable6);
    assertScaleTypeAndDrawable(drawable6, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(index));
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable)

Example 25 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testHierarchy_WithBackgroundAndSingleOverlay.

@Test
public void testHierarchy_WithBackgroundAndSingleOverlay() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setBackground(mBackground).setOverlay(mOverlay2).build();
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
    assertEquals(7, fadeDrawable.getNumberOfLayers());
    assertSame(mBackground, fadeDrawable.getDrawable(0));
    assertSame(mOverlay2, fadeDrawable.getDrawable(6));
    verifyCallback(rootDrawable, mBackground);
    verifyCallback(rootDrawable, mOverlay2);
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Test(org.junit.Test)

Aggregations

FadeDrawable (com.facebook.drawee.drawable.FadeDrawable)26 Test (org.junit.Test)22 ForwardingDrawable (com.facebook.drawee.drawable.ForwardingDrawable)4 RoundedCornersDrawable (com.facebook.drawee.drawable.RoundedCornersDrawable)3 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)3 StateListDrawable (android.graphics.drawable.StateListDrawable)2 PointF (android.graphics.PointF)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 MatrixDrawable (com.facebook.drawee.drawable.MatrixDrawable)1 Rounded (com.facebook.drawee.drawable.Rounded)1 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)1 ScaleType (com.facebook.drawee.drawable.ScalingUtils.ScaleType)1