Skip to content

Commit

Permalink
Use colored rounded rect as button for opening color picker
Browse files Browse the repository at this point in the history
Matches the style of the color temperature picker

Signed-off-by: Danny Baumann <[email protected]>
  • Loading branch information
maniac103 committed Dec 1, 2024
1 parent 420a55b commit 95d5f0d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 9 additions & 1 deletion mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ class WidgetAdapter(
View.OnLongClickListener {
private val upButton = itemView.findViewById<View>(R.id.up_button)
private val downButton = itemView.findViewById<View>(R.id.down_button)
private val selectColorButton = itemView.findViewById<ImageView>(R.id.select_color_button)

data class UpDownButtonState(
val item: Item?,
Expand All @@ -1661,7 +1662,6 @@ class WidgetAdapter(
b.setOnClickListener(this)
b.setOnLongClickListener(this)
}
val selectColorButton = itemView.findViewById<View>(R.id.select_color_button)
selectColorButton.setOnClickListener { handleRowClick() }
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
android:viewportHeight="24"
android:tint="?colorOnBackground">
<path
android:fillColor="#FF000000"
android:pathData="M12,22C6.49,22 2,17.51 2,12S6.49,2 12,2s10,4.04 10,9c0,3.31 -2.69,6 -6,6h-1.77c-0.28,0 -0.5,0.22 -0.5,0.5 0,0.12 0.05,0.23 0.13,0.33 0.41,0.47 0.64,1.06 0.64,1.67 0,1.38 -1.12,2.5 -2.5,2.5zM12,4c-4.41,0 -8,3.59 -8,8s3.59,8 8,8c0.28,0 0.5,-0.22 0.5,-0.5 0,-0.16 -0.08,-0.28 -0.14,-0.35 -0.41,-0.46 -0.63,-1.05 -0.63,-1.65 0,-1.38 1.12,-2.5 2.5,-2.5L16,15c2.21,0 4,-1.79 4,-4 0,-3.86 -3.59,-7 -8,-7z"/>
Expand Down
8 changes: 5 additions & 3 deletions mobile/src/main/res/layout/widgetlist_coloritem_buttons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
android:contentDescription="@string/content_description_color_up"
app:icon="@drawable/ic_keyboard_arrow_up_themed_24dp" />

<Button
<ImageView
style="@style/openHAB.ActionButton"
android:id="@+id/select_color_button"
android:contentDescription="@string/content_description_open_color_wheel"
app:icon="@drawable/ic_palette_outline_themed_24dp" />
android:background="@null"
android:padding="8dp"
android:scaleType="centerInside"
android:contentDescription="@string/content_description_open_color_wheel" />

<Button
style="@style/openHAB.ActionButton"
Expand Down

0 comments on commit 95d5f0d

Please sign in to comment.