public abstract class IntroActivity
extends AppCompatActivity
generatePages(Bundle) and generateFinalButtonBehaviour(). It is recommended that the
manifest entry declare android:noHistory="true" to prevent the user from navigating back
to this activity once finished. generatePages(Bundle) is called by onCreate(Bundle) to generate the Page elements to display in the activity. The method
must return a collection, it cannot return null. Pages cannot be added or removed from the
activity after this method returns. generateFinalButtonBehaviour() is called by onCreate(Bundle) to generate the behaviour to assign to the final button. The method must
return a Behaviour, it cannot return null. The behaviour of the button defines what happens when
the button is pressed. The .ProgressToNextActivity abstract class is designed to facilitate validation conditions to check
that the activity should finish, and it provides a mechanism for setting a shared preferences
flag to prevent the user from being shown the intro screen again.
The navigation bar contains
three buttons: a left button, a right button and a final button. The left button is present on
all pages, but by default it is not displayed on the last page. The button can be shown on the
last page by calling (boolean). The right button is present on
all pages but the last, and this cannot be changed as the final button replaces the right button
on the last page. By default, the left button skips ahead to the last page and the right button
moves to the next page. The behaviour of the final button is generated in generateFinalButtonBehaviour(). The behaviour of each button can be changed using the
respective 'set behaviour' method. The appearance of each button can also be changed using the
respective 'set appearance' method. These methods make it easy to display text, an icon, or both
in each button. The other methods of this activity allow finer control over the appearance of
each button.
The methods of this activity also provide the following customisation options:
| Constructor and Description |
|---|
IntroActivity() |
| Modifier and Type | Method and Description |
|---|---|
void |
disableFinalButton(boolean disabled)
Hides and disables the final button.
|
void |
disableLeftButton(boolean disabled)
Hides and disables the left button.
|
void |
disableRightButton(boolean disabled)
Hides and disables the right button.
|
void |
enableProgressIndicatorAnimations(boolean enableAnimations)
Enables or disables progress indicator animations
|
boolean |
finalButtonIsDisabled()
Returns whether or not the left button is currently disabled and hidden.
|
protected abstract IntroButton.Behaviour |
generateFinalButtonBehaviour()
Called by
onCreate(Bundle) to generate the behaviour of the final button. |
protected abstract java.util.Collection<Page> |
generatePages(android.os.Bundle savedInstanceState)
Called by
onCreate(Bundle) to generate the pages to display in this activity. |
Page |
getCurrentPage() |
IntroButton.Appearance |
getFinalButtonAppearance() |
IntroButton.Behaviour |
getFinalButtonBehaviour() |
android.graphics.drawable.Drawable |
getFinalButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the icon to display in the final button for a particular behaviour.
|
java.lang.CharSequence |
getFinalButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the text to display in the final button for a particular behaviour class.
|
int |
getFinalButtonTextColor()
Returns the color of the text in the final button.
|
float |
getFinalButtonTextSize()
Returns the size of the text in the final button.
|
Page |
getFirstPage() |
int |
getIndexOfCurrentPage() |
int |
getIndexOfPage(Page page)
Returns the index of the specified page, or -1 if the page is not in this activity.
|
Page |
getLastPage() |
IntroButton.Appearance |
getLeftButtonAppearance() |
IntroButton.Behaviour |
getLeftButtonBehaviour() |
android.graphics.drawable.Drawable |
getLeftButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the icon to display in the left button for a particular behaviour.
|
java.lang.CharSequence |
getLeftButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the text to display in the left button for a particular behaviour class.
|
int |
getLeftButtonTextColor()
Returns the color of the text in the left button.
|
float |
getLeftButtonTextSize()
Returns the size of the text in the left button.
|
Page |
getPage(int pageIndex)
Returns the page at the specified index.
|
java.util.Collection<Page> |
getPages()
Returns a reference to the pages of this activity, as an unmodifiable collection.
|
LockableViewPager.LockMode |
getPagingLockMode() |
SelectionIndicator |
getProgressIndicator() |
IntroButton.Appearance |
getRightButtonAppearance() |
IntroButton.Behaviour |
getRightButtonBehaviour() |
android.graphics.drawable.Drawable |
getRightButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the icon to display in the right button for a particular behaviour.
|
java.lang.CharSequence |
getRightButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Returns the text to display in the right button for a particular behaviour class.
|
int |
getRightButtonTextColor()
Returns the color of the text in the right button.
|
float |
getRightButtonTextSize()
Returns the size of the text in the right button.
|
android.widget.RelativeLayout |
getRootView() |
void |
goToFirstPage()
Displays the first page, if not already displayed.
|
void |
goToLastPage()
Displays the last page, if not already displayed.
|
void |
goToNextPage()
Displays the next page, if not already displayed.
|
void |
goToPage(int pageIndex)
Changes which page is currently displayed.
|
void |
goToPreviousPage()
Displays the previous page, if not already displayed.
|
void |
hideLeftButtonOnLastPage(boolean hideButton)
Sets whether or not the left button should be hidden when the last page is displayed.
|
void |
hideStatusBar()
Hides the status bar background but continues to display the icons.
|
boolean |
leftButtonIsDisabled()
Returns whether or not the left button is currently disabled and hidden.
|
boolean |
leftButtonIsHiddenOnLastPage()
Returns whether or not the left button will be hidden when the last page is displayed.
|
int |
numberOfPages() |
void |
onBackPressed()
Called when the back button is pressed.
|
protected void |
onCreate(android.os.Bundle savedInstanceState)
Initialises the UI and behaviour of this activity.
|
void |
onItemAdded(ArrayListWithCallbacks list,
java.lang.Object itemAdded,
int index) |
void |
onItemRemoved(ArrayListWithCallbacks list,
java.lang.Object itemRemoved,
int index) |
void |
onListCleared(ArrayListWithCallbacks list) |
void |
onPageScrolled(int position,
float positionOffset,
int positionOffsetPixels) |
void |
onPageScrollStateChanged(int state) |
void |
onPageSelected(int position) |
protected void |
onSaveInstanceState(android.os.Bundle outState) |
boolean |
progressIndicatorAnimationsAreEnabled() |
boolean |
rightButtonIsDisabled()
Returns whether or not the right button is currently disabled and hidden.
|
void |
setFinalButtonAppearance(IntroButton.Appearance appearance)
Sets the appearance of the final button.
|
void |
setFinalButtonBehaviour(IntroButton.Behaviour behaviour)
Sets the behaviour of the final button.
|
void |
setFinalButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the icon to display in the final button for a single behaviour class.
|
void |
setFinalButtonOnClickListener(android.view.View.OnClickListener l)
Register a callback to be invoked when the final button is clicked.
|
void |
setFinalButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the text to display in the final button for a single behaviour class.
|
void |
setFinalButtonTextColor(int color)
Sets the color of the text in the final button.
|
void |
setFinalButtonTextSize(float sizeSp)
Sets the size of the text in the final button.
|
void |
setFinalButtonTypeface(android.graphics.Typeface tf)
Sets the typeface and style in which the text of the final button should be displayed.
|
void |
setFinalButtonTypeface(android.graphics.Typeface tf,
int style)
Sets the typeface and style in which the text of the final button should be displayed.
|
void |
setLeftButtonAppearance(IntroButton.Appearance appearance)
Sets the appearance of the left button.
|
void |
setLeftButtonBehaviour(IntroButton.Behaviour behaviour)
Sets the behaviour of the left button.
|
void |
setLeftButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the icon to display in the left button for a single behaviour class.
|
void |
setLeftButtonOnClickListener(android.view.View.OnClickListener l)
Register a callback to be invoked when the left button is clicked.
|
void |
setLeftButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the text to display in the left button for a single behaviour class.
|
void |
setLeftButtonTextColor(int color)
Sets the color of the text in the left button.
|
void |
setLeftButtonTextSize(float sizeSp)
Sets the size of the text in the left button.
|
void |
setLeftButtonTypeface(android.graphics.Typeface tf)
Sets the typeface and style in which the text of the left button should be displayed.
|
void |
setLeftButtonTypeface(android.graphics.Typeface tf,
int style)
Sets the typeface and style in which the text of the left button should be displayed.
|
void |
setPageTransformer(boolean reverseDrawingOrder,
ViewPager.PageTransformer transformer)
Sets the PageTransformer which will be used to the pages of this intro screen when scrolled.
|
void |
setPagingLockMode(LockableViewPager.LockMode lockMode)
Sets the paging lock mode.
|
void |
setProgressIndicator(SelectionIndicator selectionIndicator)
Sets the selection indicator to show the user's progress through the activity.
|
void |
setRightButtonAppearance(IntroButton.Appearance appearance)
Sets the appearance of the right button.
|
void |
setRightButtonBehaviour(IntroButton.Behaviour behaviour)
Sets the behaviour of the right button when clicked.
|
void |
setRightButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the icon to display in the right button for a single behaviour class.
|
void |
setRightButtonOnClickListener(android.view.View.OnClickListener l)
Register a callback to be invoked when the right button is clicked.
|
void |
setRightButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
Sets the text to display in the right button for a single behaviour class.
|
void |
setRightButtonTextColor(int color)
Sets the text color of the right button.
|
void |
setRightButtonTextSize(float sizeSp)
Sets the size of the text in the right button.
|
void |
setRightButtonTypeface(android.graphics.Typeface tf)
Sets the typeface and style in which the text of the right button should be displayed.
|
void |
setRightButtonTypeface(android.graphics.Typeface tf,
int style)
Sets the typeface and style in which the text of the right button should be displayed.
|
void |
showStatusBar()
Shows the status bar background and prevents views from being drawn behind the status bar
(including existing views).
|
protected void onCreate(android.os.Bundle savedInstanceState)
generatePages(Bundle) to create the pages to display in this activity.savedInstanceState - if this activity is being re-initialized after previously being shut down, then this Bundle
contains the data this activity most recently saved in onSaveInstanceState(Bundle), otherwise nullprotected void onSaveInstanceState(android.os.Bundle outState)
public void onBackPressed()
protected abstract java.util.Collection<Page> generatePages(android.os.Bundle savedInstanceState)
onCreate(Bundle) to generate the pages to display in this activity. The
returned collection is copied, so further changes to the collection will have no effect after
this method returns. The natural ordering of the returned collection is used for the order of
the pages.savedInstanceState - if this activity is being re-initialized after previously being shut down, then this Bundle
contains the data this activity most recently saved in onSaveInstanceState(Bundle), otherwise nullprotected abstract IntroButton.Behaviour generateFinalButtonBehaviour()
onCreate(Bundle) to generate the behaviour of the final button. This
behaviour can be changed later using #setFinalButtonBehaviour(Behaviour). The IntroButton.ProgressToNextActivity class is
designed to simplify the implementation.public final void hideStatusBar()
android:fitsSystemWindows="false" attribute will draw to the top of
the screen. The effect of this method varies depending on the current SDK version.public final void showStatusBar()
public final android.widget.RelativeLayout getRootView()
public final void setPageTransformer(boolean reverseDrawingOrder,
ViewPager.PageTransformer transformer)
reverseDrawingOrder - true if the supplied PageTransformer requires page views to be drawn from last to first
instead of first to lasttransformer - the PageTransformer that will modify each page's animation propertiespublic final java.util.Collection<Page> getPages()
public final Page getPage(int pageIndex)
pageIndex - the index of the page to return, counting from zeroindexjava.lang.IndexOutOfBoundsException - if the index exceeds the size of the page datasetpublic final Page getCurrentPage()
public final Page getFirstPage()
public final Page getLastPage()
public final int getIndexOfPage(Page page)
page - the Page to get the index ofpage, counting from zeropublic final int getIndexOfCurrentPage()
public final void goToPage(int pageIndex)
pageIndex - the index of the page to display, counting from zerojava.lang.IndexOutOfBoundsException - if the index exceeds the size of the page datasetpublic final void goToLastPage()
public final void goToFirstPage()
public final void goToNextPage()
public final void goToPreviousPage()
public final int numberOfPages()
public final void setPagingLockMode(LockableViewPager.LockMode lockMode)
lockMode - the lock mode to use, not nullpublic final LockableViewPager.LockMode getPagingLockMode()
public void setProgressIndicator(SelectionIndicator selectionIndicator)
View.selectionIndicator - the selection indicator to use, null to clear any existing indicatorpublic SelectionIndicator getProgressIndicator()
public void enableProgressIndicatorAnimations(boolean enableAnimations)
enableAnimations - true to enable animations, false to disable thempublic boolean progressIndicatorAnimationsAreEnabled()
public final void setLeftButtonBehaviour(IntroButton.Behaviour behaviour)
#setLeftButtonOnClickListener(OnClickListener). Predefined
behaviours are provided in the IntroButton class, however custom behaviours are
accepted. To use a custom behaviour, implement IntroButton.Behaviour and pass an instance of the
implementation to this method. Alternatively, subclassing IntroButton.BehaviourAdapter simplifies the
implementation and eliminates boilerplate code.behaviour - the behaviour to use when left button is pressed, not nullpublic final IntroButton.Behaviour getLeftButtonBehaviour()
public final void setLeftButtonAppearance(IntroButton.Appearance appearance)
appearance - the predefined appearance to use, not nullpublic final IntroButton.Appearance getLeftButtonAppearance()
public final void setLeftButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
#setLeftButtonAppearance(Appearance) is the preferred method of showing no text.text - the text label to displaybehaviourClass - the behaviour class to set the label for, null to use the class of the current behaviourpublic final java.lang.CharSequence getLeftButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the text against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setLeftButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
#setLeftButtonAppearance(Appearance) is the preferred method of showing no icon.icon - the icon to displaybehaviourClass - the behaviour class to set the icon for, null to use the class of the current appearancepublic final android.graphics.drawable.Drawable getLeftButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the icon against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setLeftButtonTextColor(int color)
color - the color to use, as an ARGB hex codepublic final int getLeftButtonTextColor()
public final void setLeftButtonTextSize(float sizeSp)
sizeSp - the size to use, measured in scaled-pixelspublic final float getLeftButtonTextSize()
public final void setLeftButtonTypeface(android.graphics.Typeface tf,
int style)
tf - the typeface to usestyle - style for the typefacepublic final void setLeftButtonTypeface(android.graphics.Typeface tf)
tf - the typeface to usepublic final void setLeftButtonOnClickListener(android.view.View.OnClickListener l)
l - the callback that will run, null to clear the existing listenerpublic final void disableLeftButton(boolean disabled)
disabled - whether or not the button should be hidden/disabledpublic final boolean leftButtonIsDisabled()
public final void hideLeftButtonOnLastPage(boolean hideButton)
disableFinalButton(boolean) has been used to disable the left button then calling
this method will not display the left button. The setting will still be recorded so that if
the button is later enabled then the last page behaviour is retained.hideButton - true to hide the left button on the last page, false to show itpublic final boolean leftButtonIsHiddenOnLastPage()
public final void setRightButtonBehaviour(IntroButton.Behaviour behaviour)
#setRightButtonOnClickListener(OnClickListener).
Predefined behaviours are provided in the IntroButton class, however custom
behaviours are accepted. To use a custom behaviour, implement IntroButton.Behaviour and pass an
instance of the implementation to this method. Alternatively, subclassing IntroButton.BehaviourAdapter simplifies the
implementation and eliminates boilerplate code.behaviour - the behaviour to use when the right button is pressed, not nullpublic final IntroButton.Behaviour getRightButtonBehaviour()
public final void setRightButtonAppearance(IntroButton.Appearance appearance)
appearance - the predefined appearance to use, not nullpublic final IntroButton.Appearance getRightButtonAppearance()
public final void setRightButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
#setLeftButtonAppearance(Appearance) is the preferred method of showing no text.text - the text label to displaybehaviourClass - the behaviour class to set the label for, null to use the class of the current behaviourpublic final java.lang.CharSequence getRightButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the text against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setRightButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
setRightButtonAppearance(IntroButton.Appearance) is the preferred method of showing
no icon.icon - the icon to displaybehaviourClass - the behaviour class to set the icon for, null to use the class of the current appearancepublic final android.graphics.drawable.Drawable getRightButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the icon against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setRightButtonTextColor(int color)
color - the color to use, as an ARGB hex codepublic final int getRightButtonTextColor()
public final void setRightButtonTextSize(float sizeSp)
sizeSp - the size to use, measured in scaled-pixelspublic final float getRightButtonTextSize()
public final void setRightButtonTypeface(android.graphics.Typeface tf,
int style)
tf - the typeface to usestyle - style for the typefacepublic final void setRightButtonTypeface(android.graphics.Typeface tf)
tf - the typeface to usepublic final void setRightButtonOnClickListener(android.view.View.OnClickListener l)
l - the callback that will run, null to clear the existing listenerpublic final void disableRightButton(boolean disabled)
disabled - whether or not the button should be hidden/disabledpublic final boolean rightButtonIsDisabled()
public final void setFinalButtonBehaviour(IntroButton.Behaviour behaviour)
#setLeftButtonOnClickListener(OnClickListener). Predefined
behaviours are provided in the IntroButton class, however custom behaviours are
accepted. To use a custom behaviour, implement IntroButton.Behaviour and pass an instance of the
implementation to this method. Alternatively, subclassing IntroButton.BehaviourAdapter simplifies the
implementation and eliminates boilerplate code.behaviour - the behaviour to use when left button is pressed, not nullpublic final IntroButton.Behaviour getFinalButtonBehaviour()
public final void setFinalButtonAppearance(IntroButton.Appearance appearance)
appearance - the predefined appearance to use, not nullpublic final IntroButton.Appearance getFinalButtonAppearance()
public final void setFinalButtonText(java.lang.CharSequence text,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
#setLeftButtonAppearance(Appearance) is the preferred method of showing no text.text - the text label to displaybehaviourClass - the behaviour class to set the label for, null to use the class of the current behaviourpublic final java.lang.CharSequence getFinalButtonText(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the text against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setFinalButtonIcon(android.graphics.drawable.Drawable icon,
java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
setFinalButtonAppearance(IntroButton.Appearance) is the preferred method of showing
no icon.icon - the icon to displaybehaviourClass - the behaviour class to set the icon for, null to use the class of the current appearancepublic final android.graphics.drawable.Drawable getFinalButtonIcon(java.lang.Class<? extends IntroButton.Behaviour> behaviourClass)
behaviourClass - the behaviour class to query the icon against, null to use the class of the current
behaviourbehaviourClass, null if there is nonepublic final void setFinalButtonTextColor(int color)
color - the color to use, as an ARGB hex codepublic final int getFinalButtonTextColor()
public final void setFinalButtonTextSize(float sizeSp)
sizeSp - the size to use, measured in scaled-pixelspublic final float getFinalButtonTextSize()
public final void setFinalButtonTypeface(android.graphics.Typeface tf,
int style)
tf - the typeface to usestyle - style for the typefacepublic final void setFinalButtonTypeface(android.graphics.Typeface tf)
tf - the typeface to usepublic final void setFinalButtonOnClickListener(android.view.View.OnClickListener l)
l - the callback that will run, null to clear the existing listenerpublic final void disableFinalButton(boolean disabled)
disabled - whether or not the button should be hidden/disabledpublic final boolean finalButtonIsDisabled()
public void onPageScrolled(int position,
float positionOffset,
int positionOffsetPixels)
public void onPageSelected(int position)
public void onPageScrollStateChanged(int state)
public void onItemAdded(ArrayListWithCallbacks list,
java.lang.Object itemAdded,
int index)
public void onItemRemoved(ArrayListWithCallbacks list,
java.lang.Object itemRemoved,
int index)
public void onListCleared(ArrayListWithCallbacks list)