comparison android/DWindows.kt @ 2486:cec43818bd3e

Android: Implement dw_messagebox() ... seems we can't just cleanly exit().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 27 Apr 2021 00:16:56 +0000
parents cb5b67154399
children 83f8f4f58a98
comparison
equal deleted inserted replaced
2485:a0c493abb872 2486:cec43818bd3e
1 package org.dbsoft.dwindows 1 package org.dbsoft.dwindows
2 2
3 import android.content.DialogInterface
3 import android.content.pm.ActivityInfo 4 import android.content.pm.ActivityInfo
4 import android.os.Bundle 5 import android.os.Bundle
6 import android.os.Looper
5 import android.text.method.PasswordTransformationMethod 7 import android.text.method.PasswordTransformationMethod
6 import android.util.Half.toFloat
7 import android.util.Log 8 import android.util.Log
8 import android.view.Gravity 9 import android.view.Gravity
9 import android.view.View 10 import android.view.View
10 import android.widget.* 11 import android.widget.*
12 import androidx.appcompat.app.AlertDialog
11 import androidx.appcompat.app.AppCompatActivity 13 import androidx.appcompat.app.AppCompatActivity
12 14
13 15
14 class DWindows : AppCompatActivity() 16 class DWindows : AppCompatActivity()
15 { 17 {
74 } 76 }
75 } 77 }
76 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) 78 var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h)
77 79
78 if(item !is LinearLayout && (width != -1 || height != -1)) { 80 if(item !is LinearLayout && (width != -1 || height != -1)) {
79 item.measure(0,0) 81 item.measure(0, 0)
80 if (width > 0) { 82 if (width > 0) {
81 w = width 83 w = width
82 } else if(width == -1) { 84 } else if(width == -1) {
83 w = item.getMeasuredWidth() 85 w = item.getMeasuredWidth()
84 } 86 }
176 fun debugMessage(text: String) 178 fun debugMessage(text: String)
177 { 179 {
178 Log.d(null, text) 180 Log.d(null, text)
179 } 181 }
180 182
183 fun messageBox(title: String, body: String, flags: Int): Int
184 {
185 // make a text input dialog and show it
186 var alert = AlertDialog.Builder(this)
187 var retval: Int = 0
188
189 alert.setTitle(title)
190 alert.setMessage(body)
191 if((flags and (1 shl 3)) != 0) {
192 alert.setPositiveButton("Yes", DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
193 retval = 1
194 throw java.lang.RuntimeException()
195 });
196 }
197 if((flags and ((1 shl 1) or (1 shl 2))) != 0) {
198 alert.setNegativeButton("Ok", DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
199 retval = 0
200 throw java.lang.RuntimeException()
201 });
202 }
203 if((flags and ((1 shl 3) or (1 shl 4))) != 0) {
204 alert.setNegativeButton("No", DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
205 retval = 0
206 throw java.lang.RuntimeException()
207 });
208 }
209 if((flags and ((1 shl 2) or (1 shl 4))) != 0) {
210 alert.setNeutralButton("Cancel", DialogInterface.OnClickListener { _: DialogInterface, _: Int ->
211 retval = 2
212 throw java.lang.RuntimeException()
213 });
214 }
215 alert.show();
216
217 // loop till a runtime exception is triggered.
218 try {
219 Looper.loop()
220 } catch (e2: RuntimeException) {
221 }
222 return retval
223 }
224
181 /* 225 /*
182 * Native methods that are implemented by the 'dwindows' native library, 226 * Native methods that are implemented by the 'dwindows' native library,
183 * which is packaged with this application. 227 * which is packaged with this application.
184 */ 228 */
185 external fun dwindowsInit(dataDir: String): String 229 external fun dwindowsInit(dataDir: String): String