GuidedActionsStylist


public class GuidedActionsStylist implements FragmentAnimationProvider


GuidedActionsStylist is used within a androidx.leanback.app.GuidedStepFragment to supply the right-side panel where users can take actions. It consists of a container for the list of actions, and a stationary selector view that indicates visually the location of focus. GuidedActionsStylist has two different layouts: default is for normal actions including text, radio, checkbox, DatePicker, etc, the other when setAsButtonActions is called is recommended for button actions such as "yes", "no".

Many aspects of the base GuidedActionsStylist can be customized through theming; see the theme attributes below. Note that these attributes are not set on individual elements in layout XML, but instead would be set in a custom theme. See Styles and Themes for more information.

If these hooks are insufficient, this class may also be subclassed. Subclasses may wish to override the onProvideLayoutId method to change the layout used to display the list container and selector; override onProvideItemLayoutId and getItemViewType method to change the layout used to display each action.

To support a "click to activate" view similar to DatePicker, app needs:

Note: If an alternate list layout is provided, the following view IDs must be supplied:

These view IDs must be present in order for the stylist to function. The list ID must correspond to a VerticalGridView or subclass.

If an alternate item layout is provided, the following view IDs should be used to refer to base elements:

These view IDs are allowed to be missing, in which case the corresponding views in will be null.

In order to support editable actions, the view associated with guidedactions_item_title should be a subclass of android.widget.EditText, and should satisfy the interface and GuidedActionAutofillSupport interface. guidedStepImeAppearingAnimationguidedStepImeDisappearingAnimationguidedActionsSelectorDrawableguidedActionsListStyleguidedSubActionsListStyleguidedButtonActionsListStyleguidedActionItemContainerStyleguidedActionItemCheckmarkStyleguidedActionItemIconStyleguidedActionItemContentStyleguidedActionItemTitleStyleguidedActionItemDescriptionStyleguidedActionItemChevronStyleguidedActionPressedAnimationguidedActionUnpressedAnimationguidedActionEnabledChevronAlphaguidedActionDisabledChevronAlphaguidedActionTitleMinLinesguidedActionTitleMaxLinesguidedActionDescriptionMinLinesguidedActionVerticalPadding

Summary

Nested types

ViewHolder caches information about the action item layouts' subviews.

Constants

static final int

ViewType for DatePicker.

static final int

Default viewType that associated with default layout Id for the action item.

Public constructors

Public methods

void
collapseAction(boolean withTransition)

Collapse expanded action.

void
expandAction(@NonNull GuidedAction action, boolean withTransition)

Expand an action.

@Nullable VerticalGridView

Returns the VerticalGridView that displays the list of GuidedActions.

@Nullable GuidedAction
int

Return view type of action, each different type can have differently associated layout Id.

@Nullable VerticalGridView

Returns the VerticalGridView that displays the sub actions list of an expanded action.

final boolean
final boolean
boolean

Returns true if it is button actions list, false for normal actions list.

boolean

Returns if expand/collapse animation is supported.

boolean
boolean

Returns true if it is running an expanding or collapsing transition, false otherwise.

boolean
void
onAnimateItemChecked(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean checked
)

Animates the view holder's view (or subviews thereof) when the action has had its check state changed.

void
onAnimateItemFocused(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean focused
)

Animates the view holder's view (or subviews thereof) when the action has had its focus state changed.

void
onAnimateItemPressed(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean pressed
)

Animates the view holder's view (or subviews thereof) when the action has had its press state changed.

void

Resets the view holder's view to unpressed state.

void

Performs binding activator view value to action.

void

Sets states of check mark view, called by onBindViewHolder when action's checkset Id is other than NO_CHECK_SET.

void

Sets states of chevron view, called by onBindViewHolder.

void

Binds a ViewHolder to a particular GuidedAction.

@NonNull View
onCreateView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Creates a view appropriate for displaying a list of GuidedActions, using the provided inflater and container.

@NonNull GuidedActionsStylist.ViewHolder

Constructs a ViewHolder capable of representing GuidedActions.

