public
class
BrowseSupportFragment
extends BrandedSupportFragment
java.lang.Object | |||
↳ | android.support.v4.app.Fragment | ||
↳ | android.support.v17.leanback.app.BrandedSupportFragment | ||
↳ | android.support.v17.leanback.app.BrowseSupportFragment |
A fragment for creating Leanback browse screens. It is composed of a RowsSupportFragment and a HeadersSupportFragment.
A BrowseSupportFragment renders the elements of its ObjectAdapter
as a set
of rows in a vertical list. The elements in this adapter must be subclasses
of Row
.
The HeadersSupportFragment can be set to be either shown or hidden by default, or
may be disabled entirely. See setHeadersState(int)
for details.
By default the BrowseSupportFragment includes support for returning to the headers
when the user presses Back. For Activities that customize onBackPressed()
, you must disable this default Back key support by
calling setHeadersTransitionOnBackEnabled(boolean)
with false and
use BrowseSupportFragment.BrowseTransitionListener
and
startHeadersTransition(boolean)
.
The recommended theme to use with a BrowseSupportFragment is
Theme_Leanback_Browse
.
Nested classes | |
---|---|
class |
BrowseSupportFragment.BrowseTransitionListener
Listener for transitions between browse headers and rows. |
class |
BrowseSupportFragment.FragmentFactory<T extends Fragment>
Factory class responsible for creating fragment given the current item. |
interface |
BrowseSupportFragment.FragmentHost
Possible set of actions that |
class |
BrowseSupportFragment.ListRowFragmentFactory
FragmentFactory implementation for |
class |
BrowseSupportFragment.MainFragmentAdapter<T extends Fragment>
Interface that defines the interaction between |
interface |
BrowseSupportFragment.MainFragmentAdapterProvider
Interface to be implemented by all fragments for providing an instance of
|
class |
BrowseSupportFragment.MainFragmentAdapterRegistry
Registry class maintaining the mapping of |
class |
BrowseSupportFragment.MainFragmentRowsAdapter<T extends Fragment>
This is used to pass information to |
interface |
BrowseSupportFragment.MainFragmentRowsAdapterProvider
Interface to be implemented by |
Constants | |
---|---|
int |
HEADERS_DISABLED
The headers fragment is disabled and will never be shown. |
int |
HEADERS_ENABLED
The headers fragment is enabled and shown by default. |
int |
HEADERS_HIDDEN
The headers fragment is enabled and hidden by default. |
Public constructors | |
---|---|
BrowseSupportFragment()
|
Public methods | |
---|---|
static
Bundle
|
createArgs(Bundle args, String title, int headersState)
Creates arguments for a browse fragment. |
void
|
enableMainFragmentScaling(boolean enable)
Enables scaling of main fragment when headers are present. |
void
|
enableRowScaling(boolean enable)
This method is deprecated.
use |
ObjectAdapter
|
getAdapter()
Returns the adapter containing the rows for the fragment. |
int
|
getBrandColor()
Returns the brand color for the browse fragment. |
int
|
getHeadersState()
Returns the state of the headers column in the browse fragment. |
HeadersSupportFragment
|
getHeadersSupportFragment()
Get currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet. |
final
BrowseSupportFragment.MainFragmentAdapterRegistry
|
getMainFragmentRegistry()
|
OnItemViewClickedListener
|
getOnItemViewClickedListener()
Returns the item Clicked listener. |
OnItemViewSelectedListener
|
getOnItemViewSelectedListener()
Returns an item selection listener. |
final
ProgressBarManager
|
getProgressBarManager()
Returns the |
RowsSupportFragment
|
getRowsSupportFragment()
Get RowsSupportFragment if it's bound to BrowseSupportFragment or null if either BrowseSupportFragment has not been created yet or a different fragment is bound to it. |
int
|
getSelectedPosition()
Gets position of currently selected row. |
final
boolean
|
isHeadersTransitionOnBackEnabled()
Returns true if headers transition on back key support is enabled. |
boolean
|
isInHeadersTransition()
Returns true if the headers transition is currently running. |
boolean
|
isShowingHeaders()
Returns true if headers are shown. |
void
|
onCreate(Bundle savedInstanceState)
Called to do initial creation of a fragment. |
View
|
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view. |
void
|
onDestroy()
Called when the fragment is no longer in use. |
void
|
onDestroyView()
Called when the view previously created by |
void
|
onSaveInstanceState(Bundle outState)
Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted. |
void
|
onStart()
Called when the Fragment is visible to the user. |
void
|
onViewCreated(View view, Bundle savedInstanceState)
Called immediately after |
void
|
prepareEntranceTransition()
Enables entrance transition. |
void
|
setAdapter(ObjectAdapter adapter)
Sets the adapter containing the rows for the fragment. |
void
|
setBrandColor(int color)
Sets the brand color for the browse fragment. |
void
|
setBrowseTransitionListener(BrowseSupportFragment.BrowseTransitionListener listener)
Sets a listener for browse fragment transitions. |
void
|
setHeaderPresenterSelector(PresenterSelector headerPresenterSelector)
Sets the |
void
|
setHeadersState(int headersState)
Sets the state for the headers column in the browse fragment. |
final
void
|
setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled)
Enables/disables headers transition on back key support. |
void
|
setOnItemViewClickedListener(OnItemViewClickedListener listener)
Sets an item clicked listener on the fragment. |
void
|
setOnItemViewSelectedListener(OnItemViewSelectedListener listener)
Sets an item selection listener. |
void
|
setSelectedPosition(int position)
Sets the selected row position with smooth animation. |
void
|
setSelectedPosition(int rowPosition, boolean smooth, Presenter.ViewHolderTask rowHolderTask)
Selects a Row and perform an optional task on the Row. |
void
|
setSelectedPosition(int position, boolean smooth)
Sets the selected row position. |
void
|
startEntranceTransition()
When fragment finishes loading data, it should call startEntranceTransition() to execute the entrance transition. |
void
|
startHeadersTransition(boolean withHeaders)
Starts a headers transition. |
Protected methods | |
---|---|
Object
|
createEntranceTransition()
Create entrance transition. |
void
|
onEntranceTransitionEnd()
Callback when entrance transition is ended. |
void
|
onEntranceTransitionPrepare()
Callback when entrance transition is prepared. |
void
|
onEntranceTransitionStart()
Callback when entrance transition is started. |
void
|
runEntranceTransition(Object entranceTransition)
Run entrance transition. |
Inherited methods | |
---|---|
From
class
android.support.v17.leanback.app.BrandedSupportFragment
| |
From
class
android.support.v4.app.Fragment
| |
From
class
java.lang.Object
| |
From
interface
android.content.ComponentCallbacks
| |
From
interface
android.view.View.OnCreateContextMenuListener
|
int HEADERS_DISABLED
The headers fragment is disabled and will never be shown.
Constant Value: 3 (0x00000003)
int HEADERS_ENABLED
The headers fragment is enabled and shown by default.
Constant Value: 1 (0x00000001)
int HEADERS_HIDDEN
The headers fragment is enabled and hidden by default.
Constant Value: 2 (0x00000002)
BrowseSupportFragment ()
Bundle createArgs (Bundle args, String title, int headersState)
Creates arguments for a browse fragment.
Parameters | |
---|---|
args |
Bundle :
The Bundle to place arguments into, or null if the method
should return a new Bundle. |
title |
String :
The title of the BrowseSupportFragment. |
headersState |
int :
The initial state of the headers of the
BrowseSupportFragment. Must be one of HEADERS_ENABLED , HEADERS_HIDDEN , or HEADERS_DISABLED . |
Returns | |
---|---|
Bundle |
A Bundle with the given arguments for creating a BrowseSupportFragment. |
void enableMainFragmentScaling (boolean enable)
Enables scaling of main fragment when headers are present. For the page/row fragment,
scaling is enabled only when both this method and
isScalingEnabled()
are enabled.
Parameters | |
---|---|
enable |
boolean :
true to enable row scaling
|
void enableRowScaling (boolean enable)
This method is deprecated.
use enableMainFragmentScaling(boolean)
instead.
Parameters | |
---|---|
enable |
boolean :
true to enable row scaling
|
ObjectAdapter getAdapter ()
Returns the adapter containing the rows for the fragment.
Returns | |
---|---|
ObjectAdapter |
int getBrandColor ()
Returns the brand color for the browse fragment. The default is transparent.
Returns | |
---|---|
int |
int getHeadersState ()
Returns the state of the headers column in the browse fragment.
Returns | |
---|---|
int |
HeadersSupportFragment getHeadersSupportFragment ()
Get currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet.
Returns | |
---|---|
HeadersSupportFragment |
Currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet. |
BrowseSupportFragment.MainFragmentAdapterRegistry getMainFragmentRegistry ()
Returns | |
---|---|
BrowseSupportFragment.MainFragmentAdapterRegistry |
OnItemViewClickedListener getOnItemViewClickedListener ()
Returns the item Clicked listener.
Returns | |
---|---|
OnItemViewClickedListener |
OnItemViewSelectedListener getOnItemViewSelectedListener ()
Returns an item selection listener.
Returns | |
---|---|
OnItemViewSelectedListener |
ProgressBarManager getProgressBarManager ()
Returns the ProgressBarManager
.
Returns | |
---|---|
ProgressBarManager |
RowsSupportFragment getRowsSupportFragment ()
Get RowsSupportFragment if it's bound to BrowseSupportFragment or null if either BrowseSupportFragment has not been created yet or a different fragment is bound to it.
Returns | |
---|---|
RowsSupportFragment |
RowsSupportFragment if it's bound to BrowseSupportFragment or null otherwise. |
int getSelectedPosition ()
Gets position of currently selected row.
Returns | |
---|---|
int |
Position of currently selected row. |
boolean isHeadersTransitionOnBackEnabled ()
Returns true if headers transition on back key support is enabled.
Returns | |
---|---|
boolean |
boolean isInHeadersTransition ()
Returns true if the headers transition is currently running.
Returns | |
---|---|
boolean |
boolean isShowingHeaders ()
Returns true if headers are shown.
Returns | |
---|---|
boolean |
void onCreate (Bundle savedInstanceState)
Called to do initial creation of a fragment. This is called after
onAttach(Activity)
and before
onCreateView(LayoutInflater, ViewGroup, Bundle)
.
Note that this can be called while the fragment's activity is
still in the process of being created. As such, you can not rely
on things like the activity's content view hierarchy being initialized
at this point. If you want to do work once the activity itself is
created, see onActivityCreated(Bundle)
.
Any restored child fragments will be created before the base
Fragment.onCreate
method returns.
Parameters | |
---|---|
savedInstanceState |
Bundle :
If the fragment is being re-created from
a previous saved state, this is the state.
|
View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view.
This is optional, and non-graphical fragments can return null (which
is the default implementation). This will be called between
onCreate(Bundle)
and onActivityCreated(Bundle)
.
If you return a View from here, you will later be called in
onDestroyView()
when the view is being released.
Parameters | |
---|---|
inflater |
LayoutInflater :
The LayoutInflater object that can be used to inflate
any views in the fragment, |
container |
ViewGroup :
If non-null, this is the parent view that the fragment's
UI should be attached to. The fragment should not add the view itself,
but this can be used to generate the LayoutParams of the view. |
savedInstanceState |
Bundle :
If non-null, this fragment is being re-constructed
from a previous saved state as given here. |
Returns | |
---|---|
View |
Return the View for the fragment's UI, or null. |
void onDestroy ()
Called when the fragment is no longer in use. This is called
after onStop()
and before onDetach()
.
void onDestroyView ()
Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle)
has
been detached from the fragment. The next time the fragment needs
to be displayed, a new view will be created. This is called
after onStop()
and before onDestroy()
. It is called
regardless of whether onCreateView(LayoutInflater, ViewGroup, Bundle)
returned a
non-null view. Internally it is called after the view's state has
been saved but before it has been removed from its parent.
void onSaveInstanceState (Bundle outState)
Called to ask the fragment to save its current dynamic state, so it
can later be reconstructed in a new instance of its process is
restarted. If a new instance of the fragment later needs to be
created, the data you place in the Bundle here will be available
in the Bundle given to onCreate(Bundle)
,
onCreateView(LayoutInflater, ViewGroup, Bundle)
, and
onActivityCreated(Bundle)
.
This corresponds to Activity.onSaveInstanceState(Bundle)
and most of the discussion there
applies here as well. Note however: this method may be called
at any time before onDestroy()
. There are many situations
where a fragment may be mostly torn down (such as when placed on the
back stack with no UI showing), but its state will not be saved until
its owning activity actually needs to save its state.
Parameters | |
---|---|
outState |
Bundle :
Bundle in which to place your saved state.
|
void onStart ()
Called when the Fragment is visible to the user. This is generally
tied to Activity.onStart
of the containing
Activity's lifecycle.
void onViewCreated (View view, Bundle savedInstanceState)
Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle)
has returned, but before any saved state has been restored in to the view.
This gives subclasses a chance to initialize themselves once
they know their view hierarchy has been completely created. The fragment's
view hierarchy is not however attached to its parent at this point.
Parameters | |
---|---|
view |
View :
The View returned by onCreateView(LayoutInflater, ViewGroup, Bundle) . |
savedInstanceState |
Bundle :
If non-null, this fragment is being re-constructed
from a previous saved state as given here.
|
void prepareEntranceTransition ()
Enables entrance transition.
Entrance transition is the standard slide-in transition that shows rows of data in browse screen and details screen.
The method is ignored before LOLLIPOP (API21).
This method must be called in or
before onCreate(). Typically entrance transition should be enabled when savedInstance is
null so that fragment restored from instanceState does not run an extra entrance transition.
When the entrance transition is enabled, the fragment will make headers and content
hidden initially.
When data of rows are ready, app must call startEntranceTransition()
to kick off
the transition, otherwise the rows will be invisible forever.
It is similar to android:windowsEnterTransition and can be considered a late-executed android:windowsEnterTransition controlled by app. There are two reasons that app needs it:
Transition object is returned by createEntranceTransition(). Typically the app does not need override the default transition that browse and details provides.
void setAdapter (ObjectAdapter adapter)
Sets the adapter containing the rows for the fragment.
The items referenced by the adapter must be be derived from
Row
. These rows will be used by the rows fragment and the headers
fragment (if not disabled) to render the browse rows.
Parameters | |
---|---|
adapter |
ObjectAdapter :
An ObjectAdapter for the browse rows. All items must
derive from Row .
|
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.
Parameters | |
---|---|
color |
int :
The color to use as the brand color of the fragment.
|
void setBrowseTransitionListener (BrowseSupportFragment.BrowseTransitionListener listener)
Sets a listener for browse fragment transitions.
Parameters | |
---|---|
listener |
BrowseSupportFragment.BrowseTransitionListener :
The listener to call when a browse headers transition
begins or ends.
|
void setHeaderPresenterSelector (PresenterSelector headerPresenterSelector)
Sets the PresenterSelector
used to render the row headers.
Parameters | |
---|---|
headerPresenterSelector |
PresenterSelector :
The PresenterSelector that will determine
the Presenter for each row header.
|
void setHeadersState (int headersState)
Sets the state for the headers column in the browse fragment. Must be one
of HEADERS_ENABLED
, HEADERS_HIDDEN
, or
HEADERS_DISABLED
.
Parameters | |
---|---|
headersState |
int :
The state of the headers for the browse fragment.
|
void setHeadersTransitionOnBackEnabled (boolean headersBackStackEnabled)
Enables/disables headers transition on back key support. This is enabled by
default. The BrowseSupportFragment 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 HEADERS_ENABLED
or
HEADERS_HIDDEN
.
NOTE: If an Activity has its own onBackPressed() handling, you must
disable this feature. You may use startHeadersTransition(boolean)
and BrowseSupportFragment.BrowseTransitionListener
in your own back stack handling.
Parameters | |
---|---|
headersBackStackEnabled |
boolean
|
void setOnItemViewClickedListener (OnItemViewClickedListener listener)
Sets an item clicked listener on the fragment.
OnItemViewClickedListener will override View.OnClickListener
that
item presenter sets during onCreateViewHolder(ViewGroup)
.
So in general, developer should choose one of the listeners but not both.
Parameters | |
---|---|
listener |
OnItemViewClickedListener
|
void setOnItemViewSelectedListener (OnItemViewSelectedListener listener)
Sets an item selection listener.
Parameters | |
---|---|
listener |
OnItemViewSelectedListener
|
void setSelectedPosition (int position)
Sets the selected row position with smooth animation.
Parameters | |
---|---|
position |
int
|
void setSelectedPosition (int rowPosition, boolean smooth, Presenter.ViewHolderTask rowHolderTask)
Selects a Row and perform an optional task on the Row. For example
setSelectedPosition(10, true, new ListRowPresenterSelectItemViewHolderTask(5))
scrolls to 11th row and selects 6th item on that row. The method will be ignored if
RowsSupportFragment has not been created (i.e. before onCreateView(LayoutInflater, ViewGroup, Bundle)
).
Parameters | |
---|---|
rowPosition |
int :
Which row to select. |
smooth |
boolean :
True to scroll to the row, false for no animation. |
rowHolderTask |
Presenter.ViewHolderTask :
Optional task to perform on the Row. When the task is not null, headers
fragment will be collapsed.
|
void setSelectedPosition (int position, boolean smooth)
Sets the selected row position.
Parameters | |
---|---|
position |
int
|
smooth |
boolean
|
void startEntranceTransition ()
When fragment finishes loading data, it should call startEntranceTransition() to execute the entrance transition. startEntranceTransition() will start transition only if both two conditions are satisfied:
If startEntranceTransition() is called before onViewCreated(), it will be pending and executed when view is created.
void startHeadersTransition (boolean withHeaders)
Starts 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.
Parameters | |
---|---|
withHeaders |
boolean :
True if the headers should transition to being shown,
false if the transition should result in headers being hidden.
|
Object createEntranceTransition ()
Create entrance transition. Subclass can override to load transition from resource or construct manually. Typically app does not need to override the default transition that browse and details provides.
Returns | |
---|---|
Object |
void onEntranceTransitionEnd ()
Callback when entrance transition is ended.
void onEntranceTransitionPrepare ()
Callback when entrance transition is prepared. This is when fragment should stop user input and animations.
void onEntranceTransitionStart ()
Callback when entrance transition is started. This is when fragment should stop processing layout.
void runEntranceTransition (Object entranceTransition)
Run entrance transition. Subclass may use TransitionManager to perform go(Scene) or beginDelayedTransition(). App should not override the default implementation of browse and details fragment.
Parameters | |
---|---|
entranceTransition |
Object
|