OnboardingFragment

Added in 1.1.0
Deprecated in 1.1.0

public abstract class OnboardingFragment extends Fragment


An OnboardingFragment provides a common and simple way to build onboarding screen for applications.

Building the screen

The view structure of onboarding screen is composed of the common parts and custom parts. The common parts are composed of icon, title, description and page navigator and the custom parts are composed of background, contents and foreground.

To build the screen views, the inherited class should override:

  • onCreateBackgroundView to provide the background view. Background view has the same size as the screen and the lowest z-order.
  • onCreateContentView to provide the contents view. The content view is located in the content area at the center of the screen.
  • onCreateForegroundView to provide the foreground view. Foreground view has the same size as the screen and the highest z-order

Each of these methods can return null if the application doesn't want to provide it.

Page information

The onboarding screen may have several pages which explain the functionality of the application. The inherited class should provide the page information by overriding the methods:

Note that the information is used in onCreateView, so should be initialized before calling super.onCreateView.

Animation

Onboarding screen has three kinds of animations: Logo Splash Animation When onboarding screen appears, the logo splash animation is played by default. The animation fades in the logo image, pauses in a few seconds and fades it out.

In most cases, the logo animation needs to be customized because the logo images of applications are different from each other, or some applications may want to show their own animations.

The logo animation can be customized in two ways:

If the inherited class provides neither the logo image nor the animation, the logo animation will be omitted.

Page enter animation After logo animation finishes, page enter animation starts, which causes the header section - title and description views to fade and slide in. Users can override the default fade + slide animation by overriding onCreateTitleAnimator&onCreateDescriptionAnimator. By default we don't animate the custom views but users can provide animation by overriding onCreateEnterAnimation. Page change animation When the page changes, the default animations of the title and description are played. The inherited class can override onPageChanged to start the custom animations.

Finishing the screen

If the user finishes the onboarding screen after navigating all the pages, onFinishFragment is called. The inherited class can override this method to show another fragment or activity, or just remove this fragment.

Theming

OnboardingFragment must have access to an appropriate theme. Specifically, the fragment must receive Theme_Leanback_Onboarding, or a theme whose parent 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 Onboarding 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 LeanbackOnboardingTheme_onboardingTheme. If present, this theme will be used by OnboardingFragment as an overlay to the Activity's theme.
  • Finally, custom subclasses of OnboardingFragment 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 onboarding theme do not need to set the onboardingTheme attribute; if set, it will be ignored.) onboardingThemeonboardingHeaderStyleonboardingTitleStyleonboardingDescriptionStyleonboardingNavigatorContainerStyleonboardingPageIndicatorStyleonboardingStartButtonStyleonboardingLogoStyle

Summary

Public constructors

Public methods

final @ColorInt int

Returns the background color of the arrow if it's set through setArrowBackgroundColor.

final @ColorInt int

Returns the color of the arrow if it's set through setArrowColor.

final @ColorInt int

Returns the text color of DescriptionView if it's set through setDescriptionViewTextColor.

final @ColorInt int

Returns the background color of the dot if it's set through setDotBackgroundColor.

final int

Returns the resource id of the main icon.

final int

Returns the resource ID of the splash logo image.

final @Nullable CharSequence

Returns the start button text if it's set through setStartButtonText}.

final @ColorInt int

Returns the text color of TitleView if it's set through setTitleViewTextColor.

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

This method is deprecated.

int

Returns the theme used for styling the fragment.

void

This method is deprecated.

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

This method is deprecated.

void

Sets the background color of the arrow.

void
setArrowColor(@ColorInt int color)

Sets the color of the arrow.

void

Sets the text color for DescriptionView.

void

Sets the background color of the dots.

final void
setIconResouceId(int resourceId)

Sets the resource id for the main icon.

final void

Sets the resource ID of the splash logo image.

void

Sets the text on the start button text.

void

Sets the text color for TitleView.

Protected methods

final int

Returns the index of the current page.

abstract int

Returns the page count.

abstract @Nullable CharSequence
getPageDescription(int pageIndex)

Returns the description of the given page.

abstract @Nullable CharSequence
getPageTitle(int pageIndex)

Returns the title of the given page.

final boolean

Returns whether the logo enter animation is finished.

void

Navigates to the next page.

void

Navigates to the previous page.

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

Called to have the inherited class create background view.

abstract @Nullable View
onCreateContentView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create content view.

@NonNull Animator

Provides the entry animation for description view.

