changeset 2701:9df2c11f020f

Android: Fix dw_mle_set_word_wrap() and dw_mle_set_cursor(). Calling the wrong method in dw_mle_set_cursor(). Set maxWidth on MLE resize based on Word Wrap setting.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 16 Nov 2021 20:15:18 +0000
parents 246f23670e3b
children 4f12dc8e8f18
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Tue Nov 16 11:26:19 2021 +0000
+++ b/android/DWindows.kt	Tue Nov 16 20:15:18 2021 +0000
@@ -809,6 +809,17 @@
     }
 }
 
+private class DWMLE(c: Context): androidx.appcompat.widget.AppCompatEditText(c) {
+    protected override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
+        if(!isHorizontalScrollBarEnabled) {
+            this.maxWidth = w
+        } else {
+            this.maxWidth = -1
+        }
+        super.onSizeChanged(w, h, oldw, oldh)
+    }
+}
+
 class DWindows : AppCompatActivity() {
     var windowLayout: ViewPager2? = null
     var threadLock = ReentrantLock()
@@ -2132,7 +2143,7 @@
         waitOnUiThread {
             val dataArrayMap = SimpleArrayMap<String, Long>()
 
-            mle = EditText(this)
+            mle = DWMLE(this)
             mle!!.tag = dataArrayMap
             mle!!.id = cid
             mle!!.isSingleLine = false
--- a/android/dw.cpp	Tue Nov 16 11:26:19 2021 +0000
+++ b/android/dw.cpp	Tue Nov 16 20:15:18 2021 +0000
@@ -2717,10 +2717,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 mleSetWordWrap = env->GetMethodID(clazz, "mleSetWordWrap",
+        jmethodID mleSetCursor = env->GetMethodID(clazz, "mleSetCursor",
                                                     "(Landroid/widget/EditText;I)V");
         // Call the method on the object
-        env->CallVoidMethod(_dw_obj, mleSetWordWrap, handle, point);
+        env->CallVoidMethod(_dw_obj, mleSetCursor, handle, point);
         _dw_jni_check_exception(env);
     }
 }