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:

If app chooses not to use the helper function, it is the app's responsibility to call
setUiStyle(int) to select fragment transition and remember the stack entry where it
need pops to.

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.

LeanbackGuidedStepTheme_guidedActionsBackgroundDark

LeanbackGuidedStepTheme_guidedActionsElevation

LeanbackGuidedStepTheme_guidedStepBackground

LeanbackGuidedStepTheme_guidedStepTheme

Constants

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:

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().

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.

GuidedStepSupportFragment

Public methods

add

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.

add

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

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.

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.

getUiStyle

Read UI style from fragment arguments. Default value is UI_STYLE_ENTRANCE when
fragment is first initialized. UI style is used to choose different fragment transition
animations and determine if this is the first GuidedStepSupportFragment on backstack.

isFocusOutEndAllowed

Returns true if allows focus out of end edge of GuidedStepSupportFragment, false otherwise.
Default value is false, the reason is to disable FocusFinder to find focusable views
beneath content of GuidedStepSupportFragment. Subclass may override.

Returns

boolean

True if allows focus out of end edge of GuidedStepSupportFragment.

isFocusOutStartAllowed

Returns true if allows focus out of start edge of GuidedStepSupportFragment, false otherwise.
Default value is false, the reason is to disable FocusFinder to find focusable views
beneath content of GuidedStepSupportFragment. Subclass may override.

Note that this can be called while the fragment's activity is
still in the process of being created. As such, you can not rely
on things like the activity's content view hierarchy being initialized
at this point. If you want to do work once the activity itself is
created, see onActivityCreated(Bundle).

Any restored child fragments will be created before the base
Fragment.onCreate method returns.

Parameters

savedInstanceState

Bundle: If the fragment is being re-created from
a previous saved state, this is the state.

onCreateView

Called to have the fragment instantiate its user interface view.
This is optional, and non-graphical fragments can return null (which
is the default implementation). This will be called between
onCreate(Bundle) and onActivityCreated(Bundle).

If you return a View from here, you will later be called in
onDestroyView() when the view is being released.

Parameters

inflater

LayoutInflater: The LayoutInflater object that can be used to inflate
any views in the fragment,

container

ViewGroup: If non-null, this is the parent view that the fragment's
UI should be attached to. The fragment should not add the view itself,
but this can be used to generate the LayoutParams of the view.

savedInstanceState

Bundle: If non-null, this fragment is being re-constructed
from a previous saved state as given here.

This corresponds to Activity.onSaveInstanceState(Bundle) and most of the discussion there
applies here as well. Note however: this method may be called
at any time before onDestroy(). There are many situations
where a fragment may be mostly torn down (such as when placed on the
back stack with no UI showing), but its state will not be saved until
its owning activity actually needs to save its state.

setUiStyle

Set UI style to fragment arguments. Default value is UI_STYLE_ENTRANCE when fragment
is first initialized. UI style is used to choose different fragment transition animations and
determine if this is the first GuidedStepSupportFragment on backstack. In most cases app does not
directly call this method, app calls helper function
add(FragmentManager, GuidedStepSupportFragment, int). However if the app creates Fragment
transaction and controls backstack by itself, it would need call setUiStyle() to select the
fragment transition to use.

Protected methods

onAddSharedElementTransition

Called when this fragment is added to FragmentTransaction with UI_STYLE_REPLACE (aka
when the GuidedStepSupportFragment replacing an existing GuidedStepSupportFragment). Default implementation
establishes connections between action background views to morph action background bounds
change from disappearing GuidedStepSupportFragment into this GuidedStepSupportFragment. The default
implementation heavily relies on GuidedActionsStylist's layout, app may override this
method when modifying the default layout of GuidedActionsStylist.

TIP: because the fragment view is removed during fragment transition, in general app cannot
use two Visibility transition together. Workaround is to create your own Visibility
transition that controls multiple animators (e.g. slide and fade animation in one Transition
class).