Class ThemeSelector


  • public class ThemeSelector
    extends java.lang.Object
    Class used by the ThemedActivity to change the theme of the activity based on the values passed to it. It can also be used to change the theme of another Activity The passed theme is saved on a private SharedPreferences

    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 the Activity If this will be called on the Activity.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 calling Activity.finish() then Activity.startActivity(Intent)
      static void clearBaseBackground​(android.content.Context context)
      Clears the base background from shared preferences
      static void clearBaseTitle​(android.content.Context context)
      Clear the stored preference for base title
      static 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 preferences
      static java.lang.String getBaseTitle​(android.content.Context context)
      Gets the base title from shared preferences
      static java.lang.String getBaseTitleImageFilePath​(android.content.Context context)  
      static int getTheme​(android.content.Context context)
      Gets the them from the SharedPreferences attached to this Theme Selector class
      static 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)
      Calls Activity.setTheme(int) applying the Theme that was saved in the SharedPreferences attached to this class
      static void setBackIcon​(android.app.Activity activity, int drawable)
      Sets the back icon.
      static void setBackIcon​(android.content.Context context, int drawable)
      Sets the back icon
      static 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 the SharedPreferences attached to this Theme Selector class
      static void setTheme​(android.content.Context context, java.lang.String theme)
      Saves the send theme to the SharedPreferences attached to this Theme Selector class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThemeSelector

        public ThemeSelector()
    • Method Detail

      • changeToTheme

        public static void changeToTheme​(android.app.Activity activity,
                                         int theme)
        Called to change the theme of the Activity If this will be called on the Activity.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 calling Activity.finish() then Activity.startActivity(Intent)
        Parameters:
        activity - Calling Activity class
        theme - int Resource ID of the Style/Theme to be applied to the calling Activity
      • onActivityCreateSetTheme

        public static void onActivityCreateSetTheme​(android.app.Activity activity)
        Calls Activity.setTheme(int) applying the Theme that was saved in the SharedPreferences attached to this class
        Parameters:
        activity - the calling Activity class
      • setTheme

        public static void setTheme​(android.app.Activity activity,
                                    java.lang.String theme)
        Saves the send theme to the SharedPreferences attached to this Theme Selector class
        Parameters:
        activity - Activity who sets the Theme
        theme - 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 the SharedPreferences attached to this Theme Selector class
        Parameters:
        context - context of the application
        theme - 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 the SharedPreferences 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 resources
        drawable - 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 resources
        drawable - 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 resources
        filePath - 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 resources
        title - 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 resources
        filePath - 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