FileDocCategorySizeDatePackage
RowsSupportFragment.javaAPI DocAndroid 5.1 API23655Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.app

RowsSupportFragment

public class RowsSupportFragment extends BaseRowSupportFragment
An ordered set of rows of leanback widgets.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private ItemBridgeAdapter.ViewHolder
mSelectedViewHolder
private boolean
mExpand
private boolean
mViewsCreated
private float
mRowScaleFactor
private int
mAlignedTop
private boolean
mRowScaleEnabled
private android.support.v17.leanback.widget.ScaleFrameLayout
mScaleFrameLayout
private boolean
mInTransition
private boolean
mAfterEntranceTransition
private android.support.v17.leanback.widget.OnItemSelectedListener
mOnItemSelectedListener
private android.support.v17.leanback.widget.OnItemViewSelectedListener
mOnItemViewSelectedListener
private android.support.v17.leanback.widget.OnItemClickedListener
mOnItemClickedListener
private android.support.v17.leanback.widget.OnItemViewClickedListener
mOnItemViewClickedListener
int
mSelectAnimatorDuration
android.view.animation.Interpolator
mSelectAnimatorInterpolator
private RecyclerView.RecycledViewPool
mRecycledViewPool
private ArrayList
mPresenterMapper
private ItemBridgeAdapter.AdapterListener
mExternalAdapterListener
private final ItemBridgeAdapter.AdapterListener
mBridgeAdapterListener
Constructors Summary
Methods Summary
public voidenableRowScaling(boolean enable)
Enables scaling of rows.

param
enable true to enable row scaling

        mRowScaleEnabled = enable;
    
protected android.support.v17.leanback.widget.VerticalGridViewfindGridViewFromRoot(android.view.View view)


    
        
        return (VerticalGridView) view.findViewById(R.id.container_list);
    
private voidfreezeRows(boolean freeze)

        VerticalGridView verticalView = getVerticalGridView();
        if (verticalView != null) {
            final int count = verticalView.getChildCount();
            for (int i = 0; i < count; i++) {
                ItemBridgeAdapter.ViewHolder ibvh = (ItemBridgeAdapter.ViewHolder)
                    verticalView.getChildViewHolder(verticalView.getChildAt(i));
                RowPresenter rowPresenter = (RowPresenter) ibvh.getPresenter();
                RowPresenter.ViewHolder vh = rowPresenter.getRowViewHolder(ibvh.getViewHolder());
                rowPresenter.freeze(vh, freeze);
            }
        }
    
intgetLayoutResourceId()

        return R.layout.lb_rows_fragment;
    
public android.support.v17.leanback.widget.OnItemClickedListenergetOnItemClickedListener()
Returns the item clicked listener.

deprecated
Use {@link #getOnItemClickedListener()}

        return mOnItemClickedListener;
    
public android.support.v17.leanback.widget.OnItemViewClickedListenergetOnItemViewClickedListener()
Returns the item clicked listener.

        return mOnItemViewClickedListener;
    
public android.support.v17.leanback.widget.OnItemViewSelectedListenergetOnItemViewSelectedListener()
Returns an item selection listener.

        return mOnItemViewSelectedListener;
    
android.view.ViewgetScaleView()
Get the view that will change scale.

        return getVerticalGridView();
    
private booleanneedsScale()

        return mRowScaleEnabled && !mExpand;
    
public voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        mSelectAnimatorDuration = getResources().getInteger(
                R.integer.lb_browse_rows_anim_duration);
        mRowScaleFactor = getResources().getFraction(
                R.fraction.lb_browse_rows_scale, 1, 1);
    
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)

        View view = super.onCreateView(inflater, container, savedInstanceState);
        mScaleFrameLayout = (ScaleFrameLayout) view.findViewById(R.id.scale_frame);
        return view;
    
public voidonDestroyView()

        mViewsCreated = false;
        super.onDestroyView();
    
voidonExpandTransitionStart(boolean expand, java.lang.Runnable callback)

        onTransitionStart();
        if (expand) {
            callback.run();
            return;
        }
        // Run a "pre" layout when we go non-expand, in order to get the initial
        // positions of added rows.
        new ExpandPreLayout(callback).execute();
    
