changeset 2480:878d36588aaa

Android: Enable app rotation and fix some issues with layout. The layout is usable now, but some issues still remain, not sure if they are fixable... like the single weight regardless of orientation.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 25 Apr 2021 23:33:53 +0000
parents 54b0008a0569
children 94f0d61d6953
files android/DWindows.kt
diffstat 1 files changed, 27 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Sat Apr 24 21:28:57 2021 +0000
+++ b/android/DWindows.kt	Sun Apr 25 23:33:53 2021 +0000
@@ -1,5 +1,6 @@
 package org.dbsoft.dwindows.dwtest
 
+import android.content.pm.ActivityInfo
 import android.os.Bundle
 import android.text.method.PasswordTransformationMethod
 import android.util.Half.toFloat
@@ -15,6 +16,10 @@
     {
         super.onCreate(savedInstanceState)
 
+        // Turn on rotation
+        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
+
+        // Get the Android app path
         val m = packageManager
         var s = packageName
         val p = m.getPackageInfo(s!!, 0)
@@ -57,11 +62,14 @@
         var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT
 
         if(item is LinearLayout) {
-            if (vsize > 0) {
-                h = LinearLayout.LayoutParams.MATCH_PARENT
-            }
-            if (hsize > 0) {
-                w = LinearLayout.LayoutParams.MATCH_PARENT
+            if(box.orientation == LinearLayout.VERTICAL) {
+                if (hsize > 0) {
+                    w = LinearLayout.LayoutParams.MATCH_PARENT
+                }
+            } else {
+                if (vsize > 0) {
+                    h = LinearLayout.LayoutParams.MATCH_PARENT
+                }
             }
         }
         var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
@@ -79,18 +87,21 @@
                 h = item.getMeasuredHeight()
             }
         }
-        if(vsize > 0) {
-            if(w > 0) {
-                params.weight = w.toFloat()
-            } else {
-                params.weight = 1F
+        if(box.orientation == LinearLayout.VERTICAL) {
+            if (vsize > 0) {
+                if (w > 0) {
+                    params.weight = w.toFloat()
+                } else {
+                    params.weight = 1F
+                }
             }
-        }
-        if(hsize > 0) {
-            if(h > 0) {
-                params.weight = h.toFloat()
-            } else {
-                params.weight = 1F
+        } else {
+            if (hsize > 0) {
+                if (h > 0) {
+                    params.weight = h.toFloat()
+                } else {
+                    params.weight = 1F
+                }
             }
         }
         if(pad > 0) {