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

HeadersFragment

public class HeadersFragment extends BaseRowFragment
An internal fragment containing a list of row headers.

Fields Summary
private android.support.v17.leanback.widget.OnItemSelectedListener
mOnItemSelectedListener
private OnHeaderClickedListener
mOnHeaderClickedListener
private boolean
mHeadersEnabled
private boolean
mHeadersGone
private int
mBackgroundColor
private boolean
mBackgroundColorSet
private static final android.support.v17.leanback.widget.PresenterSelector
sHeaderPresenter
private final ItemBridgeAdapter.AdapterListener
mAdapterListener
private static android.view.View.OnLayoutChangeListener
sLayoutChangeListener
private final ItemBridgeAdapter.Wrapper
mWrapper
Constructors Summary
public HeadersFragment()


      
        setPresenterSelector(sHeaderPresenter);
    
Methods Summary
android.support.v17.leanback.widget.VerticalGridViewfindGridViewFromRoot(android.view.View view)

        return (VerticalGridView) view.findViewById(R.id.browse_headers);
    
intgetBackgroundColor()

        if (getActivity() == null) {
            throw new IllegalStateException("Activity must be attached");
        }

        if (mBackgroundColorSet) {
            return mBackgroundColor;
        }

        TypedValue outValue = new TypedValue();
        getActivity().getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true);
        return getResources().getColor(outValue.resourceId);
    
intgetLayoutResourceId()


    
      
        return R.layout.lb_headers_fragment;
    
voidonRowSelected(android.view.ViewGroup parent, android.view.View view, int position, long id)

        if (mOnItemSelectedListener != null) {
            if (position >= 0) {
                Row row = (Row) getAdapter().get(position);
                mOnItemSelectedListener.onItemSelected(null, row);
            } else {
                mOnItemSelectedListener.onItemSelected(null, null);
            }
        }
    
voidonTransitionEnd()

        if (mHeadersEnabled) {
            final VerticalGridView listView = getVerticalGridView();
            if (listView != null) {
                listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
                if (listView.hasFocus()) {
                    listView.requestFocus();
                }
            }
        }
        super.onTransitionEnd();
    
voidonTransitionStart()

        super.onTransitionStart();
        if (!mHeadersEnabled) {
            // When enabling headers fragment,  the RowHeaderView gets a focus but
            // isShown() is still false because its parent is INVSIBILE, accessibility
            // event is not sent.
            // Workaround is: prevent focus to a child view during transition and put
            // focus on it after transition is done.
            final VerticalGridView listView = getVerticalGridView();
            if (listView != null) {
                listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
                if (listView.hasFocus()) {
                    listView.requestFocus();
                }
            }
        }
    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)

        super.onViewCreated(view, savedInstanceState);
        final VerticalGridView listView = getVerticalGridView();
        if (listView == null) {
            return;
        }
        if (getBridgeAdapter() != null) {
            FocusHighlightHelper.setupHeaderItemFocusHighlight(listView);
        }
        view.setBackgroundColor(getBackgroundColor());
        updateFadingEdgeToBrandColor(getBackgroundColor());
        updateListViewVisibility();
    
voidsetBackgroundColor(int color)

        mBackgroundColor = color;
        mBackgroundColorSet = true;

        if (getView() != null) {
            getView().setBackgroundColor(mBackgroundColor);
            updateFadingEdgeToBrandColor(mBackgroundColor);
        }
    
voidsetHeadersEnabled(boolean enabled)

        mHeadersEnabled = enabled;
        updateListViewVisibility();
    
voidsetHeadersGone(boolean gone)

        mHeadersGone = gone;
        updateListViewVisibility();
    
public voidsetOnHeaderClickedListener(android.support.v17.leanback.app.HeadersFragment$OnHeaderClickedListener listener)

        mOnHeaderClickedListener = listener;
    
public voidsetOnItemSelectedListener(android.support.v17.leanback.widget.OnItemSelectedListener listener)

        mOnItemSelectedListener = listener;
    
voidupdateAdapter()

    
      
        super.updateAdapter();
        ItemBridgeAdapter adapter = getBridgeAdapter();
        if (adapter != null) {
            adapter.setAdapterListener(mAdapterListener);
            adapter.setWrapper(mWrapper);
        }
        if (adapter != null && getVerticalGridView() != null) {
            FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView());
        }
    
private voidupdateFadingEdgeToBrandColor(int backgroundColor)

        View fadingView = getView().findViewById(R.id.fade_out_edge);
        Drawable background = fadingView.getBackground();
        if (background instanceof GradientDrawable) {
            background.mutate();
            ((GradientDrawable) background).setColors(
                    new int[] {Color.TRANSPARENT, backgroundColor});
        }
    
private voidupdateListViewVisibility()

        final VerticalGridView listView = getVerticalGridView();
        if (listView != null) {
            getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE);
            if (!mHeadersGone) {
                if (mHeadersEnabled) {
                    listView.setChildrenVisibility(View.VISIBLE);
                } else {
                    listView.setChildrenVisibility(View.INVISIBLE);
                }
            }
        }