BrowseFragment

Added in 1.1.0
Deprecated in 1.1.0

class BrowseFragment : BaseFragment


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.

use BrowseSupportFragment

This class is deprecated.

use BrowseSupportFragment

This interface is deprecated.

use BrowseSupportFragment

This class is deprecated.

use BrowseSupportFragment

This class is deprecated.

use BrowseSupportFragment

This interface is deprecated.

use BrowseSupportFragment

This class is deprecated.

use BrowseSupportFragment

This class is deprecated.

use BrowseSupportFragment

This interface is deprecated.

use BrowseSupportFragment

Constants

const Int

The headers fragment is disabled and will never be shown.

const Int

The headers fragment is enabled and shown by default.

const Int

The headers fragment is enabled and hidden by default.

Public constructors

Public functions

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

Creates arguments for a browse fragment.

Unit

Enables scaling of main fragment when headers are present.

Unit

This function is deprecated.

use enableMainFragmentScaling instead.

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
onCreate(savedInstanceState: Bundle!)

This function is deprecated.

HeadersFragment!

Creates a new HeadersFragment instance.

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

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
setHeaderPresenterSelector(headerPresenterSelector: PresenterSelector!)

Sets the PresenterSelector used to render the row headers.

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.

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
setSelectedPosition(position: Int, smooth: Boolean)

Sets the selected row position.

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

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
runEntranceTransition(entranceTransition: Any!)

Run entrance transition.

Inherited functions

From androidx.leanback.app.BaseFragment
ProgressBarManager!

Returns the ProgressBarManager.

Unit
onViewCreated(view: View, savedInstanceState: Bundle?)

This function is deprecated.

Unit

Enables entrance transition.

Unit

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:

From androidx.leanback.app.BrandedFragment
Drawable?

Returns the badge drawable used in the fragment title.

Int

Returns the color used to draw the search affordance.

SearchOrbView.Colors?

Returns the androidx.leanback.widget.SearchOrbView.Colors used to draw the search affordance.

CharSequence?

Returns the title text for the fragment.

View?

Returns the view that implements TitleViewAdapter.Provider.

TitleViewAdapter?

Returns the TitleViewAdapter implemented by title view.

Unit
installTitleView(
    inflater: LayoutInflater,
    parent: ViewGroup,
    savedInstanceState: Bundle?
)

Inflate title view and add to parent.

Boolean

Returns true/false to indicate the visibility of TitleView.

View
onInflateTitleView(
    inflater: LayoutInflater,
    parent: ViewGroup?,
    savedInstanceState: Bundle?
)

Called by installTitleView to inflate title view.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

Sets the drawable displayed in the fragment title.

Unit

Sets a click listener for the search affordance.

Unit

Sets the color used to draw the search affordance.

Unit

Sets the androidx.leanback.widget.SearchOrbView.Colors used to draw the search affordance.

Unit

Sets title text for the fragment.

Unit
setTitleView(titleView: View?)

Sets the view that implemented TitleViewAdapter.

Unit
showTitle(flags: Int)

Changes title view's components visibility and shows title.

Unit

Shows or hides the title view.

From android.app.Fragment
Unit
dump(
    prefix: String!,
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
)

This function is deprecated.

Boolean
equals(o: Any!)

This function is deprecated.

Activity!

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Bundle!

This function is deprecated.

FragmentManager!

This function is deprecated.

Context!

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

FragmentManager!

This function is deprecated.

Any!

This function is deprecated.

Int

This function is deprecated.

LayoutInflater!

This function is deprecated.

LoaderManager!

This function is deprecated.

Fragment!

This function is deprecated.

Transition!

This function is deprecated.

Resources!

This function is deprecated.

Boolean

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

Transition!

This function is deprecated.

String!
getString(resId: Int)

This function is deprecated.

String!

This function is deprecated.

Fragment!

This function is deprecated.

Int

This function is deprecated.

CharSequence!
getText(resId: Int)

This function is deprecated.

Boolean

This function is deprecated.

View!

This function is deprecated.

Int

This function is deprecated.

java-static Fragment!
instantiate(context: Context!, fname: String!)

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Boolean

This function is deprecated.

Unit
onActivityCreated(savedInstanceState: Bundle!)

This function is deprecated.

Unit
onActivityResult(requestCode: Int, resultCode: Int, data: Intent!)

