diff --git a/README.md b/README.md index cd72173..50a32fa 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ package, tasks and sdk on Android 9+ (Gingerbread or above) devices. 6. [DynamicTaskUtils](https://github.com/pranavpandey/dynamic-utils#dynamictaskutils) 7. [DynamicVersionUtils](https://github.com/pranavpandey/dynamic-utils#dynamicversionutils) 8. [DynamicWindowUtils](https://github.com/pranavpandey/dynamic-utils#dynamicwindowutils) - 9. [Dependency](https://github.com/pranavpandey/dynamic-utils#dependency) + 9. [DynamicUnitUtils](https://github.com/pranavpandey/dynamic-utils#dynamicwindowutils) + 10. [Dependency](https://github.com/pranavpandey/dynamic-utils#dynamicunitutils) 3. [License](https://github.com/pranavpandey/dynamic-utils#license) --- @@ -33,7 +34,7 @@ It can be installed by adding the following dependency to your `build.gradle` fi ```groovy dependencies { - compile 'com.pranavpandey.android:dynamic-utils:0.2.0' + compile 'com.pranavpandey.android:dynamic-utils:0.3.0' } ``` @@ -49,109 +50,127 @@ for more hidden features. Helper class to change colors dynamically. -1. `adjustAlpha(color, factor)` - Adjust alpha of a color according to the given parameter. +1. `@ColorInt int adjustAlpha(color, factor)` - Adjust alpha of a color according to the given +parameter. -2. `calculateContrast(color1, color2) ` - Calculate color contrast difference between two -colors based on luma value according to XYZ color space. +2. `@ColorInt int calculateContrast(color1, color2) ` - Calculate color contrast difference +between two colors based on luma value according to XYZ color space. -3. `getAccentColor(color)` - Calculate accent color based on the given color for dynamic theme -generation. +3. `@ColorInt int getAccentColor(color)` - Calculate accent color based on the given color for +dynamic theme generation. -4. `getColorDarkness(color) ` - Calculate darkness of a color. +4. `@ColorInt int getColorDarkness(color) ` - Calculate darkness of a color. -5. `getContrastColor(color, contrastWithColor)` - Calculate contrast of a color based on the given -base color so that it will be visible always on top of the base color. +5. `@ColorInt int getContrastColor(color, contrastWithColor)` - Calculate contrast of a color +based on the given base color so that it will be visible always on top of the base color. -6. `getLessVisibleColor(color)` - Calculate less visible color of a given color. +6. `@ColorInt int getLessVisibleColor(color)` - Calculate less visible color of a given color. -7. `getTintColor(color)` - Calculate tint based on a given color for better readability. +7. `@ColorInt int getTintColor(color)` - Calculate tint based on a given color for better +readability. -8. `isColorDark(color)` - Detect light or dark color. +8. `boolean isColorDark(color)` - Detect light or dark color. -9. `shiftColor(color, by)` - Shift a color according to the given parameter. +9. `@ColorInt int shiftColor(color, by)` - Shift a color according to the given parameter. ### DynamicDeviceUtils Helper class to detect device specific features like Telephony, etc. -1. `hasTelephony(context)` - To detect if device has telephony feature or not by using PackageManager. +1. `boolean hasTelephony(context)` - To detect if device has telephony feature or not by using +PackageManager. ### DynamicDrawableUtils Helper class to perform Drawable operations. -1. `colorizeDrawable(drawable, wrap, color, mode)` - Colorize and return the mutated drawable so that, -all other references do not change. +1. `void colorizeDrawable(drawable, wrap, color, mode)` - Colorize and return the mutated drawable +so that, all other references do not change. -2. `setBackground(view, drawable)` - Set background of a given view in an efficient way by detecting -the Android SDK at runtime. +2. `Drawable setBackground(view, drawable)` - Set background of a given view in an efficient way +by detecting the Android SDK at runtime. ### DynamicLinkUtils A collection of functions to perform various operations on the URL or to generate intents. -1. `moreApps(context, publisher)` - View other apps of a Publisher in the Google Play or Android -Market. +1. `void shareApp(context, title, message)` - Share application via system default share intent +so that user can select from the available apps if more than one apps are available. -2. `rateApp(context)` - View app in the Google Play or Android Market. +2. `void viewInGooglePlay(context, packageName)` - View app in the Google Play or Android Market. -3. `report(context, appName, email)` - Ask questions or submit bug report to the developer via email. +3. `void rateApp(context)` - View app in the Google Play or Android Market. -4. `shareApp(context, title, message)` - Share application via system default share intent so that -user can select from the available apps if more than one apps are available. +4. `void moreApps(context, publisher)` - View other apps of a Publisher in the Google Play +or Android Market. -5. `viewInGooglePlay(context, packageName)` - View app in the Google Play or Android Market. +5. `void viewUrl(context, url)` - View any URL in the available app or browser. -6. `viewUrl(context, url)` - View any URL in the available app or browser. +6. `void report(context, appName, email)` - Ask questions or submit bug report to the developer +via email. ### DynamicPackageUtils Helper class to get package or app related information. -1. `getAppIcon(context)` - Load application icon from the given context. +1. `ComponentName getComponentName(context)` - Get component name from the given context. -2. `getAppLabel(context)` - Get application label from the given context. +2. `CharSequence getAppLabel(context)` - Get application label from the given context. -3. `getAppVersion(context)` - Get application version name from the given context. +3. `String getAppVersion(context)` - Get application version name from the given context. -4. `getComponentName(context)` - Get component name from the given context. +4. `Drawable getAppIcon(context)` - Load application icon from the given context. -5. `isSystemApp(applicationInfo)` - To detect the given ApplicationInfo is a system app or not. +5. `booelan isSystemApp(applicationInfo)` - To detect the given ApplicationInfo is a system app +or not. ### DynamicTaskUtils Helper class to easily execute or cancel an AsyncTask by handling all the exceptions. -1. `cancelTask(asyncTask)` - Try to cancel the supplied AsyncTask. +1. `void cancelTask(asyncTask)` - Try to cancel the supplied AsyncTask. -2. `executeTask(asyncTask)` - Try to execute the supplied AsyncTask. +2. `void executeTask(asyncTask)` - Try to execute the supplied AsyncTask. ### DynamicVersionUtils Helper class to detect the Android SDK version at runtime so that we can provide the user experience accordingly. -1. `isGingerbread()` - To detect if the current Android version is Gingerbread or above. +1. `boolean isGingerbread()` - To detect if the current Android version is Gingerbread or above. -2. `isIceCreamSandwich()` - To detect if the current Android version is Ice Cream Sandwich or above. +2. `boolean isIceCreamSandwich()` - To detect if the current Android version is Ice Cream Sandwich +or above. ... -10. `isNougat()` - To detect if the current Android version is N or above. +10. `boolean isNougat()` - To detect if the current Android version is N or above. -11. `isNougatMR1()` - To detect if the current Android version is N_MR1 or above. +11. `boolean isNougatMR1()` - To detect if the current Android version is N_MR1 or above. ### DynamicWindowUtils Helper class to perform Window operations and to detect system configurations at runtime. -1. `getAppUsableScreenSize(context)` - Get the app usable screen size. +1. `Point getAppUsableScreenSize(context)` - Get the app usable screen size. -2. `getNavigationBarSize(context)` - Get the on-screen navigation bar size. +2. `Point getRealScreenSize(context)` - Get the real screen size. -3. `getRealScreenSize(context)` - Get the real screen size. +3. `Point getNavigationBarSize(context)` - Get the on-screen navigation bar size. -4. `isNavigationBarThemeSupported(context)` - Detect support for navigation bar theme. +4. `boolean isNavigationBarThemeSupported(context)` - Detect support for navigation bar theme. + +### DynamicUnitUtils + +Helper class to perform unit conversions. + +1. `int convertDpToPixels(dp)` - To convert DP into pixels. + +2. `int convertPixelsToDp(pixels)` - To convert pixels into DP. + +3. `int convertSpToPixels(sp)` - To convert SP into pixels. + +4. `int convertPixelsToSp(pixels)` - To convert pixels into SP. ### Dependency diff --git a/build.gradle b/build.gradle index 85fbe98..8773098 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ ext { issueUrl = 'https://github.com/pranavpandey/dynamic-utils/issues' mavenGroup = 'com.pranavpandey.android' - mavenVersion = '0.2.0' + mavenVersion = '0.3.0' mavenInceptionYear = 2017 mavenArtifactId = 'dynamic-utils' bintrayRepo = 'android' @@ -47,7 +47,7 @@ ext { licenseDistribution = 'repo' allLicenses = ["Apache-2.0"] - versionCode = 2 + versionCode = 3 buildTools = '25.0.3' minSdk = 9 diff --git a/dynamic-utils/build.gradle b/dynamic-utils/build.gradle index 3b7b94d..eee6866 100644 --- a/dynamic-utils/build.gradle +++ b/dynamic-utils/build.gradle @@ -24,7 +24,6 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') compile "com.android.support:support-compat:$androidSupport" } diff --git a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicWindowUtils.java b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicWindowUtils.java index 7073b89..a827943 100644 --- a/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicWindowUtils.java +++ b/dynamic-utils/src/main/java/com/pranavpandey/android/dynamic/utils/DynamicWindowUtils.java @@ -18,7 +18,6 @@ import android.content.Context; import android.graphics.Point; -import android.os.Build; import android.support.annotation.NonNull; import android.view.Display; import android.view.WindowManager; @@ -31,34 +30,6 @@ */ public class DynamicWindowUtils { - /** - * Get the on-screen navigation bar size. - * - * @param context Context to get the resources and window service. - * - * @return On-screen navigation bar in point. - * - * @see android.content.Context#WINDOW_SERVICE - * @see android.graphics.Point - */ - public static Point getNavigationBarSize(@NonNull Context context) { - Point appUsableSize = getAppUsableScreenSize(context); - Point realScreenSize = getRealScreenSize(context); - - // navigation bar on the right - if (appUsableSize.x < realScreenSize.x) { - return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y); - } - - // navigation bar at the bottom - if (appUsableSize.y < realScreenSize.y) { - return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y); - } - - // navigation bar is not present - return new Point(); - } - /** * Get the app usable screen size. * @@ -119,6 +90,34 @@ public static Point getRealScreenSize(@NonNull Context context) { return size; } + /** + * Get the on-screen navigation bar size. + * + * @param context Context to get the resources and window service. + * + * @return On-screen navigation bar in point. + * + * @see android.content.Context#WINDOW_SERVICE + * @see android.graphics.Point + */ + public static Point getNavigationBarSize(@NonNull Context context) { + Point appUsableSize = getAppUsableScreenSize(context); + Point realScreenSize = getRealScreenSize(context); + + // navigation bar on the right + if (appUsableSize.x < realScreenSize.x) { + return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y); + } + + // navigation bar at the bottom + if (appUsableSize.y < realScreenSize.y) { + return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y); + } + + // navigation bar is not present + return new Point(); + } + /** * Detect support for navigation bar theme. *