# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1621755052 0 # Node ID 01fca19378064ab122eafbed5ff49c4d5742aaa5 # Parent 9dea42f27b0a878ed01faf09b3858a6b07f8fc16 Android: Implement dw_window_set_focus(), dw_window_default() and dw_window_get_font(). dw_window_get_font() is untested... will test it shortly in another app. diff -r 9dea42f27b0a -r 01fca1937806 android/DWindows.kt --- a/android/DWindows.kt Sun May 23 02:41:06 2021 +0000 +++ b/android/DWindows.kt Sun May 23 07:30:52 2021 +0000 @@ -739,6 +739,7 @@ private var paint = Paint() private var bgcolor: Int = 0 private var menuBar: DWMenu? = null + private var defaultItem: View? = null // Our version of runOnUiThread that waits for execution fun waitOnUiThread(runnable: Runnable) @@ -939,6 +940,19 @@ return null } + fun windowSetFocus(window: View) + { + waitOnUiThread { + window.requestFocus() + } + } + + fun windowDefault(window: View, default: View) + { + // TODO: Verify this is the correct activity... + defaultItem = default + } + fun windowSetStyle(window: View, style: Int, mask: Int) { waitOnUiThread { @@ -1054,6 +1068,35 @@ } } + fun windowGetFont(window: View): String? + { + var fontname: String? = null + + waitOnUiThread { + var typeface: Typeface? = null + var fontsize: Float? = null + + if(window is DWRender) { + typeface = window.typeface + fontsize = window.fontsize + } else if(window is TextView) { + typeface = window.typeface + fontsize = window.textSize + } else if(window is Button) { + typeface = window.typeface + fontsize = window.textSize + } + + if(typeface != null && fontsize != null) { + val isize = fontsize.toInt() + val name = typeface.toString() + + fontname = "$isize.$name" + } + } + return null + } + fun windowSetColor(window: View, fore: Int, falpha: Int, fred: Int, fgreen: Int, fblue: Int, back: Int, balpha: Int, bred: Int, bgreen: Int, bblue: Int) { var colorfore: Int = Color.rgb(fred, fgreen, fblue) @@ -1136,6 +1179,7 @@ window.visibility = View.GONE } else { window.visibility = View.VISIBLE + defaultItem?.requestFocus() } } } diff -r 9dea42f27b0a -r 01fca1937806 android/dw.cpp --- a/android/dw.cpp Sun May 23 02:41:06 2021 +0000 +++ b/android/dw.cpp Sun May 23 07:30:52 2021 +0000 @@ -5093,6 +5093,19 @@ */ void API dw_window_set_focus(HWND handle) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // 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 windowSetFocus = env->GetMethodID(clazz, "windowSetFocus", + "(Landroid/view/View;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, windowSetFocus, handle); + _dw_jni_check_exception(env); + } } /* @@ -5105,6 +5118,19 @@ */ void API dw_window_default(HWND handle, HWND defaultitem) { + JNIEnv *env; + + if(handle && defaultitem && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // 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 windowDefault = env->GetMethodID(clazz, "windowDefault", + "(Landroid/view/View;Landroid/view/View;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, windowDefault, handle, defaultitem); + _dw_jni_check_exception(env); + } } /* @@ -5162,10 +5188,10 @@ // 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 windowHideShow = env->GetMethodID(clazz, "windowSetFont", + jmethodID windowSetFont = env->GetMethodID(clazz, "windowSetFont", "(Landroid/view/View;Ljava/lang/String;)V"); // Call the method on the object - env->CallVoidMethod(_dw_obj, windowHideShow, handle, jstr); + env->CallVoidMethod(_dw_obj, windowSetFont, handle, jstr); if(!_dw_jni_check_exception(env)) return DW_ERROR_NONE; } @@ -5181,7 +5207,23 @@ */ char * API dw_window_get_font(HWND handle) { - return nullptr; + JNIEnv *env; + char *fontname = nullptr; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // 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 windowGetFont = env->GetMethodID(clazz, "windowGetFont", + "(Landroid/view/View;)Ljava/lang/String;"); + // Call the method on the object + jstring jstr = (jstring)_dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, windowGetFont, handle), _DW_REFERENCE_NONE); + + if(jstr) + fontname = strdup(env->GetStringUTFChars(jstr, nullptr)); + } + return fontname; } /* Allows the user to choose a font using the system's font chooser dialog.