Android APIs
public abstract class

RowPresenter

extends Presenter
java.lang.Object
   ↳ android.support.v17.leanback.widget.Presenter
     ↳ android.support.v17.leanback.widget.RowPresenter
Known Direct Subclasses

Class Overview

An abstract Presenter that renders a Row.

Customize UI widgets

When a subclass of RowPresenter adds UI widgets, it should subclass RowPresenter.ViewHolder and override createRowViewHolder(ViewGroup) and initializeRowViewHolder(ViewHolder). The subclass must use layout id "row_content" for the widget that will be aligned to the title of any HeadersFragment that may exist in the parent fragment. RowPresenter contains an optional and replaceable RowHeaderPresenter that renders the header. You can disable the default rendering or replace the Presenter with a new header presenter by calling setHeaderPresenter(RowHeaderPresenter).

UI events from fragments

RowPresenter receives calls from its parent (typically a Fragment) when:

Activated status

The activated status of a row is applied to the row view and it's children via setActivated(boolean). The activated status is typically used to control BaseCardView info region visibility. The row's activated status can be controlled by selected status and/or expanded status. Call setSyncActivatePolicy(int) and choose one of the four policies:

User events

RowPresenter provides OnItemSelectedListener and OnItemClickedListener. If a subclass wants to add its own View.OnFocusChangeListener or View.OnClickListener, it must do that in createRowViewHolder(ViewGroup) to be properly chained by the library. Adding View listeners after createRowViewHolder(ViewGroup) is undefined and may result in incorrect behavior by the library's listeners.

Selection animation

When a user scrolls through rows, a fragment will initiate animation and call setSelectLevel(Presenter.ViewHolder, float) with float value between 0 and 1. By default, the RowPresenter draws a dim overlay on top of the row view for views that are not selected. Subclasses may override this default effect by having isUsingDefaultSelectEffect() return false and overriding onSelectLevelChanged(ViewHolder) to apply a different selection effect.

Call setSelectEffectEnabled(boolean) to enable/disable the select effect, This will not only enable/disable the default dim effect but also subclasses must respect this flag as well.

Summary

