Class DynamicThemeUtils

java.lang.Object
com.pranavpandey.android.dynamic.theme.util.DynamicThemeUtils

public class DynamicThemeUtils extends Object
Helper class to perform theme operations.
  • Constructor Details

    • DynamicThemeUtils

      public DynamicThemeUtils()
  • Method Details

    • getThemeMap

      @NonNull public static HashMap<String,String> getThemeMap()
      Returns the key-value map to encode the theme string.
      Returns:
      The key-value map to encode the theme string.
    • getFileName

      @NonNull public static String getFileName(@Nullable String prefix, @NonNull String extension)
      Returns the file name to save the theme.
      Parameters:
      prefix - The prefix before the file name.
      extension - The file extension to be used.
      Returns:
      The file name to save the theme.
    • getFileName

      @NonNull public static String getFileName(@NonNull String extension)
      Returns the file name to save the theme.
      Parameters:
      extension - The file extension to be used.
      Returns:
      The file name to save the theme.
    • getValueFromColor

      @NonNull public static String getValueFromColor(int value)
      Converts the color integer into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the color.
    • getValueFromColor

      public static int getValueFromColor(@NonNull String value)
      Converts the color string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the color.
    • getValueFromFontScale

      @NonNull public static String getValueFromFontScale(int value)
      Converts the font scale into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the font scale.
    • getValueFromFontScale

      public static int getValueFromFontScale(@NonNull String value)
      Converts the font scale string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the font scale.
    • getValueFromCornerRadius

      @NonNull public static String getValueFromCornerRadius(int value)
      Converts the corner radius into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the corner radius.
    • getValueFromCornerRadius

      public static int getValueFromCornerRadius(@NonNull String value)
      Converts the corner radius string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the corner radius.
    • getValueFromBackgroundAware

      @NonNull public static String getValueFromBackgroundAware(int value)
      Converts the background aware into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the background aware.
    • getValueFromBackgroundAware

      public static int getValueFromBackgroundAware(@NonNull String value)
      Converts the background aware string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the background aware.
    • getValueFromContrast

      @NonNull public static String getValueFromContrast(int value)
      Converts the contrast into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the contrast.
    • getValueFromContrast

      public static int getValueFromContrast(@NonNull String value)
      Converts the contrast string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the contrast.
    • getValueFromOpacity

      @NonNull public static String getValueFromOpacity(int value)
      Converts the opacity into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the opacity.
    • getValueFromOpacity

      public static int getValueFromOpacity(@NonNull String value)
      Converts the opacity string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the opacity.
    • getValueFromElevation

      @NonNull public static String getValueFromElevation(int value)
      Converts the elevation into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the elevation.
    • getValueFromElevation

      public static int getValueFromElevation(@NonNull String value)
      Converts the elevation string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the elevation.
    • getValueFromStyle

      @NonNull public static String getValueFromStyle(int value)
      Converts the style into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the style.
    • getValueFromStyle

      public static int getValueFromStyle(@NonNull String value)
      Converts the style string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the style.
    • getValueFromType

      @NonNull public static String getValueFromType(int value)
      Converts the type into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the type.
    • getValueFromType

      public static int getValueFromType(@NonNull String value)
      Converts the type string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the type.
    • getValueFromVisibility

      @NonNull public static String getValueFromVisibility(int value)
      Converts the visibility into its string equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The string equivalent of the visibility.
    • getValueFromVisibility

      public static int getValueFromVisibility(@NonNull String value)
      Converts the visibility string into its integer equivalent.
      Parameters:
      value - The value to be converted.
      Returns:
      The integer equivalent of the visibility.
    • format

      @NonNull public static String format(@NonNull String string)
      Formats the theme string and remove extra double quotes and white spaces.
      Parameters:
      string - The theme string to be formatted.
      Returns:
      The formatted theme string.
    • isValidTheme

      public static boolean isValidTheme(@Nullable String string)
      Checks whether the string is a valid JSON.
      Parameters:
      string - The string to be checked.
      Returns:
      true if the supplied string is a valid JSON.
    • isValidThemeIntent

      public static boolean isValidThemeIntent(@Nullable Context context, @Nullable Intent intent)
      Checks whether the intent is valid for the theme.
      Parameters:
      context - The context to match the URI mime type.
      intent - The intent to get the data.
      Returns:
      true if the intent is valid for the theme.
    • encodeTheme

      @Nullable public static String encodeTheme(@Nullable StringTheme<?> theme)
      Encodes a dynamic theme.
      Parameters:
      theme - The theme to be encoded.
      Returns:
      The encoded theme string.
    • decodeTheme

      @Nullable public static String decodeTheme(@Nullable String theme)
      Decodes a theme string.
      Parameters:
      theme - The theme string to be decoded.
      Returns:
      The decoded theme string.
    • mapTheme

      @NonNull public static AppTheme<?> mapTheme(@NonNull AppTheme<?> theme, @Nullable Map<Integer,Integer> colors)
      Try to map the theme with the supplied colors.
      Parameters:
      theme - The theme to be mapped.
      colors - The color map to be used.
      Returns:
      The mapped theme according to the supplied colors.
    • getThemeUrl

      @NonNull public static String getThemeUrl(@Nullable StringTheme<?> theme)
      Returns the encoded theme string with the URL.
      Parameters:
      theme - The theme to be processed.
      Returns:
      The encoded theme string with the URL.
    • getThemeUri

      @Nullable public static Uri getThemeUri(@Nullable Intent intent)
      Returns the theme URI from the intent.
      Parameters:
      intent - The intent to get the theme URI.
      Returns:
      The theme URI according to the intent data.
      See Also:
    • getThemeData

      @Nullable public static String getThemeData(@Nullable Context context, @Nullable Uri uri)
      Returns the theme data from the URI.
      Parameters:
      context - The context to be used.
      uri - The URI to get the theme data.
      Returns:
      The theme data according to the URI.
      See Also:
    • getThemeData

      @Nullable public static String getThemeData(@Nullable Context context, @Nullable Intent intent)
      Returns the theme data from the intent.
      Parameters:
      context - The context to be used.
      intent - The intent to get the theme data.
      Returns:
      The theme data according to the intent data.
      See Also:
    • getThemeName

      @Nullable public static String getThemeName(@Nullable Context context, @Nullable Intent intent, @Nullable String defaultName)
      Returns the theme name from the intent.
      Parameters:
      context - The context to be used.
      intent - The intent to get the theme name.
      defaultName - The default name for the theme.
      Returns:
      The theme name according to the intent data.
      See Also:
    • requestThemeFile

      @Nullable public static File requestThemeFile(@NonNull Context context, @NonNull String theme, @NonNull String data)
      Request to return a dynamic theme file.
      Parameters:
      context - The context to get the app storage.
      theme - The name for the theme file.
      data - The text content for the theme file.
      Returns:
      The dynamic theme file containing the supplied data.
    • createThemeBitmap

      @Nullable public static Bitmap createThemeBitmap(@NonNull View view)
      Creates a bitmap to be shared along with the dynamic theme.
      Parameters:
      view - The theme preview to get the bitmap.
      Returns:
      The bitmap to be shared along with the dynamic theme.
    • createRemoteThemeBitmap

      @Nullable public static Bitmap createRemoteThemeBitmap(@NonNull View view)
      Creates a bitmap to be shared along with the remote dynamic theme.
      Parameters:
      view - The remote theme preview to get the bitmap.
      Returns:
      The bitmap to be shared along with the remote dynamic theme.
    • broadcastDynamicTheme

      public static void broadcastDynamicTheme(@Nullable Context context, @Nullable String theme, @Nullable String value, @Nullable String data, boolean considerSender)
      Broadcast the theme data to the supported apps.
      Parameters:
      context - The context to broadcast the theme.
      theme - The theme for the receiver.
      value - The theme value for the receiver.
      data - The theme data for the receiver.
      considerSender - true to consider the sender package if applicable.
    • broadcastDynamicTheme

      public static void broadcastDynamicTheme(@NonNull Context context, @Nullable String theme, @Nullable String value, @Nullable String data)
      Broadcast the theme data to the supported apps.
      Parameters:
      context - The context to broadcast the theme.
      theme - The theme for the receiver.
      value - The theme value for the receiver.
      data - The theme data for the receiver.
      See Also:
    • getBitmapColors

      @Nullable public static Map<Integer,Integer> getBitmapColors(@Nullable Bitmap bitmap)
      Try to extract the bitmap colors.
      Parameters:
      bitmap - The bitmap to be used.
      Returns:
      The extracted the bitmap colors map.
      See Also:
    • getWallpaperColors

      @RequiresPermission(anyOf={"android.permission.MANAGE_EXTERNAL_STORAGE","android.permission.READ_EXTERNAL_STORAGE"}, conditional=true) @Nullable public static Map<Integer,Integer> getWallpaperColors(@Nullable Context context)
      Try to extract the wallpaper colors.

      It requires Manifest.permission.READ_EXTERNAL_STORAGE permission on API 26 and below.

      Parameters:
      context - The context to get the wallpaper manager.
      Returns:
      The extracted the wallpaper colors map.
      See Also: