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

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

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