Nested Classes
class RowPresenter.ViewHolder A view holder for a Row
Constants
int SYNC_ACTIVATED_CUSTOM Don't synchronize row view activated status with selected status or expanded status, application will do its own through setActivated(boolean).
int SYNC_ACTIVATED_TO_EXPANDED Synchronizes row view's activated status to expand status of the row view holder.
int SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED Sets the row view's activated status to true when both expand and selected are true.
int SYNC_ACTIVATED_TO_SELECTED Synchronizes row view's activated status to selected status of the row view holder.
Public Constructors
RowPresenter()
Constructs a RowPresenter.
Public Methods
boolean canDrawOutOfBounds()
Return true if the Row view can draw outside its bounds.
void freeze(RowPresenter.ViewHolder holder, boolean freeze)
Freeze/Unfreeze the row, typically used when transition starts/ends.
final RowHeaderPresenter getHeaderPresenter()
Get the Presenter used for rendering the header, or null if none has been set.
final OnItemClickedListener getOnItemClickedListener()
Get the listener for item click events.
final OnItemSelectedListener getOnItemSelectedListener()
Get the listener for item or row selection.
final OnItemViewClickedListener getOnItemViewClickedListener()
Set listener for item click event.
final OnItemViewSelectedListener getOnItemViewSelectedListener()
Get listener for item or row selection.
final RowPresenter.ViewHolder getRowViewHolder(Presenter.ViewHolder holder)
Get the RowPresenter.ViewHolder from the given Presenter ViewHolder.
final boolean getSelectEffectEnabled()
Returns true if the row selection effect is enabled.
final float getSelectLevel(Presenter.ViewHolder vh)
Get the current select level.
final int getSyncActivatePolicy()
Returns policy of updating row view activated status.
boolean isUsingDefaultSelectEffect()
Return whether this RowPresenter is using the default dimming effect provided by the library.
final void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item)
Binds a View to an item.
final Presenter.ViewHolder onCreateViewHolder(ViewGroup parent)
Creates a new View.
final void onUnbindViewHolder(Presenter.ViewHolder viewHolder)
Unbinds a View from an item.
final void onViewAttachedToWindow(Presenter.ViewHolder holder)
Called when a view created by this presenter has been attached to a window.
final void onViewDetachedFromWindow(Presenter.ViewHolder holder)
Called when a view created by this presenter has been detached from its window.
void setEntranceTransitionState(RowPresenter.ViewHolder holder, boolean afterTransition)
Change visibility of views, entrance transition will be run against the views that change visibilities.
final void setHeaderPresenter(RowHeaderPresenter headerPresenter)
Set the Presenter used for rendering the header.
final void setOnItemClickedListener(OnItemClickedListener listener)
Set the listener for item click events.
final void setOnItemSelectedListener(OnItemSelectedListener listener)
Set the listener for item or row selection.
final void setOnItemViewClickedListener(OnItemViewClickedListener listener)
Set listener for item click event.
final void setOnItemViewSelectedListener(OnItemViewSelectedListener listener)
Set listener for item or row selection.
final void setRowViewExpanded(Presenter.ViewHolder holder, boolean expanded)
Set the expanded state of a Row view.
final void setRowViewSelected(Presenter.ViewHolder holder, boolean selected)
Set the selected state of a Row view.
final void setSelectEffectEnabled(boolean applyDimOnSelect)
Enables or disables the row selection effect.
final void setSelectLevel(Presenter.ViewHolder vh, float level)
Set the current select level to a value between 0 (unselected) and 1 (selected).
final void setSyncActivatePolicy(int syncActivatePolicy)
Sets policy of updating row view activated status.
Protected Methods
abstract RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent)
Called to create a ViewHolder object for a Row.
void dispatchItemSelectedListener(RowPresenter.ViewHolder vh, boolean selected)
The method is only called from onRowViewSelecetd().
void initializeRowViewHolder(RowPresenter.ViewHolder vh)
Called after a RowPresenter.ViewHolder is created for a Row.
void onBindRowViewHolder(RowPresenter.ViewHolder vh, Object item)
void onRowViewAttachedToWindow(RowPresenter.ViewHolder vh)
void onRowViewDetachedFromWindow(RowPresenter.ViewHolder vh)
void onRowViewExpanded(RowPresenter.ViewHolder vh, boolean expanded)
Subclass may override this to respond to expanded state changes of a Row.
void onRowViewSelected(RowPresenter.ViewHolder vh, boolean selected)
Subclass may override this to respond to selected state changes of a Row.
void onSelectLevelChanged(RowPresenter.ViewHolder vh)
Callback when select level is changed.
void onUnbindRowViewHolder(RowPresenter.ViewHolder vh)
[Expand]
Inherited Methods
From class android.support.v17.leanback.widget.Presenter
From class java.lang.Object

Constants

public static final int SYNC_ACTIVATED_CUSTOM

Don't synchronize row view activated status with selected status or expanded status, application will do its own through setActivated(boolean).

Constant Value: 0 (0x00000000)

public static final int SYNC_ACTIVATED_TO_EXPANDED

Synchronizes row view's activated status to expand status of the row view holder.

Constant Value: 1 (0x00000001)

public static final int SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED

Sets the row view's activated status to true when both expand and selected are true.

Constant Value: 3 (0x00000003)

public static final int SYNC_ACTIVATED_TO_SELECTED

Synchronizes row view's activated status to selected status of the row view holder.

Constant Value: 2 (0x00000002)

Public Constructors

public RowPresenter ()

Constructs a RowPresenter.

Public Methods

public boolean canDrawOutOfBounds ()

Return true if the Row view can draw outside its bounds.

public void freeze (RowPresenter.ViewHolder holder, boolean freeze)

