Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

BrowseSupportFragment

open class BrowseSupportFragment : BaseSupportFragment
kotlin.Any
   ↳ androidx.fragment.app.Fragment
   ↳ androidx.leanback.app.BrandedSupportFragment
   ↳ androidx.leanback.app.BaseSupportFragment
   ↳ androidx.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 for details.

By default the BrowseSupportFragment includes support for returning to the headers when the user presses Back. For Activities that customize , 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 androidx.leanback.R.style#Theme_Leanback_Browse.

Summary

Nested classes

open

Listener for transitions between browse headers and rows.

abstract

Factory class responsible for creating fragment given the current item.

abstract

Possible set of actions that BrowseSupportFragment exposes to clients.

open

FragmentFactory implementation for ListRow.

open

Interface that defines the interaction between BrowseSupportFragment and its main content fragment.

abstract

Interface to be implemented by all fragments for providing an instance of MainFragmentAdapter.

Registry class maintaining the mapping of Row subclasses to FragmentFactory.

open

This is used to pass information to RowsSupportFragment or its subclasses.

abstract

Interface to be implemented by RowsSupportFragment and its subclasses for providing an instance of MainFragmentRowsAdapter.

Constants

static Int

The headers fragment is disabled and will never be shown.

static Int

The headers fragment is enabled and shown by default.

static Int

The headers fragment is enabled and hidden by default.

Public constructors

A fragment for creating Leanback browse screens.

Public methods

open static Bundle!
createArgs(args: Bundle!, title: String!, headersState: Int)

Creates arguments for a browse fragment.

open Unit

Enables scaling of main fragment when headers are present.

open Unit

open ObjectAdapter!

Returns the adapter containing the rows for the fragment.

open Int

Returns the brand color for the browse fragment.

open Int

Returns the state of the headers column in the browse fragment.

open HeadersSupportFragment!

Get currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet.

open Fragment!

BrowseSupportFragment.MainFragmentAdapterRegistry!

open OnItemViewClickedListener!

Returns the item Clicked listener.

open OnItemViewSelectedListener!

Returns an item selection listener.

open RowsSupportFragment!

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.

open Int

Gets position of currently selected row.

open RowPresenter.ViewHolder!

Boolean

Returns true if headers transition on back key support is enabled.

open Boolean

Returns true if the headers transition is currently running.

open Boolean

Returns true if headers are shown.

open Unit
onCreate(savedInstanceState: Bundle?)

open HeadersSupportFragment!

Creates a new HeadersSupportFragment instance.

open View?
onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?)

open Unit

open Unit

open Unit

open Unit

open Unit

open Unit

Sets the adapter containing the rows for the fragment.

open Unit

Sets the brand color for the browse fragment.

open Unit

Sets a listener for browse fragment transitions.

open Unit
setHeaderPresenterSelector(headerPresenterSelector: PresenterSelector!)

Sets the PresenterSelector used to render the row headers.

open Unit
setHeadersState(headersState: Int)

Sets the state for the headers column in the browse fragment.

Unit
setHeadersTransitionOnBackEnabled(headersBackStackEnabled: Boolean)

Enables/disables headers transition on back key support.

open Unit

Sets an item clicked listener on the fragment.

open Unit

Sets an item selection listener.

open Unit

Sets the selected row position with smooth animation.

open Unit
setSelectedPosition(position: Int, smooth: Boolean)

Sets the selected row position.

open Unit
setSelectedPosition(rowPosition: Int, smooth: Boolean, rowHolderTask: Presenter.ViewHolderTask!)

Selects a Row and perform an optional task on the Row.

open Unit

Starts a headers transition.

Protected methods

open Any!

open Unit

open Unit

open Unit

open Unit
runEntranceTransition(entranceTransition: Any!)

Inherited functions

Constants

HEADERS_DISABLED

static val HEADERS_DISABLED: Int

The headers fragment is disabled and will never be shown.

Value: 3

HEADERS_ENABLED

static val HEADERS_ENABLED: Int

The headers fragment is enabled and shown by default.

Value: 1

HEADERS_HIDDEN

static val HEADERS_HIDDEN: Int

The headers fragment is enabled and hidden by default.

Value: 2

Public constructors

<init>

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 for details.

By default the BrowseSupportFragment includes support for returning to the headers when the user presses Back. For Activities that customize , 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 androidx.leanback.R.style#Theme_Leanback_Browse.

Public methods

createArgs

