Stay organized with collections Save and categorize content based on your preferences.
added in version 24.1.0
belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1

GuidedStepSupportFragment

public class GuidedStepSupportFragment
extends Fragment

java.lang.Object
   ↳ android.support.v4.app.Fragment
     ↳ android.support.v17.leanback.app.GuidedStepSupportFragment


A GuidedStepSupportFragment is used to guide the user through a decision or series of decisions. It is composed of a guidance view on the left and a view on the right containing a list of possible actions.

Basic Usage

Clients of GuidedStepSupportFragment must create a custom subclass to attach to their Activities. This custom subclass provides the information necessary to construct the user interface and respond to user actions. At a minimum, subclasses should override:

Clients use following helper functions to add GuidedStepSupportFragment to Activity or FragmentManager:

Theming and Stylists

GuidedStepSupportFragment delegates its visual styling to classes called stylists. The GuidanceStylist is responsible for the left guidance view, while the GuidedActionsStylist is responsible for the right actions view. The stylists use theme attributes to derive values associated with the presentation, such as colors, animations, etc. Most simple visual aspects of GuidanceStylist and GuidedActionsStylist can be customized via theming; see their documentation for more information.

GuidedStepSupportFragments must have access to an appropriate theme in order for the stylists to function properly. Specifically, the fragment must receive Theme_Leanback_GuidedStep, or a theme whose parent is is set to that theme. Themes can be provided in one of three ways:

  • The simplest way is to set the theme for the host Activity to the GuidedStep theme or a theme that derives from it.
  • If the Activity already has a theme and setting its parent theme is inconvenient, the existing Activity theme can have an entry added for the attribute LeanbackGuidedStepTheme_guidedStepTheme. If present, this theme will be used by GuidedStepSupportFragment as an overlay to the Activity's theme.
  • Finally, custom subclasses of GuidedStepSupportFragment may provide a theme through the onProvideTheme() method. This can be useful if a subclass is used across multiple Activities.

If the theme is provided in multiple ways, the onProvideTheme override has priority, followed by the Activity's theme. (Themes whose parent theme is already set to the guided step theme do not need to set the guidedStepTheme attribute; if set, it will be ignored.)

If themes do not provide enough customizability, the stylists themselves may be subclassed and provided to the GuidedStepSupportFragment through the onCreateGuidanceStylist() and onCreateActionsStylist() methods. The stylists have simple hooks so that subclasses may override layout files; subclasses may also have more complex logic to determine styling.

Guided sequences

GuidedStepSupportFragments can be grouped together to provide a guided sequence. GuidedStepSupportFragments grouped as a sequence use custom animations provided by GuidanceStylist and GuidedActionsStylist (or subclasses) during transitions between steps. Clients should use add(FragmentManager, GuidedStepSupportFragment) to place subsequent GuidedFragments onto the fragment stack so that custom animations are properly configured. (Custom animations are triggered automatically when the fragment stack is subsequently popped by any normal mechanism.)

Note: Currently GuidedStepSupportFragments grouped in this way must all be defined programmatically, rather than in XML. This restriction may be removed in the future.

Summary

XML attributes

LeanbackGuidedStepTheme_guidedActionContentWidthWeight  
LeanbackGuidedStepTheme_guidedActionContentWidthWeightTwoPanels  
LeanbackGuidedStepTheme_guidedActionsBackground  
LeanbackGuidedStepTheme_guidedActionsBackgroundDark  
LeanbackGuidedStepTheme_guidedActionsElevation  
LeanbackGuidedStepTheme_guidedStepBackground  
LeanbackGuidedStepTheme_guidedStepTheme  

Constants

String EXTRA_UI_STYLE

Fragment argument name for UI style.

int UI_STYLE_ACTIVITY_ROOT

One possible value of argument EXTRA_UI_STYLE.

int UI_STYLE_DEFAULT

This constant was deprecated in API level 24.1.0. Same value as UI_STYLE_REPLACE.

int UI_STYLE_ENTRANCE

Default value for argument EXTRA_UI_STYLE.

int UI_STYLE_REPLACE

This is the case that we use GuidedStepSupportFragment to replace another existing GuidedStepSupportFragment when moving forward to next step.

Public constructors

