Search in sources :

Example 1 with ForwardingDrawable

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

the class GenericDraweeHierarchyTest method testControlling_WithPlaceholderOnly.

@Test
public void testControlling_WithPlaceholderOnly() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, null).setActualImageScaleType(null).setFadeDuration(250).build();
    // image indexes in DH tree
    final int placeholderImageIndex = 1;
    final int actualImageIndex = 2;
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    assertEquals(mPlaceholderImage, fadeDrawable.getDrawable(placeholderImageIndex));
    assertEquals(ForwardingDrawable.class, fadeDrawable.getDrawable(actualImageIndex).getClass());
    ForwardingDrawable actualImageSettableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(actualImageIndex);
    // initial state -> final image (non-immediate)
    // initial state
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set final image (non-immediate)
    dh.setImage(mActualImage1, 1f, false);
    assertEquals(mActualImage1, actualImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> final image (immediate)
    // reset hierarchy to initial state
    dh.reset();
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set final image (immediate)
    dh.setImage(mActualImage2, 1f, true);
    assertEquals(mActualImage2, actualImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // initial state -> retry
    // reset hierarchy to initial state
    dh.reset();
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set retry
    dh.setRetry(new RuntimeException());
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> failure
    // reset hierarchy to initial state
    dh.reset();
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set failure
    dh.setFailure(new RuntimeException());
    assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) Test(org.junit.Test)

Example 2 with ForwardingDrawable

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

the class GenericDraweeHierarchyTest method testControlling_WithAllLayers.

@Test
public void testControlling_WithAllLayers() throws Exception {
    GenericDraweeHierarchy dh = mBuilder.setBackground(mBackground).setOverlays(Arrays.asList(mOverlay1, mOverlay2)).setPlaceholderImage(mPlaceholderImage, null).setRetryImage(mRetryImage, null).setFailureImage(mFailureImage, null).setProgressBarImage(mProgressBarImage, null).setActualImageScaleType(null).setFadeDuration(250).build();
    // image indexes in DH tree
    final int backgroundIndex = 0;
    final int placeholderImageIndex = 1;
    final int actualImageIndex = 2;
    final int progressBarImageIndex = 3;
    final int retryImageIndex = 4;
    final int failureImageIndex = 5;
    final int overlaysIndex = 6;
    int numOverlays = 2;
    FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
    assertEquals(mPlaceholderImage, fadeDrawable.getDrawable(placeholderImageIndex));
    assertEquals(mProgressBarImage, fadeDrawable.getDrawable(progressBarImageIndex));
    assertEquals(mRetryImage, fadeDrawable.getDrawable(retryImageIndex));
    assertEquals(mFailureImage, fadeDrawable.getDrawable(failureImageIndex));
    assertEquals(ForwardingDrawable.class, fadeDrawable.getDrawable(actualImageIndex).getClass());
    ForwardingDrawable finalImageSettableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(actualImageIndex);
    // initial state -> final image (immediate)
    // initial state, show progress bar
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set final image (immediate)
    dh.setImage(mActualImage2, 1f, true);
    assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // initial state -> final image (non-immediate)
    // reset hierarchy to initial state, show progress bar
    dh.reset();
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set final image (non-immediate)
    dh.setImage(mActualImage2, 1f, false);
    assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> temporary image (immediate) -> final image (non-immediate)
    // reset hierarchy to initial state, show progress bar
    dh.reset();
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set temporary image (immediate)
    dh.setImage(mActualImage1, 0.5f, true);
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set final image (non-immediate)
    dh.setImage(mActualImage2, 1f, false);
    assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> temporary image (non-immediate) -> final image (non-immediate)
    // reset hierarchy to initial state, show progress bar
    dh.reset();
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set temporary image (non-immediate)
    dh.setImage(mActualImage1, 0.5f, false);
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // set final image (non-immediate)
    dh.setImage(mActualImage2, 1f, false);
    assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> temporary image (immediate) -> retry
    // reset hierarchy to initial state, show progress bar
    dh.reset();
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set temporary image (immediate)
    dh.setImage(mActualImage1, 0.5f, true);
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set retry
    dh.setRetry(new RuntimeException());
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
    // initial state -> temporary image (immediate) -> failure
    // reset hierarchy to initial state, show progress bar
    dh.reset();
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    dh.setProgress(0f, true);
    assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
    assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set temporary image (immediate)
    dh.setImage(mActualImage1, 0.5f, true);
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
    // set failure
    dh.setFailure(new RuntimeException());
    assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
    assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
    assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(failureImageIndex));
    assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
    assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
    assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
    assertEquals(250, fadeDrawable.getTransitionDuration());
}
Also used : FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) Test(org.junit.Test)

Example 3 with ForwardingDrawable

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

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

the class GenericDraweeHierarchyTest method setUp.

@Before
public void setUp() {
    mBuilder = new GenericDraweeHierarchyBuilder(null);
    mBackground = DrawableTestUtils.mockDrawable();
    mOverlay1 = DrawableTestUtils.mockDrawable();
    mOverlay2 = DrawableTestUtils.mockDrawable();
    mPlaceholderImage = DrawableTestUtils.mockBitmapDrawable();
    mFailureImage = DrawableTestUtils.mockBitmapDrawable();
    mRetryImage = DrawableTestUtils.mockBitmapDrawable();
    mProgressBarImage = DrawableTestUtils.mockBitmapDrawable();
    mActualImage1 = DrawableTestUtils.mockBitmapDrawable();
    mActualImage2 = DrawableTestUtils.mockBitmapDrawable();
    mWrappedLeaf = new ColorDrawable(Color.BLUE);
    mWrappedImage = new ForwardingDrawable(new ForwardingDrawable(mWrappedLeaf));
    mFocusPoint = new PointF(0.1f, 0.4f);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) PointF(android.graphics.PointF) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) Before(org.junit.Before)

Example 5 with ForwardingDrawable

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

the class WrappingUtils method maybeApplyLeafRounding.

/**
 * Applies rounding on the drawable's leaf.
 *
 * <p>Currently only {@link BitmapDrawable} or {@link ColorDrawable} leafs can be rounded.
 *
 * <p>If the leaf cannot be rounded, or the rounding params do not specify BITMAP_ONLY mode, the
 * given drawable is returned without being rounded.
 *
 * <p>If the given drawable is a leaf itself, and it can be rounded, then the rounded drawable is
 * returned.
 *
 * <p>If the given drawable is not a leaf, and its leaf can be rounded, the leaf gets rounded, and
 * the original drawable is returned.
 *
 * @return the rounded drawable, or the original drawable if the rounding didn't take place or it
 *     took place on a drawable's child
 */
static Drawable maybeApplyLeafRounding(@Nullable Drawable drawable, @Nullable RoundingParams roundingParams, Resources resources) {
    try {
        if (FrescoSystrace.isTracing()) {
            FrescoSystrace.beginSection("WrappingUtils#maybeApplyLeafRounding");
        }
        if (drawable == null || roundingParams == null || roundingParams.getRoundingMethod() != RoundingParams.RoundingMethod.BITMAP_ONLY) {
            return drawable;
        }
        if (drawable instanceof ForwardingDrawable) {
            DrawableParent parent = findDrawableParentForLeaf((ForwardingDrawable) drawable);
            Drawable child = parent.setDrawable(sEmptyDrawable);
            child = applyLeafRounding(child, roundingParams, resources);
            parent.setDrawable(child);
            return drawable;
        } else {
            return applyLeafRounding(drawable, roundingParams, resources);
        }
    } finally {
        if (FrescoSystrace.isTracing()) {
            FrescoSystrace.endSection();
        }
    }
}
Also used : DrawableParent(com.facebook.drawee.drawable.DrawableParent) 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) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) MatrixDrawable(com.facebook.drawee.drawable.MatrixDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable)

Aggregations

ForwardingDrawable (com.facebook.drawee.drawable.ForwardingDrawable)5 FadeDrawable (com.facebook.drawee.drawable.FadeDrawable)3 Test (org.junit.Test)3 ColorDrawable (android.graphics.drawable.ColorDrawable)2 PointF (android.graphics.PointF)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)1 DrawableParent (com.facebook.drawee.drawable.DrawableParent)1 MatrixDrawable (com.facebook.drawee.drawable.MatrixDrawable)1 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)1 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)1 RoundedCornersDrawable (com.facebook.drawee.drawable.RoundedCornersDrawable)1 RoundedNinePatchDrawable (com.facebook.drawee.drawable.RoundedNinePatchDrawable)1 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)1 Before (org.junit.Before)1