open static fun createArgs(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 Bundle!: The title of the BrowseSupportFragment.
headersState Bundle!: The initial state of the headers of the BrowseSupportFragment. Must be one of HEADERS_ENABLED, , or HEADERS_DISABLED.
Return
Bundle!: A Bundle with the given arguments for creating a BrowseSupportFragment.

enableMainFragmentScaling

open fun enableMainFragmentScaling(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 MainFragmentAdapter#isScalingEnabled() are enabled.

Parameters
enable Boolean: true to enable row scaling

enableRowScaling

open fun enableRowScaling(enable: Boolean): Unit

Deprecated: use BrowseSupportFragment#enableMainFragmentScaling(boolean) instead.

Parameters
enable Boolean: true to enable row scaling

getAdapter

open fun getAdapter(): ObjectAdapter!

Returns the adapter containing the rows for the fragment.

getBrandColor

open fun getBrandColor(): Int

Returns the brand color for the browse fragment. The default is transparent.

getHeadersState

open fun getHeadersState(): Int

Returns the state of the headers column in the browse fragment.

getHeadersSupportFragment

open fun getHeadersSupportFragment(): HeadersSupportFragment!

Get currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet.

Return
HeadersSupportFragment!: Currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet.

getMainFragment

open fun getMainFragment(): Fragment!
Return
Fragment!: Current main fragment or null if not created.

getMainFragmentRegistry

fun getMainFragmentRegistry(): BrowseSupportFragment.MainFragmentAdapterRegistry!

getOnItemViewClickedListener

open fun getOnItemViewClickedListener(): OnItemViewClickedListener!

Returns the item Clicked listener.

getOnItemViewSelectedListener

open fun getOnItemViewSelectedListener(): OnItemViewSelectedListener!

Returns an item selection listener.

getRowsSupportFragment

open fun getRowsSupportFragment(): RowsSupportFragment!

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.

Return
RowsSupportFragment!: RowsSupportFragment if it's bound to BrowseSupportFragment or null otherwise.

getSelectedPosition

open fun getSelectedPosition(): Int

Gets position of currently selected row.

Return
Int: Position of currently selected row.

getSelectedRowViewHolder

open fun getSelectedRowViewHolder(): RowPresenter.ViewHolder!
Return
RowPresenter.ViewHolder!: selected row ViewHolder inside fragment created by MainFragmentRowsAdapter.

isHeadersTransitionOnBackEnabled

fun isHeadersTransitionOnBackEnabled(): Boolean

Returns true if headers transition on back key support is enabled.

isInHeadersTransition

open fun isInHeadersTransition(): Boolean

Returns true if the headers transition is currently running.

isShowingHeaders

open fun isShowingHeaders(): Boolean

Returns true if headers are shown.

onCreate

open fun onCreate(savedInstanceState: Bundle?): Unit

onCreateHeadersSupportFragment

open fun onCreateHeadersSupportFragment(): HeadersSupportFragment!

Creates a new HeadersSupportFragment instance. Subclass of BrowseSupportFragment may override and return an instance of subclass of HeadersSupportFragment, e.g. when app wants to replace presenter to render HeaderItem.

Return
HeadersSupportFragment!: A new instance of HeadersSupportFragment or its subclass.

onCreateView

open fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?

onDestroy

open fun onDestroy(): Unit

onDestroyView

open fun onDestroyView(): Unit

onSaveInstanceState

open fun onSaveInstanceState(outState: Bundle): Unit

onStart

open fun onStart(): Unit

onStop

open fun onStop(): Unit

setAdapter

open fun setAdapter(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 Row.

setBrandColor

open fun setBrandColor(color: 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.

Parameters
color Int: The color to use as the brand color of the fragment.

setBrowseTransitionListener

open fun setBrowseTransitionListener(listener: BrowseSupportFragment.BrowseTransitionListener!): Unit

Sets a listener for browse fragment transitions.

Parameters
listener BrowseSupportFragment.BrowseTransitionListener!: The listener to call when a browse headers transition begins or ends.

setHeaderPresenterSelector

open fun setHeaderPresenterSelector(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.

setHeadersState

open fun setHeadersState(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.

setHeadersTransitionOnBackEnabled

fun setHeadersTransitionOnBackEnabled(headersBackStackEnabled: Boolean): Unit

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 BrowseTransitionListener in your own back stack handling.

setOnItemViewClickedListener

open fun setOnItemViewClickedListener(listener: OnItemViewClickedListener!): Unit

Sets an item clicked listener on the fragment. OnItemViewClickedListener will override View.OnClickListener that item presenter sets during Presenter#onCreateViewHolder(ViewGroup). So in general, developer should choose one of the listeners but not both.

setOnItemViewSelectedListener

open fun setOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit

Sets an item selection listener.

setSelectedPosition

open fun setSelectedPosition(position: Int): Unit

Sets the selected row position with smooth animation.

setSelectedPosition

open fun setSelectedPosition(position: Int, smooth: Boolean): Unit

Sets the selected row position.

setSelectedPosition

open fun setSelectedPosition(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 RowsSupportFragment has not been created (i.e. before onCreateView(LayoutInflater, * ViewGroup, Bundle)).

Parameters
rowPosition Int: Which row to select.
smooth Int: True to scroll to the row, false for no animation.
rowHolderTask Int: Optional task to perform on the Row. When the task is not null, headers fragment will be collapsed.

startHeadersTransition

open fun startHeadersTransition(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 methods

createEntranceTransition

protected open fun createEntranceTransition(): Any!

onEntranceTransitionEnd

protected open fun onEntranceTransitionEnd(): Unit

onEntranceTransitionPrepare

protected open fun onEntranceTransitionPrepare(): Unit

onEntranceTransitionStart

protected open fun onEntranceTransitionStart(): Unit

runEntranceTransition

protected open fun runEntranceTransition(entranceTransition: Any!): Unit