Search in sources :

Example 1 with RoundedCornersDrawable

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

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

the class WrappingUtils method maybeWrapWithRoundedOverlayColor.

/**
 * Wraps the given drawable with a new {@link RoundedCornersDrawable}.
 *
 * <p>If the provided drawable is null, or if the rounding params do not specify OVERLAY_COLOR
 * mode, the given drawable is returned without being wrapped.
 *
 * @return the wrapping rounded drawable, or the original drawable if the wrapping didn't take
 *     place
 */
static Drawable maybeWrapWithRoundedOverlayColor(@Nullable Drawable drawable, @Nullable RoundingParams roundingParams) {
    try {
        if (FrescoSystrace.isTracing()) {
            FrescoSystrace.beginSection("WrappingUtils#maybeWrapWithRoundedOverlayColor");
        }
        if (drawable == null || roundingParams == null || roundingParams.getRoundingMethod() != RoundingParams.RoundingMethod.OVERLAY_COLOR) {
            return drawable;
        }
        RoundedCornersDrawable roundedCornersDrawable = new RoundedCornersDrawable(drawable);
        applyRoundingParams(roundedCornersDrawable, roundingParams);
        roundedCornersDrawable.setOverlayColor(roundingParams.getOverlayColor());
        return roundedCornersDrawable;
    } finally {
        if (FrescoSystrace.isTracing()) {
            FrescoSystrace.endSection();
        }
    }
}
Also used : RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable)

Example 3 with RoundedCornersDrawable

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

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

the class WrappingUtils method updateOverlayColorRounding.

/**
 * Updates the overlay-color rounding of the parent's child drawable.
 *
 * <ul>
 *   <li>If rounding mode is OVERLAY_COLOR and the child is not a RoundedCornersDrawable, a new
 *       RoundedCornersDrawable is created and the child gets wrapped with it.
 *   <li>If rounding mode is OVERLAY_COLOR and the child is already wrapped with a
 *       RoundedCornersDrawable, its rounding parameters are updated.
 *   <li>If rounding mode is not OVERLAY_COLOR and the child is wrapped with a
 *       RoundedCornersDrawable, the rounded drawable gets removed and its child gets attached
 *       directly to the parent.
 * </ul>
 */
static void updateOverlayColorRounding(DrawableParent parent, @Nullable RoundingParams roundingParams) {
    Drawable child = parent.getDrawable();
    if (roundingParams != null && roundingParams.getRoundingMethod() == RoundingParams.RoundingMethod.OVERLAY_COLOR) {
        // drawable that will do the requested rounding.
        if (child instanceof RoundedCornersDrawable) {
            RoundedCornersDrawable roundedCornersDrawable = (RoundedCornersDrawable) child;
            applyRoundingParams(roundedCornersDrawable, roundingParams);
            roundedCornersDrawable.setOverlayColor(roundingParams.getOverlayColor());
        } else {
            // Important: remove the child before wrapping it with a new parent!
            child = parent.setDrawable(sEmptyDrawable);
            child = maybeWrapWithRoundedOverlayColor(child, roundingParams);
            parent.setDrawable(child);
        }
    } else if (child instanceof RoundedCornersDrawable) {
        // Overlay rounding no longer required so remove drawable that was doing the rounding.
        RoundedCornersDrawable roundedCornersDrawable = (RoundedCornersDrawable) child;
        // Important: remove the child before wrapping it with a new parent!
        child = roundedCornersDrawable.setCurrent(sEmptyDrawable);
        parent.setDrawable(child);
        // roundedCornersDrawable is removed and will get garbage collected, clear the child callback
        sEmptyDrawable.setCallback(null);
    }
}
Also used : RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) 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)

Aggregations

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