Package 

Class FlexibleUtils


  • 
    public final class FlexibleUtils
    
                        

    Set of utility methods most used in all applications.

    • Method Detail

      • hasOreo

         static boolean hasOreo()

        API 26

      • hasNougat

         static boolean hasNougat()

        API 24

      • highlightText

         static void highlightText(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraint)

        Sets a spannable text with the accent color into the provided TextView.

        Multiple matches will be highlighted, but if the 2nd match is consecutive,the highlight is skipped.

        Internally calls fetchAccentColor.
        Parameters:
        textView - the TextView to transform and which the originalText is assigned to
        originalText - the original text which the transformation is applied to
        constraint - the text to highlight
      • highlightText

         static void highlightText(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraint, @ColorInt() int color)

        Sets a spannable text with any highlight color into the provided TextView.

        Multiple matches will be highlighted, but if the 2nd match is consecutive,the highlight is skipped.

        Parameters:
        textView - the TextView to transform and which the originalText is assigned to
        originalText - the original text which the transformation is applied to
        constraint - the text to highlight
        color - the highlight color
      • highlightWords

         static void highlightWords(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraints)

        Sets a spannable text with the accent color for each word provided by theconstraint text into the provided TextView.

        Note:

        • Words are automatically split by {@code "([, ]+)"} regular expression.
        • To Actually see the text highlighted, the filter must check words too.
        • Internally calls fetchAccentColor.
        Parameters:
        textView - the TextView to transform and which the originalText is assigned to
        originalText - the original text which the transformation is applied to
        constraints - the multiple words to highlight
      • highlightWords

         static void highlightWords(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraints, @ColorInt() int color)

        Sets a spannable text with any highlight color for each word provided by theconstraint text into the provided TextView.

        Note:

        • Words are automatically split by {@code "([, ]+)"} regular expression.
        • To Actually see the text highlighted, the filter must check words too.
        Parameters:
        textView - the TextView to transform and which the originalText is assigned to
        originalText - the original text which the transformation is applied to
        constraints - the multiple words to highlight
        color - the highlight color
      • formatDateTime

         static String formatDateTime(Date date)

        Predefined format: dd MMM yyyy HH:mm:ss z

        Parameters:
        date - the date to format
      • formatDateTime

         static String formatDateTime(Date date, String format)

        Date formatter with the provided format.

        Parameters:
        date - the date to format
        format - the format to apply
      • adjustAlpha

         static int adjustAlpha(@ColorInt() int color, @IntRange(from = 0, to = 255) int alpha)

        Adjusts the alpha of a color.

        Parameters:
        color - the color
        alpha - the alpha value we want to set 0-255
      • resetAccentColor

         static void resetAccentColor()

        Reset the internal accent color to INVALID_COLOR, to give the possibilityto re-fetch it at runtime, since once it is fetched it cannot be changed.

      • fetchAccentColor

         static int fetchAccentColor(Context context, @ColorInt() int defColor)

        Optimized method to fetch the accent color on devices with at least Lollipop.

        If accent color has been already fetched it is simply returned.

        Parameters:
        context - context
        defColor - value to return if the accentColor cannot be found
      • reveal

         static void reveal(View view, int centerX, int centerY)

        Create the reveal effect animation.

        Parameters:
        view - the View to reveal
        centerX - the x coordinate of the center of the animating circle, relative to view.
        centerY - the y coordinate of the center of the animating circle, relative to view.
      • unReveal

         static void unReveal(View view, int centerX, int centerY)

        Create the un-reveal effect animation.

        View will be set as visibility GONE.

        Parameters:
        view - the View to reveal
        centerX - the x coordinate of the center of the animating circle, relative to view.
        centerY - the y coordinate of the center of the animating circle, relative to view.