Class DynamicThemeUtils
java.lang.Object
com.pranavpandey.android.dynamic.theme.util.DynamicThemeUtils
Helper class to perform theme operations.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
broadcastDynamicTheme
(Context context, String theme, String value, String data) Broadcast the theme data to the supported apps.static void
broadcastDynamicTheme
(Context context, String theme, String value, String data, boolean considerSender) Broadcast the theme data to the supported apps.static Bitmap
createRemoteThemeBitmap
(View view) Creates a bitmap to be shared along with the remote dynamic theme.static Bitmap
createThemeBitmap
(View view) Creates a bitmap to be shared along with the dynamic theme.static String
decodeTheme
(String theme) Decodes a theme string.static String
encodeTheme
(StringTheme<?> theme) Encodes a dynamic theme.static String
Formats the theme string and remove extra double quotes and white spaces.getBitmapColors
(Bitmap bitmap) Try to extract the bitmap colors.static String
getFileName
(String extension) Returns the file name to save the theme.static String
getFileName
(String prefix, String extension) Returns the file name to save the theme.static String
getThemeData
(Context context, Intent intent) Returns the theme data from the intent.static String
getThemeData
(Context context, Uri uri) Returns the theme data from the URI.Returns the key-value map to encode the theme string.static String
getThemeName
(Context context, Intent intent, String defaultName) Returns the theme name from the intent.static Uri
getThemeUri
(Intent intent) Returns the theme URI from the intent.static String
getThemeUrl
(StringTheme<?> theme) Returns the encoded theme string with the URL.static String
getValueFromBackgroundAware
(int value) Converts the background aware into its string equivalent.static int
Converts the background aware string into its integer equivalent.static String
getValueFromColor
(int value) Converts the color integer into its string equivalent.static int
getValueFromColor
(String value) Converts the color string into its integer equivalent.static String
getValueFromContrast
(int value) Converts the contrast into its string equivalent.static int
getValueFromContrast
(String value) Converts the contrast string into its integer equivalent.static String
getValueFromCornerRadius
(int value) Converts the corner radius into its string equivalent.static int
getValueFromCornerRadius
(String value) Converts the corner radius string into its integer equivalent.static String
getValueFromElevation
(int value) Converts the elevation into its string equivalent.static int
getValueFromElevation
(String value) Converts the elevation string into its integer equivalent.static String
getValueFromFontScale
(int value) Converts the font scale into its string equivalent.static int
getValueFromFontScale
(String value) Converts the font scale string into its integer equivalent.static String
getValueFromOpacity
(int value) Converts the opacity into its string equivalent.static int
getValueFromOpacity
(String value) Converts the opacity string into its integer equivalent.static String
getValueFromStyle
(int value) Converts the style into its string equivalent.static int
getValueFromStyle
(String value) Converts the style string into its integer equivalent.static String
getValueFromType
(int value) Converts the type into its string equivalent.static int
getValueFromType
(String value) Converts the type string into its integer equivalent.static String
getValueFromVisibility
(int value) Converts the visibility into its string equivalent.static int
getValueFromVisibility
(String value) Converts the visibility string into its integer equivalent.getWallpaperColors
(Context context) Try to extract the wallpaper colors.static boolean
isValidTheme
(String string) Checks whether the string is a valid JSON.static boolean
isValidThemeIntent
(Context context, Intent intent) Checks whether the intent is valid for the theme.static AppTheme<?>
Try to map the theme with the supplied colors.static File
requestThemeFile
(Context context, String theme, String data) Request to return a dynamic theme file.
-
Constructor Details
-
DynamicThemeUtils
public DynamicThemeUtils()
-
-
Method Details
-
getThemeMap
Returns the key-value map to encode the theme string.- Returns:
- The key-value map to encode the theme string.
-
getFileName
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
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
Converts the color integer into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the color.
-
getValueFromColor
Converts the color string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the color.
-
getValueFromFontScale
Converts the font scale into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the font scale.
-
getValueFromFontScale
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
Converts the corner radius into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the corner radius.
-
getValueFromCornerRadius
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
Converts the background aware into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the background aware.
-
getValueFromBackgroundAware
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
Converts the contrast into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the contrast.
-
getValueFromContrast
Converts the contrast string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the contrast.
-
getValueFromOpacity
Converts the opacity into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the opacity.
-
getValueFromOpacity
Converts the opacity string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the opacity.
-
getValueFromElevation
Converts the elevation into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the elevation.
-
getValueFromElevation
Converts the elevation string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the elevation.
-
getValueFromStyle
Converts the style into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the style.
-
getValueFromStyle
Converts the style string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the style.
-
getValueFromType
Converts the type into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the type.
-
getValueFromType
Converts the type string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the type.
-
getValueFromVisibility
Converts the visibility into its string equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The string equivalent of the visibility.
-
getValueFromVisibility
Converts the visibility string into its integer equivalent.- Parameters:
value
- The value to be converted.- Returns:
- The integer equivalent of the visibility.
-
format
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
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
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.
-
decodeTheme
Decodes a theme string.- Parameters:
theme
- The theme string to be decoded.- Returns:
- The decoded theme string.
-
getThemeUri
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
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
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
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
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
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:
-