changeset 2689:7127de139acf

Android: Implement groupbox using RadioGroup... still missing the title and visible border seen on most other platforms, but it works for making sure radiobuttons contained inside only have one selected.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 28 Oct 2021 17:27:59 +0000
parents c359cbd0b20f
children 755d9ad07aaf
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 38 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Thu Oct 28 00:22:42 2021 +0000
+++ b/android/DWindows.kt	Thu Oct 28 17:27:59 2021 +0000
@@ -1635,6 +1635,28 @@
         return box
     }
 
+    fun groupBoxNew(type: Int, pad: Int, title: String?): LinearLayout? {
+        var box: LinearLayout? = null
+        waitOnUiThread {
+            box = RadioGroup(this)
+            val dataArrayMap = SimpleArrayMap<String, Long>()
+
+            box!!.tag = dataArrayMap
+            box!!.layoutParams =
+                LinearLayout.LayoutParams(
+                    LinearLayout.LayoutParams.WRAP_CONTENT,
+                    LinearLayout.LayoutParams.WRAP_CONTENT
+                )
+            if (type > 0) {
+                box!!.orientation = LinearLayout.VERTICAL
+            } else {
+                box!!.orientation = LinearLayout.HORIZONTAL
+            }
+            box!!.setPadding(pad, pad, pad, pad)
+        }
+        return box
+    }
+
     fun scrollBoxNew(type: Int, pad: Int) : ScrollView? {
         var scrollBox: ScrollView? = null
 
--- a/android/dw.cpp	Thu Oct 28 00:22:42 2021 +0000
+++ b/android/dw.cpp	Thu Oct 28 17:27:59 2021 +0000
@@ -1370,8 +1370,22 @@
  */
 HWND API dw_groupbox_new(int type, int pad, const char *title)
 {
-    /* TODO: Just create a normal box for now */
-    return dw_box_new(type, pad);
+    JNIEnv *env;
+
+    if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
+    {
+        // Construct 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 groupBoxNew = env->GetMethodID(clazz, "groupBoxNew",
+                                                 "(IILjava/lang/String;)Landroid/widget/LinearLayout;");
+        // Call the method on the object
+        jobject result = _dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, groupBoxNew, type, pad, jstr), _DW_REFERENCE_WEAK);
+        return result;
+    }
+    return nullptr;
 }
 
 /*