-
public final class FlexibleUtilsSet of utility methods most used in all applications.
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringDATE_TIME_FORMATpublic final static StringSPLIT_EXPRESSIONpublic final static intINVALID_COLORpublic static intcolorAccent
-
Method Summary
Modifier and Type Method Description static StringgetVersionName(Context context)static intgetVersionCode(Context context)static booleanhasOreo()API 26 static booleanhasNougat()API 24 static booleanhasMarshmallow()API 23 static booleanhasLollipop()API 21 static booleanhasJellyBean()API 16 static voidhighlightText(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraint)Sets a spannable text with the accent color into the provided TextView. static voidhighlightText(@NonNull() TextView textView, @Nullable() String originalText, @Nullable() String constraint, @ColorInt() int color)Sets a spannable text with any highlight color into the provided TextView. static voidhighlightWords(@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. static voidhighlightWords(@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. static StringtoLowerCase(@Nullable() String text)static SpannedfromHtmlCompat(String text)static voidtextAppearanceCompat(TextView textView, @StyleRes() int resId)static StringformatDateTime(Date date)Predefined format: dd MMM yyyy HH:mm:ss zstatic StringformatDateTime(Date date, String format)Date formatter with the provided format. static StringgetModeName(int mode)static StringgetClassName(@Nullable() Object o)static intadjustAlpha(@ColorInt() int color, @IntRange(from = 0, to = 255) int alpha)Adjusts the alpha of a color. static voidresetAccentColor()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. static intfetchAccentColor(Context context, @ColorInt() int defColor)Optimized method to fetch the accent color on devices with at least Lollipop. static PointgetScreenDimensions(Context context)static DisplayMetricsgetDisplayMetrics(Context context)static intdpToPx(Context context, float dp)static voidshowSoftInput(Context context, View view)Show Soft Keyboard with new Thread. static voidhideSoftInput(Activity activity)Show Soft Keyboard with new Thread. static voidhideSoftInputFrom(Context context, View view)Hide Soft Keyboard from Dialogs with new Thread. static voidreveal(View view, int centerX, int centerY)Create the reveal effect animation. static voidunReveal(View view, int centerX, int centerY)Create the un-reveal effect animation. -
-
Method Detail
-
getVersionName
static String getVersionName(Context context)
-
getVersionCode
static int getVersionCode(Context context)
-
hasOreo
static boolean hasOreo()
API 26
-
hasNougat
static boolean hasNougat()
API 24
-
hasMarshmallow
static boolean hasMarshmallow()
API 23
-
hasLollipop
static boolean hasLollipop()
API 21
-
hasJellyBean
static boolean hasJellyBean()
API 16
-
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 tooriginalText- the original text which the transformation is applied toconstraint- 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 tooriginalText- the original text which the transformation is applied toconstraint- the text to highlightcolor- 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 tooriginalText- the original text which the transformation is applied toconstraints- the multiple words to highlight
- Words are automatically split by
-
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 tooriginalText- the original text which the transformation is applied toconstraints- the multiple words to highlightcolor- the highlight color
- Words are automatically split by
-
toLowerCase
@NonNull() static String toLowerCase(@Nullable() String text)
-
fromHtmlCompat
static Spanned fromHtmlCompat(String text)
-
textAppearanceCompat
static void textAppearanceCompat(TextView textView, @StyleRes() int resId)
-
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 formatformat- the format to apply
-
getModeName
@NonNull() static String getModeName(int mode)
-
getClassName
@NonNull() static String getClassName(@Nullable() Object o)
-
adjustAlpha
static int adjustAlpha(@ColorInt() int color, @IntRange(from = 0, to = 255) int alpha)
Adjusts the alpha of a color.
- Parameters:
color- the coloralpha- 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- contextdefColor- value to return if the accentColor cannot be found
-
getScreenDimensions
@NonNull() static Point getScreenDimensions(Context context)
-
getDisplayMetrics
static DisplayMetrics getDisplayMetrics(Context context)
-
showSoftInput
static void showSoftInput(Context context, View view)
Show Soft Keyboard with new Thread.
-
hideSoftInput
static void hideSoftInput(Activity activity)
Show Soft Keyboard with new Thread.
-
hideSoftInputFrom
static void hideSoftInputFrom(Context context, View view)
Hide Soft Keyboard from Dialogs with new Thread.
-
reveal
static void reveal(View view, int centerX, int centerY)
Create the reveal effect animation.
- Parameters:
view- the View to revealcenterX- the x coordinate of the center of the animating circle, relative toview.centerY- the y coordinate of the center of the animating circle, relative toview.
-
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 revealcenterX- the x coordinate of the center of the animating circle, relative toview.centerY- the y coordinate of the center of the animating circle, relative toview.
-
-
-
-