@Nullable Animator

Called to have the inherited class create its enter animation.

abstract @Nullable View
onCreateForegroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create foreground view.

@Nullable Animator

Called to have the inherited class create its own logo animation.

@NonNull Animator

Provides the entry animation for title view.

void

Called when the onboarding flow finishes.

void

Called immediately after the logo animation is complete or no logo animation is specified.

void
onPageChanged(int newPage, int previousPage)

Called when the page has been changed.

final void
startEnterAnimation(boolean force)

Called to start entrance transition.

Inherited Constants

From android.content.ComponentCallbacks2
static final int
static final int
static final int
static final int
static final int
static final int
static final int

Inherited methods

From android.app.Fragment
void
dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args)

This method is deprecated.

final boolean

This method is deprecated.

final Activity

This method is deprecated.

boolean

This method is deprecated.

boolean

This method is deprecated.

final Bundle

This method is deprecated.

final FragmentManager

This method is deprecated.

Context

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final FragmentManager

This method is deprecated.

final Object

This method is deprecated.

final int

This method is deprecated.

final LayoutInflater

This method is deprecated.

LoaderManager

This method is deprecated.

final Fragment

This method is deprecated.

Transition

This method is deprecated.

final Resources

This method is deprecated.

final boolean

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

Transition

This method is deprecated.

final String
getString(int resId)

This method is deprecated.

final String

This method is deprecated.

final Fragment

This method is deprecated.

final int

This method is deprecated.

final CharSequence
getText(int resId)

This method is deprecated.

boolean

This method is deprecated.

View

This method is deprecated.

final int

This method is deprecated.

static Fragment
instantiate(Context context, String fname)

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

final boolean

This method is deprecated.

void
onActivityCreated(Bundle savedInstanceState)

This method is deprecated.

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

This method is deprecated.

void
onAttach(Context context)

This method is deprecated.

void
onAttachFragment(Fragment childFragment)

This method is deprecated.

void

This method is deprecated.

boolean

This method is deprecated.

void
onCreate(Bundle savedInstanceState)

This method is deprecated.

Animator
onCreateAnimator(int transit, boolean enter, int nextAnim)

This method is deprecated.

void
onCreateContextMenu(
    ContextMenu menu,
    View v,
    ContextMenu.ContextMenuInfo menuInfo
)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

LayoutInflater
onGetLayoutInflater(Bundle savedInstanceState)

This method is deprecated.

void
onHiddenChanged(boolean hidden)

This method is deprecated.

void
onInflate(AttributeSet attrs, Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void
onMultiWindowModeChanged(
    boolean isInMultiWindowMode,
    Configuration newConfig
)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onPictureInPictureModeChanged(
    boolean isInPictureInPictureMode,
    Configuration newConfig
)

This method is deprecated.

void

This method is deprecated.

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

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
onTrimMemory(int level)

This method is deprecated.

void
onViewStateRestored(Bundle savedInstanceState)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

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

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setHasOptionsMenu(boolean hasMenu)

This method is deprecated.

void

This method is deprecated.

void
setMenuVisibility(boolean menuVisible)

This method is deprecated.

void

This method is deprecated.

void
setRetainInstance(boolean retain)

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void

This method is deprecated.

void
setTargetFragment(Fragment fragment, int requestCode)

This method is deprecated.

void
setUserVisibleHint(boolean isVisibleToUser)

This method is deprecated.

boolean

This method is deprecated.

void

This method is deprecated.

void
startActivityForResult(Intent intent, int requestCode)

This method is deprecated.

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

This method is deprecated.

void

This method is deprecated.

String

This method is deprecated.

void

This method is deprecated.

Public constructors

OnboardingFragment

Added in 1.1.0
Deprecated in 1.1.0
public OnboardingFragment()

Public methods

getArrowBackgroundColor

Added in 1.1.0
Deprecated in 1.1.0
public final @ColorInt int getArrowBackgroundColor()

Returns the background color of the arrow if it's set through setArrowBackgroundColor. If no color was set, transparent is returned.

getArrowColor

Added in 1.1.0
Deprecated in 1.1.0
public final @ColorInt int getArrowColor()

Returns the color of the arrow if it's set through setArrowColor. If no color was set, transparent is returned.

getDescriptionViewTextColor

Added in 1.1.0
Deprecated in 1.1.0
public final @ColorInt int getDescriptionViewTextColor()

Returns the text color of DescriptionView if it's set through setDescriptionViewTextColor. If no color was set, transparent is returned.

getDotBackgroundColor

Added in 1.1.0
Deprecated in 1.1.0
public final @ColorInt int getDotBackgroundColor()

Returns the background color of the dot if it's set through setDotBackgroundColor. If no color was set, transparent is returned.

getIconResourceId

Added in 1.1.0
Deprecated in 1.1.0
public final int getIconResourceId()

Returns the resource id of the main icon.

getLogoResourceId

Added in 1.1.0
Deprecated in 1.1.0
public final int getLogoResourceId()

Returns the resource ID of the splash logo image.

Returns
int

The resource ID of the splash logo image.

getStartButtonText

Added in 1.1.0
Deprecated in 1.1.0
public final @Nullable CharSequence getStartButtonText()

Returns the start button text if it's set through setStartButtonText}. If no string was set, null is returned.

getTitleViewTextColor

Added in 1.1.0
Deprecated in 1.1.0
public final @ColorInt int getTitleViewTextColor()

Returns the text color of TitleView if it's set through setTitleViewTextColor. If no color was set, transparent is returned.

onCreateView

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

onProvideTheme

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

onSaveInstanceState

Added in 1.1.0
Deprecated in 1.1.0
public void onSaveInstanceState(Bundle outState)

onViewCreated

Added in 1.1.0
Deprecated in 1.1.0
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)