Freeze/Unfreeze the row, typically used when transition starts/ends. This method is called by fragment, app should not call it directly.

public final RowHeaderPresenter getHeaderPresenter ()

Get the Presenter used for rendering the header, or null if none has been set.

public final OnItemClickedListener getOnItemClickedListener ()

Get the listener for item click events.

public final OnItemSelectedListener getOnItemSelectedListener ()

Get the listener for item or row selection.

public final OnItemViewClickedListener getOnItemViewClickedListener ()

Set listener for item click event.

public final OnItemViewSelectedListener getOnItemViewSelectedListener ()

Get listener for item or row selection.

public final RowPresenter.ViewHolder getRowViewHolder (Presenter.ViewHolder holder)

Get the RowPresenter.ViewHolder from the given Presenter ViewHolder.

public final boolean getSelectEffectEnabled ()

Returns true if the row selection effect is enabled. This value not only determines whether the default dim implementation is used, but subclasses must also respect this flag.

public final float getSelectLevel (Presenter.ViewHolder vh)

Get the current select level. The value will be between 0 (unselected) and 1 (selected).

public final int getSyncActivatePolicy ()

Returns policy of updating row view activated status. Can be one of:

  • Default value SYNC_ACTIVATED_TO_EXPANDED
  • SYNC_ACTIVATED_TO_SELECTED
  • SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
  • SYNC_ACTIVATED_CUSTOM

  • public boolean isUsingDefaultSelectEffect ()

    Return whether this RowPresenter is using the default dimming effect provided by the library. Subclasses may(most likely) return false and override onSelectLevelChanged(ViewHolder).

    public final void onBindViewHolder (Presenter.ViewHolder viewHolder, Object item)

    Binds a View to an item.

    public final Presenter.ViewHolder onCreateViewHolder (ViewGroup parent)

    Creates a new View.

    public final void onUnbindViewHolder (Presenter.ViewHolder viewHolder)

    Unbinds a View from an item. Any expensive references may be released here, and any fields that are not bound for every item should be cleared here.

    public final void onViewAttachedToWindow (Presenter.ViewHolder holder)

    Called when a view created by this presenter has been attached to a window.

    This can be used as a reasonable signal that the view is about to be seen by the user. If the adapter previously freed any resources in onViewDetachedFromWindow(ViewHolder) those resources should be restored here.

    Parameters
    holder Holder of the view being attached

    public final void onViewDetachedFromWindow (Presenter.ViewHolder holder)

    Called when a view created by this presenter has been detached from its window.

    Becoming detached from the window is not necessarily a permanent condition; the consumer of an presenter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.

    Any view property animations should be cancelled here or the view may fail to be recycled.

    Parameters
    holder Holder of the view being detached

    public void setEntranceTransitionState (RowPresenter.ViewHolder holder, boolean afterTransition)

    Change visibility of views, entrance transition will be run against the views that change visibilities. Subclass may override and begin with calling super.setEntranceTransitionState(). This method is called by fragment, app should not call it directly.

    public final void setHeaderPresenter (RowHeaderPresenter headerPresenter)

    Set the Presenter used for rendering the header. Can be null to disable header rendering. The method must be called before creating any Row Views.

    public final void setOnItemClickedListener (OnItemClickedListener listener)

    Set the listener for item click events. A RowPresenter does not use this listener, but a subclass may fire an item click event if it has the concept of an item. The OnItemClickedListener will override any View.OnClickListener that an item's Presenter sets during onCreateViewHolder(ViewGroup). So in general, you should choose to use an OnItemClickedListener or a View.OnClickListener, but not both.

    public final void setOnItemSelectedListener (OnItemSelectedListener listener)

    Set the listener for item or row selection. A RowPresenter fires a row selection event with a null item. Subclasses (e.g. ListRowPresenter) can fire a selection event with the selected item.

    public final void setOnItemViewClickedListener (OnItemViewClickedListener listener)

    Set listener for item click event. RowPresenter does nothing but subclass of RowPresenter may fire item click event if it does have a concept of item. OnItemViewClickedListener will override View.OnClickListener that item presenter sets during onCreateViewHolder(ViewGroup). So in general, developer should choose one of the listeners but not both.

    public final void setOnItemViewSelectedListener (OnItemViewSelectedListener listener)

    Set listener for item or row selection. RowPresenter fires row selection event with null item, subclass of RowPresenter e.g. ListRowPresenter can fire a selection event with selected item.

    public final void setRowViewExpanded (Presenter.ViewHolder holder, boolean expanded)

    Set the expanded state of a Row view.

    Parameters
    holder The Row ViewHolder to set expanded state on.
    expanded True if the Row is expanded, false otherwise.

    public final void setRowViewSelected (Presenter.ViewHolder holder, boolean selected)

    Set the selected state of a Row view.

    Parameters
    holder The Row ViewHolder to set expanded state on.
    selected True if the Row is expanded, false otherwise.

    public final void setSelectEffectEnabled (boolean applyDimOnSelect)

    Enables or disables the row selection effect. This will not only affect the default dim effect, but subclasses must respect this flag as well.

    public final void setSelectLevel (Presenter.ViewHolder vh, float level)

    Set the current select level to a value between 0 (unselected) and 1 (selected). Subclasses may override onSelectLevelChanged(ViewHolder) to respond to changes in the selected level.

    public final void setSyncActivatePolicy (int syncActivatePolicy)

    Sets policy of updating row view activated status. Can be one of:

  • Default value SYNC_ACTIVATED_TO_EXPANDED
  • SYNC_ACTIVATED_TO_SELECTED
  • SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
  • SYNC_ACTIVATED_CUSTOM

  • Protected Methods

    protected abstract RowPresenter.ViewHolder createRowViewHolder (ViewGroup parent)

    Called to create a ViewHolder object for a Row. Subclasses will override this method to return a different concrete ViewHolder object.

    Parameters
    parent The parent View for the Row's view holder.
    Returns
    • A ViewHolder for the Row's View.

    protected void dispatchItemSelectedListener (RowPresenter.ViewHolder vh, boolean selected)

    The method is only called from onRowViewSelecetd(). Default behavior is signaling row selected events with null item. Subclass of RowPresenter having child items should override this method and dispatch events with item information.

    protected void initializeRowViewHolder (RowPresenter.ViewHolder vh)

    Called after a RowPresenter.ViewHolder is created for a Row. Subclasses may override this method and start by calling super.initializeRowViewHolder(ViewHolder).

    Parameters
    vh The ViewHolder to initialize for the Row.

    protected void onBindRowViewHolder (RowPresenter.ViewHolder vh, Object item)

    protected void onRowViewAttachedToWindow (RowPresenter.ViewHolder vh)

    protected void onRowViewDetachedFromWindow (RowPresenter.ViewHolder vh)

    protected void onRowViewExpanded (RowPresenter.ViewHolder vh, boolean expanded)

    Subclass may override this to respond to expanded state changes of a Row. The default implementation will hide/show the header view. Subclasses may make visual changes to the Row View but must not create animation on the Row view.

    protected void onRowViewSelected (RowPresenter.ViewHolder vh, boolean selected)

    Subclass may override this to respond to selected state changes of a Row. Subclass may make visual changes to Row view but must not create animation on the Row view.

    protected void onSelectLevelChanged (RowPresenter.ViewHolder vh)

    Callback when select level is changed. The default implementation applies the select level to setSelectLevel(RowHeaderPresenter.ViewHolder, float) when getSelectEffectEnabled() is true. Subclasses may override this function and implement a different select effect. In this case, you should also override isUsingDefaultSelectEffect() to disable the default dimming effect applied by the library.

    protected void onUnbindRowViewHolder (RowPresenter.ViewHolder vh)