voidonRowSelected(android.view.ViewGroup parent, android.view.View view, int position, long id)

        VerticalGridView listView = getVerticalGridView();
        if (listView == null) {
            return;
        }
        ItemBridgeAdapter.ViewHolder vh = (view == null) ? null :
            (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);

        if (mSelectedViewHolder != vh) {
            if (DEBUG) Log.v(TAG, "new row selected position " + position + " view " + view);

            if (mSelectedViewHolder != null) {
                setRowViewSelected(mSelectedViewHolder, false, false);
            }
            mSelectedViewHolder = vh;
            if (mSelectedViewHolder != null) {
                setRowViewSelected(mSelectedViewHolder, true, false);
            }
        }
    
voidonTransitionEnd()

        super.onTransitionEnd();
        mInTransition = false;
        freezeRows(false);
    
voidonTransitionStart()

        super.onTransitionStart();
        mInTransition = true;
        freezeRows(true);
    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)

        if (DEBUG) Log.v(TAG, "onViewCreated");
        super.onViewCreated(view, savedInstanceState);
        // Align the top edge of child with id row_content.
        // Need set this for directly using RowsSupportFragment.
        getVerticalGridView().setItemAlignmentViewId(R.id.row_content);
        getVerticalGridView().setSaveChildrenPolicy(VerticalGridView.SAVE_LIMITED_CHILD);

        mRecycledViewPool = null;
        mPresenterMapper = null;
    
voidsetEntranceTransitionState(boolean afterTransition)
For rows that willing to participate entrance transition, this function hide views if afterTransition is true, show views if afterTransition is false.

        mAfterEntranceTransition = afterTransition;
        VerticalGridView verticalView = getVerticalGridView();
        if (verticalView != null) {
            final int count = verticalView.getChildCount();
            for (int i = 0; i < count; i++) {
                ItemBridgeAdapter.ViewHolder ibvh = (ItemBridgeAdapter.ViewHolder)
                    verticalView.getChildViewHolder(verticalView.getChildAt(i));
                RowPresenter rowPresenter = (RowPresenter) ibvh.getPresenter();
                RowPresenter.ViewHolder vh = rowPresenter.getRowViewHolder(ibvh.getViewHolder());
                rowPresenter.setEntranceTransitionState(vh, mAfterEntranceTransition);
            }
        }
    
public voidsetExpand(boolean expand)
Set the visibility of titles/hovercard of browse rows.

        mExpand = expand;
        VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            updateRowScaling();
            final int count = listView.getChildCount();
            if (DEBUG) Log.v(TAG, "setExpand " + expand + " count " + count);
            for (int i = 0; i < count; i++) {
                View view = listView.getChildAt(i);
                ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) listView.getChildViewHolder(view);
                setRowViewExpanded(vh, mExpand);
            }
        }
    
voidsetExternalAdapterListener(ItemBridgeAdapter.AdapterListener listener)

        mExternalAdapterListener = listener;
    
voidsetItemAlignment()

        super.setItemAlignment();
        if (getVerticalGridView() != null) {
            getVerticalGridView().setItemAlignmentOffsetWithPadding(true);
        }
    
public voidsetOnItemClickedListener(android.support.v17.leanback.widget.OnItemClickedListener listener)
Sets an item clicked listener on the fragment. OnItemClickedListener will override {@link View.OnClickListener} that item presenter sets during {@link Presenter#onCreateViewHolder(ViewGroup)}. So in general, developer should choose one of the listeners but not both.

deprecated
Use {@link #setOnItemViewClickedListener(OnItemViewClickedListener)}

        mOnItemClickedListener = listener;
        if (mViewsCreated) {
            throw new IllegalStateException(
                    "Item clicked listener must be set before views are created");
        }
    
private static voidsetOnItemSelectedListener(ItemBridgeAdapter.ViewHolder vh, android.support.v17.leanback.widget.OnItemSelectedListener listener)

        ((RowPresenter) vh.getPresenter()).setOnItemSelectedListener(listener);
    
public voidsetOnItemSelectedListener(android.support.v17.leanback.widget.OnItemSelectedListener listener)
Sets an item selection listener.

deprecated
Use {@link #setOnItemViewSelectedListener(OnItemViewSelectedListener)}

        mOnItemSelectedListener = listener;
        VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            final int count = listView.getChildCount();
            for (int i = 0; i < count; i++) {
                View view = listView.getChildAt(i);
                ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder)
                        listView.getChildViewHolder(view);
                setOnItemSelectedListener(vh, mOnItemSelectedListener);
            }
        }
    
public voidsetOnItemViewClickedListener(android.support.v17.leanback.widget.OnItemViewClickedListener listener)
Sets an item clicked listener on the fragment. OnItemViewClickedListener will override {@link View.OnClickListener} that item presenter sets during {@link Presenter#onCreateViewHolder(ViewGroup)}. So in general, developer should choose one of the listeners but not both.

        mOnItemViewClickedListener = listener;
        if (mViewsCreated) {
            throw new IllegalStateException(
                    "Item clicked listener must be set before views are created");
        }
    
private static voidsetOnItemViewSelectedListener(ItemBridgeAdapter.ViewHolder vh, android.support.v17.leanback.widget.OnItemViewSelectedListener listener)

        ((RowPresenter) vh.getPresenter()).setOnItemViewSelectedListener(listener);
    
public voidsetOnItemViewSelectedListener(android.support.v17.leanback.widget.OnItemViewSelectedListener listener)
Sets an item selection listener.

        mOnItemViewSelectedListener = listener;
        VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            final int count = listView.getChildCount();
            for (int i = 0; i < count; i++) {
                View view = listView.getChildAt(i);
                ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder)
                        listView.getChildViewHolder(view);
                setOnItemViewSelectedListener(vh, mOnItemViewSelectedListener);
            }
        }
    