setArrowBackgroundColor

Added in 1.1.0
Deprecated in 1.1.0
public void setArrowBackgroundColor(@ColorInt int color)

Sets the background color of the arrow. If not set, the default color from attr PagingIndicator_arrowBgColor in the theme will be used.

Parameters
@ColorInt int color

the color to use for arrow background

setArrowColor

Added in 1.1.0
Deprecated in 1.1.0
public void setArrowColor(@ColorInt int color)

Sets the color of the arrow. This color will supersede the color set in the theme attribute PagingIndicator_arrowColor if provided. If none of these two are set, the arrow will have its original bitmap color.

Parameters
@ColorInt int color

the color to use for arrow background

setDescriptionViewTextColor

Added in 1.1.0
Deprecated in 1.1.0
public void setDescriptionViewTextColor(@ColorInt int color)

Sets the text color for DescriptionView. If not set, the default textColor set in style referenced by attr onboardingDescriptionStyle will be used.

Parameters
@ColorInt int color

the color to use as the text color for DescriptionView

setDotBackgroundColor

Added in 1.1.0
Deprecated in 1.1.0
public void setDotBackgroundColor(@ColorInt int color)

Sets the background color of the dots. If not set, the default color from attr PagingIndicator_dotBgColor in the theme will be used.

Parameters
@ColorInt int color

the color to use for dot backgrounds

setIconResouceId

Added in 1.1.0
Deprecated in 1.1.0
public final void setIconResouceId(int resourceId)

Sets the resource id for the main icon.

setLogoResourceId

Added in 1.1.0
Deprecated in 1.1.0
public final void setLogoResourceId(int id)

Sets the resource ID of the splash logo image. If the logo resource id set, the default logo splash animation will be played.

Parameters
int id

The resource ID of the logo image.

setStartButtonText

Added in 1.1.0
Deprecated in 1.1.0
public void setStartButtonText(@Nullable CharSequence text)

Sets the text on the start button text. If not set, the default text set in LeanbackOnboardingTheme_onboardingStartButtonStyle will be used.

Parameters
@Nullable CharSequence text

the start button text

setTitleViewTextColor

Added in 1.1.0
Deprecated in 1.1.0
public void setTitleViewTextColor(@ColorInt int color)

Sets the text color for TitleView. If not set, the default textColor set in style referenced by attr onboardingTitleStyle will be used.

Parameters
@ColorInt int color

the color to use as the text color for TitleView

Protected methods

getCurrentPageIndex

Added in 1.1.0
Deprecated in 1.1.0
protected final int getCurrentPageIndex()

Returns the index of the current page.

Returns
int

The index of the current page.

getPageCount

Added in 1.1.0
Deprecated in 1.1.0
protected abstract int getPageCount()

Returns the page count.

Returns
int

The page count.

getPageDescription

Added in 1.1.0
Deprecated in 1.1.0
protected abstract @Nullable CharSequence getPageDescription(int pageIndex)

Returns the description of the given page.

Parameters
int pageIndex

The page index.

Returns
@Nullable CharSequence

The description of the page.

getPageTitle

