public
abstract
class
OnboardingSupportFragment
extends Fragment
java.lang.Object | ||
↳ | android.support.v4.app.Fragment | |
↳ | android.support.v17.leanback.app.OnboardingSupportFragment |
An OnboardingSupportFragment provides a common and simple way to build onboarding screen for applications.
To build the screen views, the inherited class should override:
onCreateBackgroundView(LayoutInflater, ViewGroup)
to provide the background view. Background view has the same
size as the screen and the lowest z-order.onCreateContentView(LayoutInflater, ViewGroup)
to provide the contents view. The content view is located in
the content area at the center of the screen.onCreateForegroundView(LayoutInflater, 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(LayoutInflater, ViewGroup, 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 onCreateView(LayoutInflater, ViewGroup, 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.
OnboardingSupportFragment 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:
LeanbackOnboardingTheme_onboardingTheme
. If present, this theme will be used
by OnboardingSupportFragment 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.)
XML attributes | |
---|---|
android.support.v17.leanback:onboardingDescriptionStyle |
Theme attribute for the style of the description text in onboarding screen. |
android.support.v17.leanback:onboardingHeaderStyle |
Theme attribute for the style of the header in onboarding screen. |
android.support.v17.leanback:onboardingLogoStyle |
Theme attribute for the style of the logo in onboarding screen. |
android.support.v17.leanback:onboardingNavigatorContainerStyle |
Theme attribute for the style of the navigator container in onboarding screen. |
android.support.v17.leanback:onboardingPageIndicatorStyle |
Theme attribute for the style of the page indicator in onboarding screen. |
android.support.v17.leanback:onboardingStartButtonStyle |
Theme attribute for the style of the start button in onboarding screen. |
android.support.v17.leanback:onboardingTheme |
Theme attribute for the overall theme used in the onboarding. |
android.support.v17.leanback:onboardingTitleStyle |
Theme attribute for the style of the title text in onboarding screen. |
Public constructors | |
---|---|
OnboardingSupportFragment()
|
Public methods | |
---|---|
final
int
|
getLogoResourceId()
Returns the resource ID of the splash logo image. |
View
|
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Called to have the fragment instantiate its user interface view. |
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. |
final
void
|
setLogoResourceId(int id)
Sets the resource ID of the splash logo image. |
Protected methods | |
---|---|
final
int
|
getCurrentPageIndex()
Returns the index of the current page. |
abstract
int
|
getPageCount()
Returns the page count. |
abstract
CharSequence
|
getPageDescription(int pageIndex)
Returns the description of the given page. |
abstract
CharSequence
|
getPageTitle(int pageIndex)
Returns the title of the given page. |
abstract
View
|
onCreateBackgroundView(LayoutInflater inflater, ViewGroup container)
Called to have the inherited class create background view. |
abstract
View
|
onCreateContentView(LayoutInflater inflater, ViewGroup container)
Called to have the inherited class create content view. |
Animator
|
onCreateEnterAnimation()
Called to have the inherited class create its enter animation. |
abstract
View
|
onCreateForegroundView(LayoutInflater inflater, ViewGroup container)
Called to have the inherited class create foreground view. |
Animator
|
onCreateLogoAnimation()
Called to have the inherited class create its own logo animation. |
void
|
onFinishFragment()
Called when the onboarding flow finishes. |
void
|
onPageChanged(int newPage, int previousPage)
Called when the page has been changed. |
Inherited methods | |
---|---|
From
class
android.support.v4.app.Fragment
| |
From
class
java.lang.Object
| |
From
interface
android.content.ComponentCallbacks
| |
From
interface
android.view.View.OnCreateContextMenuListener
|
Theme attribute for the style of the description text in onboarding screen. Default is
Widget_Leanback_OnboardingDescriptionStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the header in onboarding screen. Default is
Widget_Leanback_OnboardingHeaderStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the logo in onboarding screen. Default is
Widget_Leanback_OnboardingLogoStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the navigator container in onboarding screen. Default is
Widget_Leanback_OnboardingNavigatorContainerStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the page indicator in onboarding screen. Default is
Widget_Leanback_OnboardingPageIndicatorStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the start button in onboarding screen. Default is
Widget_Leanback_OnboardingStartButtonStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the overall theme used in the onboarding. The Leanback themes set
the default for this, but a custom theme that does not derive from a leanback theme can
set this to @style/Theme.Leanback.Onboarding
in order to specify the
default OnboardingFragment styles.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Theme attribute for the style of the title text in onboarding screen. Default is
Widget_Leanback_OnboardingTitleStyle
.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
OnboardingSupportFragment ()
int getLogoResourceId ()
Returns the resource ID of the splash logo image.
Returns | |
---|---|
int |
The resource ID of the splash logo image. |
View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
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. |
Returns | |
---|---|
View |
Return the View for the fragment's UI, or null. |
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. |
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. 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
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 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.
Parameters | |
---|---|
outState |
Bundle :
Bundle in which to place your saved state.
|
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 | |
---|---|
id |
int :
The resource ID of the logo image.
|
int getCurrentPageIndex ()
Returns the index of the current page.
Returns | |
---|---|
int |
The index of the current page. |
int getPageCount ()
Returns the page count.
Returns | |
---|---|
int |
The page count. |
CharSequence getPageDescription (int pageIndex)
Returns the description of the given page.
Parameters | |
---|---|
pageIndex |
int :
The page index. |
Returns | |
---|---|
CharSequence |
The description of the page. |
CharSequence getPageTitle (int pageIndex)
Returns the title of the given page.
Parameters | |
---|---|
pageIndex |
int :
The page index. |
Returns | |
---|---|
CharSequence |
The title of the page. |
View onCreateBackgroundView (LayoutInflater inflater, 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(LayoutInflater, ViewGroup, Bundle)
.
Parameters | |
---|---|
inflater |
LayoutInflater :
The LayoutInflater object that can be used to inflate the views, |
container |
ViewGroup :
The parent view that the additional views are attached to.The fragment
should not add the view by itself. |
Returns | |
---|---|
View |
The background view for the onboarding screen, or null .
|
View onCreateContentView (LayoutInflater inflater, 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(LayoutInflater, ViewGroup, Bundle)
.
The content view would be located at the center of the screen.
Parameters | |
---|---|
inflater |
LayoutInflater :
The LayoutInflater object that can be used to inflate the views, |
container |
ViewGroup :
The parent view that the additional views are attached to.The fragment
should not add the view by itself. |
Returns | |
---|---|
View |
The content view for the onboarding screen, or null .
|
Animator onCreateEnterAnimation ()
Called to have the inherited class create its enter animation. The start animation runs after logo animation ends.
Returns | |
---|---|
Animator |
The Animator object which runs the page enter animation.
|
View onCreateForegroundView (LayoutInflater inflater, 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(LayoutInflater, ViewGroup, Bundle)
.
This foreground view would have the highest z-order.
Parameters | |
---|---|
inflater |
LayoutInflater :
The LayoutInflater object that can be used to inflate the views, |
container |
ViewGroup :
The parent view that the additional views are attached to.The fragment
should not add the view by itself. |
Returns | |
---|---|
View |
The foreground view for the onboarding screen, or null .
|
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(int)
.
If this returns null
, the logo animation is skipped.
Returns | |
---|---|
Animator |
The Animator object which runs the logo animation.
|
void onFinishFragment ()
Called when the onboarding flow finishes.
void onPageChanged (int newPage, int previousPage)
Called when the page has been changed.
Parameters | |
---|---|
newPage |
int :
The new page. |
previousPage |
int :
The previous page.
|