FileDocCategorySizeDatePackage
ShadowOverlayContainer.javaAPI DocAndroid 5.1 API8168Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.widget

ShadowOverlayContainer

public class ShadowOverlayContainer extends android.view.ViewGroup
ShadowOverlayContainer Provides a SDK version independent wrapper container to take care of shadow and/or color overlay.

Shadow and color dimmer overlay are both optional. When shadow is used, it's user's responsibility to properly call setClipChildren(false) on parent views if the shadow can appear outside bounds of parent views. {@link #prepareParentForShadow(ViewGroup)} must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

{@link #initialize(boolean, boolean, boolean)} must be first called on the container to initialize shadows and/or color overlay. Then call {@link #wrap(View)} to insert wrapped view into container.

Call {@link #setShadowFocusLevel(float)} to control shadow alpha.

Call {@link #setOverlayColor(int)} to control overlay color.

Fields Summary
private boolean
mInitialized
private android.view.View
mColorDimOverlay
private Object
mShadowImpl
private android.view.View
mWrappedView
private static final android.graphics.Rect
sTempRect
Constructors Summary
public ShadowOverlayContainer(android.content.Context context)


       
        this(context, null, 0);
    
public ShadowOverlayContainer(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public ShadowOverlayContainer(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
    
Methods Summary
public voidinitialize(boolean hasShadow, boolean hasColorDimOverlay)
Initialize shadows, color overlay.

deprecated
use {@link #initialize(boolean, boolean, boolean)} instead.

        initialize(hasShadow, hasColorDimOverlay, true);
    
public voidinitialize(boolean hasShadow, boolean hasColorDimOverlay, boolean roundedCorners)
Initialize shadows, color overlay, and rounded corners. All are optional.

        if (mInitialized) {
            throw new IllegalStateException();
        }
        mInitialized = true;
        if (hasShadow) {
            mShadowImpl = ShadowHelper.getInstance().addShadow(this, roundedCorners);
        } else if (roundedCorners) {
            RoundedRectHelper.getInstance().setRoundedRectBackground(this,
                    android.graphics.Color.TRANSPARENT);
        }
        if (hasColorDimOverlay) {
            mColorDimOverlay = LayoutInflater.from(getContext())
                    .inflate(R.layout.lb_card_color_overlay, this, false);
            addView(mColorDimOverlay);
        }
    
protected voidonLayout(boolean changed, int l, int t, int r, int b)

        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();
                child.layout(0, 0, width, height);
            }
        }
        if (mWrappedView != null) {
            sTempRect.left = (int) mWrappedView.getPivotX();
            sTempRect.top = (int) mWrappedView.getPivotY();
            offsetDescendantRectToMyCoords(mWrappedView, sTempRect);
            setPivotX(sTempRect.left);
            setPivotY(sTempRect.top);
        }
    
protected voidonMeasure(int widthMeasureSpec, int heightMeasureSpec)

        if (mWrappedView == null) {
            throw new IllegalStateException();
        }
        // padding and child margin are not supported.
        // first measure the wrapped view, then measure the shadow view and/or overlay view.
        int childWidthMeasureSpec, childHeightMeasureSpec;
        LayoutParams lp = mWrappedView.getLayoutParams();
        if (lp.width == LayoutParams.MATCH_PARENT) {
            childWidthMeasureSpec = MeasureSpec.makeMeasureSpec
                    (MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY);
        } else {
            childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
        }
        if (lp.height == LayoutParams.MATCH_PARENT) {
            childHeightMeasureSpec = MeasureSpec.makeMeasureSpec
                    (MeasureSpec.getSize(heightMeasureSpec), MeasureSpec.EXACTLY);
        } else {
            childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
        }
        mWrappedView.measure(childWidthMeasureSpec, childHeightMeasureSpec);

        int measuredWidth = mWrappedView.getMeasuredWidth();
        int measuredHeight = mWrappedView.getMeasuredHeight();

        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (child == mWrappedView) {
                continue;
            }
            lp = child.getLayoutParams();
            if (lp.width == LayoutParams.MATCH_PARENT) {
                childWidthMeasureSpec = MeasureSpec.makeMeasureSpec
                        (measuredWidth, MeasureSpec.EXACTLY);
            } else {
                childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, 0, lp.width);
            }

            if (lp.height == LayoutParams.MATCH_PARENT) {
                childHeightMeasureSpec = MeasureSpec.makeMeasureSpec
                        (measuredHeight, MeasureSpec.EXACTLY);
            } else {
                childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, 0, lp.height);
            }
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        }
        setMeasuredDimension(measuredWidth, measuredHeight);
    
public static voidprepareParentForShadow(android.view.ViewGroup parent)
{@link #prepareParentForShadow(ViewGroup)} must be called on parent of container before using shadow. Depending on sdk version, optical bounds might be applied to parent.

        ShadowHelper.getInstance().prepareParent(parent);
    
public voidsetOverlayColor(int overlayColor)
Set color (with alpha) of the overlay.

        if (mColorDimOverlay != null) {
            mColorDimOverlay.setBackgroundColor(overlayColor);
        }
    
public voidsetShadowFocusLevel(float level)
Set shadow focus level (0 to 1). 0 for unfocused, 1f for fully focused.

        if (mShadowImpl != null) {
            if (level < 0f) {
                level = 0f;
            } else if (level > 1f) {
                level = 1f;
            }
            ShadowHelper.getInstance().setShadowFocusLevel(mShadowImpl, level);
        }
    
public static booleansupportsShadow()
Return true if the platform sdk supports shadow.

        return ShadowHelper.getInstance().supportsShadow();
    
public voidwrap(android.view.View view)
Inserts view into the wrapper.

        if (!mInitialized || mWrappedView != null) {
            throw new IllegalStateException();
        }
        if (mColorDimOverlay != null) {
            addView(view, indexOfChild(mColorDimOverlay));
        } else {
            addView(view);
        }
        mWrappedView = view;