changeset 2709:3cb5aa73dace

Android: Implement dw_container_scroll(), dw_container_cursor() and dw_container_cursor_by_data().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 22 Nov 2021 02:18:08 +0000
parents 3a7dcc0ae08b
children 98cc4476b376
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 115 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Fri Nov 19 18:48:41 2021 +0000
+++ b/android/DWindows.kt	Mon Nov 22 02:18:08 2021 +0000
@@ -656,6 +656,26 @@
         }
     }
 
+    fun positionByTitle(title: String?): Int
+    {
+        for(i in 0 until rowtitle.size) {
+            if(rowtitle[i] != null && rowtitle[i] == title) {
+                return i
+            }
+        }
+        return -1
+    }
+
+    fun positionByData(rdata: Long): Int
+    {
+        for(i in 0 until rowdata.size) {
+            if (rowdata[i] == rdata) {
+                return i
+            }
+        }
+        return -1
+    }
+
     fun addRows(count: Int): Long
     {
         val startRow: Long = numberOfRows().toLong()
@@ -3246,6 +3266,60 @@
         }
     }
 
+    fun containerScroll(cont: ListView, direction: Int, rows: Int)
+    {
+        waitOnUiThread {
+            // DW_SCROLL_UP 0
+            if(direction == 0) {
+                cont.smoothScrollByOffset(-rows)
+                // DW_SCROLL_DOWN 1
+            } else if(direction == 1) {
+                cont.smoothScrollByOffset(rows)
+                // DW_SCROLL_TOP 2
+            } else if(direction == 2) {
+                cont.setSelection(0)
+                cont.smoothScrollToPosition(0)
+                // DW_SCROLL_BOTTOM 3
+            } else if(direction == 3) {
+                val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+                val pos = adapter.model.rowdata.size
+
+                if(pos > 0) {
+                    cont.setSelection(pos - 1)
+                    cont.smoothScrollToPosition(pos - 1)
+                }
+            }
+        }
+    }
+
+    fun containerCursor(cont: ListView, title: String?)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+            val pos = adapter.model.positionByTitle(title)
+
+            if(pos > -1) {
+                cont.setSelection(pos)
+                cont.smoothScrollToPosition(pos)
+            }
+
+        }
+    }
+
+    fun containerCursorByData(cont: ListView, rdata: Long)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+            val pos = adapter.model.positionByData(rdata)
+
+            if(pos > -1) {
+                cont.setSelection(pos)
+                cont.smoothScrollToPosition(pos)
+            }
+
+        }
+    }
+
     fun listBoxNew(cid: Int, multi: Int): DWListBox?
     {
         var listbox: DWListBox? = null
--- a/android/dw.cpp	Fri Nov 19 18:48:41 2021 +0000
+++ b/android/dw.cpp	Mon Nov 22 02:18:08 2021 +0000
@@ -3893,6 +3893,19 @@
  */
 void API dw_container_scroll(HWND handle, int direction, long rows)
 {
+    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 containerScroll = env->GetMethodID(clazz, "containerScroll",
+                                                     "(Landroid/widget/ListView;II)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerScroll, handle, direction, (jint)rows);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3987,6 +4000,21 @@
  */
 void API dw_container_cursor(HWND handle, const char *text)
 {
+    JNIEnv *env;
+
+    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    {
+        // Generate a string
+        jstring jstr = text ? env->NewStringUTF(text) : nullptr;
+        // 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 containerCursor = env->GetMethodID(clazz, "containerCursor",
+                                                               "(Landroid/widget/ListView;Ljava/lang/String;)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerCursor, handle, jstr);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3997,6 +4025,19 @@
  */
 void API dw_container_cursor_by_data(HWND handle, void *data)
 {
+    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 containerCursorByData = env->GetMethodID(clazz, "containerCursorByData",
+                                                              "(Landroid/widget/ListView;J)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerCursorByData, handle, (jlong)data);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*