changeset 2656:2bdbd5e83654

Android: Save splitbar settings in dataArrayMap instead of attempting to calculate them. This also allows the use of dw_window_s/get_data() on the splitbar handle.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 18 Sep 2021 23:57:31 +0000
parents 5b63a3ed8e10
children 9535f533a230
files android/DWindows.kt
diffstat 1 files changed, 29 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Wed Sep 15 08:36:21 2021 +0000
+++ b/android/DWindows.kt	Sat Sep 18 23:57:31 2021 +0000
@@ -2006,13 +2006,19 @@
 
         waitOnUiThread {
             splitbar = ConstraintLayout(this)
-
             if(splitbar != null) {
                 val constraintSet = ConstraintSet()
+                val dataArrayMap = SimpleArrayMap<String, Long>()
+
                 constraintSet.clone(splitbar)
 
+                splitbar!!.tag = dataArrayMap
                 splitbar!!.id = cid
 
+                // Add the special data to the array map
+                dataArrayMap.put("_dw_type", type.toLong())
+                dataArrayMap.put("_dw_percent", 50000000L)
+
                 // Place the top/left item
                 if(topleft != null) {
                     if(topleft.id < 1) {
@@ -2104,38 +2110,37 @@
         var position: Float = 50.0F
 
         waitOnUiThread {
-            val topleft: View? = splitbar.getChildAt(0)
-            val bottomright: View? = splitbar.getChildAt(1)
-
-            if(splitbar.width > 0 && splitbar.height > 0) {
-                if (topleft != null) {
-                    if (splitbar.width == topleft.width) {
-                        position = (topleft.height / splitbar.height) * 100.0F
-                    } else {
-                        position = (topleft.width / splitbar.width) * 100.0F
-                    }
-                } else if (bottomright != null) {
-                    if (splitbar.width == bottomright.width) {
-                        position = 100.0F - ((bottomright.height / splitbar.height) * 100.0F)
-                    } else {
-                        position = 100.0F - ((bottomright.width / splitbar.width) * 100.0F)
-                    }
-                }
+            val dataArrayMap: SimpleArrayMap<String, Long> = splitbar.tag as SimpleArrayMap<String, Long>
+            var percent: Long = 50000000L
+
+            if(dataArrayMap.containsKey("_dw_percent")) {
+                percent = dataArrayMap.get("_dw_percent")!!
             }
+
+            position = percent.toFloat() / 1000000.0F
         }
         return position
     }
 
     fun splitBarSet(splitbar: ConstraintLayout, position: Float) {
         waitOnUiThread {
-            val topleft: View? = splitbar.getChildAt(0)
-            val bottomright: View? = splitbar.getChildAt(1)
-
-            if(splitbar.width > 0 && splitbar.height > 0) {
+            val dataArrayMap: SimpleArrayMap<String, Long> = splitbar.tag as SimpleArrayMap<String, Long>
+            var percent: Float = position * 1000000.0F
+
+            if(percent > 0F) {
+                val topleft: View? = splitbar.getChildAt(0)
+                val bottomright: View? = splitbar.getChildAt(1)
                 val constraintSet = ConstraintSet()
+                var type: Long = 0L
+
+                if (dataArrayMap.containsKey("_dw_type")) {
+                    type = dataArrayMap.get("_dw_type")!!
+                }
+                dataArrayMap.put("_dw_percent", percent.toLong())
+
                 constraintSet.clone(splitbar)
                 if (topleft != null) {
-                    if (splitbar.width == topleft.width) {
+                    if (type == 1L) {
                         constraintSet.constrainPercentHeight(topleft.id, position / 100.0F)
                     } else {
                         constraintSet.constrainPercentWidth(topleft.id, position / 100.0F)
@@ -2143,7 +2148,7 @@
                 }
                 if (bottomright != null) {
                     val altper: Float = (100.0F - position) / 100.0F
-                    if (splitbar.width == bottomright.width) {
+                    if (type == 1L) {
                         constraintSet.constrainPercentHeight(bottomright.id, altper)
                     } else {
                         constraintSet.constrainPercentWidth(bottomright.id, altper)