BrowseFragment
public class BrowseFragment extends BaseFragment
| java.lang.Object | ||||
| ↳ | android.app.Fragment | |||
| ↳ | androidx.leanback.app.BrandedFragment | |||
| ↳ | androidx.leanback.app.BaseFragment | |||
| ↳ | androidx.leanback.app.BrowseFragment |
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 |
|---|
public class BrowseFragment.BrowseTransitionListenerThis class is deprecated. |
public abstract class BrowseFragment.FragmentFactory<T extends Fragment>This class is deprecated. |
public interface BrowseFragment.FragmentHostThis interface is deprecated. |
public class BrowseFragment.ListRowFragmentFactory extends BrowseFragment.FragmentFactoryThis class is deprecated. |
public class BrowseFragment.MainFragmentAdapter<T extends Fragment>This class is deprecated. |
public interface BrowseFragment.MainFragmentAdapterProviderThis interface is deprecated. |
public final class BrowseFragment.MainFragmentAdapterRegistryThis class is deprecated. |
public class BrowseFragment.MainFragmentRowsAdapter<T extends Fragment>This class is deprecated. |
public interface BrowseFragment.MainFragmentRowsAdapterProviderThis interface is deprecated. |
Constants |
|
|---|---|
static final int |
HEADERS_DISABLED = 3The headers fragment is disabled and will never be shown. |
static final int |
HEADERS_ENABLED = 1The headers fragment is enabled and shown by default. |
static final int |
HEADERS_HIDDEN = 2The headers fragment is enabled and hidden by default. |
Public constructors |
|---|
Public methods |
|
|---|---|
static Bundle |
Creates arguments for a browse fragment. |
void |
Enables scaling of main fragment when headers are present. |
void |
This method is deprecated. use |
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 |
This method is deprecated. |
HeadersFragment |
Creates a new |
@Nullable View |
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 |
Sets the brand color for the browse fragment. |
void |
Sets a listener for browse fragment transitions. |
void |
Sets the |
void |
Sets the state for the headers column in the browse fragment. |
final void |
Enables/disables headers transition on back key support. |
void |
Sets an item clicked listener on the fragment. |
void |
Sets an item selection listener. |
void |
Sets the selected row position with smooth animation. |
void |
Sets the selected row position. |
void |
Selects a Row and perform an optional task on the Row. |
void |
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 |
Run entrance transition. |
Inherited Constants |
||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
public static final int HEADERS_DISABLED = 3
The headers fragment is disabled and will never be shown.
Public constructors
Public methods
public static BundlecreateArgs(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 |
| Returns | |
|---|---|
Bundle |
A Bundle with the given arguments for creating a BrowseFragment. |
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 |
public @ColorInt intgetBrandColor()
Returns the brand color for the browse fragment. The default is transparent.
public HeadersFragmentgetHeadersFragment()
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. |
public OnItemViewSelectedListenergetOnItemViewSelectedListener()
Returns an item selection listener.
public RowsFragmentgetRowsFragment()
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. |
public int getSelectedPosition()Gets position of currently selected row.
| Returns | |
|---|---|
int |
Position of currently selected row. |
public RowPresenter.ViewHoldergetSelectedRowViewHolder()
| Returns | |
|---|---|
RowPresenter.ViewHolder |
selected row ViewHolder inside fragment created by |
public final boolean isHeadersTransitionOnBackEnabled()Returns true if headers transition on back key support is enabled.
public HeadersFragmentonCreateHeadersFragment()
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 |
public @Nullable ViewonCreateView(
LayoutInflater inflater,
@Nullable ViewGroup container,
Bundle savedInstanceState
)
public voidsetAdapter(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 |
public voidsetBrandColor(@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. |
public voidsetBrowseTransitionListener(
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. |
public voidsetHeaderPresenterSelector(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. |
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. |
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.
public voidsetOnItemViewClickedListener(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.
public voidsetOnItemViewSelectedListener(OnItemViewSelectedListener listener)
Sets an item selection listener.
public voidsetSelectedPosition(
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. |
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 ObjectcreateEntranceTransition()
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 voidrunEntranceTransition(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.