BrowseFragment
class BrowseFragment : BaseFragment
| kotlin.Any | ||||
| ↳ | android.app.Fragment | |||
| ↳ | androidx.leanback.app.BrandedFragment | |||
| ↳ | androidx.leanback.app.BaseFragment | |||
| ↳ | androidx.leanback.app.BrowseFragment |
A fragment for creating Leanback browse screens. It is composed of a RowsFragment and a HeadersFragment.
A BrowseFragment 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 HeadersFragment can be set to be either shown or hidden by default, or may be disabled entirely. See setHeadersState for details.
By default the BrowseFragment 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 with false and use BrowseFragment.BrowseTransitionListener and startHeadersTransition.
The recommended theme to use with a BrowseFragment is Theme_Leanback_Browse.
Summary
Nested types |
|---|
|
This class is deprecated. |
abstract class BrowseFragment.FragmentFactory<T : Fragment?>This class is deprecated. |
interface BrowseFragment.FragmentHostThis interface is deprecated. |
|
This class is deprecated. |
class BrowseFragment.MainFragmentAdapter<T : Fragment?>This class is deprecated. |
|
This interface is deprecated. |
|
This class is deprecated. |
class BrowseFragment.MainFragmentRowsAdapter<T : Fragment?>This class is deprecated. |
|
This interface is deprecated. |
Constants |
|
|---|---|
const Int |
HEADERS_DISABLED = 3The headers fragment is disabled and will never be shown. |
const Int |
HEADERS_ENABLED = 1The headers fragment is enabled and shown by default. |
const Int |
HEADERS_HIDDEN = 2The headers fragment is enabled and hidden by default. |
Public constructors |
|---|
Public functions |
|
|---|---|
java-static Bundle! |
Creates arguments for a browse fragment. |
Unit |
Enables scaling of main fragment when headers are present. |
Unit |
This function is deprecated. use |
ObjectAdapter! |
Returns the adapter containing the rows for the fragment. |
@ColorInt Int |
Returns the brand color for the browse fragment. |
HeadersFragment! |
Get currently bound HeadersFragment or null if HeadersFragment has not been created yet. |
Int |
Returns the state of the headers column in the browse fragment. |
Fragment! |
|
BrowseFragment.MainFragmentAdapterRegistry! |
|
OnItemViewClickedListener! |
Returns the item Clicked listener. |
OnItemViewSelectedListener! |
Returns an item selection listener. |
RowsFragment! |
Get RowsFragment if it's bound to BrowseFragment or null if either BrowseFragment has not been created yet or a different fragment is bound to it. |
Int |
Gets position of currently selected row. |
RowPresenter.ViewHolder! |
|
Boolean |
Returns true if headers transition on back key support is enabled. |
Boolean |
Returns true if the headers transition is currently running. |
Boolean |
Returns true if headers are shown. |
Unit |
This function is deprecated. |
HeadersFragment! |
Creates a new |
View? |
This function is deprecated. |
Unit |
This function is deprecated. |
Unit |
This function is deprecated. |
Unit |
This function is deprecated. |
Unit |
This function is deprecated. |
Unit |
This function is deprecated. |
Unit |
Sets the adapter containing the rows for the fragment. |
Unit |
Sets the brand color for the browse fragment. |
Unit |
Sets a listener for browse fragment transitions. |
Unit |
Sets the |
Unit |
Sets the state for the headers column in the browse fragment. |
Unit |
Enables/disables headers transition on back key support. |
Unit |
Sets an item clicked listener on the fragment. |
Unit |
Sets an item selection listener. |
Unit |
Sets the selected row position with smooth animation. |
Unit |
Sets the selected row position. |
Unit |
Selects a Row and perform an optional task on the Row. |
Unit |
Starts a headers transition. |
Protected functions |
|
|---|---|
Any! |
Create entrance transition. |
Unit |
Callback when entrance transition is ended. |
Unit |
Callback when entrance transition is prepared. |
Unit |
Callback when entrance transition is started. |
Unit |
Run entrance transition. |
Inherited Constants |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
Public constructors
Public functions
java-static funcreateArgs(args: Bundle!, title: String!, headersState: Int): Bundle!
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 BrowseFragment. |
headersState: Int |
The initial state of the headers of the BrowseFragment. Must be one of |
| Returns | |
|---|---|
Bundle! |
A Bundle with the given arguments for creating a BrowseFragment. |
funenableMainFragmentScaling(enable: Boolean): Unit
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 |
fungetBrandColor(): @ColorInt Int
Returns the brand color for the browse fragment. The default is transparent.
fungetHeadersFragment(): HeadersFragment!
Get currently bound HeadersFragment or null if HeadersFragment has not been created yet.
| Returns | |
|---|---|
HeadersFragment! |
Currently bound HeadersFragment or null if HeadersFragment has not been created yet. |
fungetOnItemViewSelectedListener(): OnItemViewSelectedListener!
Returns an item selection listener.
fungetRowsFragment(): RowsFragment!
Get RowsFragment if it's bound to BrowseFragment or null if either BrowseFragment has not been created yet or a different fragment is bound to it.
| Returns | |
|---|---|
RowsFragment! |
RowsFragment if it's bound to BrowseFragment or null otherwise. |
fungetSelectedPosition(): Int
Gets position of currently selected row.
| Returns | |
|---|---|
Int |
Position of currently selected row. |
fungetSelectedRowViewHolder(): RowPresenter.ViewHolder!
| Returns | |
|---|---|
RowPresenter.ViewHolder! |
selected row ViewHolder inside fragment created by |
funisHeadersTransitionOnBackEnabled(): Boolean
Returns true if headers transition on back key support is enabled.
funonCreateHeadersFragment(): HeadersFragment!
Creates a new HeadersFragment instance. Subclass of BrowseFragment may override and return an instance of subclass of HeadersFragment, e.g. when app wants to replace presenter to render HeaderItem.
| Returns | |
|---|---|
HeadersFragment! |
A new instance of |
funonCreateView(
inflater: LayoutInflater!,
container: ViewGroup?,
savedInstanceState: Bundle!
): View?
funsetAdapter(adapter: ObjectAdapter!): Unit
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 |
funsetBrandColor(color: @ColorInt Int): Unit
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.
funsetBrowseTransitionListener(
listener: BrowseFragment.BrowseTransitionListener!
): Unit
Sets a listener for browse fragment transitions.
| Parameters | |
|---|---|
listener: BrowseFragment.BrowseTransitionListener! |
The listener to call when a browse headers transition begins or ends. |
funsetHeaderPresenterSelector(headerPresenterSelector: PresenterSelector!): Unit
Sets the PresenterSelector used to render the row headers.
| Parameters | |
|---|---|
headerPresenterSelector: PresenterSelector! |
The PresenterSelector that will determine the Presenter for each row header. |
funsetHeadersState(headersState: Int): Unit
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. |
funsetHeadersTransitionOnBackEnabled(headersBackStackEnabled: Boolean): Unit
Enables/disables 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 HEADERS_ENABLED or HEADERS_HIDDEN.
NOTE: If an Activity has its own onBackPressed() handling, you must disable this feature. You may use startHeadersTransition and BrowseTransitionListener in your own back stack handling.
funsetOnItemViewClickedListener(listener: OnItemViewClickedListener!): Unit
Sets an item clicked listener on the fragment. OnItemViewClickedListener will override View.OnClickListener that item presenter sets during onCreateViewHolder. So in general, developer should choose one of the listeners but not both.
funsetOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit
Sets an item selection listener.
funsetSelectedPosition(
rowPosition: Int,
smooth: Boolean,
rowHolderTask: Presenter.ViewHolderTask!
): Unit
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 RowsFragment has not been created (i.e. before onCreateView).
| 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. |
funstartHeadersTransition(withHeaders: Boolean): Unit
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. |
Protected functions
createEntranceTransition
protected funcreateEntranceTransition(): Any!
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.
onEntranceTransitionEnd
protected funonEntranceTransitionEnd(): Unit
Callback when entrance transition is ended.
onEntranceTransitionPrepare
protected funonEntranceTransitionPrepare(): Unit
Callback when entrance transition is prepared. This is when fragment should stop user input and animations.
onEntranceTransitionStart
protected funonEntranceTransitionStart(): Unit
Callback when entrance transition is started. This is when fragment should stop processing layout.
runEntranceTransition
protected funrunEntranceTransition(entranceTransition: Any!): Unit
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.