Mercurial > dwindows
diff 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 |
line wrap: on
line diff
--- a/android/DWindows.kt Mon Apr 26 21:56:37 2021 +0000 +++ b/android/DWindows.kt Tue Apr 27 00:16:56 2021 +0000 @@ -1,13 +1,15 @@ package org.dbsoft.dwindows +import android.content.DialogInterface import android.content.pm.ActivityInfo import android.os.Bundle +import android.os.Looper import android.text.method.PasswordTransformationMethod -import android.util.Half.toFloat import android.util.Log import android.view.Gravity import android.view.View import android.widget.* +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity @@ -76,7 +78,7 @@ var params: LinearLayout.LayoutParams = LinearLayout.LayoutParams(w, h) if(item !is LinearLayout && (width != -1 || height != -1)) { - item.measure(0,0) + item.measure(0, 0) if (width > 0) { w = width } else if(width == -1) { @@ -178,6 +180,48 @@ Log.d(null, text) } + fun messageBox(title: String, body: String, flags: Int): Int + { + // make a text input dialog and show it + var alert = AlertDialog.Builder(this) + var retval: Int = 0 + + alert.setTitle(title) + alert.setMessage(body) + if((flags and (1 shl 3)) != 0) { + alert.setPositiveButton("Yes", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 1 + throw java.lang.RuntimeException() + }); + } + if((flags and ((1 shl 1) or (1 shl 2))) != 0) { + alert.setNegativeButton("Ok", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 0 + throw java.lang.RuntimeException() + }); + } + if((flags and ((1 shl 3) or (1 shl 4))) != 0) { + alert.setNegativeButton("No", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 0 + throw java.lang.RuntimeException() + }); + } + if((flags and ((1 shl 2) or (1 shl 4))) != 0) { + alert.setNeutralButton("Cancel", DialogInterface.OnClickListener { _: DialogInterface, _: Int -> + retval = 2 + throw java.lang.RuntimeException() + }); + } + alert.show(); + + // loop till a runtime exception is triggered. + try { + Looper.loop() + } catch (e2: RuntimeException) { + } + return retval + } + /* * Native methods that are implemented by the 'dwindows' native library, * which is packaged with this application.