VerticalGridPresenter


public class VerticalGridPresenter extends Presenter


A presenter that renders objects in a VerticalGridView.

Summary

Nested types

ViewHolder for the VerticalGridPresenter.

Public constructors

Constructs a VerticalGridPresenter with defaults.

VerticalGridPresenter(int focusZoomFactor)

Constructs a VerticalGridPresenter with the given parameters.

VerticalGridPresenter(int focusZoomFactor, boolean useFocusDimmer)

Constructs a VerticalGridPresenter with the given parameters.

Public methods

final boolean

Returns true if rounded corners are enabled for children of this row.

final void
enableChildRoundedCorners(boolean enable)

Enables or disabled rounded corners on children of this row.

final int

Returns the zoom factor used for focus highlighting.

final boolean

Returns true if keeps foreground of child of this grid, the foreground will not be used for overlay color.

int

Returns the number of columns in the vertical grid.

final @Nullable OnItemViewClickedListener

Returns the item clicked listener.

final @Nullable OnItemViewSelectedListener

Returns the item selected listener.

final boolean

Returns true if child shadow is enabled.

final boolean

Returns true if the focus dimmer is used for focus highlighting; false otherwise.

boolean

Default implementation returns true if SDK version >= 21, shadow (either static or z-order based) will be applied to each individual child of VerticalGridView.

boolean

Returns true if SDK >= L, where Z shadow is enabled so that Z order is enabled on each child of vertical grid.

void
onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @Nullable Object item
)

Binds a View to an item.

final @NonNull VerticalGridPresenter.ViewHolder

Creates a new View.

void

Unbinds a View from an item.

void
setEntranceTransitionState(
    @NonNull VerticalGridPresenter.ViewHolder holder,
    boolean afterEntrance
)

Changes the visibility of views.

final void
setKeepChildForeground(boolean keep)

Set if keeps foreground of child of this grid, the foreground will not be used for overlay color.

void
setNumberOfColumns(int numColumns)

Sets the number of columns in the vertical grid.

final void

Sets the item clicked listener.

final void

Sets the item selected listener.

final void
setShadowEnabled(boolean enabled)

Enable or disable child shadow.

Protected methods

@NonNull VerticalGridPresenter.ViewHolder

Subclass may override this to inflate a different layout.

@NonNull ShadowOverlayHelper.Options

Create ShadowOverlayHelper Options.

void

Called after a VerticalGridPresenter.ViewHolder is created.

Inherited methods

From androidx.leanback.widget.FacetProvider
abstract @Nullable Object
getFacet(@NonNull Class<Object> facetClass)

Queries optional implemented facet.

From androidx.leanback.widget.Presenter
static void

Utility method for removing all running animations on a view.

final Object
getFacet(Class<Object> facetClass)

Queries optional implemented facet.

void
onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @NonNull Object item,
    @NonNull List<Object> payloads
)

Binds a View to an item with a list of payloads.

void

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

void

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

final void
setFacet(Class<Object> facetClass, Object facetImpl)

Sets dynamic implemented facet in addition to basic Presenter functions.

void

Called to set a click listener for the given view holder.

Public constructors

VerticalGridPresenter

Added in 1.1.0
public VerticalGridPresenter()

Constructs a VerticalGridPresenter with defaults. Uses ZOOM_FACTOR_LARGE for focus zooming and enabled dimming on focus.

VerticalGridPresenter

Added in 1.1.0
public VerticalGridPresenter(int focusZoomFactor)

Constructs a VerticalGridPresenter with the given parameters.

Parameters
int focusZoomFactor

Controls the zoom factor used when an item view is focused. One of ZOOM_FACTOR_NONE, ZOOM_FACTOR_SMALL, ZOOM_FACTOR_XSMALL, ZOOM_FACTOR_MEDIUM, ZOOM_FACTOR_LARGE enabled dimming on focus.

VerticalGridPresenter

Added in 1.1.0
public VerticalGridPresenter(int focusZoomFactor, boolean useFocusDimmer)

Constructs a VerticalGridPresenter with the given parameters.

Parameters
int focusZoomFactor

Controls the zoom factor used when an item view is focused. One of ZOOM_FACTOR_NONE, ZOOM_FACTOR_SMALL, ZOOM_FACTOR_XSMALL, ZOOM_FACTOR_MEDIUM, ZOOM_FACTOR_LARGE

boolean useFocusDimmer

determines if the FocusHighlighter will use the dimmer

Public methods

areChildRoundedCornersEnabled

Added in 1.1.0
public final boolean areChildRoundedCornersEnabled()

Returns true if rounded corners are enabled for children of this row.

enableChildRoundedCorners

Added in 1.1.0
public final void enableChildRoundedCorners(boolean enable)

Enables or disabled rounded corners on children of this row. Supported on Android SDK >= L.

getFocusZoomFactor

Added in 1.1.0
public final int getFocusZoomFactor()

Returns the zoom factor used for focus highlighting.

