changeset 2686:95f61d3f3d0d

Android: Initial attempt at implmenting dw_window_get_preferred_size(). This function missing was causing layout issues in code using this function. The SeekBar (slider/scrollbar/etc) code seems to be backwards but it works this way.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 27 Oct 2021 22:00:31 +0000
parents 17c34bdaec6c
children 42ff9d95e87b
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 49 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Tue Oct 26 06:17:53 2021 +0000
+++ b/android/DWindows.kt	Wed Oct 27 22:00:31 2021 +0000
@@ -1241,6 +1241,27 @@
         }
     }
 
+    fun windowGetPreferredSize(window: View): Long
+    {
+        var retval: Long = 0
+
+        waitOnUiThread {
+            window.measure(0, 0)
+            val width = window.measuredWidth
+            val height = window.measuredHeight
+            retval = width.toLong() or (height.toLong() shl 32)
+            if(window is SeekBar) {
+                val slider = window as SeekBar
+
+                // If the widget is rotated, swap width and height
+                if(slider.rotation != 270F && slider.rotation != 90F) {
+                    retval = height.toLong() or (width.toLong() shl 32)
+                }
+            }
+        }
+        return retval
+    }
+
     fun windowGetData(window: View, name: String): Long {
         var retval = 0L
 
--- a/android/dw.cpp	Tue Oct 26 06:17:53 2021 +0000
+++ b/android/dw.cpp	Wed Oct 27 22:00:31 2021 +0000
@@ -5793,6 +5793,34 @@
  */
 void API dw_window_get_preferred_size(HWND handle, int *width, int *height)
 {
+    if(width || height)
+    {
+        JNIEnv *env;
+
+        if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+        {
+            // First get the class that contains the method you need to call
+            jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
+            // Get the method that you want to call
+            jmethodID windowGetPreferredSize = env->GetMethodID(clazz, "windowGetPreferredSize",
+                                                                "(Landroid/view/View;)J");
+            // Call the method on the object
+            jlong dimensions = env->CallLongMethod(_dw_obj, windowGetPreferredSize, handle);
+            if(_dw_jni_check_exception(env))
+                dimensions = 0;
+            if(width)
+                *width = (int)((dimensions >> 32) & 0xFFFF);
+            if(height)
+                *height = (int)(dimensions & 0xFFFF);
+        }
+        else
+        {
+            if(width)
+                *width = 0;
+            if(height)
+                *height = 0;
+        }
+    }
 }
 
 /*