public abstract class OnboardingFragment extends Fragment
To build the screen views, the inherited class should override:
onCreateBackgroundView(android.view.LayoutInflater, android.view.ViewGroup)
to provide the background view. Background view has the same
size as the screen and the lowest z-order.onCreateContentView(android.view.LayoutInflater, android.view.ViewGroup)
to provide the contents view. The content view is located in
the content area at the center of the screen.onCreateForegroundView(android.view.LayoutInflater, android.view.ViewGroup)
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.
getPageCount()
to provide the number of pages.getPageTitle(int)
to provide the title of the page.getPageDescription(int)
to provide the description of the page.
Note that the information is used in onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
, so should be initialized before
calling super.onCreateView
.
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:
setLogoResourceId(int)
to show
the default logo animation. This method should be called in Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
.onCreateLogoAnimation()
and return the
Animator
object to run.If the inherited class provides neither the logo image nor the animation, the logo animation will be omitted.
onCreateEnterAnimation()
.
onPageChanged(int, int)
to start the custom animations.
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.
OnboardingFragment must have access to an appropriate theme. Specifically, the fragment must
receive R.style#Theme_Leanback_Onboarding
, or a theme whose parent is set to that theme.
Themes can be provided in one of three ways:
R.styleable#LeanbackOnboardingTheme_onboardingTheme
. If present, this theme will be used
by OnboardingFragment as an overlay to the Activity's theme.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.)
Fragment.InstantiationException, Fragment.SavedState
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
OnboardingFragment() |
Modifier and Type | Method and Description |
---|---|
protected int |
getCurrentPageIndex()
Returns the index of the current page.
|
int |
getLogoResourceId()
Returns the resource ID of the splash logo image.
|
protected abstract int |
getPageCount()
Returns the page count.
|
protected abstract CharSequence |
getPageDescription(int pageIndex)
Returns the description of the given page.
|
protected abstract CharSequence |
getPageTitle(int pageIndex)
Returns the title of the given page.
|
protected abstract View |
onCreateBackgroundView(LayoutInflater inflater,
ViewGroup container)
Called to have the inherited class create background view.
|
protected abstract View |
onCreateContentView(LayoutInflater inflater,
ViewGroup container)
Called to have the inherited class create content view.
|
protected Animator |
onCreateEnterAnimation()
Called to have the inherited class create its enter animation.
|
protected abstract View |
onCreateForegroundView(LayoutInflater inflater,
ViewGroup container)
Called to have the inherited class create foreground view.
|
protected Animator |
onCreateLogoAnimation()
Called to have the inherited class create its own logo animation.
|
View |
onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view.
|
protected void |
onFinishFragment()
Called when the onboarding flow finishes.
|
protected void |
onPageChanged(int newPage,
int previousPage)
Called when the page has been changed.
|
int |
onProvideTheme()
Returns the theme used for styling the fragment.
|
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.
|
void |
setLogoResourceId(int id)
Sets the resource ID of the splash logo image.
|
dump, equals, getActivity, getAllowEnterTransitionOverlap, getAllowReturnTransitionOverlap, getArguments, getChildFragmentManager, getContext, getEnterTransition, getExitTransition, getFragmentManager, getHost, getId, getLayoutInflater, getLoaderManager, getParentFragment, getReenterTransition, getResources, getRetainInstance, getReturnTransition, getSharedElementEnterTransition, getSharedElementReturnTransition, getString, getString, getTag, getTargetFragment, getTargetRequestCode, getText, getUserVisibleHint, getView, hashCode, instantiate, instantiate, isAdded, isDetached, isHidden, isInLayout, isRemoving, isResumed, isVisible, onActivityCreated, onActivityResult, onAttach, onAttach, onAttachFragment, onConfigurationChanged, onContextItemSelected, onCreate, onCreateAnimator, onCreateContextMenu, onCreateOptionsMenu, onDestroy, onDestroyOptionsMenu, onDestroyView, onDetach, onHiddenChanged, onInflate, onInflate, onInflate, onLowMemory, onMultiWindowModeChanged, onOptionsItemSelected, onOptionsMenuClosed, onPause, onPictureInPictureModeChanged, onPrepareOptionsMenu, onRequestPermissionsResult, onResume, onStart, onStop, onTrimMemory, onViewCreated, onViewStateRestored, registerForContextMenu, requestPermissions, setAllowEnterTransitionOverlap, setAllowReturnTransitionOverlap, setArguments, setEnterSharedElementCallback, setEnterSharedElementTransitionCallback, setEnterTransition, setExitSharedElementCallback, setExitSharedElementTransitionCallback, setExitTransition, setHasOptionsMenu, setInitialSavedState, setMenuVisibility, setReenterTransition, setRetainInstance, setReturnTransition, setSharedElementEnterTransition, setSharedElementReturnTransition, setTargetFragment, setUserVisibleHint, shouldShowRequestPermissionRationale, startActivity, startActivity, startActivityForResult, startActivityForResult, startIntentSenderForResult, toString, unregisterForContextMenu
@Nullable public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Fragment
Fragment.onCreate(Bundle)
and Fragment.onActivityCreated(Bundle)
.
If you return a View from here, you will later be called in
Fragment.onDestroyView()
when the view is being released.
onCreateView
in class Fragment
inflater
- The LayoutInflater object that can be used to inflate
any views in the fragment,container
- 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
- If non-null, this fragment is being re-constructed
from a previous saved state as given here.public void onSaveInstanceState(Bundle outState)
Fragment
Fragment.onCreate(Bundle)
,
Fragment.onCreateView(LayoutInflater, ViewGroup, Bundle)
, and
Fragment.onActivityCreated(Bundle)
.
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 Fragment.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.
onSaveInstanceState
in class Fragment
outState
- Bundle in which to place your saved state.public int onProvideTheme()
public final void setLogoResourceId(int id)
id
- The resource ID of the logo image.public final int getLogoResourceId()
@Nullable protected Animator onCreateLogoAnimation()
This is called only if the logo image resource ID is not set by setLogoResourceId(int)
.
If this returns null
, the logo animation is skipped.
Animator
object which runs the logo animation.@Nullable protected Animator onCreateEnterAnimation()
Animator
object which runs the page enter animation.protected abstract int getPageCount()
protected abstract CharSequence getPageTitle(int pageIndex)
pageIndex
- The page index.protected abstract CharSequence getPageDescription(int pageIndex)
pageIndex
- The page index.protected final int getCurrentPageIndex()
@Nullable protected abstract View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container)
null
. This is called inside
onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
.inflater
- The LayoutInflater object that can be used to inflate the views,container
- The parent view that the additional views are attached to.The fragment
should not add the view by itself.null
.@Nullable protected abstract View onCreateContentView(LayoutInflater inflater, ViewGroup container)
null
. This is called inside
onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
.
The content view would be located at the center of the screen.
inflater
- The LayoutInflater object that can be used to inflate the views,container
- The parent view that the additional views are attached to.The fragment
should not add the view by itself.null
.@Nullable protected abstract View onCreateForegroundView(LayoutInflater inflater, ViewGroup container)
null
. This is called inside
onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
.
This foreground view would have the highest z-order.
inflater
- The LayoutInflater object that can be used to inflate the views,container
- The parent view that the additional views are attached to.The fragment
should not add the view by itself.null
.protected void onFinishFragment()
protected void onPageChanged(int newPage, int previousPage)
newPage
- The new page.previousPage
- The previous page.