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

Possible set of actions that BrowseSupportFragment exposes to clients.

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.

abstract

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

open

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

abstract

Factory class responsible for creating fragment given the current item.

open

FragmentFactory implementation for ListRow.

Registry class maintaining the mapping of Row subclasses to FragmentFactory.

Constants
static Int

The headers fragment is enabled and shown by default.

static Int

The headers fragment is enabled and hidden by default.

static Int

The headers fragment is disabled and will never be shown.

Public constructors

A fragment for creating Leanback browse screens.

Public methods
open ObjectAdapter!

Returns the adapter containing the rows for the fragment.

open Unit

Sets an item clicked listener on the fragment.

open RowPresenter.ViewHolder!

open Unit

Sets the brand color for the browse fragment.

BrowseSupportFragment.MainFragmentAdapterRegistry!

open Unit

Starts a headers transition.

open Unit

Sets an item selection listener.

open Boolean

Returns true if headers are shown.

open Int

Gets position of currently selected row.

open Unit

Enables scaling of main fragment when headers are present.

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 HeadersSupportFragment!

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

open OnItemViewSelectedListener!

Returns an item selection listener.

open Unit

open Boolean

Returns true if the headers transition is currently running.

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

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

open Unit

Sets a listener for browse fragment transitions.

open Fragment!

open Unit
onCreate(savedInstanceState: Bundle?)

open Unit

open Unit

open Int

Returns the brand color for the browse fragment.

open Unit

open HeadersSupportFragment!

Creates a new HeadersSupportFragment instance.

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

open Unit

Sets the adapter containing the rows for the fragment.

open Unit
setHeadersState(headersState: Int)

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

open Unit

open OnItemViewClickedListener!

Returns the item Clicked listener.

Boolean

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

open Unit

open Unit
setHeaderPresenterSelector(headerPresenterSelector: PresenterSelector!)

Sets the PresenterSelector used to render the row headers.

Unit
setHeadersTransitionOnBackEnabled(headersBackStackEnabled: Boolean)

Enables/disables headers transition on back key support.

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

Creates arguments for a browse fragment.

Protected methods
open Any!

open Unit

open Unit

open Unit
runEntranceTransition(entranceTransition: Any!)

open Unit

Inherited functions

Constants

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

HEADERS_DISABLED

static val HEADERS_DISABLED: Int

The headers fragment is disabled and will never be shown.

Value: 3

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

getAdapter

open fun getAdapter(): ObjectAdapter!

Returns the adapter containing the rows for the fragment.

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.

getSelectedRowViewHolder

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

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.

getMainFragmentRegistry

fun getMainFragmentRegistry(): BrowseSupportFragment.MainFragmentAdapterRegistry!

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.

setOnItemViewSelectedListener

open fun setOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit

Sets an item selection listener.

isShowingHeaders

open fun isShowingHeaders(): Boolean

Returns true if headers are shown.

getSelectedPosition

open fun getSelectedPosition(): Int

Gets position of currently selected row.

Return
Int: Position of currently selected row.

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

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.

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.

getOnItemViewSelectedListener

open fun getOnItemViewSelectedListener(): OnItemViewSelectedListener!

Returns an item selection listener.

onDestroy

open fun onDestroy(): Unit

isInHeadersTransition

open fun isInHeadersTransition(): Boolean

Returns true if the headers transition is currently running.

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.

getHeadersState

open fun getHeadersState(): Int

Returns the state of the headers column in the browse 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.

getMainFragment

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

onCreate

open fun onCreate(savedInstanceState: Bundle?): Unit

onStart

open fun onStart(): Unit

enableRowScaling

open fun enableRowScaling(enable: Boolean): Unit
Parameters
enable Boolean: true to enable row scaling

getBrandColor

open fun getBrandColor(): Int

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

onSaveInstanceState

open fun onSaveInstanceState(outState: 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?

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.

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.

onDestroyView

open fun onDestroyView(): Unit

getOnItemViewClickedListener

open fun getOnItemViewClickedListener(): OnItemViewClickedListener!

Returns the item Clicked listener.

isHeadersTransitionOnBackEnabled

fun isHeadersTransitionOnBackEnabled(): Boolean

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

onStop

open fun onStop(): Unit

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.

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.

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.

Protected methods

createEntranceTransition

protected open fun createEntranceTransition(): Any!

onEntranceTransitionPrepare

protected open fun onEntranceTransitionPrepare(): Unit

onEntranceTransitionStart

protected open fun onEntranceTransitionStart(): Unit

runEntranceTransition

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

onEntranceTransitionEnd

protected open fun onEntranceTransitionEnd(): Unit