GuidedStepSupportFragment()

Public methods

static int add(FragmentManager fragmentManager, GuidedStepSupportFragment fragment, int id)

Adds the specified GuidedStepSupportFragment to the fragment stack, replacing any existing GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom transitions.

static int add(FragmentManager fragmentManager, GuidedStepSupportFragment fragment)

Adds the specified GuidedStepSupportFragment to the fragment stack, replacing any existing GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom transitions.

static int addAsRoot(FragmentActivity activity, GuidedStepSupportFragment fragment, int id)

Adds the specified GuidedStepSupportFragment as content of Activity; no backstack entry is added so the activity will be dismissed when BACK key is pressed.

void collapseAction(boolean withTransition)

Collapse action which either has a sub actions list or action with hasEditableActivatorView() is true.

void collapseSubActions()

Collapse sub actions list.

void expandAction(GuidedAction action, boolean withTransition)

Expand a given action with sub actions list or hasEditableActivatorView() is true.

void expandSubActions(GuidedAction action)

Expand a given action's sub actions list.

GuidedAction findActionById(long id)

Find GuidedAction by Id.

int findActionPositionById(long id)

Find GuidedAction position in array by Id.

GuidedAction findButtonActionById(long id)

Find button GuidedAction by Id.

int findButtonActionPositionById(long id)

Find button GuidedAction position in array by Id.

void finishGuidedStepSupportFragments()

Convenient method to close GuidedStepSupportFragments on top of other content or finish Activity if GuidedStepSupportFragments were started in a separate activity.

View getActionItemView(int position)

Returns the view corresponding to the action at the indicated position in the list of actions for this fragment.

List<GuidedAction> getActions()

Returns the list of GuidedActions that the user may take in this fragment.

View getButtonActionItemView(int position)

Returns the view corresponding to the button action at the indicated position in the list of actions for this fragment.

List<GuidedAction> getButtonActions()

Returns the list of button GuidedActions that the user may take in this fragment.

static GuidedStepSupportFragment getCurrentGuidedStepSupportFragment(FragmentManager fm)

Returns the current GuidedStepSupportFragment on the fragment transaction stack.

GuidanceStylist getGuidanceStylist()

Returns the GuidanceStylist that displays guidance information for the user.

GuidedActionsStylist getGuidedActionsStylist()

Returns the GuidedActionsStylist that displays the actions the user may take.

GuidedActionsStylist getGuidedButtonActionsStylist()

Returns the GuidedActionsStylist that displays the button actions the user may take.

int getSelectedActionPosition()

Returns the position if the currently selected GuidedAction.

int getSelectedButtonActionPosition()

Returns the position if the currently selected button GuidedAction.

int getUiStyle()

Read UI style from fragment arguments.

boolean isExpanded()
boolean isFocusOutEndAllowed()

Returns true if allows focus out of end edge of GuidedStepSupportFragment, false otherwise.

boolean isFocusOutStartAllowed()

Returns true if allows focus out of start edge of GuidedStepSupportFragment, false otherwise.

boolean isSubActionsExpanded()
void notifyActionChanged(int position)

Notify an action has changed and update its UI.

void notifyButtonActionChanged(int position)

Notify an button action has changed and update its UI.

void onCreate(Bundle savedInstanceState)

Called to do initial creation of a fragment.

void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState)

Fills out the set of actions available to the user.

GuidedActionsStylist onCreateActionsStylist()

Creates the presenter used to style the guided actions panel.

View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called by onCreateView to inflate background view.

void onCreateButtonActions(List<GuidedAction> actions, Bundle savedInstanceState)

Fills out the set of actions shown at right available to the user.

GuidedActionsStylist onCreateButtonActionsStylist()

Creates the presenter used to style a sided actions panel for button only.

GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState)

Returns the information required to provide guidance to the user.

GuidanceStylist onCreateGuidanceStylist()

Creates the presenter used to style the guidance panel.

View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

Called to have the fragment instantiate its user interface view.

void onDestroyView()

Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment.

void onGuidedActionClicked(GuidedAction action)

Callback invoked when an action is taken by the user.

void onGuidedActionEditCanceled(GuidedAction action)

Callback invoked when an action has been canceled editing, for example when user closes IME window by BACK key.

