added in version 22.1.0
belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1

BrowseSupportFragment

public class BrowseSupportFragment
extends BaseSupportFragment

java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ android.support.v17.leanback.app.BrandedSupportFragment
       ↳ android.support.v17.leanback.app.BaseSupportFragment
         ↳ android.support.v17.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(int) for details.

By default the BrowseSupportFragment 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(boolean) with false and use BrowseSupportFragment.BrowseTransitionListener and startHeadersTransition(boolean).

The recommended theme to use with a BrowseSupportFragment is Theme_Leanback_Browse.

Summary

Nested classes

class BrowseSupportFragment.BrowseTransitionListener

Listener for transitions between browse headers and rows. 

class BrowseSupportFragment.FragmentFactory<T extends Fragment>

Factory class responsible for creating fragment given the current item. 

interface BrowseSupportFragment.FragmentHost

Possible set of actions that BrowseSupportFragment exposes to clients. 

class BrowseSupportFragment.ListRowFragmentFactory

FragmentFactory implementation for ListRow

class BrowseSupportFragment.MainFragmentAdapter<T extends Fragment>

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

interface BrowseSupportFragment.MainFragmentAdapterProvider

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

class BrowseSupportFragment.MainFragmentAdapterRegistry

Registry class maintaining the mapping of Row subclasses to BrowseSupportFragment.FragmentFactory

class BrowseSupportFragment.MainFragmentRowsAdapter<T extends Fragment>

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

interface BrowseSupportFragment.MainFragmentRowsAdapterProvider

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

Constants

int HEADERS_DISABLED

The headers fragment is disabled and will never be shown.

int HEADERS_ENABLED

The headers fragment is enabled and shown by default.

int HEADERS_HIDDEN

The headers fragment is enabled and hidden by default.

Public constructors

BrowseSupportFragment()

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 was deprecated in API level 24.1.0. use enableMainFragmentScaling(boolean) instead.

ObjectAdapter getAdapter()

Returns the adapter containing the rows for the fragment.

int getBrandColor()

Returns the brand color for the browse fragment.

int getHeadersState()

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

HeadersSupportFragment getHeadersSupportFragment()

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

Fragment getMainFragment()
final BrowseSupportFragment.MainFragmentAdapterRegistry getMainFragmentRegistry()
OnItemViewClickedListener getOnItemViewClickedListener()

Returns the item Clicked listener.

OnItemViewSelectedListener getOnItemViewSelectedListener()

Returns an item selection listener.

RowsSupportFragment getRowsSupportFragment()

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.

int getSelectedPosition()

Gets position of currently selected row.

RowPresenter.ViewHolder getSelectedRowViewHolder()
final boolean isHeadersTransitionOnBackEnabled()

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

boolean isInHeadersTransition()

Returns true if the headers transition is currently running.

boolean isShowingHeaders()

Returns true if headers are shown.

void onCreate(Bundle savedInstanceState)

Called to do initial creation of a fragment.

HeadersSupportFragment onCreateHeadersSupportFragment()

Creates a new HeadersSupportFragment instance.

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

Called to have the fragment instantiate its user interface view.

void onDestroy()

Called when the fragment is no longer in use.

void onDestroyView()

Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment.

void onSaveInstanceState(Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted.

void onStart()

Called when the Fragment is visible to the user.

void setAdapter(ObjectAdapter adapter)

Sets the adapter containing the rows for the fragment.

void setBrandColor(int color)

Sets the brand color for the browse fragment.

void setBrowseTransitionListener(BrowseSupportFragment.BrowseTransitionListener listener)

Sets a listener for browse fragment transitions.

void setHeaderPresenterSelector(PresenterSelector headerPresenterSelector)

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

Sets an item clicked listener on the fragment.

void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)

Sets an item selection listener.

void setSelectedPosition(int position)

Sets the selected row position with smooth animation.

void setSelectedPosition(int rowPosition, boolean smooth, Presenter.ViewHolderTask rowHolderTask)

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

void setSelectedPosition(int position, boolean smooth)

Sets the selected row position.

void startHeadersTransition(boolean withHeaders)

Starts a headers transition.

Protected methods

Object createEntranceTransition()

Create entrance transition.

void onEntranceTransitionEnd()

Callback when entrance transition is ended.

void onEntranceTransitionPrepare()

Callback when entrance transition is prepared.

void onEntranceTransitionStart()

Callback when entrance transition is started.

void runEntranceTransition(Object entranceTransition)

Run entrance transition.

Inherited methods

From class android.support.v17.leanback.app.BaseSupportFragment
From class android.support.v17.leanback.app.BrandedSupportFragment
From class android.support.v4.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface android.arch.lifecycle.LifecycleOwner
From interface android.arch.lifecycle.ViewModelStoreOwner

Constants

HEADERS_DISABLED

added in version 22.1.0
int HEADERS_DISABLED

The headers fragment is disabled and will never be shown.

Constant Value: 3 (0x00000003)

HEADERS_ENABLED

added in version 22.1.0
int HEADERS_ENABLED

The headers fragment is enabled and shown by default.

Constant Value: 1 (0x00000001)

HEADERS_HIDDEN

added in version 22.1.0
int HEADERS_HIDDEN

The headers fragment is enabled and hidden by default.

