All Implemented Interfaces:
SharedPreferences.OnSharedPreferenceChangeListener, Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent, BaseWidget, DynamicTintWidget, DynamicWidget
Direct Known Subclasses:
DynamicSimplePreference

public abstract class DynamicPreference extends DynamicView implements SharedPreferences.OnSharedPreferenceChangeListener, DynamicWidget
Base preference to provide the basic interface for the extending preference with an icon, title, summary, description, value and an action button.

It must be extended and the necessary methods should be implemented to create a dynamic preference.

See Also:
  • Field Details

    • DEFAULT_ENABLED

      public static final boolean DEFAULT_ENABLED
      Default value for the enabled state.
      See Also:
  • Constructor Details

  • Method Details

    • onLoadAttributes

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

      @CallSuper 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.

      Specified by:
      onUpdate in class DynamicView
    • onFinishInflate

      protected void onFinishInflate()
      Overrides:
      onFinishInflate in class View
    • onAttachedToWindow

      protected void onAttachedToWindow()
      Overrides:
      onAttachedToWindow in class ViewGroup
    • onDetachedFromWindow

      protected void onDetachedFromWindow()
      Overrides:
      onDetachedFromWindow in class ViewGroup
    • setEnabled

      public void setEnabled(boolean enabled)
      Description copied from interface: DynamicWidget
      Override this method to handle state changes for this widget.

      For example, change alpha according to the enabled or disabled state of this widget.

      Specified by:
      setEnabled in interface DynamicWidget
      Overrides:
      setEnabled in class DynamicView
      Parameters:
      enabled - true if this widget is enabled and can receive click events.
    • getBackgroundView

      @Nullable public View getBackgroundView()
      Description copied from class: DynamicView
      This method will be called to return the optional background view.

      It will be useful in tinting the background according to the contrast with color.

      Specified by:
      getBackgroundView in class DynamicView
      Returns:
      The optional background view.
    • initialize

      public void initialize()
      Description copied from interface: BaseWidget
      Initialize this widget by setting color type. If it is background aware then, background color will also taken into account while setting the color filter.
      Specified by:
      initialize in interface BaseWidget
      Overrides:
      initialize in class DynamicFrameLayout
      See Also:
    • 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 DynamicView
    • setImageView

      protected void setImageView(@Nullable ImageView imageView, @Nullable Drawable drawable)
      Set drawable for an image view.
      Parameters:
      imageView - The image view to set the drawable.
      drawable - The drawable to be set.
    • setTextView

      protected void setTextView(@Nullable TextView textView, @Nullable CharSequence text)
      Set text for a text view or hide it if the value is null.
      Parameters:
      textView - The text view to set the text.
      text - The text to be set.
    • getIcon

      @Nullable public Drawable getIcon()
      Get the icon used by this preference.
      Returns:
      The icon used by this preference.
    • setIcon

      public void setIcon(@Nullable Drawable icon, boolean update)
      Set the icon used by this preference.
      Parameters:
      icon - The icon drawable to be set.
      update - true to call onUpdate() method after setting the icon.
    • setIcon

      public void setIcon(@Nullable Drawable icon)
      Set the icon used by this preference.
      Parameters:
      icon - The icon drawable to be set.
    • getTitle

      @Nullable public CharSequence getTitle()
      Get the title used by this preference.
      Returns:
      The title used by this preference.
    • setTitle

      public void setTitle(@Nullable CharSequence title, boolean update)
      Set the title used by this preference.
      Parameters:
      title - The title to be set.
      update - true to call onUpdate() method after setting the title.
    • setTitle

      public void setTitle(@Nullable CharSequence title)
      Set the title used by this preference.
      Parameters:
      title - The title to be set.
    • getSummary

      @Nullable public CharSequence getSummary()
      Get the summary used by this preference.
      Returns:
      The summary used by this preference.
    • setSummary

      public void setSummary(@Nullable CharSequence summary, boolean update)
      Set the summary used by this preference.
      Parameters:
      summary - The summary to be set.
      update - true to call onUpdate() method after setting the summary.
    • setSummary

      public void setSummary(@Nullable CharSequence summary)
      Set the summary used by this preference.
      Parameters:
      summary - The summary to be set.
    • getDescription

      @Nullable public CharSequence getDescription()
      Get the description used by this preference.
      Returns:
      The description used by this preference.
    • setDescription

      public void setDescription(@Nullable CharSequence description, boolean update)
      Set the description used by this preference.
      Parameters:
      description - The description to be set.
      update - true to call onUpdate() method after setting the description.
    • setDescription

      public void setDescription(@Nullable CharSequence description)
      Set the description used by this preference.
      Parameters:
      description - The description to be set.
    • getValueString

      @Nullable public CharSequence getValueString()
      Get the value string used by this preference.
      Returns:
      The value string used by this preference.
    • setValueString

      public void setValueString(@Nullable CharSequence valueString, boolean update)
      Set the value string used by this preference.
      Parameters:
      valueString - The value string to be set.
      update - true to call onUpdate() method after setting the value string.
    • setValueString

      public void setValueString(@Nullable CharSequence valueString)
      Set the value string used by this preference.
      Parameters:
      valueString - The value string to be set.
    • getPreferenceKey

      @Nullable public String getPreferenceKey()
      Get the shared preferences key used by this preference.
      Returns:
      The shared preferences key used by this preference.
    • setPreferenceKey

      public void setPreferenceKey(@Nullable String preferenceKey)
      Set the shared preferences key used by this preference.
      Parameters:
      preferenceKey - The shared preferences key to be set.
    • getAltPreferenceKey

      @Nullable public String getAltPreferenceKey()
      Get the shared preferences key for alternate preference.
      Returns:
      The shared preferences key for alternate preference.
    • setAltPreferenceKey

      public void setAltPreferenceKey(@Nullable String altPreferenceKey)
      Set the shared preferences key for alternate preference.
      Parameters:
      altPreferenceKey - The alternate shared preferences key to be set.
    • getDependency

      @Nullable public String getDependency()
      Returns the shared preferences key on which this preference is dependent.
      Returns:
      The shared preferences key on which this preference is dependent.
    • setDependency

      public void setDependency(@Nullable String dependency)
      Set the shared preferences key on which this preference is dependent.
      Parameters:
      dependency - The shared preferences key to be set.
    • getActionString

      @Nullable public CharSequence getActionString()
      Get the action string used by this preference.
      Returns:
      The action string used by this preference.
    • getOnPreferenceClickListener

      @Nullable public View.OnClickListener getOnPreferenceClickListener()
      Returns the on click listener to receive preference click events.
      Returns:
      The on click listener to receive preference click events.
    • setOnPreferenceClickListener

      public void setOnPreferenceClickListener(@Nullable View.OnClickListener onPreferenceClickListener, boolean update)
      Set the on click listener to receive preference click events.
      Parameters:
      onPreferenceClickListener - The listener to be set.
      update - true to call onUpdate() method after setting the listener.
    • setOnPreferenceClickListener

      public void setOnPreferenceClickListener(@Nullable View.OnClickListener onPreferenceClickListener)
      Set the on click listener to receive preference click events.
      Parameters:
      onPreferenceClickListener - The listener to be set.
    • setActionButton

      public void setActionButton(@Nullable CharSequence actionString, @Nullable View.OnClickListener onActionClickListener, boolean update)
      Set an action button for this preference to perform secondary operations like requesting a permission, reset the preference value etc.

      Extending preference should implement the functionality in onUpdate() method.

      Parameters:
      actionString - The string to be shown for the action.
      onActionClickListener - The on click listener to perform the action when it is clicked.
      update - true to call onUpdate() method after setting the listener.
    • setActionButton

      public void setActionButton(@Nullable CharSequence actionString, @Nullable View.OnClickListener onActionClickListener)
      Set an action button for this preference to perform secondary operations like requesting a permission, reset the preference value etc.

      Extending preference should implement the functionality in onUpdate() method.

      Parameters:
      actionString - The string to be shown for the action.
      onActionClickListener - The on click listener to perform the action when it is clicked.
    • getOnActionClickListener

      @Nullable public View.OnClickListener getOnActionClickListener()
      Returns the on click listener to receive action click events.
      Returns:
      The on click listener to receive action click events.
    • getOnPromptListener

      @Nullable public DynamicPreference.OnPromptListener getOnPromptListener()
      Returns the listener to get the popup and dialog dialogs.
      Returns:
      The listener to get the popup and dialog dialogs.
    • setOnPromptListener

      public void setOnPromptListener(@Nullable DynamicPreference.OnPromptListener onPromptListener)
      Set the listener to get various callbacks related to the popup and dialog.

      It will be useful if this preference is displaying a popup or dialog and we have to restrict it from doing that.

      Parameters:
      onPromptListener - The listener to be set.
    • getPreferenceView

      @Nullable public abstract ViewGroup getPreferenceView()
      Get the preference root view.
      Returns:
      The preference root view.
    • onSharedPreferenceChanged

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