public class GuidedActionsStylist extends Object implements FragmentAnimationProvider
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(int)
and
getItemViewType(GuidedAction)
method to change the layout used to display each action.
To support a "click to activate" view similar to DatePicker, app needs:
onProvideItemLayoutId(int)
and getItemViewType(GuidedAction)
,
provides a layout id for the action.
View.setActivated(boolean)
.
onBindActivatorView(ViewHolder, GuidedAction)
to populate values into View.
onUpdateActivatorView(ViewHolder, GuidedAction)
to update action.
Note: If an alternate list layout is provided, the following view IDs must be supplied:
android.support.v17.leanback.R.id#guidedactions_list
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:
android.support.v17.leanback.R.id#guidedactions_item_content
android.support.v17.leanback.R.id#guidedactions_item_title
android.support.v17.leanback.R.id#guidedactions_item_description
android.support.v17.leanback.R.id#guidedactions_item_icon
android.support.v17.leanback.R.id#guidedactions_item_checkmark
android.support.v17.leanback.R.id#guidedactions_item_chevron
These view IDs are allowed to be missing, in which case the corresponding views in GuidedActionsStylist.ViewHolder
will be null.
In order to support editable actions, the view associated with guidedactions_item_title should
be a subclass of EditText
, and should satisfy the ImeKeyMonitor
interface.
android.R.styleable#Theme_listChoiceIndicatorSingle
,
android.R.styleable#Theme_listChoiceIndicatorMultiple
,
GuidedStepFragment
,
GuidedAction
Modifier and Type | Class and Description |
---|---|
static class |
GuidedActionsStylist.ViewHolder
ViewHolder caches information about the action item layouts' subviews.
|
Modifier and Type | Field and Description |
---|---|
static int |
VIEW_TYPE_DATE_PICKER
ViewType for DatePicker.
|
static int |
VIEW_TYPE_DEFAULT
Default viewType that associated with default layout Id for the action item.
|
Constructor and Description |
---|
GuidedActionsStylist() |
Modifier and Type | Method and Description |
---|---|
VerticalGridView |
getActionsGridView()
Returns the VerticalGridView that displays the list of GuidedActions.
|
GuidedAction |
getExpandedAction() |
int |
getItemViewType(GuidedAction action)
Return view type of action, each different type can have differently associated layout Id.
|
VerticalGridView |
getSubActionsGridView()
Returns the VerticalGridView that displays the sub actions list of an expanded action.
|
boolean |
isButtonActions()
Returns true if it is button actions list, false for normal actions list.
|
boolean |
isExpandTransitionSupported()
Returns if expand/collapse animation is supported.
|
boolean |
isInExpandTransition()
Returns true if it is running an expanding or collapsing transition, false otherwise.
|
boolean |
isSubActionsExpanded() |
void |
onAnimateItemChecked(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(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(GuidedActionsStylist.ViewHolder vh,
boolean pressed)
Animates the view holder's view (or subviews thereof) when the action has had its press
state changed.
|
void |
onAnimateItemPressedCancelled(GuidedActionsStylist.ViewHolder vh)
Resets the view holder's view to unpressed state.
|
void |
onBindActivatorView(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Performs binding activator view value to action.
|
void |
onBindCheckMarkView(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Sets states of check mark view, called by
onBindViewHolder(ViewHolder, GuidedAction)
when action's checkset Id is other than GuidedAction.NO_CHECK_SET . |
void |
onBindChevronView(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Sets states of chevron view, called by
onBindViewHolder(ViewHolder, GuidedAction) . |
void |
onBindViewHolder(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Binds a
GuidedActionsStylist.ViewHolder to a particular GuidedAction . |
View |
onCreateView(LayoutInflater inflater,
ViewGroup container)
Creates a view appropriate for displaying a list of GuidedActions, using the provided
inflater and container.
|
GuidedActionsStylist.ViewHolder |
onCreateViewHolder(ViewGroup parent)
Constructs a
GuidedActionsStylist.ViewHolder capable of representing GuidedAction s. |
GuidedActionsStylist.ViewHolder |
onCreateViewHolder(ViewGroup parent,
int viewType)
Constructs a
GuidedActionsStylist.ViewHolder capable of representing GuidedAction s. |
void |
onDestroyView()
Called when destroy the View created by GuidedActionsStylist.
|
protected void |
onEditingModeChange(GuidedActionsStylist.ViewHolder vh,
GuidedAction action,
boolean editing) |
void |
onImeAppearing(List<Animator> animators)
Animates the fragment in response to the IME appearing.
|
void |
onImeDisappearing(List<Animator> animators)
Animates the fragment in response to the IME disappearing.
|
int |
onProvideItemLayoutId()
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 |
onProvideLayoutId()
Provides the resource ID of the layout defining the host view for the list of guided actions.
|
boolean |
onUpdateActivatorView(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Performs updating GuidedAction from activator view.
|
void |
onUpdateExpandedViewHolder(GuidedActionsStylist.ViewHolder avh)
Expand or collapse GuidedActionStylist.
|
void |
setAsButtonActions()
Choose the layout resource for button actions in
onProvideLayoutId() . |
void |
setEditingMode(GuidedActionsStylist.ViewHolder vh,
GuidedAction action,
boolean editing) |
void |
setEditListener(GuidedActionAdapter.EditListener listener)
Sets listener for reporting view being edited.
|
void |
setExpandedViewHolder(GuidedActionsStylist.ViewHolder avh)
Expands or collapse the sub actions list view.
|
protected void |
setupImeOptions(GuidedActionsStylist.ViewHolder vh,
GuidedAction action)
Called by
onBindViewHolder(ViewHolder, GuidedAction) to setup IME options. |
void |
startExpandedTransition(GuidedActionsStylist.ViewHolder avh)
Start transition to expand or collapse GuidedActionStylist.
|
public static final int VIEW_TYPE_DEFAULT
public static final int VIEW_TYPE_DATE_PICKER
public View onCreateView(LayoutInflater inflater, ViewGroup container)
Note: Does not actually add the created view to the container; the caller should do this.
inflater
- The layout inflater to be used when constructing the view.container
- The view group to be passed in the call to
LayoutInflater.inflate
.public void setAsButtonActions()
onProvideLayoutId()
.public boolean isButtonActions()
public void onDestroyView()
public VerticalGridView getActionsGridView()
public VerticalGridView getSubActionsGridView()
public int onProvideLayoutId()
android.support.v17.leanback.R.layout#lb_guidedactions
or
android.support.v17.leanback.R.layout#lb_guidedbuttonactions
if
isButtonActions()
is true. If overridden, the substituted layout should contain
matching IDs for any views that should be managed by the base class; this can be achieved by
starting with a copy of the base layout file.public int getItemViewType(GuidedAction action)
VIEW_TYPE_DEFAULT
.action
- The action object.onProvideItemLayoutId(int)
.public int onProvideItemLayoutId()
android.support.v17.leanback.R.layout#lb_guidedactions_item
. If overridden,
the substituted layout should contain matching IDs for any views that should be managed by
the base class; this can be achieved by starting with a copy of the base layout file. Note
that in order for the item to support editing, the title view should both subclass EditText
and implement ImeKeyMonitor
; see GuidedActionEditText
. To support different types of Layouts, override onProvideItemLayoutId(int)
.public int onProvideItemLayoutId(int viewType)
android.support.v17.leanback.R.layout#lb_guidedactions_item
android.support.v17.leanback.R.layout#lb_guidedactions_datepicker_item
. If
overridden, the substituted layout should contain matching IDs for any views that should be
managed by the base class; this can be achieved by starting with a copy of the base layout
file. Note that in order for the item to support editing, the title view should both subclass
EditText
and implement ImeKeyMonitor
; see
GuidedActionEditText
.viewType
- View type returned by getItemViewType(GuidedAction)
public GuidedActionsStylist.ViewHolder onCreateViewHolder(ViewGroup parent)
GuidedActionsStylist.ViewHolder
capable of representing GuidedAction
s. Subclasses
may choose to return a subclass of ViewHolder. To support different view types, override
onCreateViewHolder(ViewGroup, int)
Note: Should not actually add the created view to the parent; the caller will do this.
parent
- The view group to be used as the parent of the new view.public GuidedActionsStylist.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
GuidedActionsStylist.ViewHolder
capable of representing GuidedAction
s. Subclasses
may choose to return a subclass of ViewHolder.
Note: Should not actually add the created view to the parent; the caller will do this.
parent
- The view group to be used as the parent of the new view.viewType
- The viewType returned by getItemViewType(GuidedAction)
public void onBindViewHolder(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
GuidedActionsStylist.ViewHolder
to a particular GuidedAction
.vh
- The view holder to be associated with the given action.action
- The guided action to be displayed by the view holder's view.protected void setupImeOptions(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
onBindViewHolder(ViewHolder, GuidedAction)
to setup IME options. Default
implementation assigns EditorInfo.IME_ACTION_DONE
. Subclass may override.vh
- The view holder to be associated with the given action.action
- The guided action to be displayed by the view holder's view.public void setEditingMode(GuidedActionsStylist.ViewHolder vh, GuidedAction action, boolean editing)
protected void onEditingModeChange(GuidedActionsStylist.ViewHolder vh, GuidedAction action, boolean editing)
public void onAnimateItemFocused(GuidedActionsStylist.ViewHolder vh, boolean focused)
vh
- The view holder associated with the relevant action.focused
- True if the action has become focused, false if it has lost focus.public void onAnimateItemPressed(GuidedActionsStylist.ViewHolder vh, boolean pressed)
vh
- The view holder associated with the relevant action.pressed
- True if the action has been pressed, false if it has been unpressed.public void onAnimateItemPressedCancelled(GuidedActionsStylist.ViewHolder vh)
vh
- The view holder associated with the relevant action.public void onAnimateItemChecked(GuidedActionsStylist.ViewHolder vh, boolean checked)
GuidedActionsStylist.ViewHolder.getCheckmarkView()
is instance of Checkable
.vh
- The view holder associated with the relevant action.checked
- True if the action has become checked, false if it has become unchecked.onBindCheckMarkView(ViewHolder, GuidedAction)
public void onBindCheckMarkView(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
onBindViewHolder(ViewHolder, GuidedAction)
when action's checkset Id is other than GuidedAction.NO_CHECK_SET
. Default
implementation assigns drawable loaded from theme attribute
android.R.attr#listChoiceIndicatorMultiple
for checkbox or
android.R.attr#listChoiceIndicatorSingle
for radio button. Subclass rarely needs
override the method, instead app can provide its own drawable that supports transition
animations, change theme attributes android.R.attr#listChoiceIndicatorMultiple
and
android.R.attr#listChoiceIndicatorSingle
in {android.support.v17.leanback.R.
styleable#LeanbackGuidedStepTheme}.vh
- The view holder associated with the relevant action.action
- The GuidedAction object to bind to.onAnimateItemChecked(ViewHolder, boolean)
public void onBindActivatorView(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
vh
- ViewHolder of activator view.action
- GuidedAction to bind.public boolean onUpdateActivatorView(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
vh
- ViewHolder of activator view.action
- GuidedAction to update.public void setEditListener(GuidedActionAdapter.EditListener listener)
public void onBindChevronView(GuidedActionsStylist.ViewHolder vh, GuidedAction action)
onBindViewHolder(ViewHolder, GuidedAction)
.
Subclass may override.vh
- The view holder associated with the relevant action.action
- The GuidedAction object to bind to.public void setExpandedViewHolder(GuidedActionsStylist.ViewHolder avh)
avh
- When not null, fill sub actions list of this ViewHolder into sub actions list and
hide the other items in main list. When null, collapse the sub actions list.public boolean isInExpandTransition()
public boolean isExpandTransitionSupported()
startExpandedTransition(ViewHolder)
will be used. When this method returns false,
onUpdateExpandedViewHolder(ViewHolder)
will be called.public void startExpandedTransition(GuidedActionsStylist.ViewHolder avh)
avh
- When not null, the GuidedActionStylist expands the sub actions of avh. When null
the GuidedActionStylist will collapse sub actions.public boolean isSubActionsExpanded()
public GuidedAction getExpandedAction()
public void onUpdateExpandedViewHolder(GuidedActionsStylist.ViewHolder avh)
avh
- When not null, the GuidedActionStylist expands the sub actions of avh. When null
the GuidedActionStylist will collapse sub actions.public void onImeAppearing(@NonNull List<Animator> animators)
onImeAppearing
in interface FragmentAnimationProvider
animators
- A list of animations to which this provider's animations should be added.public void onImeDisappearing(@NonNull List<Animator> animators)
onImeDisappearing
in interface FragmentAnimationProvider
animators
- A list of animations to which this provider's animations should be added.