changeset 2733:34e34d5d56e8

Android: Add a color picker preview area and a gradient slider for contrast. This allows the color picker to choose any possible color... The initial value is a little strange, but it more or less works.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 15 Dec 2021 14:53:04 +0000
parents 61821532faa0
children cd3c7740e352
files android/DWindows.kt
diffstat 1 files changed, 42 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Mon Dec 13 01:58:58 2021 +0000
+++ b/android/DWindows.kt	Wed Dec 15 14:53:04 2021 +0000
@@ -5387,14 +5387,49 @@
             waitOnUiThread {
                 val dialog = Dialog(this)
                 val colorWheel = ColorWheel(this, null, 0)
-
-                dialog.setContentView(colorWheel)
-                colorWheel.rgb = Color.rgb(red, green, blue)
-                colorChosen = colorWheel.rgb
-                colorWheel.colorChangeListener = { rgb: Int -> colorChosen = rgb }
+                val gradientBar = GradientSeekBar(this, null, 0)
+                val display = View(this)
+                val layout = RelativeLayout(this)
+                val w = RelativeLayout.LayoutParams.MATCH_PARENT
+                val h = RelativeLayout.LayoutParams.WRAP_CONTENT
+                val margin = 10
+
+                colorWheel.id = View.generateViewId()
+                gradientBar.id = View.generateViewId()
+                display.id = View.generateViewId()
+                gradientBar.orientation = GradientSeekBar.Orientation.HORIZONTAL
+
+                var params: RelativeLayout.LayoutParams = RelativeLayout.LayoutParams(w, 100)
+                params.addRule(RelativeLayout.ALIGN_PARENT_TOP)
+                params.setMargins(margin,margin,margin,margin)
+                layout.addView(display, params)
+                params = RelativeLayout.LayoutParams(w, w)
+                params.setMargins(margin,margin,margin,margin)
+                params.addRule(RelativeLayout.BELOW, display.id)
+                layout.addView(colorWheel, params)
+                params = RelativeLayout.LayoutParams(w, h)
+                params.setMargins(margin,margin,margin,margin)
+                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
+                layout.addView(gradientBar, params)
+
+                dialog.setContentView(layout)
+                colorChosen = Color.rgb(red, green, blue)
+                colorWheel.rgb = colorChosen
+                gradientBar.setBlackToColor(colorChosen)
+                gradientBar.offset = 1F
+                display.setBackgroundColor(colorChosen)
+                colorWheel.colorChangeListener = { rgb: Int ->
+                    gradientBar.setBlackToColor(rgb)
+                    display.setBackgroundColor(gradientBar.argb)
+                    colorChosen = gradientBar.argb
+                }
+                gradientBar.colorChangeListener = { offset: Float, argb: Int ->
+                    display.setBackgroundColor(argb)
+                    colorChosen = argb
+                }
                 dialog.window?.setLayout(
-                    ViewGroup.LayoutParams.MATCH_PARENT,
-                    ViewGroup.LayoutParams.MATCH_PARENT
+                        ViewGroup.LayoutParams.MATCH_PARENT,
+                        ViewGroup.LayoutParams.MATCH_PARENT
                 )
                 dialog.setOnDismissListener {
                     colorLock.lock()