@NonNull GuidedActionsStylist.ViewHolder
onCreateViewHolder(@NonNull ViewGroup parent, int viewType)

Constructs a ViewHolder capable of representing GuidedActions.

void

Called when destroy the View created by GuidedActionsStylist.

void

Animates the fragment in response to the IME appearing.

void

Animates the fragment in response to the IME disappearing.

int

Provides the resource ID of the layout defining the view for an individual guided actions.

int
onProvideItemLayoutId(int viewType)

Provides the resource ID of the layout defining the view for an individual guided actions.

int

Provides the resource ID of the layout defining the host view for the list of guided actions.

boolean

Performs updating GuidedAction from activator view.

void

Expand or collapse GuidedActionStylist.

void

Switches action to edit mode and pops up the keyboard.

void

Choose the layout resource for button actions in onProvideLayoutId.

final void
setBackKeyToCollapseActivatorView(boolean backToCollapse)

Enable or disable using BACK key to collapse GuidedAction with editable activator view.

final void
setBackKeyToCollapseSubActions(boolean backToCollapse)

Enable or disable using BACK key to collapse sub actions list.

void
setEditingMode(
    GuidedActionsStylist.ViewHolder vh,
    GuidedAction action,
    boolean editing
)

This method is deprecated.

This method is for internal library use only and should not be called directly.

void

This method is deprecated.

use expandAction and collapseAction

void

This method is deprecated.

use expandAction and collapseAction

Protected methods

void
onEditingModeChange(
    GuidedActionsStylist.ViewHolder vh,
    GuidedAction action,
    boolean editing
)

This method is deprecated.

Use onEditingModeChange.

void
@CallSuper
onEditingModeChange(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean editing,
    boolean withTransition
)

Called when editing mode of an ViewHolder is changed.

void

Called by onBindViewHolder to setup IME options.

Constants

VIEW_TYPE_DATE_PICKER

Added in 1.1.0
public static final int VIEW_TYPE_DATE_PICKER = 1

ViewType for DatePicker.

VIEW_TYPE_DEFAULT

Added in 1.1.0
public static final int VIEW_TYPE_DEFAULT = 0

Default viewType that associated with default layout Id for the action item.

Public constructors

GuidedActionsStylist

Added in 1.1.0
public GuidedActionsStylist()

Public methods

collapseAction

Added in 1.1.0
public void collapseAction(boolean withTransition)

Collapse expanded action. Do nothing if it is in animation or there is no action expanded.

Parameters
boolean withTransition

True to run transition animation, false otherwsie.

expandAction

Added in 1.1.0
public void expandAction(@NonNull GuidedAction action, boolean withTransition)

Expand an action. Do nothing if it is in animation or there is action expanded.

Parameters
@NonNull GuidedAction action

Action to expand.

boolean withTransition

True to run transition animation, false otherwsie.

getActionsGridView

Added in 1.1.0
public @Nullable VerticalGridView getActionsGridView()

Returns the VerticalGridView that displays the list of GuidedActions.

Returns
@Nullable VerticalGridView

The VerticalGridView for this presenter.

getExpandedAction

Added in 1.1.0
public @Nullable GuidedAction getExpandedAction()
Returns
@Nullable GuidedAction

Current expanded GuidedAction or null if not expanded.

getItemViewType

Added in 1.1.0
public int getItemViewType(@NonNull GuidedAction action)

Return view type of action, each different type can have differently associated layout Id. Default implementation returns VIEW_TYPE_DEFAULT.

Parameters
@NonNull GuidedAction action

The action object.

Returns
int

View type that used in onProvideItemLayoutId.

getSubActionsGridView

Added in 1.1.0
public @Nullable VerticalGridView getSubActionsGridView()

Returns the VerticalGridView that displays the sub actions list of an expanded action.

Returns
@Nullable VerticalGridView

The VerticalGridView that displays the sub actions list of an expanded action.

isBackKeyToCollapseActivatorView

Added in 1.1.0
public final boolean isBackKeyToCollapseActivatorView()
Returns
boolean

