# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1619482616 0 # Node ID cec43818bd3e65b249cbe7b4ede28c10874372cb # Parent a0c493abb8729dd5ac09b51b59433bbf847ceefc Android: Implement dw_messagebox() ... seems we can't just cleanly exit(). diff -r a0c493abb872 -r cec43818bd3e android/DWindows.kt --- 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. diff -r a0c493abb872 -r cec43818bd3e android/dw.cpp --- a/android/dw.cpp Mon Apr 26 21:56:37 2021 +0000 +++ b/android/dw.cpp Tue Apr 27 00:16:56 2021 +0000 @@ -592,6 +592,27 @@ */ int API dw_messagebox(const char *title, int flags, const char *format, ...) { + va_list args; + char outbuf[1025] = {0}; + JNIEnv *env; + + va_start(args, format); + vsnprintf(outbuf, 1024, format, args); + va_end(args); + + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // Construct a String + jstring jstr = env->NewStringUTF(outbuf); + jstring jstrtitle = env->NewStringUTF(title); + // 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 messageBox = env->GetMethodID(clazz, "messageBox", + "(Ljava/lang/String;Ljava/lang/String;I)I"); + // Call the method on the object + return env->CallIntMethod(_dw_obj, messageBox, jstrtitle, jstr, flags); + } return 0; }