Mercurial > dwindows
changeset 2482:4888503c3e3e
Android: Implement dw_debug() using the Android Log class.
Make eventHandler() second View and string parameters nullable.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 26 Apr 2021 18:34:51 +0000 |
parents | 94f0d61d6953 |
children | 9f7af6d8c6a4 |
files | android/DWindows.kt android/dw.cpp |
diffstat | 2 files changed, 36 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Mon Apr 26 11:01:58 2021 +0000 +++ b/android/DWindows.kt Mon Apr 26 18:34:51 2021 +0000 @@ -4,6 +4,7 @@ import android.os.Bundle 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.* @@ -129,7 +130,9 @@ { val button = Button(this) button.text = text - button.setOnClickListener { eventHandler(button, button, 8, "", "", 0, 0, 0, 0) } + button.setOnClickListener { + eventHandler(button, null, 8, null, null, 0, 0, 0, 0) + } return button } @@ -147,7 +150,9 @@ { val radiobutton = RadioButton(this) radiobutton.text = text - radiobutton.setOnClickListener { eventHandler(radiobutton, radiobutton, 8, "", "", 0, 0, 0, 0) } + radiobutton.setOnClickListener { + eventHandler(radiobutton, null, 8, null, null, 0, 0, 0, 0) + } return radiobutton } @@ -155,6 +160,9 @@ { val checkbox = CheckBox(this) checkbox.text = text + checkbox.setOnClickListener { + eventHandler(checkbox, null, 8, null, null, 0, 0, 0, 0) + } return checkbox } @@ -165,12 +173,17 @@ return textview } + fun debugMessage(text: String) + { + Log.d(null, text) + } + /* * Native methods that are implemented by the 'dwindows' native library, * which is packaged with this application. */ external fun dwindowsInit(dataDir: String): String - external fun eventHandler(obj1: Any, obj2: Any, message: Int, str1: String, str2: String, int1: Int, int2: Int, int3: Int, int4: Int): Int + external fun eventHandler(obj1: View, obj2: View?, message: Int, str1: String?, str2: String?, int1: Int, int2: Int, int3: Int, int4: Int): Int companion object {
--- a/android/dw.cpp Mon Apr 26 11:01:58 2021 +0000 +++ b/android/dw.cpp Mon Apr 26 18:34:51 2021 +0000 @@ -348,6 +348,7 @@ void *params[8] = { (void *)obj2, (void *)utf81, (void *)utf82, DW_INT_TO_POINTER(int1), DW_INT_TO_POINTER(int2), DW_INT_TO_POINTER(int3), DW_INT_TO_POINTER(int4), NULL }; + return _dw_event_handler(obj1, params, message); } @@ -543,15 +544,30 @@ { va_list args; char outbuf[1025] = {0}; + JNIEnv *env; va_start(args, format); vsnprintf(outbuf, 1024, format, args); va_end(args); - /* Output to stderr, if there is another way to send it - * on the implementation platform, change this. - */ - fprintf(stderr, "%s", outbuf); + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // Construct a String + jstring jstr = env->NewStringUTF(outbuf); + // 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 debugMessage = env->GetMethodID(clazz, "debugMessage", + "(Ljava/lang/String;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, debugMessage, jstr); + } + else { + /* Output to stderr, if there is another way to send it + * on the implementation platform, change this. + */ + fprintf(stderr, "%s", outbuf); + } } /*