Utility functions to perform dynamic operations on Android.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dynamic-utils Add crash info support for feedback Jan 31, 2019
gradle/wrapper Gradle plugin 3.4.0-alpha08 Dec 14, 2018
graphics Update library icon Jan 14, 2019
.gitignore Initial commit Jun 23, 2017
.travis.yml Gradle plugin 3.4.0-alpha09 Dec 21, 2018
CNAME Improve javadocs generation Jun 27, 2018
LICENSE Update license Jan 21, 2018
README.md Version 2.2.0 Jan 22, 2019
build.gradle Version 2.2.0 Jan 22, 2019
gradle.properties Migrate to AndroidX Nov 8, 2018
gradlew Initial commit Jun 23, 2017
gradlew.bat
settings.gradle Add license in gradle files Mar 10, 2018

README.md

Dynamic Utils

License Build Status Download

A collection of static methods to perform various operations including color, device, drawable, package, tasks and sdk on Android 9+ (Gingerbread or above) devices.

Since v0.4.0, it uses 26.x.x support libraries so, minimum SDK will be Android 14+ (ICS or above).
Since v2.0.0, it uses AndroidX so, first migrate your project to AndroidX.


Contents


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {
    // For AndroidX enabled projects.
    implementation 'com.pranavpandey.android:dynamic-utils:2.2.0'

    // For legacy projects.
    implementation 'com.pranavpandey.android:dynamic-utils:1.3.0'
}

Usage

It is divided into different classes according to their category for easy understanding and usage. This library is fully commented so I am highlighting some of the functions below, keep exploring for more hidden features.

For complete reference, please read the documentation.

DynamicAnimUtils

Helper class to perform animation related operations.

  • void playAnimation(view, animator) - Play an animator animation on a view.

DynamicBitmapUtils

Helper class to perform bitmap operations.

  • Bitmap getBitmapFormDrawable(drawable) - Get bitmap from the supplied drawable.

  • Bitmap resizeBitmap(bitmap, newWidth, newHeight) - Resize bitmap to the new width and height.

  • Bitmap applyColorFilter(bitmap, colorFilter) - Apply color filter on the supplied bitmap.

  • Bitmap applyColorFilter(bitmap, color) - Apply monochrome color filter on the supplied bitmap.

  • @ColorInt int getDominantColor(bitmap) - Extract the dominant color form the supplied bitmap.

DynamicColorUtils

Helper class to change colors dynamically.

  • @ColorInt int adjustAlpha(color, factor) - Adjust alpha of a color according to the given parameter.

  • @ColorInt int calculateContrast(color1, color2) - Calculate color contrast difference between two colors based on luma value according to XYZ color space.

  • @ColorInt int getAccentColor(color) - Calculate accent color based on the given color for dynamic theme generation.

  • @ColorInt int getColorDarkness(color) - Calculate darkness of a color.

  • @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.

  • @ColorInt int getLessVisibleColor(color) - Calculate less visible color of a given color.

  • @ColorInt int getTintColor(color) - Calculate tint based on a given color for better readability.

  • boolean isColorDark(color) - Detect light or dark color.

  • @ColorInt int shiftColor(color, by) - Shift a color according to the given parameter.

DynamicDeviceUtils

Helper class to detect device specific features like Telephony, etc.

  • boolean hasTelephony(context) - To detect if device has telephony feature or not by using PackageManager.

DynamicDrawableUtils

Helper class to perform Drawable operations.

  • void colorizeDrawable(drawable, wrap, color, mode) - Colorize and return the mutated drawable so that, all other references do not change.

  • 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.

  • 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.

  • void viewInGooglePlay(context, packageName) - View app in the Google Play or Android Market.

  • void rateApp(context) - View app in the Google Play or Android Market.

  • void moreApps(context, publisher) - View other apps of a Publisher in the Google Play or Android Market.

  • void viewUrl(context, url) - View any URL in the available app or browser.

  • 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.

  • ComponentName getComponentName(context) - Get component name from the given context.

  • CharSequence getAppLabel(context) - Get application label from the given context.

  • String getAppVersion(context) - Get application version name from the given context.

  • Drawable getAppIcon(context) - Load application icon from the given context.

  • boolean 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.

  • void cancelTask(asyncTask) - Try to cancel the supplied AsyncTask.

  • void executeTask(asyncTask) - Try to execute the supplied AsyncTask.

DynamicUnitUtils

Helper class to perform unit conversions.

  • int convertDpToPixels(dp) - To convert DP into pixels.

  • int convertPixelsToDp(pixels) - To convert pixels into DP.

  • int convertSpToPixels(sp) - To convert SP into pixels.

  • int convertPixelsToSp(pixels) - To convert pixels into SP.

DynamicVersionUtils

Helper class to detect the Android SDK version at runtime so that we can provide the user experience accordingly. Pass true in the alternate method to check for equality.

  • boolean isIceCreamSandwich() - To detect if the current Android version is Ice Cream Sandwich or above.

  • boolean isIceCreamSandwich(equals) - To detect if the current Android version is Ice Cream Sandwich or above.

...

  • boolean isOreoMR1() - To detect if the current Android version is OreoMR1 or above.

  • boolean isOreoMR1(equals) - To detect if the current Android version is OreoMR1 or above.

DynamicViewUtils

Helper class to perform view operations.

  • void setLightStatusBar(view, isLight) - Set light status bar if we are using light primary color on Android M or above devices.

  • void setLightNavigationBar(view, isLight) - Set light navigation bar if we are using light primary color on Android O or above devices.

DynamicWindowUtils

Helper class to perform Window operations and to detect system configurations at runtime.

  • Point getAppUsableScreenSize(context) - Get the app usable screen size.

  • Point getRealScreenSize(context) - Get the real screen size.

  • Point getNavigationBarSize(context) - Get the on-screen navigation bar size.

  • boolean isNavigationBarPresent(context) - Detect if on-screen navigation bar is present or not.

  • boolean isNavigationBarThemeSupported(context) - Detect support for navigation bar theme.


Translations

  • German (de) - Flubberlutsch
  • Indonesian (in) - Gamal Kevin A
  • Italian (it) - Nicola
  • Spanish (es) - Dave
  • Turkish (tr) - Fatih Fırıncı
  • Chinese (Simplified) (zh-rCN) - John Canny

License

Copyright 2017 Pranav Pandey

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.