comparison android/DWindows.kt @ 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
comparison
equal deleted inserted replaced
2479:54b0008a0569 2480:878d36588aaa
1 package org.dbsoft.dwindows.dwtest 1 package org.dbsoft.dwindows.dwtest
2 2
3 import android.content.pm.ActivityInfo
3 import android.os.Bundle 4 import android.os.Bundle
4 import android.text.method.PasswordTransformationMethod 5 import android.text.method.PasswordTransformationMethod
5 import android.util.Half.toFloat 6 import android.util.Half.toFloat
6 import android.view.Gravity 7 import android.view.Gravity
7 import android.view.View 8 import android.view.View
13 { 14 {
14 override fun onCreate(savedInstanceState: Bundle?) 15 override fun onCreate(savedInstanceState: Bundle?)
15 { 16 {
16 super.onCreate(savedInstanceState) 17 super.onCreate(savedInstanceState)
17 18
19 // Turn on rotation
20 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR)
21
22 // Get the Android app path
18 val m = packageManager 23 val m = packageManager
19 var s = packageName 24 var s = packageName
20 val p = m.getPackageInfo(s!!, 0) 25 val p = m.getPackageInfo(s!!, 0)
21 s = p.applicationInfo.dataDir 26 s = p.applicationInfo.dataDir
22 27
55 { 60 {
56 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT 61 var w: Int = LinearLayout.LayoutParams.WRAP_CONTENT
57 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT 62 var h: Int = LinearLayout.LayoutParams.WRAP_CONTENT
58 63
59 if(item is LinearLayout) { 64 if(item is LinearLayout) {
60 if (vsize > 0) { 65 if(box.orientation == LinearLayout.VERTICAL) {
61 h = LinearLayout.LayoutParams.MATCH_PARENT 66 if (hsize > 0) {
62 } 67 w = LinearLayout.LayoutParams.MATCH_PARENT
63 if (hsize > 0) { 68 }
64 w = LinearLayout.LayoutParams.MATCH_PARENT 69 } else {
70 if (vsize > 0) {
71 h = LinearLayout.LayoutParams.MATCH_PARENT
72 }
65 } 73 }
66 } 74 }
67 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) 75 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
68 76
69 if(item !is LinearLayout && (width != -1 || height != -1)) { 77 if(item !is LinearLayout && (width != -1 || height != -1)) {
77 h = height 85 h = height
78 } else if(height == -1) { 86 } else if(height == -1) {
79 h = item.getMeasuredHeight() 87 h = item.getMeasuredHeight()
80 } 88 }
81 } 89 }
82 if(vsize > 0) { 90 if(box.orientation == LinearLayout.VERTICAL) {
83 if(w > 0) { 91 if (vsize > 0) {
84 params.weight = w.toFloat() 92 if (w > 0) {
85 } else { 93 params.weight = w.toFloat()
86 params.weight = 1F 94 } else {
95 params.weight = 1F
96 }
87 } 97 }
88 } 98 } else {
89 if(hsize > 0) { 99 if (hsize > 0) {
90 if(h > 0) { 100 if (h > 0) {
91 params.weight = h.toFloat() 101 params.weight = h.toFloat()
92 } else { 102 } else {
93 params.weight = 1F 103 params.weight = 1F
104 }
94 } 105 }
95 } 106 }
96 if(pad > 0) { 107 if(pad > 0) {
97 params.setMargins(pad, pad, pad, pad) 108 params.setMargins(pad, pad, pad, pad)
98 } 109 }