void onGuidedActionEdited(GuidedAction action)

This method was deprecated in API level 24.1.0. Override onGuidedActionEditedAndProceed(GuidedAction) and/or onGuidedActionEditCanceled(GuidedAction).

long onGuidedActionEditedAndProceed(GuidedAction action)

Callback invoked when an action has been edited, for example when user clicks confirm button in IME window.

void onGuidedActionFocused(GuidedAction action)

Callback invoked when an action is focused (made to be the current selection) by the user.

int onProvideTheme()

Returns the theme used for styling the fragment.

void onResume()

Called when the fragment is visible to the user and actively running.

void onSaveInstanceState(Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted.

boolean onSubGuidedActionClicked(GuidedAction action)

Callback invoked when an action in sub actions is taken by the user.

void openInEditMode(GuidedAction action)

Opens the provided action in edit mode and raises ime.

void popBackStackToGuidedStepSupportFragment(Class guidedStepFragmentClass, int flags)

Convenient method to pop to fragment with Given class.

void setActions(List<GuidedAction> actions)

Sets the list of GuidedActions that the user may take in this fragment.

void setActionsDiffCallback(DiffCallback<GuidedAction> diffCallback)

Sets the RecyclerView DiffCallback used when setActions(List) is called.

void setButtonActions(List<GuidedAction> actions)

Sets the list of button GuidedActions that the user may take in this fragment.

void setSelectedActionPosition(int position)

Scrolls the action list to the position indicated, selecting that action's view.

void setSelectedButtonActionPosition(int position)

Scrolls the action list to the position indicated, selecting that button action's view.

void setUiStyle(int style)

Set UI style to fragment arguments.

Protected methods

void onAddSharedElementTransition(FragmentTransaction ft, GuidedStepSupportFragment disappearing)

Called when this fragment is added to FragmentTransaction with UI_STYLE_REPLACE (aka when the GuidedStepSupportFragment replacing an existing GuidedStepSupportFragment).

void onProvideFragmentTransitions()

Called by Constructor to provide fragment transitions.

Inherited methods

From class android.support.v4.app.Fragment
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.view.View.OnCreateContextMenuListener
From interface android.arch.lifecycle.LifecycleOwner
From interface android.arch.lifecycle.ViewModelStoreOwner

XML attributes

LeanbackGuidedStepTheme_guidedActionContentWidthWeight

LeanbackGuidedStepTheme_guidedActionContentWidthWeightTwoPanels

LeanbackGuidedStepTheme_guidedActionsBackground

LeanbackGuidedStepTheme_guidedActionsBackgroundDark

LeanbackGuidedStepTheme_guidedActionsElevation

LeanbackGuidedStepTheme_guidedStepBackground

LeanbackGuidedStepTheme_guidedStepTheme

Constants

EXTRA_UI_STYLE

added in version 24.1.0
String EXTRA_UI_STYLE

Fragment argument name for UI style. The argument value is persisted in fragment state and used to select fragment transition. The value is initially UI_STYLE_ENTRANCE and might be changed in one of the three helper functions:

Argument value can be either:

Constant Value: "uiStyle"

UI_STYLE_ACTIVITY_ROOT

added in version 24.1.0
int UI_STYLE_ACTIVITY_ROOT

One possible value of argument EXTRA_UI_STYLE. This is the case that we show first GuidedStepSupportFragment in a separate activity. The default behavior of this style:

  • Enter transition is assigned null (will rely on activity transition), exit transition is same as UI_STYLE_ENTRANCE. Note: Changing exit transition by UI style is not working because fragment transition asks for exit transition before UI style is restored in Fragment.onCreate().

Constant Value: 2 (0x00000002)

UI_STYLE_DEFAULT

added in version 24.1.0
int UI_STYLE_DEFAULT

This constant was deprecated in API level 24.1.0.
Same value as UI_STYLE_REPLACE.

Constant Value: 0 (0x00000000)

UI_STYLE_ENTRANCE

added in version 24.1.0
int UI_STYLE_ENTRANCE

Default value for argument EXTRA_UI_STYLE. The default value is assigned in GuidedStepSupportFragment constructor. This is the case that we show GuidedStepSupportFragment on top of other content. The default behavior of this style:

  • Enter transition slides in from two sides, exit transition slide out to START(left). Background will be faded in. Note: Changing exit transition by UI style is not working because fragment transition asks for exit transition before UI style is restored in Fragment .onCreate().
When popping multiple GuidedStepSupportFragment, finishGuidedStepSupportFragments() also changes the top GuidedStepSupportFragment to UI_STYLE_ENTRANCE in order to run the return transition (reverse of enter transition) of UI_STYLE_ENTRANCE.

Constant Value: 1 (0x00000001)

UI_STYLE_REPLACE

added in version 24.1.0
int UI_STYLE_REPLACE

This is the case that we use GuidedStepSupportFragment to replace another existing GuidedStepSupportFragment when moving forward to next step. Default behavior of this style is:

  • Enter transition slides in from END(right), exit transition same as UI_STYLE_ENTRANCE.

Constant Value: 0 (0x00000000)

Public constructors

GuidedStepSupportFragment

added in version 24.1.0
GuidedStepSupportFragment ()

Public methods

add

added in version 24.1.0
int add (FragmentManager fragmentManager, 
                GuidedStepSupportFragment fragment, 
                int id)

Adds the specified GuidedStepSupportFragment to the fragment stack, replacing any existing GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom transitions. A backstack entry is added, so the fragment will be dismissed when BACK key is pressed.

  • If current fragment on stack is GuidedStepSupportFragment: assign UI_STYLE_REPLACE and onAddSharedElementTransition(FragmentTransaction, GuidedStepSupportFragment) will be called to perform shared element transition between GuidedStepSupportFragments.
  • If current fragment on stack is not GuidedStepSupportFragment: assign UI_STYLE_ENTRANCE

    Note: currently fragments added using this method must be created programmatically rather than via XML.

    Parameters
    fragmentManager FragmentManager: The FragmentManager to be used in the transaction.

    fragment GuidedStepSupportFragment: The GuidedStepSupportFragment to be inserted into the fragment stack.

    id int: The id of container to add GuidedStepSupportFragment, can be android.R.id.content.

    Returns
    int The ID returned by the call FragmentTransaction.commit.

  • add

    added in version 24.1.0
    int add (FragmentManager fragmentManager, 
                    GuidedStepSupportFragment fragment)

    Adds the specified GuidedStepSupportFragment to the fragment stack, replacing any existing GuidedStepSupportFragments in the stack, and configuring the fragment-to-fragment custom transitions. A backstack entry is added, so the fragment will be dismissed when BACK key is pressed.

  • If current fragment on stack is GuidedStepSupportFragment: assign UI_STYLE_REPLACE
  • If current fragment on stack is not GuidedStepSupportFragment: assign UI_STYLE_ENTRANCE

    Note: currently fragments added using this method must be created programmatically rather than via XML.

    Parameters
    fragmentManager FragmentManager: The FragmentManager to be used in the transaction.

    fragment GuidedStepSupportFragment: The GuidedStepSupportFragment to be inserted into the fragment stack.

    Returns
    int The ID returned by the call FragmentTransaction.commit.

  • addAsRoot

    added in version 24.1.0
    int addAsRoot (FragmentActivity activity, 
                    GuidedStepSupportFragment fragment, 
                    int id)

    Adds the specified GuidedStepSupportFragment as content of Activity; no backstack entry is added so the activity will be dismissed when BACK key is pressed. The method is typically called in Activity.onCreate() when savedInstanceState is null. When savedInstanceState is not null, the Activity is being restored, do not call addAsRoot() to duplicate the Fragment restored by FragmentManager. UI_STYLE_ACTIVITY_ROOT is assigned. Note: currently fragments added using this method must be created programmatically rather than via XML.

    Parameters
    activity FragmentActivity: The Activity to be used to insert GuidedstepFragment.

    fragment GuidedStepSupportFragment: The GuidedStepSupportFragment to be inserted into the fragment stack.

    id int: The id of container to add GuidedStepSupportFragment, can be android.R.id.content.

    Returns
    int The ID returned by the call FragmentTransaction.commit, or -1 there is already GuidedStepSupportFragment.

    collapseAction

    added in version 25.1.0
    void collapseAction (boolean withTransition)

    Collapse action which either has a sub actions list or action with hasEditableActivatorView() is true.

    Parameters
    withTransition boolean: True to run transition animation, false otherwise.

    collapseSubActions

    added in version 24.1.0
    void collapseSubActions ()

    Collapse sub actions list.

    See also:

    expandAction

    added in version 25.1.0
    void expandAction (GuidedAction action, 
                    boolean withTransition)

    Expand a given action with sub actions list or hasEditableActivatorView() is true. The method must be called after onCreateView(LayoutInflater, ViewGroup, Bundle) creates fragment view.

    Parameters
    action GuidedAction: GuidedAction to expand.

    withTransition boolean: True to run transition animation, false otherwise.

    expandSubActions

    added in version 24.1.0
    void expandSubActions (GuidedAction action)

    Expand a given action's sub actions list.

    Parameters
    action GuidedAction: GuidedAction to expand.

    findActionById

    added in version 24.1.0
    GuidedAction findActionById (long id)

    Find GuidedAction by Id.

    Parameters
    id long: Id of the action to search.

    Returns
    GuidedAction GuidedAction object or null if not found.

    findActionPositionById

    added in version 24.1.0
    int findActionPositionById (long id)

    Find GuidedAction position in array by Id.

    Parameters
    id long: Id of the action to search.

    Returns
    int position of GuidedAction object in array or -1 if not found.

    findButtonActionById

    added in version 24.1.0
    GuidedAction findButtonActionById (long id)

    Find button GuidedAction by Id.

    Parameters
    id long: Id of the button action to search.

    Returns
    GuidedAction GuidedAction object or null if not found.

    findButtonActionPositionById

    added in version 24.1.0
    int findButtonActionPositionById (long id)

    Find button GuidedAction position in array by Id.

    Parameters
    id long: Id of the button action to search.

    Returns
    int position of GuidedAction object in array or -1 if not found.

    finishGuidedStepSupportFragments

    added in version 24.1.0
    void finishGuidedStepSupportFragments ()

    Convenient method to close GuidedStepSupportFragments on top of other content or finish Activity if GuidedStepSupportFragments were started in a separate activity. Pops all stack entries including UI_STYLE_ENTRANCE; if UI_STYLE_ENTRANCE is not found, finish the activity. Note that this method must be paired with add(FragmentManager, GuidedStepSupportFragment, int) which sets up the stack entry name for finding which fragment we need to pop back to.

    getActionItemView

    added in version 24.1.0
    View getActionItemView (int position)

    Returns the view corresponding to the action at the indicated position in the list of actions for this fragment.

    Parameters
    position int: The integer position of the action of interest.

    Returns
    View The View corresponding to the action at the indicated position, or null if that action is not currently onscreen.

    getActions

    added in version 24.1.0
    List<GuidedAction> getActions ()

    Returns the list of GuidedActions that the user may take in this fragment.

    Returns
    List<GuidedAction> The list of GuidedActions for this fragment.

    getButtonActionItemView

    added in version 24.1.0
    View getButtonActionItemView (int position)

    Returns the view corresponding to the button action at the indicated position in the list of actions for this fragment.

    Parameters
    position int: The integer position of the button action of interest.

    Returns
    View The View corresponding to the button action at the indicated position, or null if that action is not currently onscreen.

    getButtonActions

    added in version 24.1.0
    List<GuidedAction> getButtonActions ()

    Returns the list of button GuidedActions that the user may take in this fragment.

    Returns
    List<GuidedAction> The list of button GuidedActions for this fragment.

    getCurrentGuidedStepSupportFragment

    added in version 24.1.0
    GuidedStepSupportFragment getCurrentGuidedStepSupportFragment (FragmentManager fm)

    Returns the current GuidedStepSupportFragment on the fragment transaction stack.

    Parameters
    fm FragmentManager

    Returns
    GuidedStepSupportFragment The current GuidedStepSupportFragment, if any, on the fragment transaction stack.

    getGuidanceStylist

    added in version 24.1.0
    GuidanceStylist getGuidanceStylist ()

    Returns the GuidanceStylist that displays guidance information for the user.

    Returns
    GuidanceStylist The GuidanceStylist for this fragment.