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

VerticalGridSupportFragment

public class VerticalGridSupportFragment extends android.support.v4.app.Fragment
A fragment for creating leanback vertical grids.

Renders a vertical grid of objects given a {@link VerticalGridPresenter} and an {@link ObjectAdapter}.

Fields Summary
private static final String
TAG
private static boolean
DEBUG
private android.support.v17.leanback.widget.BrowseFrameLayout
mBrowseFrame
private String
mTitle
private android.graphics.drawable.Drawable
mBadgeDrawable
private android.support.v17.leanback.widget.ObjectAdapter
mAdapter
private android.support.v17.leanback.widget.VerticalGridPresenter
mGridPresenter
private VerticalGridPresenter.ViewHolder
mGridViewHolder
private android.support.v17.leanback.widget.OnItemSelectedListener
mOnItemSelectedListener
private android.support.v17.leanback.widget.OnItemClickedListener
mOnItemClickedListener
private android.support.v17.leanback.widget.OnItemViewSelectedListener
mOnItemViewSelectedListener
private android.support.v17.leanback.widget.OnItemViewClickedListener
mOnItemViewClickedListener
private View.OnClickListener
mExternalOnSearchClickedListener
private int
mSelectedPosition
private android.support.v17.leanback.widget.TitleView
mTitleView
private SearchOrbView.Colors
mSearchAffordanceColors
private boolean
mSearchAffordanceColorSet
private boolean
mShowingTitle
private static android.support.v17.leanback.transition.TransitionHelper
sTransitionHelper
private Object
mTitleUpTransition
private Object
mTitleDownTransition
private Object
mSceneWithTitle
private Object
mSceneWithoutTitle
private final android.support.v17.leanback.widget.OnItemViewSelectedListener
mRowSelectedListener
private final BrowseFrameLayout.OnFocusSearchListener
mOnFocusSearchListener
Constructors Summary
Methods Summary
public android.support.v17.leanback.widget.ObjectAdaptergetAdapter()
Returns the object adapter.

        return mAdapter;
    
public android.graphics.drawable.DrawablegetBadgeDrawable()
Returns the badge drawable.

        return mBadgeDrawable;
    
public android.support.v17.leanback.widget.VerticalGridPresentergetGridPresenter()
Returns the grid presenter.

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

deprecated
Use {@link #getOnItemViewClickedListener()}

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

        return mOnItemViewClickedListener;
    
public intgetSearchAffordanceColor()
Returns the color used to draw the search affordance.

        return getSearchAffordanceColors().color;
    
public SearchOrbView.ColorsgetSearchAffordanceColors()
Returns the {@link SearchOrbView.Colors} used to draw the search affordance.

        if (mSearchAffordanceColorSet) {
            return mSearchAffordanceColors;
        }
        if (mTitleView == null) {
            throw new IllegalStateException("Fragment views not yet created");
        }
        return mTitleView.getSearchAffordanceColors();
    
public java.lang.StringgetTitle()
Returns the title for the fragment.

        return mTitle;
    
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)


    
         
              
        ViewGroup root = (ViewGroup) inflater.inflate(R.layout.lb_vertical_grid_fragment,
                container, false);

        mBrowseFrame = (BrowseFrameLayout) root.findViewById(R.id.browse_frame);
        mBrowseFrame.setOnFocusSearchListener(mOnFocusSearchListener);

        mTitleView = (TitleView) root.findViewById(R.id.browse_title_group);
        mTitleView.setBadgeDrawable(mBadgeDrawable);
        mTitleView.setTitle(mTitle);
        if (mSearchAffordanceColorSet) {
            mTitleView.setSearchAffordanceColors(mSearchAffordanceColors);
        }
        if (mExternalOnSearchClickedListener != null) {
            mTitleView.setOnSearchClickedListener(mExternalOnSearchClickedListener);
        }

        mSceneWithTitle = sTransitionHelper.createScene(root, new Runnable() {
            @Override
            public void run() {
                mTitleView.setVisibility(View.VISIBLE);
            }
        });
        mSceneWithoutTitle = sTransitionHelper.createScene(root, new Runnable() {
            @Override
            public void run() {
                mTitleView.setVisibility(View.INVISIBLE);
            }
        });
        Context context = getActivity();
        mTitleUpTransition = sTransitionHelper.loadTransition(context, R.transition.lb_title_out);
        mTitleDownTransition = sTransitionHelper.loadTransition(context, R.transition.lb_title_in);

        return root;
    
public voidonDestroyView()

        super.onDestroyView();
        mGridViewHolder = null;
    
public voidonPause()

        mTitleView.enableAnimation(false);
        super.onPause();
    
public voidonResume()

        super.onResume();
        mTitleView.enableAnimation(true);
    
