public abstract class RowPresenter extends Presenter
Presenter
that renders an Object in RowsFragment, the object can be
subclass Row
or a generic one. When the object is not Row
class,
RowPresenter.ViewHolder.getRow()
returns null.
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)
.
setRowViewSelected(Presenter.ViewHolder, boolean)
. The event
is triggered immediately when there is a row selection change before the selection
animation is started. Selected status may control activated status of the row (see
"Activated status" below).
Subclasses of RowPresenter may override onRowViewSelected(ViewHolder, boolean)
.
setRowViewExpanded(Presenter.ViewHolder, boolean)
when BrowseFragment hides fast lane on the left.
The event is triggered immediately before the expand animation is started.
Row title is shown when row is expanded. Expanded status may control activated status
of the row (see "Activated status" below).
Subclasses of RowPresenter may override onRowViewExpanded(ViewHolder, boolean)
.
View.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:
SYNC_ACTIVATED_TO_EXPANDED
Activated status is synced with row expanded statusSYNC_ACTIVATED_TO_SELECTED
Activated status is synced with row selected statusSYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
Activated status is set to true
when both expanded and selected status are trueSYNC_ACTIVATED_CUSTOM
Activated status is not controlled by selected status
or expanded status, application can control activated status by its own.
Application should call RowPresenter.ViewHolder.setActivated(boolean)
to change
activated status of row view.
OnItemViewSelectedListener
and OnItemViewClickedListener
.
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.
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.
Modifier and Type | Class and Description |
---|---|
static class |
RowPresenter.ViewHolder
A ViewHolder for a
Row . |
Presenter.ViewHolderTask
Modifier and Type | Field and Description |
---|---|
static int |
SYNC_ACTIVATED_CUSTOM
Don't synchronize row view activated status with selected status or expanded status,
application will do its own through
RowPresenter.ViewHolder.setActivated(boolean) . |
static int |
SYNC_ACTIVATED_TO_EXPANDED
Synchronizes row view's activated status to expand status of the row view holder.
|
static int |
SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
Sets the row view's activated status to true when both expand and selected are true.
|
static int |
SYNC_ACTIVATED_TO_SELECTED
Synchronizes row view's activated status to selected status of the row view holder.
|
Constructor and Description |
---|
RowPresenter()
Constructs a RowPresenter.
|
Modifier and Type | Method and Description |
---|---|
protected abstract RowPresenter.ViewHolder |
createRowViewHolder(ViewGroup parent)
Called to create a ViewHolder object for a Row.
|
protected void |
dispatchItemSelectedListener(RowPresenter.ViewHolder vh,
boolean selected)
This method is only called from
onRowViewSelected(ViewHolder, boolean) onRowViewSelected. |
void |
freeze(RowPresenter.ViewHolder holder,
boolean freeze)
Freezes/unfreezes the row, typically used when a transition starts/ends.
|
RowHeaderPresenter |
getHeaderPresenter()
Returns the Presenter used for rendering the header, or null if none has been
set.
|
RowPresenter.ViewHolder |
getRowViewHolder(Presenter.ViewHolder holder)
Returns the
RowPresenter.ViewHolder from the given RowPresenter
ViewHolder. |
boolean |
getSelectEffectEnabled()
Returns true if the row selection effect is enabled.
|
float |
getSelectLevel(Presenter.ViewHolder vh)
Returns the current select level.
|
int |
getSyncActivatePolicy()
Returns the policy of updating row view activated status.
|
protected void |
initializeRowViewHolder(RowPresenter.ViewHolder vh)
Called after a
RowPresenter.ViewHolder is created for a Row. |
protected boolean |
isClippingChildren()
Returns true if the Row view should clip it's children.
|
boolean |
isUsingDefaultSelectEffect()
Returns true if this RowPresenter is using the default dimming effect.
|
protected void |
onBindRowViewHolder(RowPresenter.ViewHolder vh,
Object item)
Binds the given row object to the given ViewHolder.
|
void |
onBindViewHolder(Presenter.ViewHolder viewHolder,
Object item)
Binds a
View to an item. |
Presenter.ViewHolder |
onCreateViewHolder(ViewGroup parent)
Creates a new
View . |
protected void |
onRowViewAttachedToWindow(RowPresenter.ViewHolder vh)
Invoked when the row view is attached to the window.
|
protected void |
onRowViewDetachedFromWindow(RowPresenter.ViewHolder vh)
Invoked when the row view is detached from the window.
|
protected void |
onRowViewExpanded(RowPresenter.ViewHolder vh,
boolean expanded)
Called when the row view's expanded state changes.
|
protected void |
onRowViewSelected(RowPresenter.ViewHolder vh,
boolean selected)
Called when the given row view changes selection state.
|
protected void |
onSelectLevelChanged(RowPresenter.ViewHolder vh)
Callback when the select level changes.
|
protected void |
onUnbindRowViewHolder(RowPresenter.ViewHolder vh)
Unbinds the given ViewHolder.
|
void |
onUnbindViewHolder(Presenter.ViewHolder viewHolder)
Unbinds a
View from an item. |
void |
onViewAttachedToWindow(Presenter.ViewHolder holder)
Called when a view created by this presenter has been attached to a window.
|
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 afterEntrance)
Changes the visibility of views.
|
void |
setHeaderPresenter(RowHeaderPresenter headerPresenter)
Sets the Presenter used for rendering the header.
|
void |
setRowViewExpanded(Presenter.ViewHolder holder,
boolean expanded)
Sets the expanded state of a Row view.
|
void |
setRowViewSelected(Presenter.ViewHolder holder,
boolean selected)
Sets the selected state of a Row view.
|
void |
setSelectEffectEnabled(boolean applyDimOnSelect)
Enables or disables the row selection effect.
|
void |
setSelectLevel(Presenter.ViewHolder vh,
float level)
Sets the current select level to a value between 0 (unselected) and 1 (selected).
|
void |
setSyncActivatePolicy(int syncActivatePolicy)
Sets the policy of updating row view activated status.
|
cancelAnimationsRecursive, getFacet, setFacet, setOnClickListener
public static final int SYNC_ACTIVATED_CUSTOM
RowPresenter.ViewHolder.setActivated(boolean)
.public static final int SYNC_ACTIVATED_TO_EXPANDED
public static final int SYNC_ACTIVATED_TO_SELECTED
public static final int SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
public final Presenter.ViewHolder onCreateViewHolder(ViewGroup parent)
Presenter
View
.onCreateViewHolder
in class Presenter
protected abstract RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent)
parent
- The parent View for the Row's view holder.protected boolean isClippingChildren()
initializeRowViewHolder(ViewHolder)
. Note that
Slide transition or explode transition need turn off clipChildren.
Default value is false.protected void initializeRowViewHolder(RowPresenter.ViewHolder vh)
RowPresenter.ViewHolder
is created for a Row.
Subclasses may override this method and start by calling
super.initializeRowViewHolder(ViewHolder).vh
- The ViewHolder to initialize for the Row.public final void setHeaderPresenter(RowHeaderPresenter headerPresenter)
public final RowHeaderPresenter getHeaderPresenter()
public final RowPresenter.ViewHolder getRowViewHolder(Presenter.ViewHolder holder)
RowPresenter.ViewHolder
from the given RowPresenter
ViewHolder.public final void setRowViewExpanded(Presenter.ViewHolder holder, boolean expanded)
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)
holder
- The Row ViewHolder to set expanded state on.selected
- True if the Row is expanded, false otherwise.protected void onRowViewExpanded(RowPresenter.ViewHolder vh, boolean expanded)
public final void setSyncActivatePolicy(int syncActivatePolicy)
SYNC_ACTIVATED_TO_EXPANDED
SYNC_ACTIVATED_TO_SELECTED
SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
SYNC_ACTIVATED_CUSTOM
public final int getSyncActivatePolicy()
SYNC_ACTIVATED_TO_EXPANDED
SYNC_ACTIVATED_TO_SELECTED
SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED
SYNC_ACTIVATED_CUSTOM
protected void dispatchItemSelectedListener(RowPresenter.ViewHolder vh, boolean selected)
onRowViewSelected(ViewHolder, boolean)
onRowViewSelected.
The default behavior is to signal row selected events with a null item parameter.
A Subclass of RowPresenter having child items should override this method and dispatch
events with item information.protected void onRowViewSelected(RowPresenter.ViewHolder vh, boolean selected)
public final void setSelectLevel(Presenter.ViewHolder vh, float level)
onSelectLevelChanged(ViewHolder)
to
respond to changes in the selected level.public final float getSelectLevel(Presenter.ViewHolder vh)
protected void onSelectLevelChanged(RowPresenter.ViewHolder vh)
RowHeaderPresenter.setSelectLevel(RowHeaderPresenter.ViewHolder, float)
when getSelectEffectEnabled()
is true. Subclasses may override
this function and implement a different select effect. In this case,
the method isUsingDefaultSelectEffect()
should also be overridden to disable
the default dimming effect.public final void setSelectEffectEnabled(boolean applyDimOnSelect)
public final boolean getSelectEffectEnabled()
public boolean isUsingDefaultSelectEffect()
onSelectLevelChanged(ViewHolder)
.public final void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item)
Presenter
View
to an item.onBindViewHolder
in class Presenter
protected void onBindRowViewHolder(RowPresenter.ViewHolder vh, Object item)
RowPresenter
overriding
onBindRowViewHolder(ViewHolder, Object)
must call through the super class's
implementation of this method.public final void onUnbindViewHolder(Presenter.ViewHolder viewHolder)
Presenter
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.onUnbindViewHolder
in class Presenter
protected void onUnbindRowViewHolder(RowPresenter.ViewHolder vh)
RowPresenter
overriding onUnbindRowViewHolder(ViewHolder)
must call through the super class's implementation of this method.public final void onViewAttachedToWindow(Presenter.ViewHolder holder)
Presenter
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
Presenter.onViewDetachedFromWindow(ViewHolder)
those resources should be restored here.
onViewAttachedToWindow
in class Presenter
holder
- Holder of the view being attachedprotected void onRowViewAttachedToWindow(RowPresenter.ViewHolder vh)
public final void onViewDetachedFromWindow(Presenter.ViewHolder holder)
Presenter
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.onViewDetachedFromWindow
in class Presenter
holder
- Holder of the view being detachedprotected void onRowViewDetachedFromWindow(RowPresenter.ViewHolder vh)
public void freeze(RowPresenter.ViewHolder holder, boolean freeze)
public void setEntranceTransitionState(RowPresenter.ViewHolder holder, boolean afterEntrance)
holder
- The ViewHolder of the row.afterEntrance
- true if children of row participating in entrance transition
should be set to visible, false otherwise.