True if using BACK key to collapse GuidedAction with editable activator view, false otherwise. Default value is true.

isBackKeyToCollapseSubActions

Added in 1.1.0
public final boolean isBackKeyToCollapseSubActions()
Returns
boolean

True if using BACK key to collapse sub actions list, false otherwise. Default value is true.

isButtonActions

Added in 1.1.0
public boolean isButtonActions()

Returns true if it is button actions list, false for normal actions list.

Returns
boolean

True if it is button actions list, false for normal actions list.

isExpandTransitionSupported

Added in 1.1.0
public boolean isExpandTransitionSupported()

Returns if expand/collapse animation is supported. When this method returns true, startExpandedTransition will be used. When this method returns false, onUpdateExpandedViewHolder will be called.

Returns
boolean

True if it is running an expanding or collapsing transition, false otherwise.

isExpanded

Added in 1.1.0
public boolean isExpanded()
Returns
boolean

True if there is getExpandedAction is not null, false otherwise.

isInExpandTransition

Added in 1.1.0
public boolean isInExpandTransition()

Returns true if it is running an expanding or collapsing transition, false otherwise.

Returns
boolean

True if it is running an expanding or collapsing transition, false otherwise.

isSubActionsExpanded

Added in 1.1.0
public boolean isSubActionsExpanded()
Returns
boolean

True if sub actions list is expanded.

onAnimateItemChecked

Added in 1.1.0
public void onAnimateItemChecked(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean checked
)

Animates the view holder's view (or subviews thereof) when the action has had its check state changed. Default implementation calls setChecked() if getCheckmarkView is instance of Checkable.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

boolean checked

True if the action has become checked, false if it has become unchecked.

onAnimateItemFocused

Added in 1.1.0
public void onAnimateItemFocused(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean focused
)

Animates the view holder's view (or subviews thereof) when the action has had its focus state changed.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

boolean focused

True if the action has become focused, false if it has lost focus.

onAnimateItemPressed

Added in 1.1.0
public void onAnimateItemPressed(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    boolean pressed
)

Animates the view holder's view (or subviews thereof) when the action has had its press state changed.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

boolean pressed

True if the action has been pressed, false if it has been unpressed.

onAnimateItemPressedCancelled

Added in 1.1.0
public void onAnimateItemPressedCancelled(
    @NonNull GuidedActionsStylist.ViewHolder vh
)

Resets the view holder's view to unpressed state.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

onBindActivatorView

Added in 1.1.0
public void onBindActivatorView(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    @NonNull GuidedAction action
)

Performs binding activator view value to action. Default implementation supports GuidedDatePickerAction, subclass may override to add support of other views.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

ViewHolder of activator view.

@NonNull GuidedAction action

GuidedAction to bind.

onBindCheckMarkView

Added in 1.1.0
public void onBindCheckMarkView(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    @NonNull GuidedAction action
)

Sets states of check mark view, called by onBindViewHolder when action's checkset Id is other than NO_CHECK_SET. Default implementation assigns drawable loaded from theme attribute listChoiceIndicatorMultiple for checkbox or listChoiceIndicatorSingle for radio button. Subclass rarely needs override the method, instead app can provide its own drawable that supports transition animations, change theme attributes listChoiceIndicatorMultiple and listChoiceIndicatorSingle in {androidx.leanback.R. styleable#LeanbackGuidedStepTheme}.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

@NonNull GuidedAction action

The GuidedAction object to bind to.

onBindChevronView

Added in 1.1.0
public void onBindChevronView(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    @NonNull GuidedAction action
)

Sets states of chevron view, called by onBindViewHolder. Subclass may override.

Parameters
@NonNull GuidedActionsStylist.ViewHolder vh

The view holder associated with the relevant action.

@NonNull GuidedAction action

The GuidedAction object to bind to.

onBindViewHolder

Added in 1.1.0
public void onBindViewHolder(
    @NonNull GuidedActionsStylist.ViewHolder vh,
    @NonNull GuidedAction action
)

Binds a ViewHolder to a particular GuidedAction.

Parameters