private static voidsetRowViewExpanded(ItemBridgeAdapter.ViewHolder vh, boolean expanded)

        ((RowPresenter) vh.getPresenter()).setRowViewExpanded(vh.getViewHolder(), expanded);
    
private static voidsetRowViewSelected(ItemBridgeAdapter.ViewHolder vh, boolean selected, boolean immediate)

        RowViewHolderExtra extra = (RowViewHolderExtra) vh.getExtraObject();
        extra.animateSelect(selected, immediate);
        ((RowPresenter) vh.getPresenter()).setRowViewSelected(vh.getViewHolder(), selected);
    
voidsetScalePivots(float pivotX, float pivotY)
Set pivots to scale rows fragment.

        // set pivot on ScaleFrameLayout, it will be propagated to its child VerticalGridView
        // where we actually change scale.
        mScaleFrameLayout.setPivotX(pivotX);
        mScaleFrameLayout.setPivotY(pivotY);
    
voidsetWindowAlignmentFromTop(int alignedTop)

        mAlignedTop = alignedTop;
        final VerticalGridView gridView = getVerticalGridView();
        if (gridView != null) {
            updateWindowAlignOffset();
            // align to a fixed position from top
            gridView.setWindowAlignmentOffsetPercent(
                    VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
            gridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
        }
    
private voidsetupSharedViewPool(ItemBridgeAdapter.ViewHolder bridgeVh)


        
        RowPresenter rowPresenter = (RowPresenter) bridgeVh.getPresenter();
        RowPresenter.ViewHolder rowVh = rowPresenter.getRowViewHolder(bridgeVh.getViewHolder());

        if (rowVh instanceof ListRowPresenter.ViewHolder) {
            HorizontalGridView view = ((ListRowPresenter.ViewHolder) rowVh).getGridView();
            // Recycled view pool is shared between all list rows
            if (mRecycledViewPool == null) {
                mRecycledViewPool = view.getRecycledViewPool();
            } else {
                view.setRecycledViewPool(mRecycledViewPool);
            }

            ItemBridgeAdapter bridgeAdapter =
                    ((ListRowPresenter.ViewHolder) rowVh).getBridgeAdapter();
            if (mPresenterMapper == null) {
                mPresenterMapper = bridgeAdapter.getPresenterMapper();
            } else {
                bridgeAdapter.setPresenterMapper(mPresenterMapper);
            }
        }
    
voidupdateAdapter()

        super.updateAdapter();
        mSelectedViewHolder = null;
        mViewsCreated = false;

        ItemBridgeAdapter adapter = getBridgeAdapter();
        if (adapter != null) {
            adapter.setAdapterListener(mBridgeAdapterListener);
        }
    
private voidupdateRowScaling()

        final float scaleFactor = needsScale() ? mRowScaleFactor : 1f;
        mScaleFrameLayout.setLayoutScaleY(scaleFactor);
        getScaleView().setScaleY(scaleFactor);
        getScaleView().setScaleX(scaleFactor);
        updateWindowAlignOffset();
    
private voidupdateWindowAlignOffset()

        int alignOffset = mAlignedTop;
        if (needsScale()) {
            alignOffset = (int) (alignOffset / mRowScaleFactor + 0.5f);
        }
        getVerticalGridView().setWindowAlignmentOffset(alignOffset);