diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicBitmapUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicBitmapUtils.java index 62ec359..65d2853 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicBitmapUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicBitmapUtils.java @@ -40,19 +40,19 @@ public class DynamicBitmapUtils { * * @return The bitmap from the supplied drawable. */ - public @Nullable static Bitmap getBitmapFormDrawable(@NonNull Drawable drawable) { - try { - Bitmap bitmap; - - bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), - drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - - return bitmap; - } catch (Exception ignored) { + public @Nullable static Bitmap getBitmapFormDrawable(@Nullable Drawable drawable) { + if (drawable != null) { + try { + Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), + drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + + return bitmap; + } catch (Exception ignored) { + } } return null; diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicTaskUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicTaskUtils.java index 02eb5d0..c1f59fb 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicTaskUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicTaskUtils.java @@ -36,12 +36,8 @@ public static void executeTask(@Nullable AsyncTask asyncTask) { try { if (asyncTask != null && asyncTask.getStatus() != AsyncTask.Status.RUNNING) { - if (DynamicVersionUtils.isHoneycomb()) { - asyncTask.executeOnExecutor( - AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) null); - } else { - asyncTask.execute((Object[]) null); - } + asyncTask.executeOnExecutor( + AsyncTask.THREAD_POOL_EXECUTOR, (Object[]) null); } } catch (Exception ignored) { } diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicVersionUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicVersionUtils.java index a06e4e4..09b0c47 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicVersionUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicVersionUtils.java @@ -27,103 +27,123 @@ public class DynamicVersionUtils { /** - * To detect if the current Android version is Gingerbread or above. + * To detect if the current Android version is Ice Cream Sandwich or above. * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#GINGERBREAD}. - * - * @deprecated Minimum SDK is now {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. */ - public static boolean isGingerbread() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD; + public static boolean isIceCreamSandwich() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; } /** - * To detect if the current Android version is Gingerbread MR1 or above. + * To detect if the current Android version is Ice Cream Sandwich or above. * - * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#GINGERBREAD_MR1}. + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). * - * @deprecated Minimum SDK is now {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. */ - public static boolean isGingerbreadMR1() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1; + public static boolean isIceCreamSandwich(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH + : isIceCreamSandwich(); } /** - * To detect if the current Android version is Honeycomb or above. + * To detect if the current Android version is Ice Cream Sandwich MR1 or above. * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#HONEYCOMB}. - * - * @deprecated Minimum SDK is now {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1}. */ - public static boolean isHoneycomb() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; + public static boolean isIceCreamSandwichMR1() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1; } /** - * To detect if the current Android version is Honeycomb MR1 or above. + * To detect if the current Android version is Ice Cream Sandwich MR1 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#HONEYCOMB_MR1}. + * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1}. + */ + public static boolean isIceCreamSandwichMR1(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1 + : isIceCreamSandwichMR1(); + } + + /** + * To detect if the current Android version is Jelly Bean or above. * - * @deprecated Minimum SDK is now {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#JELLY_BEAN}. */ - public static boolean isHoneycombMR1() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1; + public static boolean isJellyBean() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; } /** - * To detect if the current Android version is Honeycomb MR2 or above. + * To detect if the current Android version is Jelly Bean or above. * - * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#HONEYCOMB_MR2}. + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). * - * @deprecated Minimum SDK is now {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#JELLY_BEAN}. */ - public static boolean isHoneycombMR2() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2; + public static boolean isJellyBean(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN + : isJellyBean(); } /** - * To detect if the current Android version is Ice Cream Sandwich or above. + * To detect if the current Android version is Jelly Bean MR1 or above. * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH}. + * {@link Build.VERSION_CODES#JELLY_BEAN_MR1}. */ - public static boolean isIceCreamSandwich() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; + public static boolean isJellyBeanMR1() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; } /** - * To detect if the current Android version is Ice Cream Sandwich MR1 or above. + * To detect if the current Android version is Jelly Bean MR1 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#ICE_CREAM_SANDWICH_MR1}. + * {@link Build.VERSION_CODES#JELLY_BEAN_MR1}. */ - public static boolean isIceCreamSandwichMR1() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1; + public static boolean isJellyBeanMR1(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 + : isJellyBeanMR1(); } /** - * To detect if the current Android version is JellyBean or above. + * To detect if the current Android version is Jelly Bean MR2 or above. * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#JELLY_BEAN}. + * {@link Build.VERSION_CODES#JELLY_BEAN_MR2}. */ - public static boolean isJellyBean() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN; + public static boolean isJellyBeanMR2() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2; } /** - * To detect if the current Android version is JellyBean MR1 or above. + * To detect if the current Android version is Jelly Bean MR2 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). * * @return {@code true} if current version is greater than or equal to - * {@link Build.VERSION_CODES#JELLY_BEAN_MR1}. + * {@link Build.VERSION_CODES#JELLY_BEAN_MR2}. */ - public static boolean isJellyBeanMR1() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1; + public static boolean isJellyBeanMR2(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2 + : isJellyBeanMR2(); } /** @@ -136,6 +156,44 @@ public static boolean isKitKat() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT; } + /** + * To detect if the current Android version is KitKat or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#KITKAT}. + */ + public static boolean isKitKat(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT + : isKitKat(); + } + + /** + * To detect if the current Android version is KitKat Watch or above. + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#KITKAT_WATCH}. + */ + public static boolean isKitKatWatch() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH; + } + + /** + * To detect if the current Android version is KitKat Watch or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#KITKAT_WATCH}. + */ + public static boolean isKitKatWatch(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT_WATCH + : isKitKatWatch(); + } + /** * To detect if the current Android version is Lollipop or above. * @@ -146,6 +204,20 @@ public static boolean isLollipop() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; } + /** + * To detect if the current Android version is Lollipop or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#LOLLIPOP}. + */ + public static boolean isLollipop(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP + : isLollipop(); + } + /** * To detect if the current Android version is Lollipop MR1 or above. * @@ -157,7 +229,21 @@ public static boolean isLollipopMR1() { } /** - * To detect if the current Android version is M or above. + * To detect if the current Android version is Lollipop MR1 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#LOLLIPOP_MR1}. + */ + public static boolean isLollipopMR1(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 + : isLollipopMR1(); + } + + /** + * To detect if the current Android version is Marshmallow or above. * * @return {@code true} if current version is greater than or equal to * {@link Build.VERSION_CODES#M}. @@ -167,7 +253,21 @@ public static boolean isMarshmallow() { } /** - * To detect if the current Android version is N or above. + * To detect if the current Android version is Marshmallow or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#M}. + */ + public static boolean isMarshmallow(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.M + : isMarshmallow(); + } + + /** + * To detect if the current Android version is Nougat or above. * * @return {@code true} if current version is greater than or equal to * {@link Build.VERSION_CODES#N}. @@ -177,7 +277,21 @@ public static boolean isNougat() { } /** - * To detect if the current Android version is N_MR1 or above. + * To detect if the current Android version is Nougat or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#N}. + */ + public static boolean isNougat(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.N + : isNougat(); + } + + /** + * To detect if the current Android version is Nougat MR1 or above. * * @return {@code true} if current version is greater than or equal to * {@link Build.VERSION_CODES#N_MR1}. @@ -187,7 +301,21 @@ public static boolean isNougatMR1() { } /** - * To detect if the current Android version is O or above. + * To detect if the current Android version is Nougat MR1 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#N_MR1}. + */ + public static boolean isNougatMR1(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1 + : isNougatMR1(); + } + + /** + * To detect if the current Android version is Oreo or above. * * @return {@code true} if current version is greater than or equal to * {@link Build.VERSION_CODES#O}. @@ -197,7 +325,21 @@ public static boolean isOreo() { } /** - * To detect if the current Android version is O_MR1 or above. + * To detect if the current Android version is Oreo or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#O}. + */ + public static boolean isOreo(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.O + : isOreo(); + } + + /** + * To detect if the current Android version is Oreo MR1 or above. * * @return {@code true} if current version is greater than or equal to * {@link Build.VERSION_CODES#O_MR1}. @@ -205,4 +347,18 @@ public static boolean isOreo() { public static boolean isOreoMR1() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1; } + + /** + * To detect if the current Android version is Oreo MR1 or above. + * + * @param equals {@code true} to match equal (==). + * {@code false} to match greater than or equal (>=). + * + * @return {@code true} if current version is greater than or equal to + * {@link Build.VERSION_CODES#O_MR1}. + */ + public static boolean isOreoMR1(boolean equals) { + return equals ? Build.VERSION.SDK_INT == Build.VERSION_CODES.O_MR1 + : isOreoMR1(); + } }