Fields Summary |
---|
static final String | HEADER_STACK_INDEX |
static final String | HEADER_SHOW |
static final String | TITLE_SHOW |
private static final String | TAG |
private static final String | LB_HEADERS_BACKSTACK |
private static boolean | DEBUG |
public static final int | HEADERS_ENABLEDThe headers fragment is enabled and shown by default. |
public static final int | HEADERS_HIDDENThe headers fragment is enabled and hidden by default. |
public static final int | HEADERS_DISABLEDThe headers fragment is disabled and will never be shown. |
private static final float | SLIDE_DISTANCE_FACTOR |
private RowsFragment | mRowsFragment |
private HeadersFragment | mHeadersFragment |
private android.support.v17.leanback.widget.ObjectAdapter | mAdapter |
private String | mTitle |
private android.graphics.drawable.Drawable | mBadgeDrawable |
private int | mHeadersState |
private int | mBrandColor |
private boolean | mBrandColorSet |
private android.support.v17.leanback.widget.BrowseFrameLayout | mBrowseFrame |
private android.support.v17.leanback.widget.TitleView | mTitleView |
private boolean | mShowingTitle |
private boolean | mHeadersBackStackEnabled |
private String | mWithHeadersBackStackName |
private boolean | mShowingHeaders |
private boolean | mCanShowHeaders |
private int | mContainerListMarginStart |
private int | mContainerListAlignTop |
private boolean | mRowScaleEnabled |
private SearchOrbView.Colors | mSearchAffordanceColors |
private boolean | mSearchAffordanceColorSet |
private android.support.v17.leanback.widget.OnItemSelectedListener | mExternalOnItemSelectedListener |
private android.view.View.OnClickListener | mExternalOnSearchClickedListener |
private android.support.v17.leanback.widget.OnItemClickedListener | mOnItemClickedListener |
private android.support.v17.leanback.widget.OnItemViewSelectedListener | mExternalOnItemViewSelectedListener |
private android.support.v17.leanback.widget.OnItemViewClickedListener | mOnItemViewClickedListener |
private int | mSelectedPosition |
private android.support.v17.leanback.widget.PresenterSelector | mHeaderPresenterSelector |
private Object | mSceneWithTitle |
private Object | mSceneWithoutTitle |
private Object | mSceneWithHeaders |
private Object | mSceneWithoutHeaders |
private Object | mSceneAfterEntranceTransition |
private Object | mTitleUpTransition |
private Object | mTitleDownTransition |
private Object | mHeadersTransition |
private BackStackListener | mBackStackChangedListener |
private BrowseTransitionListener | mBrowseTransitionListener |
private static final String | ARG_TITLE |
private static final String | ARG_BADGE_URI |
private static final String | ARG_HEADERS_STATE |
private final BrowseFrameLayout.OnFocusSearchListener | mOnFocusSearchListener |
private final BrowseFrameLayout.OnChildFocusListener | mOnChildFocusListener |
private HeadersFragment.OnHeaderClickedListener | mHeaderClickedListener |
private android.support.v17.leanback.widget.OnItemViewSelectedListener | mRowViewSelectedListener |
private android.support.v17.leanback.widget.OnItemSelectedListener | mRowSelectedListener |
private android.support.v17.leanback.widget.OnItemSelectedListener | mHeaderSelectedListener |
private final SetSelectionRunnable | mSetSelectionRunnable |
Methods Summary |
---|
public static android.os.Bundle | createArgs(android.os.Bundle args, java.lang.String title, int headersState)Create arguments for a browse fragment.
if (args == null) {
args = new Bundle();
}
args.putString(ARG_TITLE, title);
args.putInt(ARG_HEADERS_STATE, headersState);
return args;
|
protected java.lang.Object | createEntranceTransition()
return sTransitionHelper.loadTransition(getActivity(),
R.transition.lb_browse_entrance_transition);
|
private void | createHeadersTransition()
mHeadersTransition = sTransitionHelper.loadTransition(getActivity(),
mShowingHeaders ?
R.transition.lb_browse_headers_in : R.transition.lb_browse_headers_out);
sTransitionHelper.setTransitionListener(mHeadersTransition, new TransitionListener() {
@Override
public void onTransitionStart(Object transition) {
}
@Override
public void onTransitionEnd(Object transition) {
mHeadersTransition = null;
mRowsFragment.onTransitionEnd();
mHeadersFragment.onTransitionEnd();
if (mShowingHeaders) {
VerticalGridView headerGridView = mHeadersFragment.getVerticalGridView();
if (headerGridView != null && !headerGridView.hasFocus()) {
headerGridView.requestFocus();
}
} else {
VerticalGridView rowsGridView = mRowsFragment.getVerticalGridView();
if (rowsGridView != null && !rowsGridView.hasFocus()) {
rowsGridView.requestFocus();
}
}
if (mBrowseTransitionListener != null) {
mBrowseTransitionListener.onHeadersTransitionStop(mShowingHeaders);
}
}
});
|
public void | enableRowScaling(boolean enable)Enables scaling of rows when headers are present.
By default enabled to increase density.
mRowScaleEnabled = enable;
if (mRowsFragment != null) {
mRowsFragment.enableRowScaling(mRowScaleEnabled);
}
|
public android.support.v17.leanback.widget.ObjectAdapter | getAdapter()Returns the adapter containing the rows for the fragment.
return mAdapter;
|
public android.graphics.drawable.Drawable | getBadgeDrawable()Returns the badge drawable used in the fragment title.
return mBadgeDrawable;
|
public int | getBrandColor()Returns the brand color for the browse fragment.
The default is transparent.
return mBrandColor;
|
public int | getHeadersState()Returns the state of the headers column in the browse fragment.
return mHeadersState;
|
public android.support.v17.leanback.widget.OnItemClickedListener | getOnItemClickedListener()Returns the item clicked listener.
return mOnItemClickedListener;
|
public android.support.v17.leanback.widget.OnItemViewClickedListener | getOnItemViewClickedListener()Returns the item Clicked listener.
return mOnItemViewClickedListener;
|
public android.support.v17.leanback.widget.OnItemViewSelectedListener | getOnItemViewSelectedListener()Returns an item selection listener.
return mExternalOnItemViewSelectedListener;
|
public int | getSearchAffordanceColor()Returns the color used to draw the search affordance.
return getSearchAffordanceColors().color;
|
public SearchOrbView.Colors | getSearchAffordanceColors()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.String | getTitle()Returns the title for the browse fragment.
return mTitle;
|
public final boolean | isHeadersTransitionOnBackEnabled()Returns true if headers transition on back key support is enabled.
return mHeadersBackStackEnabled;
|
public boolean | isInHeadersTransition()Returns true if the headers transition is currently running.
return mHeadersTransition != null;
|
public boolean | isShowingHeaders()Returns true if headers are shown.
return mShowingHeaders;
|
private boolean | isVerticalScrolling()
// don't run transition
return mHeadersFragment.getVerticalGridView().getScrollState()
!= HorizontalGridView.SCROLL_STATE_IDLE
|| mRowsFragment.getVerticalGridView().getScrollState()
!= HorizontalGridView.SCROLL_STATE_IDLE;
|
public void | onCreate(android.os.Bundle savedInstanceState)
super.onCreate(savedInstanceState);
TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.LeanbackTheme);
mContainerListMarginStart = (int) ta.getDimension(
R.styleable.LeanbackTheme_browseRowsMarginStart, 0);
mContainerListAlignTop = (int) ta.getDimension(
R.styleable.LeanbackTheme_browseRowsMarginTop, 0);
ta.recycle();
readArguments(getArguments());
if (mCanShowHeaders) {
if (mHeadersBackStackEnabled) {
mWithHeadersBackStackName = LB_HEADERS_BACKSTACK + this;
mBackStackChangedListener = new BackStackListener();
getFragmentManager().addOnBackStackChangedListener(mBackStackChangedListener);
mBackStackChangedListener.load(savedInstanceState);
} else {
if (savedInstanceState != null) {
mShowingHeaders = savedInstanceState.getBoolean(HEADER_SHOW);
}
}
}
|
public android.view.View | onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)
if (getChildFragmentManager().findFragmentById(R.id.browse_container_dock) == null) {
mRowsFragment = new RowsFragment();
mHeadersFragment = new HeadersFragment();
getChildFragmentManager().beginTransaction()
.replace(R.id.browse_headers_dock, mHeadersFragment)
.replace(R.id.browse_container_dock, mRowsFragment).commit();
} else {
mHeadersFragment = (HeadersFragment) getChildFragmentManager()
.findFragmentById(R.id.browse_headers_dock);
mRowsFragment = (RowsFragment) getChildFragmentManager()
.findFragmentById(R.id.browse_container_dock);
}
mHeadersFragment.setHeadersGone(!mCanShowHeaders);
mRowsFragment.setAdapter(mAdapter);
if (mHeaderPresenterSelector != null) {
mHeadersFragment.setPresenterSelector(mHeaderPresenterSelector);
}
mHeadersFragment.setAdapter(mAdapter);
mRowsFragment.enableRowScaling(mRowScaleEnabled);
mRowsFragment.setOnItemSelectedListener(mRowSelectedListener);
mRowsFragment.setOnItemViewSelectedListener(mRowViewSelectedListener);
mHeadersFragment.setOnItemSelectedListener(mHeaderSelectedListener);
mHeadersFragment.setOnHeaderClickedListener(mHeaderClickedListener);
mRowsFragment.setOnItemClickedListener(mOnItemClickedListener);
mRowsFragment.setOnItemViewClickedListener(mOnItemViewClickedListener);
View root = inflater.inflate(R.layout.lb_browse_fragment, container, false);
mBrowseFrame = (BrowseFrameLayout) root.findViewById(R.id.browse_frame);
mBrowseFrame.setOnFocusSearchListener(mOnFocusSearchListener);
mBrowseFrame.setOnChildFocusListener(mOnChildFocusListener);
mTitleView = (TitleView) root.findViewById(R.id.browse_title_group);
mTitleView.setTitle(mTitle);
mTitleView.setBadgeDrawable(mBadgeDrawable);
if (mSearchAffordanceColorSet) {
mTitleView.setSearchAffordanceColors(mSearchAffordanceColors);
}
if (mExternalOnSearchClickedListener != null) {
mTitleView.setOnSearchClickedListener(mExternalOnSearchClickedListener);
}
if (mBrandColorSet) {
mHeadersFragment.setBackgroundColor(mBrandColor);
}
mSceneWithTitle = sTransitionHelper.createScene(mBrowseFrame, new Runnable() {
@Override
public void run() {
mTitleView.setVisibility(View.VISIBLE);
}
});
mSceneWithoutTitle = sTransitionHelper.createScene(mBrowseFrame, new Runnable() {
@Override
public void run() {
mTitleView.setVisibility(View.INVISIBLE);
}
});
mSceneWithHeaders = sTransitionHelper.createScene(mBrowseFrame, new Runnable() {
@Override
public void run() {
showHeaders(true);
}
});
mSceneWithoutHeaders = sTransitionHelper.createScene(mBrowseFrame, new Runnable() {
@Override
public void run() {
showHeaders(false);
}
});
mSceneAfterEntranceTransition = sTransitionHelper.createScene(mBrowseFrame, new Runnable() {
@Override
public void run() {
setEntranceTransitionEndState();
}
});
Context context = getActivity();
mTitleUpTransition = LeanbackTransitionHelper.loadTitleOutTransition(context,
sTransitionHelper);
mTitleDownTransition = LeanbackTransitionHelper.loadTitleInTransition(context,
sTransitionHelper);
if (savedInstanceState != null) {
mShowingTitle = savedInstanceState.getBoolean(TITLE_SHOW);
}
mTitleView.setVisibility(mShowingTitle ? View.VISIBLE: View.INVISIBLE);
return root;
|
public void | onDestroy()
if (mBackStackChangedListener != null) {
getFragmentManager().removeOnBackStackChangedListener(mBackStackChangedListener);
}
super.onDestroy();
|
protected void | onEntranceTransitionEnd()
mRowsFragment.onTransitionEnd();
mHeadersFragment.onTransitionEnd();
|
protected void | onEntranceTransitionStart()
mHeadersFragment.onTransitionStart();
mRowsFragment.onTransitionStart();
|
public void | onPause()
mTitleView.enableAnimation(false);
super.onPause();
|
public void | onResume()
super.onResume();
mTitleView.enableAnimation(true);
|
private void | onRowSelected(int position)
if (position != mSelectedPosition) {
mSetSelectionRunnable.mPosition = position;
mBrowseFrame.getHandler().post(mSetSelectionRunnable);
if (getAdapter() == null || getAdapter().size() == 0 || position == 0) {
if (!mShowingTitle) {
sTransitionHelper.runTransition(mSceneWithTitle, mTitleDownTransition);
mShowingTitle = true;
}
} else if (mShowingTitle) {
sTransitionHelper.runTransition(mSceneWithoutTitle, mTitleUpTransition);
mShowingTitle = false;
}
}
|
public void | onSaveInstanceState(android.os.Bundle outState)
if (mBackStackChangedListener != null) {
mBackStackChangedListener.save(outState);
} else {
outState.putBoolean(HEADER_SHOW, mShowingHeaders);
}
outState.putBoolean(TITLE_SHOW, mShowingTitle);
|
public void | onStart()
super.onStart();
mHeadersFragment.setWindowAlignmentFromTop(mContainerListAlignTop);
mHeadersFragment.setItemAlignment();
mRowsFragment.setWindowAlignmentFromTop(mContainerListAlignTop);
mRowsFragment.setItemAlignment();
mRowsFragment.setScalePivots(0, mContainerListAlignTop);
if (mCanShowHeaders && mShowingHeaders && mHeadersFragment.getView() != null) {
mHeadersFragment.getView().requestFocus();
} else if ((!mCanShowHeaders || !mShowingHeaders)
&& mRowsFragment.getView() != null) {
mRowsFragment.getView().requestFocus();
}
if (mCanShowHeaders) {
showHeaders(mShowingHeaders);
}
if (isEntranceTransitionEnabled()) {
setEntranceTransitionStartState();
}
|
private void | readArguments(android.os.Bundle args)
if (args == null) {
return;
}
if (args.containsKey(ARG_TITLE)) {
setTitle(args.getString(ARG_TITLE));
}
if (args.containsKey(ARG_HEADERS_STATE)) {
setHeadersState(args.getInt(ARG_HEADERS_STATE));
}
|
protected void | runEntranceTransition(java.lang.Object entranceTransition)
sTransitionHelper.runTransition(mSceneAfterEntranceTransition,
entranceTransition);
|
public void | setAdapter(android.support.v17.leanback.widget.ObjectAdapter adapter)Sets the adapter containing the rows for the fragment.
The items referenced by the adapter must be be derived from
{@link Row}. These rows will be used by the rows fragment and the headers
fragment (if not disabled) to render the browse rows.
mAdapter = adapter;
if (mRowsFragment != null) {
mRowsFragment.setAdapter(adapter);
mHeadersFragment.setAdapter(adapter);
}
|
public void | setBadgeDrawable(android.graphics.drawable.Drawable drawable)Sets the drawable displayed in the browse fragment title.
if (mBadgeDrawable != drawable) {
mBadgeDrawable = drawable;
if (mTitleView != null) {
mTitleView.setBadgeDrawable(drawable);
}
}
|
public void | setBrandColor(int color)Sets the brand color for the browse fragment. The brand color is used as
the primary color for UI elements in the browse fragment. For example,
the background color of the headers fragment uses the brand color.
mBrandColor = color;
mBrandColorSet = true;
if (mHeadersFragment != null) {
mHeadersFragment.setBackgroundColor(mBrandColor);
}
|
public void | setBrowseTransitionListener(android.support.v17.leanback.app.BrowseFragment$BrowseTransitionListener listener)Set a listener for browse fragment transitions.
mBrowseTransitionListener = listener;
|
void | setEntranceTransitionEndState()
setHeadersOnScreen(mShowingHeaders);
setSearchOrbViewOnScreen(true);
mRowsFragment.setEntranceTransitionState(true);
|
void | setEntranceTransitionStartState()
setHeadersOnScreen(false);
setSearchOrbViewOnScreen(false);
mRowsFragment.setEntranceTransitionState(false);
|
public void | setHeaderPresenterSelector(android.support.v17.leanback.widget.PresenterSelector headerPresenterSelector)Sets the {@link PresenterSelector} used to render the row headers.
mHeaderPresenterSelector = headerPresenterSelector;
if (mHeadersFragment != null) {
mHeadersFragment.setPresenterSelector(mHeaderPresenterSelector);
}
|
private void | setHeadersOnScreen(boolean onScreen)
MarginLayoutParams lp;
View containerList;
containerList = mHeadersFragment.getView();
lp = (MarginLayoutParams) containerList.getLayoutParams();
lp.setMarginStart(onScreen ? 0 : -mContainerListMarginStart);
containerList.setLayoutParams(lp);
|
public void | setHeadersState(int headersState)Sets the state for the headers column in the browse fragment. Must be one
of {@link #HEADERS_ENABLED}, {@link #HEADERS_HIDDEN}, or
{@link #HEADERS_DISABLED}.
if (headersState < HEADERS_ENABLED || headersState > HEADERS_DISABLED) {
throw new IllegalArgumentException("Invalid headers state: " + headersState);
}
if (DEBUG) Log.v(TAG, "setHeadersState " + headersState);
if (headersState != mHeadersState) {
mHeadersState = headersState;
switch (headersState) {
case HEADERS_ENABLED:
mCanShowHeaders = true;
mShowingHeaders = true;
break;
case HEADERS_HIDDEN:
mCanShowHeaders = true;
mShowingHeaders = false;
break;
case HEADERS_DISABLED:
mCanShowHeaders = false;
mShowingHeaders = false;
break;
default:
Log.w(TAG, "Unknown headers state: " + headersState);
break;
}
if (mHeadersFragment != null) {
mHeadersFragment.setHeadersGone(!mCanShowHeaders);
}
}
|
public final void | setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled)Enable/disable headers transition on back key support. This is enabled by
default. The BrowseFragment will add a back stack entry when headers are
showing. Running a headers transition when the back key is pressed only
works when the headers state is {@link #HEADERS_ENABLED} or
{@link #HEADERS_HIDDEN}.
NOTE: If an Activity has its own onBackPressed() handling, you must
disable this feature. You may use {@link #startHeadersTransition(boolean)}
and {@link BrowseTransitionListener} in your own back stack handling.
mHeadersBackStackEnabled = headersBackStackEnabled;
|
public void | setOnItemClickedListener(android.support.v17.leanback.widget.OnItemClickedListener listener)Sets an item clicked listener on the fragment.
OnItemClickedListener will override {@link View.OnClickListener} that
an item presenter may set during
{@link Presenter#onCreateViewHolder(ViewGroup)}. So in general, you
should choose to use an {@link OnItemClickedListener} or a
{@link View.OnClickListener} on your item views, but not both.
mOnItemClickedListener = listener;
if (mRowsFragment != null) {
mRowsFragment.setOnItemClickedListener(listener);
}
|
public void | setOnItemSelectedListener(android.support.v17.leanback.widget.OnItemSelectedListener listener)Sets an item selection listener. This listener will be called when an
item or row is selected by a user.
mExternalOnItemSelectedListener = listener;
|
public void | setOnItemViewClickedListener(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 (mRowsFragment != null) {
mRowsFragment.setOnItemViewClickedListener(listener);
}
|
public void | setOnItemViewSelectedListener(android.support.v17.leanback.widget.OnItemViewSelectedListener listener)Sets an item selection listener.
mExternalOnItemViewSelectedListener = listener;
|
public void | setOnSearchClickedListener(android.view.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 fragment title. When set to non-null, the title will
contain an element that a user may click to begin a search.
The listener's {@link View.OnClickListener#onClick onClick} method
will be invoked when the user clicks on the search element.
mExternalOnSearchClickedListener = listener;
if (mTitleView != null) {
mTitleView.setOnSearchClickedListener(listener);
}
|
private void | setRowsAlignedLeft(boolean alignLeft)
MarginLayoutParams lp;
View containerList;
containerList = mRowsFragment.getView();
lp = (MarginLayoutParams) containerList.getLayoutParams();
lp.setMarginStart(alignLeft ? 0 : mContainerListMarginStart);
containerList.setLayoutParams(lp);
|
public void | setSearchAffordanceColor(int color)Sets the color used to draw the search affordance.
A default brighter color will be set by the framework.
setSearchAffordanceColors(new SearchOrbView.Colors(color));
|
public void | setSearchAffordanceColors(SearchOrbView.Colors colors)Sets the {@link SearchOrbView.Colors} used to draw the search affordance.
mSearchAffordanceColors = colors;
mSearchAffordanceColorSet = true;
if (mTitleView != null) {
mTitleView.setSearchAffordanceColors(mSearchAffordanceColors);
}
|
void | setSearchOrbViewOnScreen(boolean onScreen)
View searchOrbView = mTitleView.getSearchAffordanceView();
MarginLayoutParams lp = (MarginLayoutParams) searchOrbView.getLayoutParams();
lp.setMarginStart(onScreen ? 0 : -mContainerListMarginStart);
searchOrbView.setLayoutParams(lp);
|
public void | setSelectedPosition(int position)Sets the selected row position with smooth animation.
setSelectedPosition(position, true);
|
public void | setSelectedPosition(int position, boolean smooth)Sets the selected row position.
mSetSelectionRunnable.mPosition = position;
mSetSelectionRunnable.mSmooth = smooth;
mBrowseFrame.getHandler().post(mSetSelectionRunnable);
|
private void | setSelection(int position, boolean smooth)
if (position != NO_POSITION) {
mRowsFragment.setSelectedPosition(position, smooth);
mHeadersFragment.setSelectedPosition(position, smooth);
}
mSelectedPosition = position;
|
public void | setTitle(java.lang.String title)Sets a title for the browse fragment.
mTitle = title;
if (mTitleView != null) {
mTitleView.setTitle(title);
}
|
private void | showHeaders(boolean show)
if (DEBUG) Log.v(TAG, "showHeaders " + show);
mHeadersFragment.setHeadersEnabled(show);
setHeadersOnScreen(show);
setRowsAlignedLeft(!show);
mRowsFragment.setExpand(!show);
|
public void | startHeadersTransition(boolean withHeaders)Start a headers transition.
This method will begin a transition to either show or hide the
headers, depending on the value of withHeaders. If headers are disabled
for this browse fragment, this method will throw an exception.
if (!mCanShowHeaders) {
throw new IllegalStateException("Cannot start headers transition");
}
if (isInHeadersTransition() || mShowingHeaders == withHeaders) {
return;
}
startHeadersTransitionInternal(withHeaders);
|
private void | startHeadersTransitionInternal(boolean withHeaders)
if (getFragmentManager().isDestroyed()) {
return;
}
mShowingHeaders = withHeaders;
mRowsFragment.onExpandTransitionStart(!withHeaders, new Runnable() {
@Override
public void run() {
mHeadersFragment.onTransitionStart();
createHeadersTransition();
if (mBrowseTransitionListener != null) {
mBrowseTransitionListener.onHeadersTransitionStart(withHeaders);
}
sTransitionHelper.runTransition(withHeaders ? mSceneWithHeaders : mSceneWithoutHeaders,
mHeadersTransition);
if (mHeadersBackStackEnabled) {
if (!withHeaders) {
getFragmentManager().beginTransaction()
.addToBackStack(mWithHeadersBackStackName).commit();
} else {
int index = mBackStackChangedListener.mIndexOfHeadersBackStack;
if (index >= 0) {
BackStackEntry entry = getFragmentManager().getBackStackEntryAt(index);
getFragmentManager().popBackStackImmediate(entry.getId(),
FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
}
}
});
|