Android APIs
public class

DetailsSupportFragment

extends Fragment
java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ android.support.v17.leanback.app.DetailsSupportFragment
Known Direct Subclasses

Class Overview

A fragment for creating Leanback details screens.

A DetailsSupportFragment 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 Adapter's PresenterSelector must maintains subclasses of RowPresenter.

When FullWidthDetailsOverviewRowPresenter is found in adapter, DetailsSupportFragment will setup default behavior of the DetailsOverviewRow:
  • The alignment of FullWidthDetailsOverviewRowPresenter is setup in setupDetailsOverviewRowPresenter(FullWidthDetailsOverviewRowPresenter).
  • The view status switching of FullWidthDetailsOverviewRowPresenter is done in onSetDetailsOverviewRowStatus(FullWidthDetailsOverviewRowPresenter, FullWidthDetailsOverviewRowPresenter.ViewHolder, int, int, int).
  • The recommended activity themes to use with a DetailsSupportFragment are

  • Theme_Leanback_Details with activity shared element transition for FullWidthDetailsOverviewRowPresenter.
  • Theme_Leanback_Details_NoSharedElementTransition if shared element transition is not needed, for example if first row is not rendered by FullWidthDetailsOverviewRowPresenter.
  • Summary

    Public Constructors
    DetailsSupportFragment()
    Public Methods
    ObjectAdapter getAdapter()
    Returns the list of rows.
    Drawable getBadgeDrawable()
    Returns the badge drawable used in the fragment title.
    OnItemViewClickedListener getOnItemViewClickedListener()
    Returns the item clicked listener.
    int getSearchAffordanceColor()
    Returns the color used to draw the search affordance.
    SearchOrbView.Colors getSearchAffordanceColors()
    Returns the SearchOrbView.Colors used to draw the search affordance.
    String getTitle()
    Returns the title for the browse fragment.
    void onCreate(Bundle savedInstanceState)
    Called to do initial creation of a fragment.
    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    Called to have the fragment instantiate its user interface view.
    void onDestroyView()
    Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment.
    void onPause()
    Called when the Fragment is no longer resumed.
    void onResume()
    Called when the fragment is visible to the user and actively running.
    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 onViewCreated(View view, Bundle savedInstanceState)
    Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view.
    void prepareEntranceTransition()
    Enables entrance transition.
    void setAdapter(ObjectAdapter adapter)
    Sets the list of rows for the fragment.
    void setBadgeDrawable(Drawable drawable)
    Sets the drawable displayed in the browse fragment title.
    void setOnItemViewClickedListener(OnItemViewClickedListener listener)
    Sets an item clicked listener.
    void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)
    Sets an item selection listener.
    void setOnSearchClickedListener(View.OnClickListener listener)
    Sets a click listener for the search affordance.
    void setSearchAffordanceColor(int color)
    Sets the color used to draw the search affordance.
    void setSearchAffordanceColors(SearchOrbView.Colors colors)
    Sets the SearchOrbView.Colors used to draw the search affordance.
    void setSelectedPosition(int position, boolean smooth)
    Sets the selected row position.
    void setSelectedPosition(int position)
    Sets the selected row position with smooth animation.
    void setTitle(String title)
    Sets a title for the browse fragment.
    void startEntranceTransition()
    When fragment finishes loading data, it should call startEntranceTransition() to execute the entrance transition.
    Protected Methods
    Object createEntranceTransition()
    Create entrance transition.
    View inflateTitle(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)
    Called by onCreateView(LayoutInflater, ViewGroup, Bundle) to inflate TitleView.
    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 onSetDetailsOverviewRowStatus(FullWidthDetailsOverviewRowPresenter presenter, FullWidthDetailsOverviewRowPresenter.ViewHolder viewHolder, int adapterPosition, int selectedPosition, int selectedSubPosition)
    Called to change DetailsOverviewRow view status when current selected row position or selected sub position changed.
    void onSetRowStatus(RowPresenter presenter, RowPresenter.ViewHolder viewHolder, int adapterPosition, int selectedPosition, int selectedSubPosition)
    Called on every visible row to change view status when current selected row position or selected sub position changed.
    void runEntranceTransition(Object entranceTransition)
    Run entrance transition.
    void setupDetailsOverviewRowPresenter(FullWidthDetailsOverviewRowPresenter presenter)
    void setupPresenter(Presenter rowPresenter)
    Called to setup each Presenter of Adapter passed in setAdapter(ObjectAdapter).
    [Expand]
    Inherited Methods
    From class android.support.v4.app.Fragment
    From class java.lang.Object
    From interface android.content.ComponentCallbacks
    From interface android.view.View.OnCreateContextMenuListener

    Public Constructors

    public DetailsSupportFragment ()

    Public Methods

    public ObjectAdapter getAdapter ()

    Returns the list of rows.

    public Drawable getBadgeDrawable ()

    Returns the badge drawable used in the fragment title.

    public OnItemViewClickedListener getOnItemViewClickedListener ()

    Returns the item clicked listener.

    public int getSearchAffordanceColor ()

    Returns the color used to draw the search affordance.

    public SearchOrbView.Colors getSearchAffordanceColors ()

    Returns the SearchOrbView.Colors used to draw the search affordance.

    public String getTitle ()

    Returns the title for the browse fragment.

    public 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).

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

    public 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 The LayoutInflater object that can be used to inflate any views in the fragment,
    container 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 If non-null, this fragment is being re-constructed from a previous saved state as given here.
    Returns
    • Return the View for the fragment's UI, or null.

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

    public void onPause ()

    Called when the Fragment is no longer resumed. This is generally tied to Activity.onPause of the containing Activity's lifecycle.

    public void onResume ()

    Called when the fragment is visible to the user and actively running. This is generally tied to Activity.onResume of the containing Activity's lifecycle.

    public 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. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given to onCreate(Bundle), onCreateView(LayoutInflater, ViewGroup, Bundle), and onActivityCreated(Bundle).

    This corresponds to Activity.onSaveInstanceState(Bundle) and most of the discussion there applies here as well. Note however: this method may be called at any time before onDestroy(). There are many situations where a fragment may be mostly torn down (such as when placed on the back stack with no UI showing), but its state will not be saved until its owning activity actually needs to save its state.

    Parameters
    outState Bundle in which to place your saved state.

    public void onStart ()

    Called when the Fragment is visible to the user. This is generally tied to Activity.onStart of the containing Activity's lifecycle.

    public void onViewCreated (View view, Bundle savedInstanceState)

    Called immediately after onCreateView(LayoutInflater, ViewGroup, Bundle) has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment's view hierarchy is not however attached to its parent at this point.

    Parameters
    view The View returned by onCreateView(LayoutInflater, ViewGroup, Bundle).
    savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state as given here.

    public void prepareEntranceTransition ()

    Enables entrance transition.

    Entrance transition is the standard slide-in transition that shows rows of data in browse screen and details screen.

    The method is ignored before LOLLIPOP (API21).

    This method must be called in or before onCreate(). Typically entrance transition should be enabled when savedInstance is null so that fragment restored from instanceState does not run an extra entrance transition. When the entrance transition is enabled, the fragment will make headers and content hidden initially. When data of rows are ready, app must call startEntranceTransition() to kick off the transition, otherwise the rows will be invisible forever.

    It is similar to android:windowsEnterTransition and can be considered a late-executed android:windowsEnterTransition controlled by app. There are two reasons that app needs it:

  • Workaround the problem that activity transition is not available between launcher and app. Browse activity must programmatically start the slide-in transition.
  • Separates DetailsOverviewRow transition from other rows transition. So that the DetailsOverviewRow transition can be executed earlier without waiting for all rows to be loaded.
  • Transition object is returned by createEntranceTransition(). Typically the app does not need override the default transition that browse and details provides.

    public void setAdapter (ObjectAdapter adapter)

    Sets the list of rows for the fragment.

    public void setBadgeDrawable (Drawable drawable)

    Sets the drawable displayed in the browse fragment title.

    Parameters
    drawable The Drawable to display in the browse fragment title.

    public void setOnItemViewClickedListener (OnItemViewClickedListener listener)

    Sets an item clicked listener.

    public void setOnItemViewSelectedListener (OnItemViewSelectedListener listener)

    Sets an item selection listener.

    public void setOnSearchClickedListener (View.OnClickListener listener)

    Sets a click listener for the search affordance.

    The presence of a listener will change the visibility of the search affordance in the fragment title. When set to non-null, the title will contain an element that a user may click to begin a search.

    The listener's onClick method will be invoked when the user clicks on the search element.

    Parameters
    listener The listener to call when the search element is clicked.

    public void setSearchAffordanceColor (int color)

    Sets the color used to draw the search affordance. A default brighter color will be set by the framework.

    Parameters
    color The color to use for the search affordance.

    public void setSearchAffordanceColors (SearchOrbView.Colors colors)

    Sets the SearchOrbView.Colors used to draw the search affordance.

    public void setSelectedPosition (int position, boolean smooth)

    Sets the selected row position.

    public void setSelectedPosition (int position)

    Sets the selected row position with smooth animation.

    public void setTitle (String title)

    Sets a title for the browse fragment.

    Parameters
    title The title of the browse fragment.

    public void startEntranceTransition ()

    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:

  • prepareEntranceTransition() was called.
  • has not executed entrance transition yet.
  • If startEntranceTransition() is called before onViewCreated(), it will be pending and executed when view is created.

    Protected Methods

    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.

    protected View inflateTitle (LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState)

    Called by onCreateView(LayoutInflater, ViewGroup, Bundle) to inflate TitleView. Default implementation uses layout file lb_browse_title. Subclass may override and use its own layout or return null if no title is needed.

    protected void onEntranceTransitionEnd ()

    Callback when entrance transition is ended.

    protected void onEntranceTransitionPrepare ()

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

    protected void onEntranceTransitionStart ()

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

    protected void onSetDetailsOverviewRowStatus (FullWidthDetailsOverviewRowPresenter presenter, FullWidthDetailsOverviewRowPresenter.ViewHolder viewHolder, int adapterPosition, int selectedPosition, int selectedSubPosition)

    Called to change DetailsOverviewRow view status when current selected row position or selected sub position changed. Subclass may override. The default implementation switches between three states based on the positions: STATE_HALF, STATE_FULL and STATE_SMALL.

    Parameters
    presenter The presenter used to create row ViewHolder.
    viewHolder The visible (attached) row ViewHolder, note that it may or may not be selected.
    adapterPosition The adapter position of viewHolder inside adapter.
    selectedPosition The adapter position of currently selected row.
    selectedSubPosition The sub position within currently selected row. This is used When a row has multiple alignment positions.

    protected void onSetRowStatus (RowPresenter presenter, RowPresenter.ViewHolder viewHolder, int adapterPosition, int selectedPosition, int selectedSubPosition)

    Called on every visible row to change view status when current selected row position or selected sub position changed. Subclass may override. The default implementation calls onSetDetailsOverviewRowStatus(FullWidthDetailsOverviewRowPresenter, FullWidthDetailsOverviewRowPresenter.ViewHolder, int, int, int) if presenter is instance of FullWidthDetailsOverviewRowPresenter.

    Parameters
    presenter The presenter used to create row ViewHolder.
    viewHolder The visible (attached) row ViewHolder, note that it may or may not be selected.
    adapterPosition The adapter position of viewHolder inside adapter.
    selectedPosition The adapter position of currently selected row.
    selectedSubPosition The sub position within currently selected row. This is used When a row has multiple alignment positions.

    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.

    protected void setupDetailsOverviewRowPresenter (FullWidthDetailsOverviewRowPresenter presenter)

    Called to setup FullWidthDetailsOverviewRowPresenter. The default implementation adds two aligment positions(ItemAlignmentFacet) for ViewHolder of FullWidthDetailsOverviewRowPresenter to align in fragment.

    protected void setupPresenter (Presenter rowPresenter)

    Called to setup each Presenter of Adapter passed in setAdapter(ObjectAdapter). Note that setup should only change the Presenter behavior that is meaningful in DetailsSupportFragment. For example how a row is aligned in details Fragment. The default implementation invokes setupDetailsOverviewRowPresenter(FullWidthDetailsOverviewRowPresenter)