private voidonRowSelected(int position)

        if (position != mSelectedPosition) {
            if (!mGridViewHolder.getGridView().hasPreviousViewInSameRow(position)) {
                // if has no sibling in front of it,  show title
                if (!mShowingTitle) {
                    sTransitionHelper.runTransition(mSceneWithTitle, mTitleDownTransition);
                    mShowingTitle = true;
                }
            } else if (mShowingTitle) {
                sTransitionHelper.runTransition(mSceneWithoutTitle, mTitleUpTransition);
                mShowingTitle = false;
            }
            mSelectedPosition = position;
        }
    
public voidonStart()

        super.onStart();
        mGridViewHolder.getGridView().requestFocus();
    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)

        ViewGroup gridDock = (ViewGroup) view.findViewById(R.id.browse_grid_dock);
        mGridViewHolder = mGridPresenter.onCreateViewHolder(gridDock);
        gridDock.addView(mGridViewHolder.view);

        updateAdapter();
    
public voidsetAdapter(android.support.v17.leanback.widget.ObjectAdapter adapter)
Sets the object adapter for the fragment.

        mAdapter = adapter;
        updateAdapter();
    
public voidsetBadgeDrawable(android.graphics.drawable.Drawable drawable)
Sets the badge drawable displayed in the title area.


                  
        
        if (drawable != mBadgeDrawable) {
            mBadgeDrawable = drawable;
            if (mTitleView != null) {
                mTitleView.setBadgeDrawable(drawable);
            }
        }
    
public voidsetGridPresenter(android.support.v17.leanback.widget.VerticalGridPresenter gridPresenter)
Sets the grid presenter.

        if (gridPresenter == null) {
            throw new IllegalArgumentException("Grid presenter may not be null");
        }
        mGridPresenter = gridPresenter;
        mGridPresenter.setOnItemViewSelectedListener(mRowSelectedListener);
        if (mOnItemViewClickedListener != null) {
            mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener);
        }
        if (mOnItemClickedListener != null) {
            mGridPresenter.setOnItemClickedListener(mOnItemClickedListener);
        }
    
public voidsetOnItemClickedListener(android.support.v17.leanback.widget.OnItemClickedListener listener)
Sets an item clicked listener.

deprecated
Use {@link #setOnItemViewClickedListener(OnItemViewClickedListener)}

        mOnItemClickedListener = listener;
        if (mGridPresenter != null) {
            mGridPresenter.setOnItemClickedListener(mOnItemClickedListener);
        }
    
public voidsetOnItemSelectedListener(android.support.v17.leanback.widget.OnItemSelectedListener listener)
Sets an item selection listener.

deprecated
Use {@link #setOnItemViewSelectedListener(OnItemViewSelectedListener)}


                  
        
        mOnItemSelectedListener = listener;
    
public voidsetOnItemViewClickedListener(android.support.v17.leanback.widget.OnItemViewClickedListener listener)
Sets an item clicked listener.

        mOnItemViewClickedListener = listener;
        if (mGridPresenter != null) {
            mGridPresenter.setOnItemViewClickedListener(mOnItemViewClickedListener);
        }
    
public voidsetOnItemViewSelectedListener(android.support.v17.leanback.widget.OnItemViewSelectedListener listener)
Sets an item selection listener.

        mOnItemViewSelectedListener = listener;
    
public voidsetOnSearchClickedListener(View.OnClickListener listener)
Sets a click listener for the search affordance.

The presence of a listener will change the visibility of the search affordance in the title area. When set to non-null, the title area will contain a call to search action.

The listener's onClick method will be invoked when the user clicks on the search action.

param
listener The listener to invoke when the search affordance is clicked, or null to hide the search affordance.

        mExternalOnSearchClickedListener = listener;
        if (mTitleView != null) {
            mTitleView.setOnSearchClickedListener(listener);
        }
    
public voidsetSearchAffordanceColor(int color)
Sets the color used to draw the search affordance. A default brighter color will be set by the framework.

param
color The color to use for the search affordance.

        setSearchAffordanceColors(new SearchOrbView.Colors(color));
    
public voidsetSearchAffordanceColors(SearchOrbView.Colors colors)
Sets the {@link SearchOrbView.Colors} used to draw the search affordance.

        mSearchAffordanceColors = colors;
        mSearchAffordanceColorSet = true;
        if (mTitleView != null) {
            mTitleView.setSearchAffordanceColors(mSearchAffordanceColors);
        }
    
public voidsetSelectedPosition(int position)
Sets the selected item position.

        mSelectedPosition = position;
        if(mGridViewHolder != null && mGridViewHolder.getGridView().getAdapter() != null) {
            mGridViewHolder.getGridView().setSelectedPositionSmooth(position);
        }
    
public voidsetTitle(java.lang.String title)
Sets a title for the fragment.

        mTitle = title;
        if (mTitleView != null) {
            mTitleView.setTitle(mTitle);
        }
    
private voidupdateAdapter()

        if (mGridViewHolder != null) {
            mGridPresenter.onBindViewHolder(mGridViewHolder, mAdapter);
            if (mSelectedPosition != -1) {
                mGridViewHolder.getGridView().setSelectedPosition(mSelectedPosition);
            }
        }