Mercurial > dwindows
changeset 2510:f54051c3f2a5
Android: Implement MLE functions. Fix issues with checkboxes and sliders.
Started enabling all notebook tabs in the test program... but a number of
controls still missing, so functionality is still spotty at this point.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 07 May 2021 09:35:14 +0000 |
parents | eaac1317b851 |
children | 0945d0428dfe |
files | android/DWindows.kt android/dw.cpp |
diffstat | 2 files changed, 215 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Thu May 06 23:29:13 2021 +0000 +++ b/android/DWindows.kt Fri May 07 09:35:14 2021 +0000 @@ -3,7 +3,6 @@ import android.content.ClipData import android.content.ClipboardManager import android.content.DialogInterface -import android.content.Intent import android.content.pm.ActivityInfo import android.content.res.Configuration import android.graphics.Bitmap @@ -15,12 +14,14 @@ import android.os.Looper import android.text.InputFilter import android.text.InputFilter.LengthFilter +import android.text.InputType import android.text.method.PasswordTransformationMethod import android.util.Base64 import android.util.Log import android.view.Gravity import android.view.View import android.view.ViewGroup +import android.view.inputmethod.EditorInfo import android.webkit.WebView import android.webkit.WebViewClient import android.widget.* @@ -533,6 +534,101 @@ return textview } + fun mleNew(cid: Int): EditText? + { + var mle: EditText? = null + + waitOnUiThread { + var dataArrayMap = SimpleArrayMap<String, Long>() + + mle = EditText(this) + mle!!.tag = dataArrayMap + mle!!.id = cid + mle!!.isSingleLine = false + mle!!.imeOptions = EditorInfo.IME_FLAG_NO_ENTER_ACTION + mle!!.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) + mle!!.isVerticalScrollBarEnabled = true + mle!!.scrollBarStyle = View.SCROLLBARS_INSIDE_INSET + mle!!.setHorizontallyScrolling(true) + } + return mle + } + + fun mleSetWordWrap(mle: EditText, state: Int) + { + waitOnUiThread { + if (state != 0) { + mle.setHorizontallyScrolling(false) + } else { + mle.setHorizontallyScrolling(true) + } + } + } + + fun mleSetEditable(mle: EditText, state: Int) + { + waitOnUiThread { + if (state != 0) { + mle!!.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) + } else { + mle!!.inputType = InputType.TYPE_NULL + } + } + } + + fun mleSetCursor(mle: EditText, point: Int) + { + waitOnUiThread { + mle.setSelection(point) + } + } + + fun mleClear(mle: EditText) + { + waitOnUiThread { + mle.setText("") + } + } + + fun mleImport(mle: EditText, text: String, startpoint: Int): Int + { + var retval: Int = startpoint + + waitOnUiThread { + val origtext = mle.text + val origlen = origtext.toString().length + + if(startpoint < 1) { + val newtext = text + origtext.toString() + + mle.setText(newtext) + retval = origlen + text.length + } else if(startpoint >= origlen) { + val newtext = origtext.toString() + text + + mle.setText(newtext) + retval = origlen + text.length + } else { + val newtext = origtext.substring(0, startpoint) + text + origtext.substring(startpoint) + + mle.setText(newtext) + retval = startpoint + text.length + } + mle.setSelection(retval) + } + return retval + } + + fun mleDelete(mle: EditText, startpoint: Int, length: Int) + { + waitOnUiThread { + val origtext = mle.text + val newtext = origtext.substring(0, startpoint) + origtext.substring(startpoint + length) + + mle.setText(newtext) + } + } + fun notebookNew(cid: Int, top: Int): RelativeLayout? { var notebook: RelativeLayout? = null @@ -778,7 +874,7 @@ } override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - eventHandler(slider, null, 14, null, null, slider!!.progress, 0, 0, 0) + eventHandlerInt(slider as View, 14, slider!!.progress, 0, 0, 0) } }) }
--- a/android/dw.cpp Thu May 06 23:29:13 2021 +0000 +++ b/android/dw.cpp Fri May 07 09:35:14 2021 +0000 @@ -1432,8 +1432,7 @@ 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); - jclass clazz = env->FindClass(DW_CLASS_NAME); + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID checkOrRadioGetChecked = env->GetMethodID(clazz, "checkOrRadioGetChecked", "(Landroid/view/View;)Z"); @@ -1456,8 +1455,7 @@ 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); - jclass clazz = env->FindClass(DW_CLASS_NAME); + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); // Get the method that you want to call jmethodID checkOrRadioSetChecked = env->GetMethodID(clazz, "checkOrRadioSetChecked", "(Landroid/view/View;I)V"); @@ -1633,6 +1631,19 @@ */ HWND API dw_mle_new(ULONG cid) { + JNIEnv *env; + + if((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 mleNew = env->GetMethodID(clazz, "mleNew", + "(I)Landroid/widget/EditText;"); + // Call the method on the object + jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, mleNew, (int)cid)); + return result; + } return 0; } @@ -1647,7 +1658,22 @@ */ unsigned int API dw_mle_import(HWND handle, const char *buffer, int startpoint) { - return 0; + JNIEnv *env; + int retval = 0; + + if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // Construct a String + jstring jstr = env->NewStringUTF(buffer); + // 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 mleImport = env->GetMethodID(clazz, "mleImport", + "(Landroid/widget/EditText;Ljava/lang/String;I)I"); + // Call the method on the object + retval = env->CallIntMethod(_dw_obj, mleImport, handle, jstr, startpoint); + } + return retval; } /* @@ -1660,6 +1686,19 @@ */ void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) { + if(buffer && length > 0) { + char *text = dw_window_get_text(handle); + + if (text) { + int len = strlen(text); + + if (startpoint < len) + strncpy(buffer, &text[startpoint], length); + else + buffer[0] = '\0'; + free(text); + } + } } /* @@ -1671,10 +1710,31 @@ */ void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) { - if(bytes) - *bytes = 0; - if(lines) - *lines = 0; + char *text = dw_window_get_text(handle); + + if(bytes) { + if(text) { + *bytes = strlen(text); + } else { + *bytes = 0; + } + } + if(lines) { + if(text) + { + int count = 0; + char *tmp = text; + + while((tmp = strchr(tmp, '\n'))) { + count++; + } + *lines = count; + } else { + *lines = 0; + } + } + if(text) + free(text); } /* @@ -1695,6 +1755,18 @@ */ void API dw_mle_clear(HWND handle) { + JNIEnv *env; + + if((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 mleClear = env->GetMethodID(clazz, "mleClear", + "(Landroid/widget/EditText;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, mleClear, handle); + } } /* @@ -1715,6 +1787,18 @@ */ void API dw_mle_set_editable(HWND handle, int state) { + JNIEnv *env; + + if((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 mleSetEditable = env->GetMethodID(clazz, "mleSetEditable", + "(Landroid/widget/EditText;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, mleSetEditable, handle, state); + } } /* @@ -1725,6 +1809,18 @@ */ void API dw_mle_set_word_wrap(HWND handle, int state) { + JNIEnv *env; + + if((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 mleSetWordWrap = env->GetMethodID(clazz, "mleSetWordWrap", + "(Landroid/widget/EditText;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, mleSetWordWrap, handle, state); + } } /* @@ -1735,6 +1831,18 @@ */ void API dw_mle_set_cursor(HWND handle, int point) { + JNIEnv *env; + + if((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 mleSetWordWrap = env->GetMethodID(clazz, "mleSetWordWrap", + "(Landroid/widget/EditText;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, mleSetWordWrap, handle, point); + } } /*