getKeepChildForeground

Added in 1.1.0
public final boolean getKeepChildForeground()

Returns true if keeps foreground of child of this grid, the foreground will not be used for overlay color. Default value is true.

Returns
boolean

True if keeps foreground of child of this grid.

getNumberOfColumns

Added in 1.1.0
public int getNumberOfColumns()

Returns the number of columns in the vertical grid.

getOnItemViewClickedListener

Added in 1.1.0
public final @Nullable OnItemViewClickedListener getOnItemViewClickedListener()

Returns the item clicked listener.

getOnItemViewSelectedListener

Added in 1.1.0
public final @Nullable OnItemViewSelectedListener getOnItemViewSelectedListener()

Returns the item selected listener.

getShadowEnabled

Added in 1.1.0
public final boolean getShadowEnabled()

Returns true if child shadow is enabled. This is not only for enable/disable default shadow implementation but also subclass must respect this flag.

isFocusDimmerUsed

Added in 1.1.0
public final boolean isFocusDimmerUsed()

Returns true if the focus dimmer is used for focus highlighting; false otherwise.

isUsingDefaultShadow

Added in 1.1.0
public boolean isUsingDefaultShadow()

Default implementation returns true if SDK version >= 21, shadow (either static or z-order based) will be applied to each individual child of VerticalGridView. Subclass may return false to disable default implementation of shadow and provide its own.

isUsingZOrder

Added in 1.1.0
public boolean isUsingZOrder(@NonNull Context context)

Returns true if SDK >= L, where Z shadow is enabled so that Z order is enabled on each child of vertical grid. If subclass returns false in isUsingDefaultShadow() and does not use Z-shadow on SDK >= L, it should override isUsingZOrder() return false.

onBindViewHolder

Added in 1.2.0-alpha04
public void onBindViewHolder(
    @NonNull Presenter.ViewHolder viewHolder,
    @Nullable Object item
)

Binds a View to an item.

onCreateViewHolder

Added in 1.2.0-alpha04
public final @NonNull VerticalGridPresenter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent)

Creates a new View.

onUnbindViewHolder

Added in 1.2.0-alpha04
public void onUnbindViewHolder(@NonNull 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.

setEntranceTransitionState

Added in 1.1.0
public void setEntranceTransitionState(
    @NonNull VerticalGridPresenter.ViewHolder holder,
    boolean afterEntrance
)

Changes the visibility of views. The entrance transition will be run against the views that change visibilities. This method is called by the fragment, it should not be called directly by the application.

Parameters
@NonNull VerticalGridPresenter.ViewHolder holder

The ViewHolder for the vertical grid.

boolean afterEntrance

true if children of vertical grid participating in entrance transition should be set to visible, false otherwise.

setKeepChildForeground

Added in 1.1.0
public final void setKeepChildForeground(boolean keep)

Set if keeps foreground of child of this grid, the foreground will not be used for overlay color. Default value is true.

Parameters
boolean keep

True if keep foreground of child of this grid.

setNumberOfColumns

Added in 1.1.0
public void setNumberOfColumns(int numColumns)

Sets the number of columns in the vertical grid.

setOnItemViewClickedListener

Added in 1.1.0
public final void setOnItemViewClickedListener(
    @Nullable OnItemViewClickedListener listener
)

Sets the item clicked listener. OnItemViewClickedListener will override View.OnClickListener that item presenter sets during onCreateViewHolder. So in general, developer should choose one of the listeners but not both.

setOnItemViewSelectedListener

Added in 1.1.0
public final void setOnItemViewSelectedListener(
    @Nullable OnItemViewSelectedListener listener
)

Sets the item selected listener. Since this is a grid the row parameter is always null.

setShadowEnabled

Added in 1.1.0
public final void setShadowEnabled(boolean enabled)

Enable or disable child shadow. This is not only for enable/disable default shadow implementation but also subclass must respect this flag.

Protected methods

createGridViewHolder

Added in 1.1.0
protected @NonNull VerticalGridPresenter.ViewHolder createGridViewHolder(@NonNull ViewGroup parent)

Subclass may override this to inflate a different layout.

createShadowOverlayOptions

Added in 1.1.0
protected @NonNull ShadowOverlayHelper.Options createShadowOverlayOptions()

Create ShadowOverlayHelper Options. Subclass may override. e.g. return new ShadowOverlayHelper.Options().roundedCornerRadius(10);

Returns
@NonNull ShadowOverlayHelper.Options

The options to be used for shadow, overlay and rounded corner.

initializeGridViewHolder

Added in 1.1.0
protected void initializeGridViewHolder(@NonNull VerticalGridPresenter.ViewHolder vh)

Called after a VerticalGridPresenter.ViewHolder is created. Subclasses may override this method and start by calling super.initializeGridViewHolder(ViewHolder).

Parameters
@NonNull VerticalGridPresenter.ViewHolder vh

The ViewHolder to initialize for the vertical grid.