Search in sources :

Example 1 with DrawableParent

use of com.facebook.drawee.drawable.DrawableParent 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)

Example 2 with DrawableParent

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

the class WrappingUtils method findDrawableParentForLeaf.

/**
 * Finds the immediate parent of a leaf drawable.
 */
static DrawableParent findDrawableParentForLeaf(DrawableParent parent) {
    while (true) {
        Drawable child = parent.getDrawable();
        if (child == parent || !(child instanceof DrawableParent)) {
            break;
        }
        parent = (DrawableParent) child;
    }
    return parent;
}
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)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)2 DrawableParent (com.facebook.drawee.drawable.DrawableParent)2 ForwardingDrawable (com.facebook.drawee.drawable.ForwardingDrawable)2 MatrixDrawable (com.facebook.drawee.drawable.MatrixDrawable)2 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)2 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)2 RoundedCornersDrawable (com.facebook.drawee.drawable.RoundedCornersDrawable)2 RoundedNinePatchDrawable (com.facebook.drawee.drawable.RoundedNinePatchDrawable)2 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)2