Added in 1.1.0
Deprecated in 1.1.0
protected abstract @Nullable CharSequence getPageTitle(int pageIndex)

Returns the title of the given page.

Parameters
int pageIndex

The page index.

Returns
@Nullable CharSequence

The title of the page.

isLogoAnimationFinished

Added in 1.1.0
Deprecated in 1.1.0
protected final boolean isLogoAnimationFinished()

Returns whether the logo enter animation is finished.

Returns
boolean

true if the logo enter transition is finished, false otherwise

moveToNextPage

Added in 1.1.0
Deprecated in 1.1.0
protected void moveToNextPage()

Navigates to the next page.

moveToPreviousPage

Added in 1.1.0
Deprecated in 1.1.0
protected void moveToPreviousPage()

Navigates to the previous page.

onCreateBackgroundView

Added in 1.1.0
Deprecated in 1.1.0
protected abstract @Nullable View onCreateBackgroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create background view. This is optional and the fragment which doesn't have the background view can return null. This is called inside onCreateView.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The background view for the onboarding screen, or null.

onCreateContentView

Added in 1.1.0
Deprecated in 1.1.0
protected abstract @Nullable View onCreateContentView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create content view. This is optional and the fragment which doesn't have the content view can return null. This is called inside onCreateView.

The content view would be located at the center of the screen.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The content view for the onboarding screen, or null.

onCreateDescriptionAnimator

Added in 1.1.0
Deprecated in 1.1.0
protected @NonNull Animator onCreateDescriptionAnimator()

Provides the entry animation for description view. This allows users to override the default fade and slide animation. Returning null will disable the animation.

onCreateEnterAnimation

Added in 1.1.0
Deprecated in 1.1.0
protected @Nullable Animator onCreateEnterAnimation()

Called to have the inherited class create its enter animation. The start animation runs after logo animation ends.

Returns
@Nullable Animator

The Animator object which runs the page enter animation.

onCreateForegroundView

Added in 1.1.0
Deprecated in 1.1.0
protected abstract @Nullable View onCreateForegroundView(
    @NonNull LayoutInflater inflater,
    @NonNull ViewGroup container
)

Called to have the inherited class create foreground view. This is optional and the fragment which doesn't need the foreground view can return null. This is called inside onCreateView.

This foreground view would have the highest z-order.

Parameters
@NonNull LayoutInflater inflater

The LayoutInflater object that can be used to inflate the views,

@NonNull ViewGroup container

The parent view that the additional views are attached to.The fragment should not add the view by itself.

Returns
@Nullable View

The foreground view for the onboarding screen, or null.

onCreateLogoAnimation

Added in 1.1.0
Deprecated in 1.1.0
protected @Nullable Animator onCreateLogoAnimation()

Called to have the inherited class create its own logo animation.

This is called only if the logo image resource ID is not set by setLogoResourceId. If this returns null, the logo animation is skipped.

Returns
@Nullable Animator

The Animator object which runs the logo animation.

onCreateTitleAnimator

Added in 1.1.0
Deprecated in 1.1.0
protected @NonNull Animator onCreateTitleAnimator()

Provides the entry animation for title view. This allows users to override the default fade and slide animation. Returning null will disable the animation.

onFinishFragment

Added in 1.1.0
Deprecated in 1.1.0
protected void onFinishFragment()

Called when the onboarding flow finishes.

onLogoAnimationFinished

Added in 1.1.0
Deprecated in 1.1.0
protected void onLogoAnimationFinished()

Called immediately after the logo animation is complete or no logo animation is specified. This method can also be called when the activity is recreated, i.e. when no logo animation are performed. By default, this method will hide the logo view and start the entrance animation for this fragment. Overriding subclasses can provide their own data loading logic as to when the entrance animation should be executed.

onPageChanged

Added in 1.1.0
Deprecated in 1.1.0
protected void onPageChanged(int newPage, int previousPage)

Called when the page has been changed.

Parameters
int newPage

The new page.

int previousPage

The previous page.

startEnterAnimation

Added in 1.1.0
Deprecated in 1.1.0
protected final void startEnterAnimation(boolean force)

Called to start entrance transition. This can be called by subclasses when the logo animation and data loading is complete. If force flag is set to false, it will only start the animation if it's not already done yet. Otherwise, it will always start the enter animation. In both cases, the logo view will hide and the rest of fragment views become visible after this call.

Parameters
boolean force

true if enter animation has to be performed regardless of whether it's been done in the past, false otherwise