changeset 2558:ebc6a4ff5f1f

Android: Implement container row data and titles, required for the callbacks.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 18 May 2021 01:04:52 +0000
parents 756331246f94
children b5e8a319fde6
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 216 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Mon May 17 21:11:40 2021 +0000
+++ b/android/DWindows.kt	Tue May 18 01:04:52 2021 +0000
@@ -465,6 +465,8 @@
     var columns = mutableListOf<String?>()
     var types = mutableListOf<Int>()
     var data = mutableListOf<Any?>()
+    var rowdata = mutableListOf<Long>()
+    var rowtitle = mutableListOf<String?>()
 
     fun numberOfColumns(): Int
     {
@@ -511,6 +513,36 @@
         }
     }
 
+    fun changeRowData(row: Int, rdata: Long)
+    {
+        if(row > -1 && row < rowdata.size) {
+            rowdata[row] = rdata
+        }
+    }
+
+    fun getRowData(row: Int): Long
+    {
+        if(row > -1 && row < rowdata.size) {
+            return rowdata[row]
+        }
+        return 0
+    }
+
+    fun changeRowTitle(row: Int, title: String?)
+    {
+        if(row > -1 && row < rowtitle.size) {
+            rowtitle[row] = title
+        }
+    }
+
+    fun getRowTitle(row: Int): String?
+    {
+        if(row > -1 && row < rowtitle.size) {
+            return rowtitle[row]
+        }
+        return null
+    }
+
     fun addColumn(title: String?, type: Int)
     {
         columns.add(title)
@@ -519,14 +551,62 @@
         data.clear()
     }
 
+    fun deleteRows(count: Int)
+    {
+        if(count < rowdata.size) {
+            for(i in 0 until count) {
+                for(j in 0 until columns.size) {
+                    data.removeAt(0)
+                }
+                rowdata.removeAt(0)
+                rowtitle.removeAt(0)
+            }
+        } else {
+            data.clear()
+            rowdata.clear()
+            rowtitle.clear()
+        }
+    }
+
+    fun deleteRowByTitle(title: String?)
+    {
+        for(i in 0 until rowtitle.size) {
+            if(rowtitle[i] != null && rowtitle[i] == title) {
+                for(j in 0 until columns.size) {
+                    data.removeAt(i * columns.size)
+                }
+                rowdata.removeAt(i)
+                rowtitle.removeAt(i)
+            }
+        }
+    }
+
+    fun deleteRowByData(rdata: Long)
+    {
+        for(i in 0 until rowdata.size) {
+            if(rowdata[i] == rdata) {
+                for(j in 0 until columns.size) {
+                    data.removeAt(i * columns.size)
+                }
+                rowdata.removeAt(i)
+                rowtitle.removeAt(i)
+            }
+        }
+    }
+
     fun addRows(count: Int): Long
     {
         var startRow: Long = numberOfRows().toLong()
 
-        for(i in 0 until (count * columns.size))
+        for(i in 0 until count)
         {
-            // Fill in with nulls to be set later
-            data.add(null)
+            for(j in 0 until columns.size)
+            {
+                // Fill in with nulls to be set later
+                data.add(null)
+            }
+            rowdata.add(0)
+            rowtitle.add(null)
         }
         return startRow
     }
@@ -534,6 +614,8 @@
     fun clear()
     {
         data.clear()
+        rowdata.clear()
+        rowtitle.clear()
     }
 }
 
@@ -1953,6 +2035,24 @@
         }
     }
 
+    fun containerChangeRowData(cont: ListView, row: Int, data: Long)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+
+            adapter.model.changeRowData(row, data)
+        }
+    }
+
+    fun containerChangeRowTitle(cont: ListView, row: Int, title: String?)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+
+            adapter.model.changeRowTitle(row, title)
+        }
+    }
+
     fun containerGetColumnType(cont: ListView, column: Int): Int
     {
         var type: Int = 0
@@ -1965,6 +2065,33 @@
         return type
     }
 
