From 091a44c8b05859e0c092fbdb0bf311b3fb9d6d49 Mon Sep 17 00:00:00 2001 From: Ethan Davidson Date: Sun, 31 Oct 2021 11:20:00 -0400 Subject: [PATCH 1/3] make configuration fields public to support building the preference in code https://developer.android.com/guide/topics/ui/settings/programmatic-hierarchy --- .../ColorPickerPreference.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt index ce8199b..5eeaed5 100644 --- a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt +++ b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -@file:Suppress("unused") +@file:Suppress("unused", "MemberVisibilityCanBePrivate") package com.skydoves.colorpickerpreference @@ -47,15 +47,15 @@ class ColorPickerPreference : Preference { private lateinit var preferenceColorPickerView: ColorPickerView var preferenceColorListener: ColorPickerViewListener? = null - private var defaultColor: Int = Color.BLACK - private var cornerRadius: Int = 0 - private var paletteDrawable: Drawable? = null - private var selectorDrawable: Drawable? = null - private var title: String? = null - private var positive: String? = null - private var negative: String? = null - private var isAttachAlphaSlideBar = true - private var isAttachBrightnessSlideBar = true + var defaultColor: Int = Color.BLACK + var cornerRadius: Int = 0 + var paletteDrawable: Drawable? = null + var selectorDrawable: Drawable? = null + var title: String? = null + var positive: String? = null + var negative: String? = null + var isAttachAlphaSlideBar = true + var isAttachBrightnessSlideBar = true constructor(context: Context) : super(context) From dd88aec1b753a1ce1dbe9bf40caf0f4bcf525a03 Mon Sep 17 00:00:00 2001 From: Ethan Davidson Date: Sun, 31 Oct 2021 12:37:28 -0400 Subject: [PATCH 2/3] rename fields title was renamed to keep it from shadowing Preference.title isAttach fields were renamed to make them more ergonomic when building preference in code --- .../ColorPickerPreference.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt index 5eeaed5..74c6a0f 100644 --- a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt +++ b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt @@ -51,11 +51,11 @@ class ColorPickerPreference : Preference { var cornerRadius: Int = 0 var paletteDrawable: Drawable? = null var selectorDrawable: Drawable? = null - var title: String? = null + var dialogTitle: String? = null var positive: String? = null var negative: String? = null - var isAttachAlphaSlideBar = true - var isAttachBrightnessSlideBar = true + var attachAlphaSlideBar = true + var attachBrightnessSlideBar = true constructor(context: Context) : super(context) @@ -99,25 +99,25 @@ class ColorPickerPreference : Preference { typedArray.getDimensionPixelSize(R.styleable.ColorPickerPreference_preference_colorBox_radius, cornerRadius) paletteDrawable = typedArray.getDrawable(R.styleable.ColorPickerPreference_preference_palette) selectorDrawable = typedArray.getDrawable(R.styleable.ColorPickerPreference_preference_selector) - title = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_title) + dialogTitle = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_title) positive = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_positive) negative = typedArray.getString(R.styleable.ColorPickerPreference_preference_dialog_negative) - isAttachAlphaSlideBar = + attachAlphaSlideBar = typedArray.getBoolean( R.styleable.ColorPickerPreference_preference_attachAlphaSlideBar, - isAttachAlphaSlideBar + attachAlphaSlideBar ) - isAttachBrightnessSlideBar = + attachBrightnessSlideBar = typedArray.getBoolean( R.styleable.ColorPickerPreference_preference_attachBrightnessSlideBar, - isAttachBrightnessSlideBar + attachBrightnessSlideBar ) } private fun onInit() { widgetLayoutResource = R.layout.layout_colorpicker_preference preferenceDialog = ColorPickerDialog.Builder(context).apply { - setTitle(title) + setTitle(dialogTitle) setPositiveButton( positive, ColorEnvelopeListener { envelope, _ -> @@ -132,8 +132,8 @@ class ColorPickerPreference : Preference { } ) setNegativeButton(negative) { dialogInterface, _ -> dialogInterface.dismiss() } - attachAlphaSlideBar(isAttachAlphaSlideBar) - attachBrightnessSlideBar(isAttachBrightnessSlideBar) + attachAlphaSlideBar(attachAlphaSlideBar) + attachBrightnessSlideBar(attachBrightnessSlideBar) this@ColorPickerPreference.preferenceColorPickerView = this.colorPickerView.apply { paletteDrawable?.let { setPaletteDrawable(it) } selectorDrawable?.let { setSelectorDrawable(it) } From 8f04b8f4afa87751c6ba0e61039537b522ab2153 Mon Sep 17 00:00:00 2001 From: Ethan Davidson Date: Sun, 31 Oct 2021 12:53:39 -0400 Subject: [PATCH 3/3] make onInit public when declaring prefs in code, you need to call this after setting all the config variables. It's not pretty but it was the easiest way to get this working --- .../com/skydoves/colorpickerpreference/ColorPickerPreference.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt index 74c6a0f..eaf34ce 100644 --- a/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt +++ b/colorpickerpreference/src/main/java/com/skydoves/colorpickerpreference/ColorPickerPreference.kt @@ -114,7 +114,7 @@ class ColorPickerPreference : Preference { ) } - private fun onInit() { + fun onInit() { widgetLayoutResource = R.layout.layout_colorpicker_preference preferenceDialog = ColorPickerDialog.Builder(context).apply { setTitle(dialogTitle)