Class DynamicToast


  • public class DynamicToast
    extends java.lang.Object
    Helper class to display themed Toast with icon and text.

    If no color is supplied, it will display default toast based on the vanilla Android.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DynamicToast.Config
      Configuration class to customise the DynamicToast attributes.
    • Constructor Summary

      Constructors 
      Constructor Description
      DynamicToast()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text)
      Make a standard toast that just contains a text view.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, int duration)
      Make a standard toast that just contains a text view.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, android.graphics.drawable.Drawable icon)
      Make a error toast with icon and the text.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, android.graphics.drawable.Drawable icon, int duration)
      Make a themed toast with icon and the text.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, android.graphics.drawable.Drawable icon, java.lang.Integer tintColor, java.lang.Integer backgroundColor)
      Make a themed toast with text, icon, background and the tint color.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, android.graphics.drawable.Drawable icon, java.lang.Integer tintColor, java.lang.Integer backgroundColor, int duration)
      Make a themed toast with text, icon, background and the tint color.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, java.lang.Integer tintColor, java.lang.Integer backgroundColor)
      Make a themed toast with icon and the text.
      static android.widget.Toast make​(android.content.Context context, java.lang.CharSequence text, java.lang.Integer tintColor, java.lang.Integer backgroundColor, int duration)
      Make a themed toast with text, background and the tint color.
      static android.widget.Toast makeError​(android.content.Context context, java.lang.CharSequence text)
      Make a error toast with icon and the text.
      static android.widget.Toast makeError​(android.content.Context context, java.lang.CharSequence text, int duration)
      Make a error toast with icon and the text.
      static android.widget.Toast makeSuccess​(android.content.Context context, java.lang.CharSequence text)
      Make a success toast with icon and the text.
      static android.widget.Toast makeSuccess​(android.content.Context context, java.lang.CharSequence text, int duration)
      Make a success toast with icon and the text.
      static android.widget.Toast makeWarning​(android.content.Context context, java.lang.CharSequence text)
      Make a warning toast with icon and the text.
      static android.widget.Toast makeWarning​(android.content.Context context, java.lang.CharSequence text, int duration)
      Make a warning toast with icon and the text.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DynamicToast

        public DynamicToast()
    • Method Detail

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text)
        Make a standard toast that just contains a text view.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                int duration)
        Make a standard toast that just contains a text view.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeError

        @NonNull
        public static android.widget.Toast makeError​(@NonNull
                                                     android.content.Context context,
                                                     @Nullable
                                                     java.lang.CharSequence text)
        Make a error toast with icon and the text.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeError

        @NonNull
        public static android.widget.Toast makeError​(@NonNull
                                                     android.content.Context context,
                                                     @Nullable
                                                     java.lang.CharSequence text,
                                                     int duration)
        Make a error toast with icon and the text.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeSuccess

        @NonNull
        public static android.widget.Toast makeSuccess​(@NonNull
                                                       android.content.Context context,
                                                       @Nullable
                                                       java.lang.CharSequence text)
        Make a success toast with icon and the text.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeSuccess

        @NonNull
        public static android.widget.Toast makeSuccess​(@NonNull
                                                       android.content.Context context,
                                                       @Nullable
                                                       java.lang.CharSequence text,
                                                       int duration)
        Make a success toast with icon and the text.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeWarning

        @NonNull
        public static android.widget.Toast makeWarning​(@NonNull
                                                       android.content.Context context,
                                                       @Nullable
                                                       java.lang.CharSequence text)
        Make a warning toast with icon and the text.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • makeWarning

        @NonNull
        public static android.widget.Toast makeWarning​(@NonNull
                                                       android.content.Context context,
                                                       @Nullable
                                                       java.lang.CharSequence text,
                                                       int duration)
        Make a warning toast with icon and the text.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable
                                                android.graphics.drawable.Drawable icon)
        Make a error toast with icon and the text.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        icon - The toast icon to show.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable
                                                android.graphics.drawable.Drawable icon,
                                                int duration)
        Make a themed toast with icon and the text.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        icon - The toast icon to show.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable @ColorInt
                                                java.lang.Integer tintColor,
                                                @Nullable @ColorInt
                                                java.lang.Integer backgroundColor)
        Make a themed toast with icon and the text.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        tintColor - The toast tint color based on the toast background.

        It will automatically check for the contrast to provide best visibility.

        backgroundColor - The toast background color.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable @ColorInt
                                                java.lang.Integer tintColor,
                                                @Nullable @ColorInt
                                                java.lang.Integer backgroundColor,
                                                int duration)
        Make a themed toast with text, background and the tint color.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        tintColor - The toast tint color based on the toast background.

        It will automatically check for the contrast to provide best visibility.

        backgroundColor - The toast background color.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable
                                                android.graphics.drawable.Drawable icon,
                                                @Nullable @ColorInt
                                                java.lang.Integer tintColor,
                                                @Nullable @ColorInt
                                                java.lang.Integer backgroundColor)
        Make a themed toast with text, icon, background and the tint color.

        The toast duration will be Toast.LENGTH_SHORT.

        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        icon - The toast icon to show.
        tintColor - The toast tint color based on the toast background.

        It will automatically check for the contrast to provide best visibility.

        backgroundColor - The toast background color.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.

      • make

        @NonNull
        public static android.widget.Toast make​(@NonNull
                                                android.content.Context context,
                                                @Nullable
                                                java.lang.CharSequence text,
                                                @Nullable
                                                android.graphics.drawable.Drawable icon,
                                                @Nullable @ColorInt
                                                java.lang.Integer tintColor,
                                                @Nullable @ColorInt
                                                java.lang.Integer backgroundColor,
                                                int duration)
        Make a themed toast with text, icon, background and the tint color.
        Parameters:
        context - The context to use.
        text - The text to show. Can be formatted text.
        icon - The toast icon to show.
        tintColor - The toast tint color based on the toast background.

        It will automatically check for the contrast to provide best visibility.

        backgroundColor - The toast background color.
        duration - The duration for the toast, either Toast.LENGTH_SHORT or Toast.LENGTH_LONG.
        Returns:
        The toast with the supplied parameters.

        Use Toast.show() to display the toast.