From 179e2a1a6c090b3e4c113864537d3dd8e159b053 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Sun, 1 Dec 2024 13:29:33 +0100 Subject: [PATCH] Use colored rounded rect as button for opening color picker Matches the style of the color temperature picker Signed-off-by: Danny Baumann --- .../main/java/org/openhab/habdroid/ui/WidgetAdapter.kt | 10 +++++++++- .../res/drawable/ic_palette_outline_themed_24dp.xml | 3 ++- .../main/res/layout/widgetlist_coloritem_buttons.xml | 8 +++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt index 41b289ca8e..ce568338d7 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt @@ -1648,6 +1648,7 @@ class WidgetAdapter( View.OnLongClickListener { private val upButton = itemView.findViewById(R.id.up_button) private val downButton = itemView.findViewById(R.id.down_button) + private val selectColorButton = itemView.findViewById(R.id.select_color_button) data class UpDownButtonState( val item: Item?, @@ -1661,7 +1662,6 @@ class WidgetAdapter( b.setOnClickListener(this) b.setOnLongClickListener(this) } - val selectColorButton = itemView.findViewById(R.id.select_color_button) selectColorButton.setOnClickListener { handleRowClick() } } @@ -1675,6 +1675,14 @@ class WidgetAdapter( downButton.tag = UpDownButtonState(widget.item, "OFF", "DECREASE") } super.bind(widget) + + val hsv = widget.state?.asHsv + val color = hsv?.toColor() + if (color == null || hsv.value == 0F) { + selectColorButton.setImageResource(R.drawable.ic_palette_outline_themed_24dp) + } else { + selectColorButton.setImageDrawable(color.toColoredRoundedRect(selectColorButton.context)) + } } override fun onClick(view: View) { diff --git a/mobile/src/main/res/drawable/ic_palette_outline_themed_24dp.xml b/mobile/src/main/res/drawable/ic_palette_outline_themed_24dp.xml index d1bc2624c2..8483e22673 100644 --- a/mobile/src/main/res/drawable/ic_palette_outline_themed_24dp.xml +++ b/mobile/src/main/res/drawable/ic_palette_outline_themed_24dp.xml @@ -2,7 +2,8 @@ android:width="24dp" android:height="24dp" android:viewportWidth="24" - android:viewportHeight="24"> + android:viewportHeight="24" + android:tint="?colorOnBackground"> diff --git a/mobile/src/main/res/layout/widgetlist_coloritem_buttons.xml b/mobile/src/main/res/layout/widgetlist_coloritem_buttons.xml index 2028638022..ff6edae575 100644 --- a/mobile/src/main/res/layout/widgetlist_coloritem_buttons.xml +++ b/mobile/src/main/res/layout/widgetlist_coloritem_buttons.xml @@ -9,11 +9,13 @@ android:contentDescription="@string/content_description_color_up" app:icon="@drawable/ic_keyboard_arrow_up_themed_24dp" /> -