BrowseFragment

Added in 1.1.0
Deprecated in 1.1.0

public class BrowseFragment extends 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

public abstract class BrowseFragment.FragmentFactory<T extends Fragment>

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

static final int

The headers fragment is disabled and will never be shown.

static final int

The headers fragment is enabled and shown by default.

static final int

The headers fragment is enabled and hidden by default.

Public constructors

Public methods

static Bundle
createArgs(Bundle args, String title, int headersState)

Creates arguments for a browse fragment.

void
enableMainFragmentScaling(boolean enable)

Enables scaling of main fragment when headers are present.

void
enableRowScaling(boolean enable)

This method 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
final 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
final 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.

void
onCreate(Bundle savedInstanceState)

This method is deprecated.

HeadersFragment

Creates a new HeadersFragment instance.

@Nullable View
onCreateView(
    LayoutInflater inflater,
    @Nullable ViewGroup container,
    Bundle savedInstanceState
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

Sets the adapter containing the rows for the fragment.

void
setBrandColor(@ColorInt int color)

Sets the brand color for the browse fragment.

void

Sets a listener for browse fragment transitions.

void

Sets the PresenterSelector used to render the row headers.

void
setHeadersState(int headersState)

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

final void
setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled)

Enables/disables headers transition on back key support.

void

Sets an item clicked listener on the fragment.

void

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
startHeadersTransition(boolean withHeaders)

Starts a headers transition.

Protected methods

Object

Create entrance transition.

void

Callback when entrance transition is ended.

void

Callback when entrance transition is prepared.

void

Callback when entrance transition is started.

void
runEntranceTransition(Object entranceTransition)

Run entrance transition.

Inherited Constants

From android.content.ComponentCallbacks2
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Inherited methods

From androidx.leanback.app.BaseFragment
final ProgressBarManager

Returns the ProgressBarManager.

void
onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

This method is deprecated.

void

Enables entrance transition.

void

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
@Nullable Drawable

Returns the badge drawable used in the fragment title.

int

Returns the color used to draw the search affordance.

@Nullable SearchOrbView.Colors

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

@Nullable CharSequence

Returns the title text for the fragment.

@Nullable View

Returns the view that implements TitleViewAdapter.Provider.

@Nullable TitleViewAdapter

Returns the TitleViewAdapter implemented by title view.

void
installTitleView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup parent,
    @Nullable Bundle savedInstanceState
)

Inflate title view and add to parent.

final boolean

Returns true/false to indicate the visibility of TitleView.

@NonNull View
onInflateTitleView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup parent,
    @Nullable Bundle savedInstanceState
)

Called by installTitleView to inflate title view.

void

This method is deprecated.

void

This method is deprecated.

void

Sets the drawable displayed in the fragment title.

void

Sets a click listener for the search affordance.

void

Sets the color used to draw the search affordance.

void

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

void

Sets title text for the fragment.

void

Sets the view that implemented TitleViewAdapter.

void
showTitle(int flags)

Changes title view's components visibility and shows title.

void
showTitle(boolean show)

Shows or hides the title view.

From android.app.Fragment
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

This method is deprecated.

final boolean

This method is deprecated.

final Activity

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

final Bundle

This method is deprecated.

final FragmentManager

This method is deprecated.

Context

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final FragmentManager

This method is deprecated.

final Object

This method is deprecated.

final int

This method is deprecated.

final LayoutInflater

This method is deprecated.

LoaderManager

This method is deprecated.

final Fragment

This method is deprecated.

Transition

This method is deprecated.

final Resources

This method is deprecated.

final boolean

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final String
getString(int resId)

This method is deprecated.

final String

This method is deprecated.

final Fragment

This method is deprecated.

final int

This method is deprecated.

final CharSequence
getText(int resId)

This method is deprecated.

boolean

This method is deprecated.

View

This method is deprecated.

final int

This method is deprecated.

static Fragment
instantiate(Context context, String fname)

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

void
onActivityCreated(Bundle savedInstanceState)

This method is deprecated.

void
onActivityResult(int requestCode, int resultCode, Intent data)

This method is deprecated.

void
onAttach(Context context)

This method is deprecated.

void
onAttachFragment(Fragment childFragment)