This function is deprecated.

Unit
onAttach(context: Context!)

This function is deprecated.

Unit
onAttachFragment(childFragment: Fragment!)

This function is deprecated.

Unit

This function is deprecated.

Boolean

This function is deprecated.

Unit
onCreate(savedInstanceState: Bundle!)

This function is deprecated.

Animator!
onCreateAnimator(transit: Int, enter: Boolean, nextAnim: Int)

This function is deprecated.

Unit
onCreateContextMenu(
    menu: ContextMenu!,
    v: View!,
    menuInfo: ContextMenu.ContextMenuInfo!
)

This function is deprecated.

Unit
onCreateOptionsMenu(menu: Menu!, inflater: MenuInflater!)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

LayoutInflater!
onGetLayoutInflater(savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit
onInflate(attrs: AttributeSet!, savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit
onMultiWindowModeChanged(
    isInMultiWindowMode: Boolean,
    newConfig: Configuration!
)

This function is deprecated.

Boolean

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
onPictureInPictureModeChanged(
    isInPictureInPictureMode: Boolean,
    newConfig: Configuration!
)

This function is deprecated.

Unit

This function is deprecated.

Unit
onRequestPermissionsResult(
    requestCode: Int,
    permissions: Array<String!>!,
    grantResults: IntArray!
)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
onTrimMemory(level: Int)

This function is deprecated.

Unit
onViewCreated(view: View!, savedInstanceState: Bundle!)

This function is deprecated.

Unit
onViewStateRestored(savedInstanceState: Bundle!)

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
requestPermissions(permissions: Array<String!>!, requestCode: Int)

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

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit

This function is deprecated.

Unit
setMenuVisibility(menuVisible: Boolean)

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
setTargetFragment(fragment: Fragment!, requestCode: Int)

This function is deprecated.

Unit
setUserVisibleHint(isVisibleToUser: Boolean)

This function is deprecated.

Boolean

This function is deprecated.

Unit

This function is deprecated.

Unit
startActivityForResult(intent: Intent!, requestCode: Int)

This function is deprecated.

Unit
startIntentSenderForResult(
    intent: IntentSender!,
    requestCode: Int,
    fillInIntent: Intent!,
    flagsMask: Int,
    flagsValues: Int,
    extraFlags: Int,
    options: Bundle!
)

This function is deprecated.

Unit

This function is deprecated.

String!

This function is deprecated.

Unit

This function is deprecated.

Constants

HEADERS_DISABLED

Added in 1.1.0
Deprecated in 1.1.0
const val HEADERS_DISABLED = 3: Int

The headers fragment is disabled and will never be shown.

HEADERS_ENABLED

Added in 1.1.0
Deprecated in 1.1.0
const val HEADERS_ENABLED = 1: Int

The headers fragment is enabled and shown by default.

HEADERS_HIDDEN

Added in 1.1.0
Deprecated in 1.1.0
const val HEADERS_HIDDEN = 2: Int

The headers fragment is enabled and hidden by default.

Public constructors

BrowseFragment

Added in 1.1.0
Deprecated in 1.1.0
BrowseFragment()

Public functions

createArgs

Added in 1.1.0
Deprecated in 1.1.0
java-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: String!

The title of the BrowseFragment.

headersState: Int

The initial state of the headers of the BrowseFragment. Must be one of HEADERS_ENABLED, HEADERS_HIDDEN, or HEADERS_DISABLED.

Returns
Bundle!

A Bundle with the given arguments for creating a BrowseFragment.

enableMainFragmentScaling

Added in 1.1.0
Deprecated in 1.1.0
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 isScalingEnabled are enabled.

Parameters
enable: Boolean

true to enable row scaling

enableRowScaling

Added in 1.1.0
Deprecated in 1.1.0
fun enableRowScaling(enable: Boolean): Unit
Parameters
enable: Boolean

true to enable row scaling

getAdapter

Added in 1.1.0
Deprecated in 1.1.0
fun getAdapter(): ObjectAdapter!

Returns the adapter containing the rows for the fragment.

getBrandColor

Added in 1.1.0
Deprecated in 1.1.0
fun getBrandColor(): @ColorInt Int

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

getHeadersFragment

Added in 1.1.0
Deprecated in 1.1.0
fun getHeadersFragment(): 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.

getHeadersState

Added in 1.1.0
Deprecated in 1.1.0
fun getHeadersState(): Int

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

getMainFragment

Added in 1.1.0
Deprecated in 1.1.0
fun getMainFragment(): Fragment!
Returns
Fragment!

Current main fragment or null if not created.

getMainFragmentRegistry

Added in 1.1.0
Deprecated in 1.1.0
fun getMainFragmentRegistry(): BrowseFragment.MainFragmentAdapterRegistry!

getOnItemViewClickedListener

Added in 1.1.0
Deprecated in 1.1.0
fun getOnItemViewClickedListener(): OnItemViewClickedListener!

Returns the item Clicked listener.

getOnItemViewSelectedListener

Added in 1.1.0
Deprecated in 1.1.0
fun getOnItemViewSelectedListener(): OnItemViewSelectedListener!

Returns an item selection listener.

getRowsFragment

Added in 1.1.0
Deprecated in 1.1.0
fun getRowsFragment(): 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.

getSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
fun getSelectedPosition(): Int

Gets position of currently selected row.

Returns
Int

Position of currently selected row.

getSelectedRowViewHolder

Added in 1.1.0
Deprecated in 1.1.0
fun getSelectedRowViewHolder(): RowPresenter.ViewHolder!
Returns
RowPresenter.ViewHolder!

selected row ViewHolder inside fragment created by MainFragmentRowsAdapter.

isHeadersTransitionOnBackEnabled

Added in 1.1.0
Deprecated in 1.1.0
fun isHeadersTransitionOnBackEnabled(): Boolean

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

isInHeadersTransition

Added in 1.1.0
Deprecated in 1.1.0
fun isInHeadersTransition(): Boolean

Returns true if the headers transition is currently running.

isShowingHeaders

Added in 1.1.0
Deprecated in 1.1.0
fun isShowingHeaders(): Boolean

Returns true if headers are shown.

onCreate

fun onCreate(savedInstanceState: Bundle!): Unit

onCreateHeadersFragment

Added in 1.1.0
Deprecated in 1.1.0
fun onCreateHeadersFragment(): 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 HeadersFragment or its subclass.

onCreateView

Added in 1.1.0
Deprecated in 1.1.0
fun onCreateView(
    inflater: LayoutInflater!,
    container: ViewGroup?,
    savedInstanceState: Bundle!
): View?

onDestroy

Added in 1.1.0
Deprecated in 1.1.0
fun onDestroy(): Unit

onDestroyView

fun onDestroyView(): Unit

onSaveInstanceState

fun onSaveInstanceState(outState: Bundle!): Unit

onStart

fun onStart(): Unit

onStop

Added in 1.1.0
Deprecated in 1.1.0
fun onStop(): Unit

setAdapter

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
fun setBrandColor(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.

Parameters
color: @ColorInt Int

The color to use as the brand color of the fragment.

setBrowseTransitionListener

Added in 1.1.0
Deprecated in 1.1.0
fun setBrowseTransitionListener(
    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.

setHeaderPresenterSelector

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
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

Added in 1.1.0
Deprecated in 1.1.0
fun setHeadersTransitionOnBackEnabled(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.

setOnItemViewClickedListener

Added in 1.1.0
Deprecated in 1.1.0
fun setOnItemViewClickedListener(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.

setOnItemViewSelectedListener

Added in 1.1.0
Deprecated in 1.1.0
fun setOnItemViewSelectedListener(listener: OnItemViewSelectedListener!): Unit

Sets an item selection listener.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
fun setSelectedPosition(position: Int): Unit

Sets the selected row position with smooth animation.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
fun setSelectedPosition(position: Int, smooth: Boolean): Unit

Sets the selected row position.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
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 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.

startHeadersTransition

Added in 1.1.0
Deprecated in 1.1.0
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 functions

createEntranceTransition

protected fun createEntranceTransition(): 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 fun onEntranceTransitionEnd(): Unit

Callback when entrance transition is ended.

onEntranceTransitionPrepare

protected fun onEntranceTransitionPrepare(): Unit

Callback when entrance transition is prepared. This is when fragment should stop user input and animations.

onEntranceTransitionStart

protected fun onEntranceTransitionStart(): Unit

Callback when entrance transition is started. This is when fragment should stop processing layout.

runEntranceTransition

protected fun runEntranceTransition(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.