GuidedStepSupportFragment


public class GuidedStepSupportFragment extends Fragment


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:

  • addAsRoot, to be called during Activity onCreate, adds GuidedStepSupportFragment as the first Fragment in activity.
  • add or add, to add GuidedStepSupportFragment on top of existing Fragments or replacing existing GuidedStepSupportFragment when moving forward to next step.
  • finishGuidedStepSupportFragments can either finish the activity or pop all GuidedStepSupportFragment from stack.
  • If app chooses not to use the helper function, it is the app's responsibility to call setUiStyle 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 is responsible for the left guidance view, while the 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 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.guidedStepThemeguidedStepBackgroundguidedActionContentWidthWeightguidedActionContentWidthWeightTwoPanelsguidedActionsBackgroundguidedActionsBackgroundDarkguidedActionsElevation

Summary

Constants

static final String
EXTRA_UI_STYLE = "uiStyle"

Fragment argument name for UI style.

static final int

One possible value of argument EXTRA_UI_STYLE.

static final int

This field is deprecated.

Same value as UI_STYLE_REPLACE.

static final int

Default value for argument EXTRA_UI_STYLE.

static final int

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

Public constructors

Public methods

static int
add(
    @NonNull FragmentManager fragmentManager,
    @NonNull 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
add(
    @NonNull FragmentManager fragmentManager,
    @NonNull 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
addAsRoot(
    @NonNull FragmentActivity activity,
    @NonNull 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

Collapse sub actions list.

void
expandAction(@NonNull GuidedAction action, boolean withTransition)

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

void

Expand a given action's sub actions list.

@Nullable GuidedAction
findActionById(long id)

Find GuidedAction by Id.

int

Find GuidedAction position in array by Id.

@Nullable GuidedAction

Find button GuidedAction by Id.

int

Find button GuidedAction position in array by Id.

void

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

@Nullable View
getActionItemView(int position)

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

@NonNull List<GuidedAction>

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

@Nullable View

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

@NonNull List<GuidedAction>

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

static @Nullable GuidedStepSupportFragment

Returns the current GuidedStepSupportFragment on the fragment transaction stack.

@NonNull GuidanceStylist

Returns the GuidanceStylist that displays guidance information for the user.

@NonNull GuidedActionsStylist

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

@NonNull GuidedActionsStylist

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

int

Returns the position if the currently selected GuidedAction.

int

Returns the position if the currently selected button GuidedAction.

int

Read UI style from fragment arguments.

boolean
boolean

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

boolean

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

boolean
void
notifyActionChanged(int position)

Notify an action has changed and update its UI.

void

Notify an button action has changed and update its UI.

void
onCreate(@Nullable Bundle savedInstanceState)

Called to do initial creation of a fragment.

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

Fills out the set of actions available to the user.

@NonNull GuidedActionsStylist

Creates the presenter used to style the guided actions panel.

@Nullable View
onCreateBackgroundView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

Called by onCreateView to inflate background view.

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

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

@NonNull GuidedActionsStylist

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

@NonNull GuidanceStylist.Guidance
onCreateGuidance(@Nullable Bundle savedInstanceState)

Returns the information required to provide guidance to the user.

@NonNull GuidanceStylist

Creates the presenter used to style the guidance panel.

@Nullable View
onCreateView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

Called to have the fragment instantiate its user interface view.

void

Called when the view previously created by #onCreateView has been detached from the fragment.

void

Callback invoked when an action is taken by the user.

void

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

void

This method is deprecated.

Override onGuidedActionEditedAndProceed and/or onGuidedActionEditCanceled.

long

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

void

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

int

Returns the theme used for styling the fragment.

void

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

void

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

boolean

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

void

Opens the provided action in edit mode and raises ime.

void
popBackStackToGuidedStepSupportFragment(
    @NonNull Class<Object> guidedStepFragmentClass,
    int flags
)

Convenient method to pop to fragment with Given class.

void

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

void

Sets the RecyclerView DiffCallback used when setActions is called.

void

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

void

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

void

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

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

void

Called by Constructor to provide fragment transitions.

Inherited methods

From androidx.activity.result.ActivityResultCaller
abstract ActivityResultLauncher<I>
<I, O> registerForActivityResult(
    ActivityResultContract<I, O> contract,
    ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

From android.content.ComponentCallbacks
abstract void
abstract void
From androidx.fragment.app.Fragment
void
dump(
    @NonNull String prefix,
    @Nullable FileDescriptor fd,
    @NonNull PrintWriter writer,
    @Nullable String[] args
)

Print the Fragments's state into the given stream.

final boolean

Subclasses can not override equals().

final @Nullable FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

boolean

Returns whether the the exit transition and enter transition overlap or not.

boolean

Returns whether the the return transition and reenter transition overlap or not.

final @Nullable Bundle

Return the arguments supplied when the fragment was instantiated, if any.

final @NonNull FragmentManager

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

@Nullable Context

Return the Context this fragment is currently associated with.

@NonNull CreationExtras

The Fragment's arguments when this is first called will be used as the defaults to any androidx.lifecycle.SavedStateHandle passed to a view model created using this extra.

@NonNull ViewModelProvider.Factory
@Nullable Object

Returns the Transition that will be used to move Views into the initial scene.

@Nullable Object

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

final @Nullable FragmentManager

This method is deprecated.

This has been removed in favor of getParentFragmentManager() which throws an IllegalStateException if the FragmentManager is null.

final @Nullable Object

Return the host object of this fragment.

final int

Return the identifier this fragment is known by.

final @NonNull LayoutInflater

Returns the cached LayoutInflater used to inflate Views of this Fragment.

@NonNull Lifecycle

Overriding this method is no longer supported and this method will be made final in a future version of Fragment.

@NonNull LoaderManager

This method is deprecated.

Use LoaderManager.getInstance(this).

final @Nullable Fragment

Returns the parent Fragment containing this Fragment.

final @NonNull FragmentManager

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

@Nullable Object

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

final @NonNull Resources

Return requireActivity().getResources().

final boolean

This method is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

@Nullable Object

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

final @NonNull SavedStateRegistry
@Nullable Object

Returns the Transition that will be used for shared elements transferred into the content Scene.

@Nullable Object

Return the Transition that will be used for shared elements transferred back during a pop of the back stack.

final @NonNull String
getString(@StringRes int resId)

Return a localized string from the application's package's default string table.

final @NonNull String
getString(@StringRes int resId, @Nullable Object[] formatArgs)

Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in java.util.Formatter and format.

final @Nullable String

Get the tag name of the fragment, if specified.

final @Nullable Fragment

This method is deprecated.

Instead of using a target fragment to pass results, use setFragmentResult to deliver results to FragmentResultListener instances registered by other fragments via setFragmentResultListener.

final int

This method is deprecated.

When using the target fragment replacement of setFragmentResultListener and setFragmentResult, consider using setArguments to pass a requestKey if you need to support dynamic request keys.

final @NonNull CharSequence
getText(@StringRes int resId)

Return a localized, styled CharSequence from the application's package's default string table.

boolean

This method is deprecated.

Use setMaxLifecycle instead.

@Nullable View

Get the root view for the fragment's layout (the one returned by onCreateView), if provided.

@NonNull LifecycleOwner

Get a LifecycleOwner that represents the Fragment's View lifecycle.

@NonNull LiveData<LifecycleOwner>

Retrieve a LiveData which allows you to observe the lifecycle of the Fragment's View.

@NonNull ViewModelStore

Returns the ViewModelStore associated with this Fragment

final int

Subclasses can not override hashCode().

static @NonNull Fragment

This method is deprecated.

Use getFragmentFactory and instantiate

static @NonNull Fragment
instantiate(
    @NonNull Context context,
    @NonNull String fname,
    @Nullable Bundle args
)

This method is deprecated.

Use getFragmentFactory and instantiate, manually calling setArguments on the returned Fragment.

final boolean

Return true if the fragment is currently added to its activity.

final boolean

Return true if the fragment has been explicitly detached from the UI.

final boolean

Return true if the fragment has been hidden.

final boolean

Return true if the layout is included as part of an activity view hierarchy via the tag.

final boolean

Return true if this fragment is currently being removed from its activity.

final boolean

Return true if the fragment is in the resumed state.

final boolean

Returns true if this fragment is added and its state has already been saved by its host.

final boolean

Return true if the fragment is currently visible to the user.

void

This method is deprecated.

use onViewCreated for code touching the view created by onCreateView and onCreate for other initialization.

void
onActivityResult(int requestCode, int resultCode, @Nullable Intent data)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

This method is deprecated.

See onAttach.

void

Called when a fragment is first attached to its context.

void

This method is deprecated.

The responsibility for listening for fragments being attached has been moved to FragmentManager.

void
boolean

This hook is called whenever an item in a context menu is selected.

@Nullable Animation
@MainThread
onCreateAnimation(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animation.

@Nullable Animator
@MainThread
onCreateAnimator(int transit, boolean enter, int nextAnim)

Called when a fragment loads an animator.

void

Called when a context menu for the view is about to be shown.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the fragment is no longer in use.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the fragment is no longer attached to its activity.

@NonNull LayoutInflater
onGetLayoutInflater(@Nullable Bundle savedInstanceState)

Returns the LayoutInflater used to inflate Views of this Fragment.

void
@MainThread
onHiddenChanged(boolean hidden)

Called when the hidden state (as returned by isHidden of the fragment or another fragment in its hierarchy has changed.

void
@UiThread
@CallSuper
onInflate(
    @NonNull Activity activity,
    @NonNull AttributeSet attrs,
    @Nullable Bundle savedInstanceState
)

This method is deprecated.

See onInflate.

void
@UiThread
@CallSuper
onInflate(
    @NonNull Context context,
    @NonNull AttributeSet attrs,
    @Nullable Bundle savedInstanceState
)

Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity.

void
void
onMultiWindowModeChanged(boolean isInMultiWindowMode)

Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa.

boolean

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void

Called when the Fragment is no longer resumed.

void
onPictureInPictureModeChanged(boolean isInPictureInPictureMode)

Called by the system when the activity changes to and from picture-in-picture mode.

void

This method is deprecated.

androidx.activity.ComponentActivity now implements MenuHost, an interface that allows any component, including your activity itself, to add menu items by calling addMenuProvider without forcing all components through this single method override.

void
@MainThread
onPrimaryNavigationFragmentChanged(
    boolean isPrimaryNavigationFragment
)

Callback for when the primary navigation state of this Fragment has changed.

void
onRequestPermissionsResult(
    int requestCode,
    @NonNull String[] permissions,
    @NonNull int[] grantResults
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

Called when the Fragment is visible to the user.

void

Called when the Fragment is no longer started.

void
@MainThread
onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

Called immediately after onCreateView has returned, but before any saved state has been restored in to the view.

void

Called when all saved state has been restored into the view hierarchy of the fragment.

void

Postpone the entering Fragment transition until startPostponedEnterTransition or executePendingTransactions has been called.

final void
postponeEnterTransition(long duration, @NonNull TimeUnit timeUnit)

Postpone the entering Fragment transition for a given amount of time and then call startPostponedEnterTransition.

final @NonNull ActivityResultLauncher<I>
@MainThread
<I, O> registerForActivityResult(
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

final @NonNull ActivityResultLauncher<I>
@MainThread
<I, O> registerForActivityResult(
    @NonNull ActivityResultContract<I, O> contract,
    @NonNull ActivityResultRegistry registry,
    @NonNull ActivityResultCallback<O> callback
)

Register a request to start an activity for result, designated by the given contract.

void

Registers a context menu to be shown for the given view (multiple views can show the context menu).

final void
requestPermissions(@NonNull String[] permissions, int requestCode)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

final @NonNull FragmentActivity

Return the FragmentActivity this fragment is currently associated with.

final @NonNull Bundle

Return the arguments supplied when the fragment was instantiated.

final @NonNull Context

Return the Context this fragment is currently associated with.

final @NonNull FragmentManager

This method is deprecated.

This has been renamed to getParentFragmentManager() to make it clear that you are accessing the FragmentManager that contains this Fragment and not the FragmentManager associated with child Fragments.

final @NonNull Object

Return the host object of this fragment.

final @NonNull Fragment

Returns the parent Fragment containing this Fragment.

final @NonNull View

Get the root view for the fragment's layout (the one returned by onCreateView).

void

Sets whether the the exit transition and enter transition overlap or not.

void

Sets whether the the return transition and reenter transition overlap or not.

void

Supply the construction arguments for this fragment.

void

When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.

void

Sets the Transition that will be used to move Views into the initial scene.

void

When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.

void

Sets the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

This method is no longer needed when using a MenuProvider to provide a Menu to your activity, which replaces onCreateOptionsMenu as the recommended way to provide a consistent, optionally Lifecycle-aware, and modular way to handle menu creation and item selection.

void

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState.

void
setMenuVisibility(boolean menuVisible)

Set a hint for whether this fragment's menu should be visible.

void

Sets the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

void
setRetainInstance(boolean retain)

This method is deprecated.

Instead of retaining the Fragment itself, use a non-retained Fragment and keep retained state in a ViewModel attached to that Fragment.

void

Sets the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

void

Sets the Transition that will be used for shared elements transferred into the content Scene.

void

Sets the Transition that will be used for shared elements transferred back during a pop of the back stack.

void
setTargetFragment(@Nullable Fragment fragment, int requestCode)

This method is deprecated.

Instead of using a target fragment to pass results, the fragment requesting a result should use setFragmentResultListener to register a FragmentResultListener with a requestKey using its parent fragment manager.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

If you are manually calling this method, use setMaxLifecycle instead.

boolean

Gets whether you should show UI with rationale before requesting a permission.

void

Call startActivity from the fragment's containing Activity.

void

Call startActivity from the fragment's containing Activity.

void
startActivityForResult(@NonNull Intent intent, int requestCode)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void
startActivityForResult(
    @NonNull Intent intent,
    int requestCode,
    @Nullable Bundle options
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void
startIntentSenderForResult(
    @NonNull IntentSender intent,
    int requestCode,
    @Nullable Intent fillInIntent,
    int flagsMask,
    int flagsValues,
    int extraFlags,
    @Nullable Bundle options
)

This method is deprecated.

This method has been deprecated in favor of using the Activity Result API which brings increased type safety via an ActivityResultContract and the prebuilt contracts for common intents available in androidx.activity.result.contract.ActivityResultContracts, provides hooks for testing, and allow receiving results in separate, testable classes independent from your fragment.

void

Begin postponed transitions after postponeEnterTransition was called.

@NonNull String
void

Prevents a context menu to be shown for the given view.

From androidx.lifecycle.HasDefaultViewModelProviderFactory
From androidx.lifecycle.LifecycleOwner
abstract Lifecycle
From androidx.savedstate.SavedStateRegistryOwner
From android.view.View.OnCreateContextMenuListener
abstract void
From androidx.lifecycle.ViewModelStoreOwner

Constants

EXTRA_UI_STYLE

Added in 1.1.0
public static final String EXTRA_UI_STYLE = "uiStyle"

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:

UI_STYLE_ACTIVITY_ROOT

Added in 1.1.0
public static final int UI_STYLE_ACTIVITY_ROOT = 2

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_DEFAULT

Added in 1.1.0
Deprecated in 1.1.0
public static final int UI_STYLE_DEFAULT = 0

UI_STYLE_ENTRANCE

Added in 1.1.0
public static final int UI_STYLE_ENTRANCE = 1

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.

UI_STYLE_REPLACE

Added in 1.1.0
public static final int UI_STYLE_REPLACE = 0

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.

Public constructors

GuidedStepSupportFragment

Added in 1.1.0
public GuidedStepSupportFragment()

Public methods

add

Added in 1.1.0
public static int add(
    @NonNull FragmentManager fragmentManager,
    @NonNull 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
@NonNull FragmentManager fragmentManager

The FragmentManager to be used in the transaction.

@NonNull GuidedStepSupportFragment fragment

The GuidedStepSupportFragment to be inserted into the fragment stack.

Returns
int

The ID returned by the call FragmentTransaction.commit.

add

Added in 1.1.0
public static int add(
    @NonNull FragmentManager fragmentManager,
    @NonNull 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.

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

Parameters
@NonNull FragmentManager fragmentManager

The FragmentManager to be used in the transaction.

@NonNull GuidedStepSupportFragment fragment

The GuidedStepSupportFragment to be inserted into the fragment stack.

int id

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

Returns
int

The ID returned by the call FragmentTransaction.commit.

addAsRoot

Added in 1.1.0
public static int addAsRoot(
    @NonNull FragmentActivity activity,
    @NonNull 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
@NonNull FragmentActivity activity

The Activity to be used to insert GuidedstepFragment.

@NonNull GuidedStepSupportFragment fragment

The GuidedStepSupportFragment to be inserted into the fragment stack.

int id

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 1.1.0
public void collapseAction(boolean withTransition)

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

Parameters
boolean withTransition

True to run transition animation, false otherwise.

collapseSubActions

Added in 1.1.0
public void collapseSubActions()

Collapse sub actions list.

See also
getSubActions

expandAction

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

Expand a given action with sub actions list or hasEditableActivatorView is true. The method must be called after onCreateView creates fragment view.

Parameters
@NonNull GuidedAction action

GuidedAction to expand.

boolean withTransition

True to run transition animation, false otherwise.

expandSubActions

Added in 1.1.0
public void expandSubActions(@NonNull GuidedAction action)

Expand a given action's sub actions list.

Parameters
@NonNull GuidedAction action

GuidedAction to expand.

See also
expandAction

findActionById

Added in 1.1.0
public @Nullable GuidedAction findActionById(long id)

Find GuidedAction by Id.

Parameters
long id

Id of the action to search.

Returns
@Nullable GuidedAction

GuidedAction object or null if not found.

findActionPositionById

Added in 1.1.0
public int findActionPositionById(long id)

Find GuidedAction position in array by Id.

Parameters
long id

Id of the action to search.

Returns
int

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

findButtonActionById

Added in 1.1.0
public @Nullable GuidedAction findButtonActionById(long id)

Find button GuidedAction by Id.

Parameters
long id

Id of the button action to search.

Returns
@Nullable GuidedAction

GuidedAction object or null if not found.

findButtonActionPositionById

Added in 1.1.0
public int findButtonActionPositionById(long id)

Find button GuidedAction position in array by Id.

Parameters
long id

Id of the button action to search.

Returns
int

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

finishGuidedStepSupportFragments

Added in 1.1.0
public 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 which sets up the stack entry name for finding which fragment we need to pop back to.

getActionItemView

Added in 1.1.0
public @Nullable View getActionItemView(int position)

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

Parameters
int position

The integer position of the action of interest.

Returns
@Nullable View

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

getActions

Added in 1.1.0
public @NonNull List<GuidedActiongetActions()

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

Returns
@NonNull List<GuidedAction>

The list of GuidedActions for this fragment.

getButtonActionItemView

Added in 1.1.0
public @Nullable 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
int position

The integer position of the button action of interest.

Returns
@Nullable View

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

getButtonActions

Added in 1.1.0
public @NonNull List<GuidedActiongetButtonActions()

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

Returns
@NonNull List<GuidedAction>

The list of button GuidedActions for this fragment.

getCurrentGuidedStepSupportFragment

Added in 1.1.0
public static @Nullable GuidedStepSupportFragment getCurrentGuidedStepSupportFragment(@NonNull FragmentManager fm)

Returns the current GuidedStepSupportFragment on the fragment transaction stack.

Returns
@Nullable GuidedStepSupportFragment

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

getGuidanceStylist

Added in 1.1.0
public @NonNull GuidanceStylist getGuidanceStylist()

Returns the GuidanceStylist that displays guidance information for the user.

Returns
@NonNull GuidanceStylist

The GuidanceStylist for this fragment.

getGuidedActionsStylist

Added in 1.1.0
public @NonNull GuidedActionsStylist getGuidedActionsStylist()

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

Returns
@NonNull GuidedActionsStylist

The GuidedActionsStylist for this fragment.

getGuidedButtonActionsStylist

Added in 1.1.0
public @NonNull GuidedActionsStylist getGuidedButtonActionsStylist()

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

Returns
@NonNull GuidedActionsStylist

The GuidedActionsStylist for this fragment.

getSelectedActionPosition

Added in 1.1.0
public int getSelectedActionPosition()

Returns the position if the currently selected GuidedAction.

Returns
int

position The integer position of the currently selected action.

getSelectedButtonActionPosition

Added in 1.1.0
public int getSelectedButtonActionPosition()

Returns the position if the currently selected button GuidedAction.

Returns
int

position The integer position of the currently selected button action.

getUiStyle

Added in 1.1.0
public int 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.

isExpanded

Added in 1.1.0
public boolean isExpanded()
Returns
boolean

True if is current expanded including subactions list or action with hasEditableActivatorView is true.

isFocusOutEndAllowed

Added in 1.1.0
public boolean 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

Added in 1.1.0
public boolean 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.

Returns
boolean

True if allows focus out of start edge of GuidedStepSupportFragment.

isSubActionsExpanded

Added in 1.1.0
public boolean isSubActionsExpanded()
Returns
boolean

True if the sub actions list is expanded, false otherwise.

notifyActionChanged

Added in 1.1.0
public void notifyActionChanged(int position)

Notify an action has changed and update its UI.

Parameters
int position

Position of the GuidedAction in array.

notifyButtonActionChanged

Added in 1.1.0
public void notifyButtonActionChanged(int position)

Notify an button action has changed and update its UI.

Parameters
int position

Position of the button GuidedAction in array.

onCreate

public void onCreate(@Nullable Bundle savedInstanceState)

Called to do initial creation of a fragment. This is called after #onAttach(Activity) and before #onCreateView(LayoutInflater, ViewGroup, Bundle).

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, add a on the activity's Lifecycle, removing it when it receives the Lifecycle.State#CREATED callback.

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

onCreateActions

Added in 1.1.0
public void onCreateActions(
    @NonNull List<GuidedAction> actions,
    @Nullable Bundle savedInstanceState
)

Fills out the set of actions available to the user. This hook is called during onCreate. The default leaves the list of actions empty; subclasses should override.

Parameters
@NonNull List<GuidedAction> actions

A non-null, empty list ready to be populated.

@Nullable Bundle savedInstanceState

The saved instance state from onCreate.

onCreateActionsStylist

Added in 1.1.0
public @NonNull GuidedActionsStylist onCreateActionsStylist()

Creates the presenter used to style the guided actions panel. The default implementation returns a basic GuidedActionsStylist.

Returns
@NonNull GuidedActionsStylist

The GuidedActionsStylist used in this fragment.

onCreateBackgroundView

Added in 1.1.0
public @Nullable View onCreateBackgroundView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

Called by onCreateView to inflate background view. Default implementation loads view from lb_guidedstep_background which holds a reference to guidedStepBackground.

Parameters
@NonNull LayoutInflater inflater

LayoutInflater to load background view.

@Nullable ViewGroup container

Parent view of background view.

@Nullable Bundle savedInstanceState
Returns
@Nullable View

Created background view or null if no background.

onCreateButtonActions

Added in 1.1.0
public void onCreateButtonActions(
    @NonNull List<GuidedAction> actions,
    @Nullable Bundle savedInstanceState
)

Fills out the set of actions shown at right available to the user. This hook is called during onCreate. The default leaves the list of actions empty; subclasses may override.

Parameters
@NonNull List<GuidedAction> actions

A non-null, empty list ready to be populated.

@Nullable Bundle savedInstanceState

The saved instance state from onCreate.

onCreateButtonActionsStylist

Added in 1.1.0
public @NonNull GuidedActionsStylist onCreateButtonActionsStylist()

Creates the presenter used to style a sided actions panel for button only. The default implementation returns a basic GuidedActionsStylist.

Returns
@NonNull GuidedActionsStylist

The GuidedActionsStylist used in this fragment.

onCreateGuidance

Added in 1.1.0
public @NonNull GuidanceStylist.Guidance onCreateGuidance(@Nullable Bundle savedInstanceState)

Returns the information required to provide guidance to the user. This hook is called during onCreateView. May be overridden to return a custom subclass of for use in a subclass of GuidanceStylist. The default returns a Guidance object with empty fields; subclasses should override.

Parameters
@Nullable Bundle savedInstanceState

The saved instance state from onCreateView.

Returns
@NonNull GuidanceStylist.Guidance

The Guidance object representing the information used to guide the user.

onCreateGuidanceStylist

Added in 1.1.0
public @NonNull GuidanceStylist onCreateGuidanceStylist()

Creates the presenter used to style the guidance panel. The default implementation returns a basic GuidanceStylist.

Returns
@NonNull GuidanceStylist

The GuidanceStylist used in this fragment.

onCreateView

public @Nullable View onCreateView(
    @NonNull LayoutInflater inflater,
    @Nullable ViewGroup container,
    @Nullable Bundle savedInstanceState
)

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

A default View can be returned by calling #Fragment(int) in your constructor. Otherwise, this method returns null.

It is recommended to only inflate the layout in this method and move logic that operates on the returned View to #onViewCreated(View, Bundle).

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

onDestroyView

public void onDestroyView()

Called when the view previously created by #onCreateView has been detached from the fragment. The next time the fragment needs to be displayed, a new view will be created. This is called after #onStop() and before #onDestroy(). It is called regardless of whether #onCreateView returned a non-null view. Internally it is called after the view's state has been saved but before it has been removed from its parent.

onGuidedActionClicked

Added in 1.1.0
public void onGuidedActionClicked(@NonNull GuidedAction action)

Callback invoked when an action is taken by the user. Subclasses should override in order to act on the user's decisions.

Parameters
@NonNull GuidedAction action

The chosen action.

onGuidedActionEditCanceled

Added in 1.1.0
public void onGuidedActionEditCanceled(@NonNull GuidedAction action)

Callback invoked when an action has been canceled editing, for example when user closes IME window by BACK key. Default implementation calls deprecated method onGuidedActionEdited.

Parameters
@NonNull GuidedAction action

The action which has been canceled editing.

onGuidedActionEdited

Added in 1.1.0
Deprecated in 1.1.0
public void onGuidedActionEdited(GuidedAction action)

Callback invoked when an action's title or description has been edited, this happens either when user clicks confirm button in IME or user closes IME window by BACK key.

onGuidedActionEditedAndProceed

Added in 1.1.0
public long onGuidedActionEditedAndProceed(@NonNull GuidedAction action)

Callback invoked when an action has been edited, for example when user clicks confirm button in IME window. Default implementation calls deprecated method onGuidedActionEdited and returns ACTION_ID_NEXT.

Parameters
@NonNull GuidedAction action

The action that has been edited.

Returns
long

ID of the action will be focused or ACTION_ID_NEXT, ACTION_ID_CURRENT.

onGuidedActionFocused

Added in 1.1.0
public void onGuidedActionFocused(@NonNull GuidedAction action)

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

onProvideTheme

Added in 1.1.0
public int onProvideTheme()

Returns the theme used for styling the fragment. The default returns -1, indicating that the host Activity's theme should be used.

Returns
int

The theme resource ID of the theme to use in this fragment, or -1 to use the host Activity's theme.

onResume

public void onResume()

Called when the fragment is visible to the user and actively running. This is generally tied to Activity.onResume of the containing Activity's lifecycle.

onSaveInstanceState

public void onSaveInstanceState(@NonNull Bundle outState)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance if its process is restarted. If a new instance of the fragment later needs to be created, the data you place in the Bundle here will be available in the Bundle given to #onCreate(Bundle), #onCreateView(LayoutInflater, ViewGroup, Bundle), and #onViewCreated(View, Bundle).

This corresponds to Activity#onSaveInstanceState(Bundle) 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.

onSubGuidedActionClicked

Added in 1.1.0
public boolean onSubGuidedActionClicked(@NonNull GuidedAction action)

Callback invoked when an action in sub actions is taken by the user. Subclasses should override in order to act on the user's decisions. Default return value is true to close the sub actions list.

Parameters
@NonNull GuidedAction action

The chosen action.

Returns
boolean

true to collapse the sub actions list, false to keep it expanded.

openInEditMode

Added in 1.1.0
public void openInEditMode(@Nullable GuidedAction action)

Opens the provided action in edit mode and raises ime. This can be used to programmatically skip the extra click required to go into edit mode. This method can be invoked in onCreateView.

popBackStackToGuidedStepSupportFragment

Added in 1.1.0
public void popBackStackToGuidedStepSupportFragment(
    @NonNull Class<Object> guidedStepFragmentClass,
    int flags
)

Convenient method to pop to fragment with Given class.

Parameters
@NonNull Class<Object> guidedStepFragmentClass

Name of the Class of GuidedStepSupportFragment to pop to.

int flags

Either 0 or POP_BACK_STACK_INCLUSIVE.

setActions

Added in 1.1.0
public void setActions(@NonNull List<GuidedAction> actions)

Sets the list of GuidedActions that the user may take in this fragment. Uses DiffCallback set by setActionsDiffCallback.

Parameters
@NonNull List<GuidedAction> actions

The list of GuidedActions for this fragment.

setActionsDiffCallback

Added in 1.1.0
public void setActionsDiffCallback(
    @Nullable DiffCallback<GuidedAction> diffCallback
)

Sets the RecyclerView DiffCallback used when setActions is called. By default GuidedStepSupportFragment uses androidx.leanback.widget.GuidedActionDiffCallback. Sets it to null if app wants to refresh the whole list.

Parameters
@Nullable DiffCallback<GuidedAction> diffCallback

DiffCallback used in setActions.

setButtonActions

Added in 1.1.0
public void setButtonActions(@NonNull List<GuidedAction> actions)

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

Parameters
@NonNull List<GuidedAction> actions

The list of button GuidedActions for this fragment.

setSelectedActionPosition

Added in 1.1.0
public void setSelectedActionPosition(int position)

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

Parameters
int position

The integer position of the action of interest.

setSelectedButtonActionPosition

Added in 1.1.0
public void setSelectedButtonActionPosition(int position)

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

Parameters
int position

The integer position of the button action of interest.

setUiStyle

Added in 1.1.0
public void setUiStyle(int style)

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

Added in 1.1.0
protected void onAddSharedElementTransition(
    @NonNull FragmentTransaction ft,
    @NonNull GuidedStepSupportFragment disappearing
)

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.

Parameters
@NonNull FragmentTransaction ft

The FragmentTransaction to add shared element.

@NonNull GuidedStepSupportFragment disappearing

The disappearing fragment.

onProvideFragmentTransitions

Added in 1.1.0
protected void onProvideFragmentTransitions()

Called by Constructor to provide fragment transitions. The default implementation assigns transitions based on getUiStyle:

  • UI_STYLE_REPLACE Slide from/to end(right) for enter transition, slide from/to start(left) for exit transition, shared element enter transition is set to ChangeBounds.
  • UI_STYLE_ENTRANCE Enter transition is set to slide from both sides, exit transition is same as UI_STYLE_REPLACE, no shared element enter transition.
  • UI_STYLE_ACTIVITY_ROOT Enter transition is set to null and app should rely on activity transition, exit transition is same as UI_STYLE_REPLACE, no shared element enter transition.

The default implementation heavily relies on GuidedActionsStylist and GuidanceStylist layout, app may override this method when modifying the default layout of GuidedActionsStylist or GuidanceStylist.

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