This method is deprecated.

void

This method is deprecated.

boolean

This method is deprecated.

void
onCreate(Bundle savedInstanceState)

This method is deprecated.

Animator
onCreateAnimator(int transit, boolean enter, int nextAnim)

This method is deprecated.

void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

LayoutInflater
onGetLayoutInflater(Bundle savedInstanceState)

This method is deprecated.

void
onHiddenChanged(boolean hidden)

This method is deprecated.

void
onInflate(AttributeSet attrs, Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void
onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    Configuration newConfig
)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    Configuration newConfig
)

This method is deprecated.

void

This method is deprecated.

void
onRequestPermissionsResult(
    int requestCode,
    String[] permissions,
    int[] grantResults
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onTrimMemory(int level)

This method is deprecated.

void
onViewCreated(View view, Bundle savedInstanceState)

This method is deprecated.

void
onViewStateRestored(Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

final void
requestPermissions(String[] permissions, int requestCode)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

void

This method is deprecated.

void
setMenuVisibility(boolean menuVisible)

This method is deprecated.

void

This method is deprecated.

void
setRetainInstance(boolean retain)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setTargetFragment(Fragment fragment, int requestCode)

This method is deprecated.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void
startActivityForResult(Intent intent, int requestCode)

This method is deprecated.

void
startIntentSenderForResult(
    IntentSender intent,
    int requestCode,
    Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    Bundle options
)

This method is deprecated.

void

This method is deprecated.

String

This method is deprecated.

void

This method is deprecated.

Constants

HEADERS_DISABLED

Added in 1.1.0
Deprecated in 1.1.0
public static final int HEADERS_DISABLED = 3

The headers fragment is disabled and will never be shown.

HEADERS_ENABLED

Added in 1.1.0
Deprecated in 1.1.0
public static final int HEADERS_ENABLED = 1

The headers fragment is enabled and shown by default.

HEADERS_HIDDEN

Added in 1.1.0
Deprecated in 1.1.0
public static final int HEADERS_HIDDEN = 2

The headers fragment is enabled and hidden by default.

Public constructors

BrowseFragment

Added in 1.1.0
Deprecated in 1.1.0
public BrowseFragment()

Public methods

createArgs

Added in 1.1.0
Deprecated in 1.1.0
public static Bundle createArgs(Bundle args, String title, int headersState)

Creates arguments for a browse fragment.

Parameters
Bundle args

The Bundle to place arguments into, or null if the method should return a new Bundle.

String title

The title of the BrowseFragment.

int headersState

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
public void enableMainFragmentScaling(boolean enable)

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
boolean enable

true to enable row scaling

enableRowScaling

Added in 1.1.0
Deprecated in 1.1.0
public void enableRowScaling(boolean enable)
Parameters
boolean enable

true to enable row scaling

getAdapter

Added in 1.1.0
Deprecated in 1.1.0
public ObjectAdapter getAdapter()

Returns the adapter containing the rows for the fragment.

getBrandColor

Added in 1.1.0
Deprecated in 1.1.0
public @ColorInt int getBrandColor()

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

getHeadersFragment

Added in 1.1.0
Deprecated in 1.1.0
public HeadersFragment getHeadersFragment()

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
public int getHeadersState()

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

getMainFragment

Added in 1.1.0
Deprecated in 1.1.0
public Fragment getMainFragment()
Returns
Fragment

Current main fragment or null if not created.

getMainFragmentRegistry

Added in 1.1.0
Deprecated in 1.1.0
public final BrowseFragment.MainFragmentAdapterRegistry getMainFragmentRegistry()

getOnItemViewClickedListener

Added in 1.1.0
Deprecated in 1.1.0
public OnItemViewClickedListener getOnItemViewClickedListener()

Returns the item Clicked listener.

getOnItemViewSelectedListener

Added in 1.1.0
Deprecated in 1.1.0
public OnItemViewSelectedListener getOnItemViewSelectedListener()

Returns an item selection listener.

getRowsFragment

Added in 1.1.0
Deprecated in 1.1.0
public RowsFragment getRowsFragment()

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
public int getSelectedPosition()

Gets position of currently selected row.

Returns
int

Position of currently selected row.

getSelectedRowViewHolder

Added in 1.1.0
Deprecated in 1.1.0
public RowPresenter.ViewHolder getSelectedRowViewHolder()
Returns
RowPresenter.ViewHolder

selected row ViewHolder inside fragment created by MainFragmentRowsAdapter.

isHeadersTransitionOnBackEnabled

Added in 1.1.0
Deprecated in 1.1.0
public final boolean isHeadersTransitionOnBackEnabled()

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

isInHeadersTransition

Added in 1.1.0
Deprecated in 1.1.0
public boolean isInHeadersTransition()

Returns true if the headers transition is currently running.

isShowingHeaders

Added in 1.1.0
Deprecated in 1.1.0
public boolean isShowingHeaders()

Returns true if headers are shown.

onCreate

public void onCreate(Bundle savedInstanceState)

onCreateHeadersFragment

Added in 1.1.0
Deprecated in 1.1.0
public HeadersFragment onCreateHeadersFragment()

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
public @Nullable View onCreateView(
    LayoutInflater inflater,
    @Nullable ViewGroup container,
    Bundle savedInstanceState
)

onDestroy

Added in 1.1.0
Deprecated in 1.1.0
public void onDestroy()

onDestroyView

public void onDestroyView()

onSaveInstanceState

public void onSaveInstanceState(Bundle outState)

onStart

public void onStart()

onStop

Added in 1.1.0
Deprecated in 1.1.0
public void onStop()

setAdapter

Added in 1.1.0
Deprecated in 1.1.0
public void setAdapter(ObjectAdapter adapter)

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
ObjectAdapter adapter

An ObjectAdapter for the browse rows. All items must derive from Row.

setBrandColor

Added in 1.1.0
Deprecated in 1.1.0
public void setBrandColor(@ColorInt int color)

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
@ColorInt int color

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

setBrowseTransitionListener

Added in 1.1.0
Deprecated in 1.1.0
public void setBrowseTransitionListener(
    BrowseFragment.BrowseTransitionListener listener
)

Sets a listener for browse fragment transitions.

Parameters
BrowseFragment.BrowseTransitionListener listener

The listener to call when a browse headers transition begins or ends.

setHeaderPresenterSelector

Added in 1.1.0
Deprecated in 1.1.0
public void setHeaderPresenterSelector(PresenterSelector headerPresenterSelector)

Sets the PresenterSelector used to render the row headers.

Parameters
PresenterSelector headerPresenterSelector

The PresenterSelector that will determine the Presenter for each row header.

setHeadersState

Added in 1.1.0
Deprecated in 1.1.0
public void setHeadersState(int headersState)

Sets the state for the headers column in the browse fragment. Must be one of HEADERS_ENABLED, HEADERS_HIDDEN, or HEADERS_DISABLED.

Parameters
int headersState

The state of the headers for the browse fragment.

setHeadersTransitionOnBackEnabled

Added in 1.1.0
Deprecated in 1.1.0
public final void setHeadersTransitionOnBackEnabled(boolean headersBackStackEnabled)

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
public void setOnItemViewClickedListener(OnItemViewClickedListener listener)

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
public void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)

Sets an item selection listener.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
public void setSelectedPosition(int position)

Sets the selected row position with smooth animation.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
public void setSelectedPosition(int position, boolean smooth)

Sets the selected row position.

setSelectedPosition

Added in 1.1.0
Deprecated in 1.1.0
public void setSelectedPosition(
    int rowPosition,
    boolean smooth,
    Presenter.ViewHolderTask rowHolderTask
)

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
int rowPosition

Which row to select.

boolean smooth

True to scroll to the row, false for no animation.

Presenter.ViewHolderTask rowHolderTask

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
public void startHeadersTransition(boolean withHeaders)

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
boolean withHeaders

True if the headers should transition to being shown, false if the transition should result in headers being hidden.

Protected methods

createEntranceTransition

protected Object createEntranceTransition()

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 void onEntranceTransitionEnd()

Callback when entrance transition is ended.

onEntranceTransitionPrepare

protected void onEntranceTransitionPrepare()

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

onEntranceTransitionStart

protected void onEntranceTransitionStart()

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

runEntranceTransition

protected void runEntranceTransition(Object entranceTransition)

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.