Type Parameters:
T - The type of the dynamic app theme this preference will handle.
All Implemented Interfaces:
SharedPreferences.OnSharedPreferenceChangeListener, Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent, DynamicThemeResolver<T>, BaseWidget, DynamicTintWidget, DynamicWidget
Direct Known Subclasses:
DynamicRemoteThemePreference, DynamicThemePreference

public abstract class ThemePreference<T extends DynamicAppTheme> extends DynamicSpinnerPreference implements DynamicThemeResolver<T>
A DynamicSpinnerPreference to display and edit the DynamicAppTheme.
  • Field Details

    • mDefaultTheme

      protected String mDefaultTheme
      Default theme value for this preference.
    • mTheme

      protected String mTheme
      Current theme value for this preference.
    • mDynamicTheme

      protected T extends DynamicAppTheme mDynamicTheme
      Current dynamic theme value for this preference.
    • mThemePreviewEnabled

      protected boolean mThemePreviewEnabled
      true if the theme preview is enabled.
    • mThemePreview

      protected ThemePreview<T extends DynamicAppTheme> mThemePreview
      Theme preview used by this preference.
    • mThemePreviewIcon

      protected ImageView mThemePreviewIcon
      Theme preview icon used by this preference.
    • mThemePreviewDescription

      protected TextView mThemePreviewDescription
      Theme preview description used by this preference.
    • mOnThemeClickListener

      protected View.OnClickListener mOnThemeClickListener
      On click listener to receive theme click events.
  • Constructor Details

  • Method Details

    • onLoadAttributes

      protected void onLoadAttributes(@Nullable AttributeSet attrs)
      Description copied from class: DynamicView
      Load values from the supplied attribute set.
      Overrides:
      onLoadAttributes in class DynamicSpinnerPreference
      Parameters:
      attrs - The attribute set to load the values.
    • onInflate

      protected void onInflate()
      Description copied from class: DynamicView
      This method will be called after loading the attributed.

      Initialize the view layout here.

      Overrides:
      onInflate in class DynamicSpinnerPreference
    • getPreferenceKey

      @Nullable public String getPreferenceKey()
      Description copied from class: DynamicPreference
      Get the shared preferences key used by this preference.
      Overrides:
      getPreferenceKey in class DynamicPreference
      Returns:
      The shared preferences key used by this preference.
    • getAltPreferenceKey

      @Nullable public String getAltPreferenceKey()
      Description copied from class: DynamicPreference
      Get the shared preferences key for alternate preference.
      Overrides:
      getAltPreferenceKey in class DynamicPreference
      Returns:
      The shared preferences key for alternate preference.
    • onUpdate

      protected void onUpdate()
      Description copied from class: DynamicView
      This method will be called whenever there is a change in the view attributes or parameters.

      It is better to do any real time calculation like updating the value string or checked state in this method.

      Overrides:
      onUpdate in class DynamicSpinnerPreference
    • onEnabled

      protected void onEnabled(boolean enabled)
      Description copied from class: DynamicView
      This method will be called whenever there is a change in the view state.

      Either enabled or disabled, other views like icon, title, color, etc. must be updated here to reflect the overall view state.

      Overrides:
      onEnabled in class DynamicSimplePreference
      Parameters:
      enabled - true if this view is enabled and can receive click events.
    • setColor

      public void setColor()
      Description copied from interface: DynamicWidget
      Set color for this widget according to the supplied values.
      Specified by:
      setColor in interface DynamicWidget
      Overrides:
      setColor in class DynamicSimplePreference
    • getDynamicTheme

      @Nullable public T getDynamicTheme()
      Returns the current dynamic theme value for this preference.
      Returns:
      The current dynamic theme value for this preference.
    • setDynamicTheme

      public void setDynamicTheme(@Nullable T theme)
      Set the current dynamic theme value for this preference.
      Parameters:
      theme - The current dynamic theme value to be set.
    • isThemePreviewEnabled

      public boolean isThemePreviewEnabled()
      Checks whether the theme preview is enabled.
      Returns:
      true if the theme preview is enabled.
    • setThemePreviewEnabled

      public void setThemePreviewEnabled(boolean enabled)
      Enable or disable the theme preview.
      Parameters:
      enabled - true to enable the theme preview.
    • getDefaultTheme

      @Nullable public String getDefaultTheme()
      Get the default theme value for this preference.
      Returns:
      The default theme value for this preference.
    • setDefaultTheme

      public void setDefaultTheme(@NonNull String defaultTheme)
      Set the default theme value for this preference.
      Parameters:
      defaultTheme - The default theme value to be set.
    • getTheme

      @Nullable public String getTheme()
      Get the current theme value for this preference.
      Returns:
      The current theme value for this preference.
    • setTheme

      public void setTheme(@NonNull String theme, boolean save)
      Set the current theme value of this preference.
      Parameters:
      theme - The theme value to be set.
      save - true to update the shared preferences.
    • setTheme

      public void setTheme(@NonNull String theme)
      Set the current theme value of this preference.
      Parameters:
      theme - The theme value to be set.
    • getOnThemeClickListener

      @Nullable public View.OnClickListener getOnThemeClickListener()
      Returns the on click listener to receive theme click events.
      Returns:
      The on click listener to receive theme click events.
    • setOnThemeClickListener

      public void setOnThemeClickListener(@Nullable View.OnClickListener onThemeClickListener)
      Set the on click listener for theme to receive the click events and to perform edit operation.
      Parameters:
      onThemeClickListener - The on click listener to be set.
    • getThemePreview

      @NonNull public ThemePreview<T> getThemePreview()
      Get the theme preview used by this preference.
      Returns:
      The theme preview used by this preference.
    • getThemePreviewRoot

      @NonNull public ViewGroup getThemePreviewRoot()
      Get the root view for the theme preview used by this preference.
      Returns:
      The root view for the theme preview used by this preference.
    • getThemePreviewIcon

      @Nullable public ImageView getThemePreviewIcon()
      Get the theme preview icon used by this preference.
      Returns:
      The theme preview icon used by this preference.
    • getThemePreviewDescription

      @Nullable public TextView getThemePreviewDescription()
      Get the theme preview description used by this preference.
      Returns:
      The theme preview description used by this preference.
    • onSharedPreferenceChanged

      public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String key)
      Specified by:
      onSharedPreferenceChanged in interface SharedPreferences.OnSharedPreferenceChangeListener
      Overrides:
      onSharedPreferenceChanged in class DynamicSpinnerPreference