+    fun containerDelete(cont: ListView, rowcount: Int)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+
+            adapter.model.deleteRows(rowcount)
+        }
+    }
+
+    fun containerRowDeleteByTitle(cont: ListView, title: String?)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+
+            adapter.model.deleteRowByTitle(title)
+        }
+    }
+
+    fun containerRowDeleteByData(cont: ListView, data: Long)
+    {
+        waitOnUiThread {
+            val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
+
+            adapter.model.deleteRowByData(data)
+        }
+    }
+
     fun containerClear(cont: ListView)
     {
         waitOnUiThread {
--- a/android/dw.cpp	Mon May 17 21:11:40 2021 +0000
+++ b/android/dw.cpp	Tue May 18 01:04:52 2021 +0000
@@ -105,9 +105,9 @@
 
     if(!_dw_jni_check_exception(env) && obj)
     {
-        if(reference == 1)
+        if(reference == _DW_REFERENCE_WEAK)
             result = env->NewWeakGlobalRef(obj);
-        else if(reference == 2)
+        else if(reference == _DW_REFERENCE_STRONG)
             result = env->NewGlobalRef(obj);
         else
             result = obj;
@@ -3029,7 +3029,8 @@
                                                           "(Landroid/widget/ListView;Ljava/lang/String;I)V");
                 // Call the method on the object
                 env->CallVoidMethod(_dw_obj, containerNew, handle, jstr, (int)flags[z]);
-                _dw_jni_check_exception(env);
+                if(!_dw_jni_check_exception(env))
+                    return DW_ERROR_NONE;
             }
         }
     }
@@ -3060,9 +3061,11 @@
 {
     unsigned long fsflags[2] = { DW_CFA_BITMAPORICON, DW_CFA_STRING };
     char *fstitles[2] = { (char *)"Icon", (char *)"Filename" };
-    dw_container_setup(handle, fsflags, fstitles, 2, 0);
-    dw_container_setup(handle, flags, titles, count, 0);
-    return DW_ERROR_GENERAL;
+    int retval = dw_container_setup(handle, fsflags, fstitles, 2, 0);
+
+    if(retval == DW_ERROR_NONE)
+        retval = dw_container_setup(handle, flags, titles, count, 0);
+    return retval;
 }
 
 /*
@@ -3237,6 +3240,14 @@
  */
 void API dw_container_set_row_data(void *pointer, int row, void *data)
 {
+    HWND handle = (HWND)pointer;
+
+    if(handle)
+    {
+        int rowstart = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_rowstart"));
+
+        dw_container_change_row_data(handle, row + rowstart, data);
+    }
 }
 
 /*
@@ -3248,6 +3259,19 @@
  */
 void API dw_container_change_row_data(HWND handle, int row, void *data)
 {
+    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 containerChangeRowData = env->GetMethodID(clazz, "containerChangeRowData",
+                                                            "(Landroid/widget/ListView;IJ)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerChangeRowData, handle, row, (jlong)data);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3336,6 +3360,21 @@
  */
 void API dw_container_change_row_title(HWND handle, int row, const char *title)
 {
+    JNIEnv *env;
+
+    if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    {
+        // Generate a string
+        jstring jstr = title ? env->NewStringUTF(title) : 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 containerChangeRowTitle = env->GetMethodID(clazz, "containerChangeRowTitle",
+                                                             "(Landroid/widget/ListView;ILjava/lang/String;)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerChangeRowTitle, handle, row, jstr);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3385,6 +3424,19 @@
  */
 void API dw_container_delete(HWND handle, int rowcount)
 {
+    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 containerDelete = env->GetMethodID(clazz, "containerDelete",
+                                                     "(Landroid/widget/ListView;I)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerDelete, handle, rowcount);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3457,6 +3509,21 @@
  */
 void API dw_container_delete_row(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 containerRowDeleteByTitle = env->GetMethodID(clazz, "containerRowDeleteByTitle",
+                                                               "(Landroid/widget/ListView;Ljava/lang/String;)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerRowDeleteByTitle, handle, jstr);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*
@@ -3467,6 +3534,19 @@
  */
 void API dw_container_delete_row_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 containerRowDeleteByData = env->GetMethodID(clazz, "containerRowDeleteByData",
+                                                              "(Landroid/widget/ListView;J)V");
+        // Call the method on the object
+        env->CallVoidMethod(_dw_obj, containerRowDeleteByData, handle, (jlong)data);
+        _dw_jni_check_exception(env);
+    }
 }
 
 /*