Class DynamicThemeUtils
java.lang.Object
com.pranavpandey.android.dynamic.theme.util.DynamicThemeUtils
Helper class to perform theme operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidbroadcastDynamicTheme(Context context, String theme, String value, String data) Broadcast the theme data to the supported apps.static voidbroadcastDynamicTheme(Context context, String theme, String value, String data, boolean considerSender) Broadcast the theme data to the supported apps.static BitmapcreateRemoteThemeBitmap(View view) Creates a bitmap to be shared along with the remote dynamic theme.static BitmapcreateThemeBitmap(View view) Creates a bitmap to be shared along with the dynamic theme.static StringdecodeTheme(String theme) Decodes a theme string.static StringencodeTheme(StringTheme<?> theme) Encodes a dynamic theme.static StringFormats the theme string and remove extra double quotes and white spaces.getBitmapColors(Bitmap bitmap) Try to extract the bitmap colors.static StringgetFileName(String extension) Returns the file name to save the theme.static StringgetFileName(String prefix, String extension) Returns the file name to save the theme.static StringgetThemeData(Context context, Intent intent) Returns the theme data from the intent.static StringgetThemeData(Context context, Uri uri) Returns the theme data from the URI.Returns the key-value map to encode the theme string.static StringgetThemeName(Context context, Intent intent, String defaultName) Returns the theme name from the intent.static UrigetThemeUri(Intent intent) Returns the theme URI from the intent.static StringgetThemeUrl(StringTheme<?> theme) Returns the encoded theme string with the URL.static StringgetValueFromBackgroundAware(int value) Converts the background aware into its string equivalent.static intConverts the background aware string into its integer equivalent.static StringgetValueFromColor(int value) Converts the color integer into its string equivalent.static intgetValueFromColor(String value) Converts the color string into its integer equivalent.static StringgetValueFromContrast(int value) Converts the contrast into its string equivalent.static intgetValueFromContrast(String value) Converts the contrast string into its integer equivalent.static StringgetValueFromCornerRadius(int value) Converts the corner radius into its string equivalent.static intgetValueFromCornerRadius(String value) Converts the corner radius string into its integer equivalent.static StringgetValueFromElevation(int value) Converts the elevation into its string equivalent.static intgetValueFromElevation(String value) Converts the elevation string into its integer equivalent.static StringgetValueFromFontScale(int value) Converts the font scale into its string equivalent.static intgetValueFromFontScale(String value) Converts the font scale string into its integer equivalent.static StringgetValueFromOpacity(int value) Converts the opacity into its string equivalent.static intgetValueFromOpacity(String value) Converts the opacity string into its integer equivalent.static StringgetValueFromStyle(int value) Converts the style into its string equivalent.static intgetValueFromStyle(String value) Converts the style string into its integer equivalent.static StringgetValueFromType(int value) Converts the type into its string equivalent.static intgetValueFromType(String value) Converts the type string into its integer equivalent.static StringgetValueFromVisibility(int value) Converts the visibility into its string equivalent.static intgetValueFromVisibility(String value) Converts the visibility string into its integer equivalent.getWallpaperColors(Context context) Try to extract the wallpaper colors.getWallpaperColorsExpressive(Context context) Try to extract the expressive wallpaper colors.static booleanisValidTheme(String string) Checks whether the string is a valid JSON.static booleanisValidThemeIntent(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 FilerequestThemeFile(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:
trueif 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:
trueif 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-trueto 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_STORAGEpermission on API 26 and below.- Parameters:
context- The context to get the wallpaper manager.- Returns:
- The extracted the wallpaper colors map.
- See Also:
-
getWallpaperColorsExpressive
@RequiresPermission(anyOf={"android.permission.MANAGE_EXTERNAL_STORAGE","android.permission.READ_EXTERNAL_STORAGE"}, conditional=true) @Nullable public static Map<Integer,Integer> getWallpaperColorsExpressive(@Nullable Context context) Try to extract the expressive wallpaper colors.It requires
Manifest.permission.READ_EXTERNAL_STORAGEpermission on API 26 and below.- Parameters:
context- The context to get the wallpaper manager.- Returns:
- The extracted the expressive wallpaper colors map.
- See Also:
-