From 20991ff4ef175c47393f03c8b9e02566f5102034 Mon Sep 17 00:00:00 2001 From: Ismael Reyes Date: Thu, 1 Oct 2020 18:18:49 +0200 Subject: [PATCH] Added convenience methods to get and set color value saved in preference --- .../android/colorpicker/ColorPreference.java | 18 ++++++++++++++++++ .../colorpicker/ColorPreferenceCompat.java | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreference.java b/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreference.java index 0021dd5..bbcdf3a 100644 --- a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreference.java +++ b/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreference.java @@ -204,6 +204,24 @@ public String getFragmentTag() { return "color_" + getKey(); } + /** + * Get the color of the key. This should be one of the entries in {@link #getPresets()}. + * + * @return The color of the key + */ + public int getColor() { + return color; + } + + /** + * Sets the color selected. This should be one of the entries in {@link #getPresets()}. + * + * @param color The color to set for the key + */ + public void setColor(@ColorInt int color) { + this.color = color; + } + public interface OnShowDialogListener { void onShowColorPickerDialog(String title, int currentColor); diff --git a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreferenceCompat.java b/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreferenceCompat.java index 42e579e..ee75a43 100644 --- a/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreferenceCompat.java +++ b/library/src/main/java/com/jaredrummler/android/colorpicker/ColorPreferenceCompat.java @@ -200,6 +200,24 @@ public String getFragmentTag() { return "color_" + getKey(); } + /** + * Get the color of the key. This should be one of the entries in {@link #getPresets()}. + * + * @return The color of the key + */ + public int getColor() { + return color; + } + + /** + * Sets the color selected. This should be one of the entries in {@link #getPresets()}. + * + * @param color The color to set for the key + */ + public void setColor(@ColorInt int color) { + this.color = color; + } + public interface OnShowDialogListener { void onShowColorPickerDialog(String title, int currentColor);