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

HorizontalHoverCardSwitcher

public final class HorizontalHoverCardSwitcher extends PresenterSwitcher
Helper class that stay bellow a HorizontalGridView and shows a hover card and align the hover card left to left of selected child view. If there is no space when scroll to the end, right edge hover card will be aligned to right of parent view excluding right padding.

Fields Summary
int
mCardLeft
int
mCardRight
private int[]
mTmpOffsets
private android.graphics.Rect
mTmpRect
Constructors Summary
Methods Summary
protected voidinsertView(android.view.View view)


    
        
        // append hovercard to the end of container
        getParentViewGroup().addView(view);
    
protected voidonViewSelected(android.view.View view)

        int rightLimit = getParentViewGroup().getWidth() -
                getParentViewGroup().getPaddingRight();
        int leftLimit = getParentViewGroup().getPaddingLeft();
        // measure the hover card width; if it's too large, align hover card
        // end edge with row view's end edge, otherwise align start edges.
        view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        MarginLayoutParams params = (MarginLayoutParams) view.getLayoutParams();
        boolean isRtl = ViewCompat.getLayoutDirection(view) == View.LAYOUT_DIRECTION_RTL;
        if (!isRtl && mCardLeft + view.getMeasuredWidth() > rightLimit) {
            params.leftMargin = rightLimit  - view.getMeasuredWidth();
        } else if (isRtl && mCardLeft < leftLimit) {
            params.leftMargin = leftLimit;
        } else if (isRtl) {
            params.leftMargin = mCardRight - view.getMeasuredWidth();
        } else {
            params.leftMargin = mCardLeft;
        }
        view.requestLayout();
    
public voidselect(HorizontalGridView gridView, android.view.View childView, java.lang.Object object)
Select a childView inside a grid view and create/bind a corresponding hover card view for the object.

        ViewGroup parent = getParentViewGroup();
        gridView.getViewSelectedOffsets(childView, mTmpOffsets);
        mTmpRect.set(0, 0, childView.getWidth(), childView.getHeight());
        parent.offsetDescendantRectToMyCoords(childView, mTmpRect);
        mCardLeft = mTmpRect.left - mTmpOffsets[0];
        mCardRight = mTmpRect.right - mTmpOffsets[0];
        select(object);