Search in sources :

Example 6 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testSetRoundingParams_ToNoneFrom.

private void testSetRoundingParams_ToNoneFrom(RoundingParams prev) {
    RoundingParams roundingParams = null;
    GenericDraweeHierarchy dh = testRoundingParams_createHierarchy(prev, roundingParams);
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
    if (prev != null && prev.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) {
        // Rounded leafs remain rounded, but with reset params, so no leaf rounding actually occurs
        testRoundingParams_RoundedLeafs(rootDrawable, fadeDrawable, roundingParams);
    } else {
        testRoundingParams_NoRoundedLeafs(rootDrawable, fadeDrawable);
    }
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable)

Example 7 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testSetRoundingParams_ToOverlayFrom.

private void testSetRoundingParams_ToOverlayFrom(RoundingParams prev) {
    RoundingParams roundingParams = RoundingParams.fromCornersRadius(7).setOverlayColor(0xFFFFFFFF).setBorder(0x12345678, 5).setPadding(10);
    GenericDraweeHierarchy dh = testRoundingParams_createHierarchy(prev, roundingParams);
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    RoundedCornersDrawable roundedDrawable = (RoundedCornersDrawable) rootDrawable.getCurrent();
    assertRoundingParams(roundingParams, roundedDrawable);
    assertEquals(roundingParams.getOverlayColor(), roundedDrawable.getOverlayColor());
    FadeDrawable fadeDrawable = (FadeDrawable) roundedDrawable.getCurrent();
    if (prev != null && prev.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) {
        // Rounded leafs remain rounded, but with reset params, so no leaf rounding actually occurs
        testRoundingParams_RoundedLeafs(rootDrawable, fadeDrawable, null);
    } else {
        testRoundingParams_NoRoundedLeafs(rootDrawable, fadeDrawable);
    }
}
Also used : RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable)

Example 8 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testControlling_WithCornerRadii.

@Test
public void testControlling_WithCornerRadii() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, null).setActualImageScaleType(null).setRoundingParams(RoundingParams.fromCornersRadius(10)).setFadeDuration(250).build();
    // actual image index in DH tree
    final int imageIndex = 2;
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    ForwardingDrawable settableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(imageIndex);
    // set temporary image
    dh.setImage(mActualImage1, 0.5f, true);
    assertNotSame(mActualImage1, settableDrawable.getCurrent());
    assertEquals(RoundedBitmapDrawable.class, settableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(imageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    verifyCallback(dh.getTopLevelDrawable(), settableDrawable.getCurrent());
    // set final image
    dh.setImage(mActualImage2, 1f, false);
    assertNotSame(mActualImage2, settableDrawable.getCurrent());
    assertEquals(RoundedBitmapDrawable.class, settableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(imageIndex));
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    verifyCallback(dh.getTopLevelDrawable(), settableDrawable.getCurrent());
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) Test(org.junit.Test)

Example 9 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testHierarchy_WithRoundedLeafs.

@Test
public void testHierarchy_WithRoundedLeafs() throws Exception {
    RoundingParams roundingParams = RoundingParams.asCircle();
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mWrappedImage, ScaleType.CENTER).setFailureImage(mFailureImage, ScaleType.CENTER).setRetryImage(mRetryImage, null).setRoundingParams(roundingParams).build();
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
    assertNotNull(fadeDrawable);
    assertScaleTypeAndDrawable(mWrappedImage, ScaleType.CENTER, fadeDrawable.getDrawable(1));
    Rounded roundedPlaceholder = (Rounded) mWrappedImage.getCurrent().getCurrent();
    assertRoundingParams(roundingParams, roundedPlaceholder);
    Rounded roundedFailureImage = (Rounded) fadeDrawable.getDrawable(5).getCurrent();
    assertRoundingParams(roundingParams, roundedFailureImage);
    Rounded roundedRetryImage = (Rounded) fadeDrawable.getDrawable(4);
    assertRoundingParams(roundingParams, roundedRetryImage);
    verifyCallback(rootDrawable, mWrappedImage.getCurrent().getCurrent());
    verifyCallback(rootDrawable, (Drawable) roundedFailureImage);
    verifyCallback(rootDrawable, (Drawable) roundedRetryImage);
}
Also used : Rounded(com.facebook.drawee.drawable.Rounded) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Test(org.junit.Test)

Example 10 with FadeDrawable

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

the class GenericDraweeHierarchyTest method testHierarchy_WithBackgroundAndMultipleOverlays.

@Test
public void testHierarchy_WithBackgroundAndMultipleOverlays() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, ScaleType.CENTER).setRetryImage(mRetryImage, ScaleType.FIT_CENTER).setFailureImage(mFailureImage, ScaleType.FIT_CENTER).setProgressBarImage(mProgressBarImage, ScaleType.CENTER).setActualImageScaleType(ScaleType.CENTER_CROP).setBackground(mBackground).setOverlays(Arrays.asList(mOverlay1, mOverlay2)).build();
    RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
    FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
    assertEquals(8, fadeDrawable.getNumberOfLayers());
    assertSame(mBackground, fadeDrawable.getDrawable(0));
    assertScaleTypeAndDrawable(mPlaceholderImage, ScaleType.CENTER, fadeDrawable.getDrawable(1));
    assertActualImageScaleType(ScaleType.CENTER_CROP, null, fadeDrawable.getDrawable(2));
    assertScaleTypeAndDrawable(mProgressBarImage, ScaleType.CENTER, fadeDrawable.getDrawable(3));
    assertScaleTypeAndDrawable(mRetryImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(4));
    assertScaleTypeAndDrawable(mFailureImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(5));
    assertSame(mOverlay1, fadeDrawable.getDrawable(6));
    assertSame(mOverlay2, fadeDrawable.getDrawable(7));
    verifyCallback(rootDrawable, mBackground);
    verifyCallback(rootDrawable, mPlaceholderImage);
    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