Package com.cheetahdigital.uikit.helper
Class ThemeSelector
- java.lang.Object
-
- com.cheetahdigital.uikit.helper.ThemeSelector
-
public class ThemeSelector extends java.lang.Object
Class used by theThemedActivity
to change the theme of the activity based on the values passed to it. It can also be used to change the theme of anotherActivity
The passed theme is saved on a privateSharedPreferences
Guidelines in creating your own Theme
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_THEME
-
Constructor Summary
Constructors Constructor Description ThemeSelector()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
changeToTheme(android.app.Activity activity, int theme)
Called to change the theme of theActivity
If this will be called on theActivity.onResume()
or other lifecycle methods, make sure to check that this method will only be called once because this method will 'restart' the activity by callingActivity.finish()
thenActivity.startActivity(Intent)
static void
clearBaseBackground(android.content.Context context)
Clears the base background from shared preferencesstatic void
clearBaseTitle(android.content.Context context)
Clear the stored preference for base titlestatic void
clearTheme(android.content.Context context)
Clears theme from shared preferences.static int
getBackIcon(android.app.Activity activity)
Gets the back icon from shared preferences.static java.lang.String
getBaseBackground(android.content.Context context)
Gets the base background from shared preferencesstatic java.lang.String
getBaseTitle(android.content.Context context)
Gets the base title from shared preferencesstatic java.lang.String
getBaseTitleImageFilePath(android.content.Context context)
static int
getTheme(android.content.Context context)
Gets the them from theSharedPreferences
attached to this Theme Selector classstatic java.lang.String
getThemeName(android.content.Context context)
Gets the theme name from shared preferences.static boolean
isStringNumeric(java.lang.String value)
static void
onActivityCreateSetTheme(android.app.Activity activity)
CallsActivity.setTheme(int)
applying the Theme that was saved in theSharedPreferences
attached to this classstatic void
setBackIcon(android.app.Activity activity, int drawable)
Sets the back icon.static void
setBackIcon(android.content.Context context, int drawable)
Sets the back iconstatic void
setBaseBackground(android.content.Context context, java.lang.String filePath)
Sets the background into shared preferences.static void
setBaseTitle(android.content.Context context, java.lang.String title)
Sets the base title into shared preferences.static void
setBaseTitleImageFilePath(android.content.Context context, java.lang.String filePath)
Sets the base title image file path into shared preferences.static void
setTheme(android.app.Activity activity, java.lang.String theme)
Saves the send theme to theSharedPreferences
attached to this Theme Selector classstatic void
setTheme(android.content.Context context, java.lang.String theme)
Saves the send theme to theSharedPreferences
attached to this Theme Selector class
-
-
-
Field Detail
-
DEFAULT_THEME
public static final java.lang.String DEFAULT_THEME
- See Also:
- Constant Field Values
-
-
Method Detail
-
changeToTheme
public static void changeToTheme(android.app.Activity activity, int theme)
Called to change the theme of theActivity
If this will be called on theActivity.onResume()
or other lifecycle methods, make sure to check that this method will only be called once because this method will 'restart' the activity by callingActivity.finish()
thenActivity.startActivity(Intent)
- Parameters:
activity
- CallingActivity
classtheme
- int Resource ID of the Style/Theme to be applied to the callingActivity
-
onActivityCreateSetTheme
public static void onActivityCreateSetTheme(android.app.Activity activity)
CallsActivity.setTheme(int)
applying the Theme that was saved in theSharedPreferences
attached to this class- Parameters:
activity
- the callingActivity
class
-
setTheme
public static void setTheme(android.app.Activity activity, java.lang.String theme)
Saves the send theme to theSharedPreferences
attached to this Theme Selector class- Parameters:
activity
- Activity who sets the Themetheme
- int value of the style resource, example: R.style.Theme_Original
-
setTheme
public static void setTheme(android.content.Context context, java.lang.String theme)
Saves the send theme to theSharedPreferences
attached to this Theme Selector class- Parameters:
context
- context of the applicationtheme
- int value of the style resource, example: R.style.Theme_Original
-
isStringNumeric
public static boolean isStringNumeric(java.lang.String value)
-
getTheme
public static int getTheme(android.content.Context context)
Gets the them from theSharedPreferences
attached to this Theme Selector class- Parameters:
context
- calling Context- Returns:
- returns the saved value from the
SharedPreferences
-
getThemeName
public static java.lang.String getThemeName(android.content.Context context)
Gets the theme name from shared preferences.- Parameters:
context
- used to get resources- Returns:
- theme name saved in preference
-
setBackIcon
public static void setBackIcon(android.app.Activity activity, @DrawableRes int drawable)
Sets the back icon.- Parameters:
activity
- used to get resourcesdrawable
- resource id of the icon
-
setBackIcon
public static void setBackIcon(android.content.Context context, @DrawableRes int drawable)
Sets the back icon- Parameters:
context
- used to get resourcesdrawable
- resource id of the icon
-
getBackIcon
public static int getBackIcon(android.app.Activity activity)
Gets the back icon from shared preferences.- Parameters:
activity
- used to get resources- Returns:
- resource id of back icon saved in preference
-
clearTheme
public static void clearTheme(android.content.Context context)
Clears theme from shared preferences.- Parameters:
context
- used to get resources
-
setBaseBackground
public static void setBaseBackground(android.content.Context context, java.lang.String filePath)
Sets the background into shared preferences.- Parameters:
context
- used to get resourcesfilePath
- path of file
-
getBaseBackground
public static java.lang.String getBaseBackground(android.content.Context context)
Gets the base background from shared preferences- Parameters:
context
- used to get resources- Returns:
- file path of background saved in preference
-
clearBaseBackground
public static void clearBaseBackground(android.content.Context context)
Clears the base background from shared preferences- Parameters:
context
- used to get resources
-
setBaseTitle
public static void setBaseTitle(android.content.Context context, java.lang.String title)
Sets the base title into shared preferences.- Parameters:
context
- used to get resourcestitle
- value of homepage header title
-
getBaseTitle
public static java.lang.String getBaseTitle(android.content.Context context)
Gets the base title from shared preferences- Parameters:
context
- used to get resources- Returns:
- homepage header title saved in preference
-
setBaseTitleImageFilePath
public static void setBaseTitleImageFilePath(android.content.Context context, java.lang.String filePath)
Sets the base title image file path into shared preferences.- Parameters:
context
- used to get resourcesfilePath
- path of file
-
getBaseTitleImageFilePath
public static java.lang.String getBaseTitleImageFilePath(android.content.Context context)
- Parameters:
context
- used to get resources- Returns:
- file path of base title image
-
clearBaseTitle
public static void clearBaseTitle(android.content.Context context)
Clear the stored preference for base title- Parameters:
context
- used to get resources
-
-