Constant Value: 2 (0x00000002)

Public constructors

BrowseSupportFragment

added in version 22.1.0
BrowseSupportFragment ()

Public methods

createArgs

added in version 22.1.0
Bundle createArgs (Bundle args, 
                String title, 
                int headersState)

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 BrowseSupportFragment.

headersState int: The initial state of the headers of the BrowseSupportFragment. Must be one of HEADERS_ENABLED, HEADERS_HIDDEN, or HEADERS_DISABLED.

Returns
Bundle A Bundle with the given arguments for creating a BrowseSupportFragment.

enableMainFragmentScaling

added in version 24.1.0
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
enable boolean: true to enable row scaling

enableRowScaling

added in version 22.1.0
void enableRowScaling (boolean enable)

This method was deprecated in API level 24.1.0.
use enableMainFragmentScaling(boolean) instead.

Parameters
enable boolean: true to enable row scaling

getAdapter

added in version 22.1.0
ObjectAdapter getAdapter ()

Returns the adapter containing the rows for the fragment.

Returns
ObjectAdapter

getBrandColor

added in version 22.1.0
int getBrandColor ()

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

Returns
int

getHeadersState

added in version 22.1.0
int getHeadersState ()

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

Returns
int

getHeadersSupportFragment

added in version 24.1.0
HeadersSupportFragment getHeadersSupportFragment ()

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

Returns
HeadersSupportFragment Currently bound HeadersSupportFragment or null if HeadersSupportFragment has not been created yet.

getMainFragment

added in version 25.1.0
Fragment getMainFragment ()

Returns
Fragment Current main fragment or null if not created.

getOnItemViewClickedListener

added in version 22.1.0
OnItemViewClickedListener getOnItemViewClickedListener ()

Returns the item Clicked listener.

Returns
OnItemViewClickedListener

getOnItemViewSelectedListener

added in version 22.1.0
OnItemViewSelectedListener getOnItemViewSelectedListener ()

Returns an item selection listener.

Returns
OnItemViewSelectedListener

getRowsSupportFragment

added in version 24.1.0
RowsSupportFragment getRowsSupportFragment ()

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.

Returns
RowsSupportFragment RowsSupportFragment if it's bound to BrowseSupportFragment or null otherwise.

getSelectedPosition

added in version 24.1.0
int getSelectedPosition ()

Gets position of currently selected row.

Returns
int Position of currently selected row.

getSelectedRowViewHolder

added in version 25.1.0
RowPresenter.ViewHolder getSelectedRowViewHolder ()

Returns
RowPresenter.ViewHolder selected row ViewHolder inside fragment created by BrowseSupportFragment.MainFragmentRowsAdapter.

isHeadersTransitionOnBackEnabled

added in version 22.1.0
boolean isHeadersTransitionOnBackEnabled ()

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

Returns
boolean

isInHeadersTransition

added in version 22.1.0
boolean isInHeadersTransition ()

Returns true if the headers transition is currently running.

Returns
boolean

isShowingHeaders

added in version 22.1.0
boolean isShowingHeaders ()

Returns true if headers are shown.

Returns
boolean

onCreate

added in version 24.1.0
void onCreate (Bundle savedInstanceState)

Called to do initial creation of a fragment. This is called after onAttach(Activity) and before onCreateView(LayoutInflater, ViewGroup, Bundle).

Note that this can be called while the fragment's activity is still in the process of being created. As such, you can not rely on things like the activity's content view hierarchy being initialized at this point. If you want to do work once the activity itself is created, see onActivityCreated(Bundle).

Any restored child fragments will be created before the base Fragment.onCreate method returns.

Parameters
savedInstanceState Bundle: If the fragment is being re-created from a previous saved state, this is the state.

onCreateHeadersSupportFragment

added in version 25.4.0
HeadersSupportFragment onCreateHeadersSupportFragment ()

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.

Returns
HeadersSupportFragment A new instance of HeadersSupportFragment or its subclass.

onCreateView

added in version 24.1.0
View onCreateView (LayoutInflater inflater, 
                ViewGroup container, 
                Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view. This is optional, and non-graphical fragments can return null (which is the default implementation). This will be called between onCreate(Bundle) and onActivityCreated(Bundle).

If you return a View from here, you will later be called in onDestroyView() when the view is being released.

Parameters
inflater LayoutInflater: The LayoutInflater object that can be used to inflate any views in the fragment,

container ViewGroup: If non-null, this is the parent view that the fragment's UI should be attached to. The fragment should not add the view itself, but this can be used to generate the LayoutParams of the view.

savedInstanceState Bundle: If non-null, this fragment is being re-constructed from a previous saved state as given here.

Returns
View Return the View for the fragment's UI, or null.

onDestroy

added in version 24.1.0
void onDestroy ()

Called when the fragment is no longer in use. This is called after onStop() and before onDetach().

onDestroyView

added in version 24.1.0
void onDestroyView ()

Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment. The next time the fragment needs to be displayed, a new view will be created. This is called after onStop() and before onDestroy(). It is called regardless of whether onCreateView(LayoutInflater, ViewGroup, Bundle) returned a non-null view. Internally it is called after the view's state has been saved but before it has been removed from its parent.

onSaveInstanceState

added in