Class PromptOptions<T extends PromptOptions>

java.lang.Object
uk.co.samuelwall.materialtaptargetprompt.extras.PromptOptions<T>
Type Parameters:
T - The subclass that extends this.
Direct Known Subclasses:
MaterialTapTargetPrompt.Builder

public class PromptOptions<T extends PromptOptions>
extends java.lang.Object
Contains all the settings for creating a prompt.
  • Constructor Details

    • PromptOptions

      public PromptOptions​(@NonNull ResourceFinder resourceFinder)
      Constructor.
      Parameters:
      resourceFinder - The resource finder implementation to use to find resources.
  • Method Details

    • load

      public void load​(@StyleRes int themeResId)
      Loads the supplied theme into the prompt overwriting any previously set values if they are set in the theme.
      Parameters:
      themeResId - The resource id for the theme.
    • getResourceFinder

      @NonNull public ResourceFinder getResourceFinder()
      Get the resource finder being used.
      Returns:
      The resource finder being used.
    • setTarget

      @NonNull public T setTarget​(@Nullable android.view.View target)
      Set the view for the prompt to focus on.
      Parameters:
      target - The view that the prompt will highlight.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setTarget

      @NonNull public T setTarget​(@IdRes int target)
      Set the view for the prompt to focus on using the given resource id.
      Parameters:
      target - The view that the prompt will highlight.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getTargetView

      @Nullable public android.view.View getTargetView()
      Gets the view that the prompt is targeting.
      Returns:
      The target view or null if not set or targeting a position.
    • setTarget

      @NonNull public T setTarget​(float left, float top)
      Set the centre point as a screen position
      Parameters:
      left - Centre point from screen left
      top - Centre point from screen top
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getTargetPosition

      @Nullable public android.graphics.PointF getTargetPosition()
      Get the position on the screen that is being targeted.
      Returns:
      The target position or null if targeting a view.
    • setTargetRenderView

      @NonNull public T setTargetRenderView​(@Nullable android.view.View view)
      Change the view that is rendered as the target. By default the view from setTarget(View) is rendered as the target.
      Parameters:
      view - The view to use to render the prompt target
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getTargetRenderView

      @Nullable public android.view.View getTargetRenderView()
      Get the view that is rendered as the target.
      Returns:
      The view used to render the prompt target.
    • isTargetSet

      public boolean isTargetSet()
      Has the target been set successfully?
      Returns:
      True if set successfully.
    • setPrimaryText

      @NonNull public T setPrimaryText​(@StringRes int resId)
      Set the primary text using the given resource id.
      Parameters:
      resId - The string resource id for the primary text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setPrimaryText

      @NonNull public T setPrimaryText​(@Nullable java.lang.String text)
      Set the primary text to the given string
      Parameters:
      text - The primary text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setPrimaryText

      @NonNull public T setPrimaryText​(@Nullable java.lang.CharSequence text)
      Set the primary text to the given CharSequence. It is recommended that you don't go crazy with custom Spannables.
      Parameters:
      text - The primary text as CharSequence
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPrimaryText

      @Nullable public java.lang.CharSequence getPrimaryText()
      Get the text to draw for the primary text.
      Returns:
      The primary text.
    • setPrimaryTextSize

      @NonNull public T setPrimaryTextSize​(@Dimension float size)
      Set the primary text font size.
      Parameters:
      size - The primary text font size
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setPrimaryTextSize

      @NonNull public T setPrimaryTextSize​(@DimenRes int resId)
      Set the primary text font size using the given resource id.
      Parameters:
      resId - The resource id for the primary text size
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPrimaryTextSize

      @Dimension public float getPrimaryTextSize()
      Get the primary text font size.
      Returns:
      The primary text font size.
    • setPrimaryTextColour

      @NonNull public T setPrimaryTextColour​(int colour)
      Set the primary text colour.
      Parameters:
      colour - The primary text colour resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPrimaryTextColour

      public int getPrimaryTextColour()
      Gets the primary text font colour.
      Returns:
      The primary text font colour.
    • setPrimaryTextTypeface

      @NonNull public T setPrimaryTextTypeface​(@Nullable android.graphics.Typeface typeface)
      Sets the typeface and style used to display the primary text.
      Parameters:
      typeface - The primary text typeface
    • setPrimaryTextTypeface

      @NonNull public T setPrimaryTextTypeface​(@Nullable android.graphics.Typeface typeface, int style)
      Sets the typeface used to display the primary text.
      Parameters:
      typeface - The primary text typeface
      style - The typeface style
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPrimaryTextTypeface

      @Nullable public android.graphics.Typeface getPrimaryTextTypeface()
      Get the typeface for the primary text.
      Returns:
      The primary text typeface.
    • getPrimaryTextTypefaceStyle

      public int getPrimaryTextTypefaceStyle()
      Get the primary text typeface style.
      Returns:
      the primary text typeface style.
    • setSecondaryText

      @NonNull public T setSecondaryText​(@StringRes int resId)
      Set the secondary text using the given resource id.
      Parameters:
      resId - The secondary text resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setSecondaryText

      @NonNull public T setSecondaryText​(@Nullable java.lang.String text)
      Set the secondary text.
      Parameters:
      text - The secondary text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setSecondaryText

      @NonNull public T setSecondaryText​(@Nullable java.lang.CharSequence text)
      Set the secondary text. It is recommended that you don't go crazy with custom Spannables.
      Parameters:
      text - The secondary text as a CharSequence
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getSecondaryText

      @Nullable public java.lang.CharSequence getSecondaryText()
      Get the secondary text.
      Returns:
      The secondary text.
    • setSecondaryTextSize

      @NonNull public T setSecondaryTextSize​(@DimenRes int resId)
      Set the secondary text font size using the give resource id.
      Parameters:
      resId - The secondary text string resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setSecondaryTextSize

      @NonNull public T setSecondaryTextSize​(@Dimension float size)
      Set the secondary text font size.
      Parameters:
      size - The secondary text font size
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getSecondaryTextSize

      @Dimension public float getSecondaryTextSize()
      Get the secondary text size.
      Returns:
      The secondary text size.
    • setSecondaryTextColour

      @NonNull public T setSecondaryTextColour​(int colour)
      Set the secondary text colour.
      Parameters:
      colour - The secondary text colour resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getSecondaryTextColour

      public int getSecondaryTextColour()
      Get the secondary text colour.
      Returns:
      The secondary text colour.
    • setSecondaryTextTypeface

      @NonNull public T setSecondaryTextTypeface​(@Nullable android.graphics.Typeface typeface)
      Sets the typeface used to display the secondary text.
      Parameters:
      typeface - The secondary text typeface
    • setSecondaryTextTypeface

      @NonNull public T setSecondaryTextTypeface​(@Nullable android.graphics.Typeface typeface, int style)
      Sets the typeface and style used to display the secondary text.
      Parameters:
      typeface - The secondary text typeface
      style - The typeface style
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getSecondaryTextTypeface

      @Nullable public android.graphics.Typeface getSecondaryTextTypeface()
      Get the secondary text typeface.
      Returns:
      The secondary text typeface.
    • getSecondaryTextTypefaceStyle

      public int getSecondaryTextTypefaceStyle()
      Get the secondary text typeface style.
      Returns:
      The secondary text typeface style.
    • setContentDescription

      @NonNull public T setContentDescription​(@StringRes int resId)
      Set the accessibility content description text using the given resource id.
      Parameters:
      resId - The string resource id for the accessibility content description text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setContentDescription

      @NonNull public T setContentDescription​(@Nullable java.lang.String text)
      Set the accessibility content description text to the given string
      Parameters:
      text - The accessibility content description text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getContentDescription

      @Nullable public java.lang.String getContentDescription()
      Get the text for the accessibility content description. Defaults to a concatenation of primary and secondary texts.
      Returns:
      The accessibility content description text.
    • setTextPadding

      @NonNull public T setTextPadding​(@DimenRes int resId)
      Set the text left and right padding using the given resource id.
      Parameters:
      resId - The text padding dimension resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setTextPadding

      @NonNull public T setTextPadding​(@Dimension float padding)
      Set the text left and right padding.
      Parameters:
      padding - The padding on the text left and right
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getTextPadding

      @Dimension public float getTextPadding()
      Get the text left and right padding.
      Returns:
      The text left and right padding.
    • setTextSeparation

      @NonNull public T setTextSeparation​(@DimenRes int resId)
      Set the distance between the primary and secondary text using the given resource id.
      Parameters:
      resId - The dimension resource id for the text separation
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setTextSeparation

      @NonNull public T setTextSeparation​(@Dimension float separation)
      Set the distance between the primary and secondary text.
      Parameters:
      separation - The distance separation between the primary and secondary text
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getTextSeparation

      @Dimension public float getTextSeparation()
      Get the distance between the primary and secondary text.
      Returns:
      the distance between the primary and secondary text.
    • setFocalPadding

      @NonNull public T setFocalPadding​(@DimenRes int resId)
      Set the padding between the text and the focal point using the given resource id.
      Parameters:
      resId - The dimension resource id for the focal to text distance
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setFocalPadding

      @NonNull public T setFocalPadding​(@Dimension float padding)
      Set the padding between the text and the focal point.
      Parameters:
      padding - The distance between the text and focal
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getFocalPadding

      @Dimension public float getFocalPadding()
      Get the padding between the text and the focal.
      Returns:
      The padding between the text and the focal.
    • setAnimationInterpolator

      @NonNull public T setAnimationInterpolator​(@Nullable android.view.animation.Interpolator interpolator)
      Set the interpolator to use in animations.
      Parameters:
      interpolator - The animation interpolator to use
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getAnimationInterpolator

      @Nullable public android.view.animation.Interpolator getAnimationInterpolator()
      Get the animation interpolator that is used.
      Returns:
      The animation interpolator that is used.
    • setIdleAnimationEnabled

      @NonNull public T setIdleAnimationEnabled​(boolean enabled)
      Enable/disable focal animation. true by default
      Parameters:
      enabled - Idle animation enabled
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getIdleAnimationEnabled

      public boolean getIdleAnimationEnabled()
      Is the focal animation enabled.
      Returns:
      True if the idle animation is enabled.
    • setIcon

      @NonNull public T setIcon​(@DrawableRes int resId)
      Set the icon to draw in the focal point using the given resource id.
      Parameters:
      resId - The drawable resource id for the icon
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setIconDrawable

      @NonNull public T setIconDrawable​(@Nullable android.graphics.drawable.Drawable drawable)
      Set the icon to draw in the focal point.
      Parameters:
      drawable - The drawable for the icon
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getIconDrawable

      @Nullable public android.graphics.drawable.Drawable getIconDrawable()
      Get the icon drawn as the target.
      Returns:
      The icon drawn as the target.
    • setIconDrawableTintList

      @NonNull public T setIconDrawableTintList​(@Nullable android.content.res.ColorStateList tint)
      Applies a tint to the icon drawable
      Parameters:
      tint - the tint to apply to the icon drawable, null will remove the tint.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setIconDrawableTintMode

      @NonNull public T setIconDrawableTintMode​(@Nullable android.graphics.PorterDuff.Mode tintMode)
      Sets the PorterDuff mode to use to apply the tint.
      Parameters:
      tintMode - the tint mode to use on the icon drawable, null will remove the tint.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setIconDrawableColourFilter

      @NonNull public T setIconDrawableColourFilter​(int colour)
      Sets the colour to use to tint the icon drawable.
      Parameters:
      colour - The colour to use to tint the icon drawable, call setIconDrawableTintList(ColorStateList) or setIconDrawableTintMode(PorterDuff.Mode) with null to remove the tint.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setPromptStateChangeListener

      @NonNull public T setPromptStateChangeListener​(@Nullable MaterialTapTargetPrompt.PromptStateChangeListener listener)
      Set the listener to listen for when the prompt state changes.
      Parameters:
      listener - The listener to use
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setSequenceListener

      public void setSequenceListener​(@Nullable MaterialTapTargetPrompt.PromptStateChangeListener listener)
      Set the internal listener to listen for when the prompt state changes. This does not return a builder is it's not intended to be user during the creation of Prompts
      Parameters:
      listener - The listener to use
    • onPromptStateChanged

      public void onPromptStateChanged​(@NonNull MaterialTapTargetPrompt prompt, int state)
      Handles emitting the prompt state changed events.
      Parameters:
      state - The state that the prompt is now in.
    • onExtraPromptStateChanged

      public void onExtraPromptStateChanged​(@NonNull MaterialTapTargetPrompt prompt, int state)
      Handles emitting the additional prompt state changed events.
      Parameters:
      state - The state that the prompt is now in.
    • setCaptureTouchEventOnFocal

      @NonNull public T setCaptureTouchEventOnFocal​(boolean captureTouchEvent)
      Set if the prompt should stop touch events on the focal point from passing to underlying views. Default is false.
      Parameters:
      captureTouchEvent - True to capture touch events in the prompt
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getCaptureTouchEventOnFocal

      public boolean getCaptureTouchEventOnFocal()
      Get if the prompt should stop touch events on the focal point from passing to underlying views.
      Returns:
      True to capture touch events in the prompt
    • setMaxTextWidth

      @NonNull public T setMaxTextWidth​(@DimenRes int resId)
      Set the max width that the primary and secondary text can be using the given resource id.
      Parameters:
      resId - The dimension resource id for the max width that the text can reach
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setMaxTextWidth

      @NonNull public T setMaxTextWidth​(@Dimension float width)
      Set the max width that the primary and secondary text can be.
      Parameters:
      width - The max width that the text can reach
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getMaxTextWidth

      @Dimension public float getMaxTextWidth()
      Get the maximum width that the primary and secondary text can be.
      Returns:
      The maximum text width.
    • setBackgroundColour

      @NonNull public T setBackgroundColour​(int colour)
      Set the background colour. The Material Design Guidelines specify that this should be 244 or hex F4.
      Parameters:
      colour - The background colour colour resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getBackgroundColour

      public int getBackgroundColour()
      Get the background colour.
      Returns:
      The background colour.
    • setFocalColour

      @NonNull public T setFocalColour​(int colour)
      Set the focal point colour.
      Parameters:
      colour - The focal colour colour resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getFocalColour

      public int getFocalColour()
      Get the focal point colour.
      Returns:
      The focal point colour.
    • setFocalRadius

      @NonNull public T setFocalRadius​(@DimenRes int resId)
      Set the focal point radius using the given resource id.
      Parameters:
      resId - The focal radius dimension resource id
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setFocalRadius

      @NonNull public T setFocalRadius​(@Dimension float radius)
      Set the focal point radius.
      Parameters:
      radius - The focal radius
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getFocalRadius

      @Dimension public float getFocalRadius()
      Get the focal point radius for the circle prompt focal.
      Returns:
      The radius used for the circle prompt focal.
    • setAutoDismiss

      @NonNull public T setAutoDismiss​(boolean autoDismiss)
      Set whether the prompt should dismiss itself when a touch event occurs outside the focal. Default is true. Listen for the MaterialTapTargetPrompt.STATE_NON_FOCAL_PRESSED event in the setPromptStateChangeListener(MaterialTapTargetPrompt.PromptStateChangeListener) to handle the prompt being pressed outside the focal area.
      Parameters:
      autoDismiss - True - prompt will dismiss when touched outside the focal, false - no action taken.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getAutoDismiss

      public boolean getAutoDismiss()
      Get whether the prompt should dismiss itself when a touch event occurs outside the focal.
      Returns:
      True - prompt will dismiss when touched outside the focal, false - no action taken.
    • setAutoFinish

      @NonNull public T setAutoFinish​(boolean autoFinish)
      Set whether the prompt should finish itself when a touch event occurs inside the focal. Default is true. Listen for the MaterialTapTargetPrompt.STATE_FOCAL_PRESSED event in the setPromptStateChangeListener(MaterialTapTargetPrompt.PromptStateChangeListener) to handle the prompt target being pressed.
      Parameters:
      autoFinish - True - prompt will finish when touched inside the focal, false - no action taken.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getAutoFinish

      public boolean getAutoFinish()
      Get if the prompt should finish itself when a touch event occurs inside the focal.
      Returns:
      True if the prompt should finish itself when a touch event occurs inside the focal.
    • setCaptureTouchEventOutsidePrompt

      @NonNull public T setCaptureTouchEventOutsidePrompt​(boolean captureTouchEventOutsidePrompt)
      Set if the prompt should stop touch events outside the prompt from passing to underlying views. Default is false.
      Parameters:
      captureTouchEventOutsidePrompt - True to capture touch events out side the prompt
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getCaptureTouchEventOutsidePrompt

      public boolean getCaptureTouchEventOutsidePrompt()
      Get if the prompt should stop touch events outside the prompt from passing to underlying views.
      Returns:
      True if touch events will not be passed to views below the prompt.
    • setTextGravity

      @NonNull public T setTextGravity​(int gravity)
      Set the primary and secondary text horizontal layout gravity. Default: Gravity.START
      Parameters:
      gravity - The horizontal gravity
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • setPrimaryTextGravity

      @NonNull public T setPrimaryTextGravity​(int gravity)
      Set the primary text horizontal layout gravity. Default: Gravity.START
      Parameters:
      gravity - The horizontal gravity
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPrimaryTextGravity

      public int getPrimaryTextGravity()
      Gets the gravity for the primary text.
      Returns:
      The primary texts gravity.
    • setSecondaryTextGravity

      @NonNull public T setSecondaryTextGravity​(int gravity)
      Set the secondary text horizontal layout gravity. Default: Gravity.START
      Parameters:
      gravity - The horizontal gravity
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getSecondaryTextGravity

      public int getSecondaryTextGravity()
      Gets the gravity for the secondary text.
      Returns:
      The secondary texts gravity.
    • setClipToView

      @NonNull public T setClipToView​(@Nullable android.view.View view)
      Set the view to clip the prompt to. The prompt won't draw outside the bounds of this view. Default: R.id.content

      Null can be used to stop the prompt being clipped to a view.

      Parameters:
      view - The view to clip to
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getClipToView

      @Nullable public android.view.View getClipToView()
      Get the view that the prompt canvas is clipped to. The prompt won't draw outside the bounds of this view.
      Returns:
      The view that the prompt canvas is clipped to.
    • setBackButtonDismissEnabled

      @NonNull public T setBackButtonDismissEnabled​(boolean enabled)
      Back button can be used to dismiss the prompt. Default: true
      Parameters:
      enabled - True for back button dismiss enabled
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getBackButtonDismissEnabled

      public boolean getBackButtonDismissEnabled()
      Will the pressing the system back button dismiss the prompt.
      Returns:
      True if pressing the system back button will dismiss the prompt, false otherwise.
    • setPromptBackground

      @NonNull public T setPromptBackground​(@NonNull PromptBackground promptBackground)
      Sets the renderer for the prompt background.
      Parameters:
      promptBackground - The background shape to use.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPromptBackground

      @NonNull public PromptBackground getPromptBackground()
      Get the prompt focal renderer.
      Returns:
      The prompt focal instance.
    • setPromptFocal

      @NonNull public T setPromptFocal​(@NonNull PromptFocal promptFocal)
      Sets the renderer for the prompt focal.
      Parameters:
      promptFocal - The focal shape to use.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPromptFocal

      @NonNull public PromptFocal getPromptFocal()
      Get the prompt focal renderer.
      Returns:
      The prompt focal instance.
    • setPromptText

      @NonNull public T setPromptText​(@NonNull PromptText promptText)
      Set the PromptText implementation to use to render the prompt text.
      Parameters:
      promptText - The prompt text implementation.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • getPromptText

      @NonNull public PromptText getPromptText()
      Get the PromptText implementation used to render the prompt text.
      Returns:
      This Builder object to allow for chaining of calls to set methods
    • create

      @Nullable public MaterialTapTargetPrompt create()
      Creates an MaterialTapTargetPrompt with the arguments supplied to this builder.

      Calling this method does not display the prompt. If no additional processing is needed, show() may be called instead to both create and display the prompt.

      Will return null if a valid target has not been set or the primary text is null. To check that a valid target has been set call isTargetSet().

      Returns:
      The created builder or null if no target
    • show

      @Nullable public MaterialTapTargetPrompt show()
      Creates a MaterialTapTargetPrompt with the arguments supplied to this builder and immediately displays the prompt.

      Calling this method is functionally identical to:

           MaterialTapTargetPrompt prompt = builder.create();
           prompt.show();
       

      Will return null if a valid target has not been set or the primary text and secondary text are null. To check that a valid target has been set call isTargetSet().

      Returns:
      The created builder or null if no target
    • showFor

      @Nullable public MaterialTapTargetPrompt showFor​(long milliseconds)
      Creates a MaterialTapTargetPrompt with the arguments supplied to this builder and immediately displays the prompt for the number of milliseconds supplied.

      Calling this method is functionally identical to:

           MaterialTapTargetPrompt prompt = builder.create();
           prompt.showFor(milliseconds);
       

      Will return null if a valid target has not been set or the primary text and secondary text are null. To check that a valid target has been set call isTargetSet().

      Parameters:
      milliseconds - The number of milliseconds to show the prompt for.
      Returns:
      The created builder or null if no target