public class BrowseSupportFragment extends BrandedSupportFragment
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 FragmentActivity.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
android.support.v17.leanback.R.style#Theme_Leanback_Browse
.
Modifier and Type | Class and Description |
---|---|
static class |
BrowseSupportFragment.BrowseTransitionListener
Listener for transitions between browse headers and rows.
|
static class |
BrowseSupportFragment.FragmentFactory<T extends Fragment>
Factory class responsible for creating fragment given the current item.
|
static interface |
BrowseSupportFragment.FragmentHost
Possible set of actions that
BrowseSupportFragment exposes to clients. |
static class |
BrowseSupportFragment.ListRowFragmentFactory
FragmentFactory implementation for
ListRow . |
static class |
BrowseSupportFragment.MainFragmentAdapter<T extends Fragment>
Interface that defines the interaction between
BrowseSupportFragment and it's main
content fragment. |
static interface |
BrowseSupportFragment.MainFragmentAdapterProvider
Interface to be implemented by all fragments for providing an instance of
BrowseSupportFragment.MainFragmentAdapter . |
static class |
BrowseSupportFragment.MainFragmentAdapterRegistry
Registry class maintaining the mapping of
Row subclasses to BrowseSupportFragment.FragmentFactory . |
static class |
BrowseSupportFragment.MainFragmentRowsAdapter<T extends Fragment>
This is used to pass information to
RowsSupportFragment or its subclasses. |
static interface |
BrowseSupportFragment.MainFragmentRowsAdapterProvider
Interface to be implemented by
RowsSupportFragment and it's subclasses for providing
an instance of BrowseSupportFragment.MainFragmentRowsAdapter . |
Fragment.InstantiationException, Fragment.SavedState
Modifier and Type | Field and Description |
---|---|
static int |
HEADERS_DISABLED
The headers fragment is disabled and will never be shown.
|
static int |
HEADERS_ENABLED
The headers fragment is enabled and shown by default.
|
static int |
HEADERS_HIDDEN
The headers fragment is enabled and hidden by default.
|
Constructor and Description |
---|
BrowseSupportFragment() |
Modifier and Type | Method and Description |
---|---|
static Bundle |
createArgs(Bundle args,
String title,
int headersState)
Creates arguments for a browse fragment.
|
protected Object |
createEntranceTransition()
Create entrance transition.
|
void |
enableMainFragmentScaling(boolean enable)
Enables scaling of main fragment when headers are present.
|
void |
enableRowScaling(boolean enable)
Deprecated.
use
enableMainFragmentScaling(boolean) instead. |
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.
|
BrowseSupportFragment.MainFragmentAdapterRegistry |
getMainFragmentRegistry() |
OnItemViewClickedListener |
getOnItemViewClickedListener()
Returns the item Clicked listener.
|
OnItemViewSelectedListener |
getOnItemViewSelectedListener()
Returns an item selection listener.
|
ProgressBarManager |
getProgressBarManager()
Returns the
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.
|
int |
getSelectedPosition()
Gets position of currently selected row.
|
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
Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) has
been detached from the fragment. |
protected void |
onEntranceTransitionEnd()
Callback when entrance transition is ended.
|
protected void |
onEntranceTransitionPrepare()
Callback when entrance transition is prepared.
|
protected void |
onEntranceTransitionStart()
Callback when entrance transition is started.
|
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
Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
has returned, but before any saved state has been restored in to the view. |
void |
prepareEntranceTransition()
Enables entrance transition.
|
protected void |
runEntranceTransition(Object entranceTransition)
Run 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
PresenterSelector used to render the row headers. |
void |
setHeadersState(int headersState)
Sets the state for the headers column in the browse fragment.
|
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 position,
boolean smooth)
Sets the selected row position.
|
void |
setSelectedPosition(int rowPosition,
boolean smooth,
Presenter.ViewHolderTask rowHolderTask)
Selects a Row and perform an optional task on the Row.
|
void |
startEntranceTransition()
When fragment finishes loading data, it should call startEntranceTransition()
to execute the entrance transition.
|
void |
startHeadersTransition(boolean withHeaders)
Starts a headers transition.
|
getBadgeDrawable, getSearchAffordanceColor, getSearchAffordanceColors, getTitle, getTitleView, getTitleViewAdapter, installTitleView, isShowingTitle, onInflateTitleView, onPause, onResume, setBadgeDrawable, setOnSearchClickedListener, setSearchAffordanceColor, setSearchAffordanceColors, setTitle, setTitleView, showTitle, showTitle
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, hasOptionsMenu, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isMenuVisible, isRemoving, isResumed, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreateAnimation, onCreateContextMenu, onCreateOptionsMenu, onDestroyOptionsMenu, onDetach, onHiddenChanged, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onStop, onViewStateRestored, registerForContextMenu, requestPermissions, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterTransition, setExitSharedElementCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, toString, unregisterForContextMenu
public static final int HEADERS_ENABLED
public static final int HEADERS_HIDDEN
public static final int HEADERS_DISABLED
public static Bundle createArgs(Bundle args, String title, int headersState)
args
- The Bundle to place arguments into, or null if the method
should return a new Bundle.title
- The title of the BrowseSupportFragment.headersState
- The initial state of the headers of the
BrowseSupportFragment. Must be one of HEADERS_ENABLED
, HEADERS_HIDDEN
, or HEADERS_DISABLED
.public void setBrandColor(int color)
color
- The color to use as the brand color of the fragment.public int getBrandColor()
public void setAdapter(ObjectAdapter adapter)
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.
adapter
- An ObjectAdapter for the browse rows. All items must
derive from Row
.public final BrowseSupportFragment.MainFragmentAdapterRegistry getMainFragmentRegistry()
public ObjectAdapter getAdapter()
public void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)
public OnItemViewSelectedListener getOnItemViewSelectedListener()
public RowsSupportFragment getRowsSupportFragment()
public HeadersSupportFragment getHeadersSupportFragment()
public void setOnItemViewClickedListener(OnItemViewClickedListener listener)
View.OnClickListener
that
item presenter sets during Presenter.onCreateViewHolder(ViewGroup)
.
So in general, developer should choose one of the listeners but not both.public OnItemViewClickedListener getOnItemViewClickedListener()
public void startHeadersTransition(boolean withHeaders)
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.
withHeaders
- True if the headers should transition to being shown,
false if the transition should result in headers being hidden.public boolean isInHeadersTransition()
public boolean isShowingHeaders()
public void setBrowseTransitionListener(BrowseSupportFragment.BrowseTransitionListener listener)
listener
- The listener to call when a browse headers transition
begins or ends.@Deprecated public void enableRowScaling(boolean enable)
enableMainFragmentScaling(boolean)
instead.enable
- true to enable row scalingpublic void enableMainFragmentScaling(boolean enable)
BrowseSupportFragment.MainFragmentAdapter.isScalingEnabled()
are enabled.enable
- true to enable row scalingpublic void onSaveInstanceState(Bundle outState)
Fragment
Fragment.onCreate(Bundle)
,
Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
, and
Fragment.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 Fragment.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.
onSaveInstanceState
in class BrandedSupportFragment
outState
- Bundle in which to place your saved state.public void onCreate(Bundle savedInstanceState)
Fragment
Fragment.onAttach(Activity)
and before
Fragment.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 Fragment.onActivityCreated(Bundle)
.
Any restored child fragments will be created before the base
Fragment.onCreate
method returns.
public void onDestroyView()
Fragment
Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.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 Fragment.onStop()
and before Fragment.onDestroy()
. It is called
regardless of whether Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.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.onDestroyView
in class BrandedSupportFragment
public void onDestroy()
Fragment
Fragment.onStop()
and before Fragment.onDetach()
.public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Fragment
Fragment.onCreate(Bundle)
and Fragment.onActivityCreated(Bundle)
.
If you return a View from here, you will later be called in
Fragment.onDestroyView()
when the view is being released.
onCreateView
in class Fragment
inflater
- The LayoutInflater object that can be used to inflate
any views in the fragment,container
- 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
- If non-null, this fragment is being re-constructed
from a previous saved state as given here.public void setHeaderPresenterSelector(PresenterSelector headerPresenterSelector)
PresenterSelector
used to render the row headers.headerPresenterSelector
- The PresenterSelector that will determine
the Presenter for each row header.public void setSelectedPosition(int position)
public int getSelectedPosition()
public void setSelectedPosition(int position, boolean smooth)
public void setSelectedPosition(int rowPosition, boolean smooth, Presenter.ViewHolderTask rowHolderTask)
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)
).rowPosition
- Which row to select.smooth
- True to scroll to the row, false for no animation.rowHolderTask
- Optional task to perform on the Row. When the task is not null, headers
fragment will be collapsed.public void onStart()
Fragment
Activity.onStart
of the containing
Activity's lifecycle.onStart
in class BrandedSupportFragment
public final void setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled)
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.
public final boolean isHeadersTransitionOnBackEnabled()
public void setHeadersState(int headersState)
HEADERS_ENABLED
, HEADERS_HIDDEN
, or
HEADERS_DISABLED
.headersState
- The state of the headers for the browse fragment.public int getHeadersState()
protected Object createEntranceTransition()
protected void runEntranceTransition(Object entranceTransition)
protected void onEntranceTransitionPrepare()
protected void onEntranceTransitionStart()
protected void onEntranceTransitionEnd()
public void onViewCreated(View view, Bundle savedInstanceState)
Fragment
Fragment.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.onViewCreated
in class BrandedSupportFragment
view
- The View returned by Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
.savedInstanceState
- If non-null, this fragment is being re-constructed
from a previous saved state as given here.public void prepareEntranceTransition()
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.
public void startEntranceTransition()
If startEntranceTransition() is called before onViewCreated(), it will be pending and executed when view is created.
public final ProgressBarManager getProgressBarManager()
ProgressBarManager
.