# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1631598831 0 # Node ID 7101b569260146ed7fc1bbd93f1daf7e74e2fee6 # Parent 76d876c441c98cfd3cd8eadb2d131934213f4bb3 Android: Attempt at implementing splitbar using ConstraintLayout. Getting errors with the layout with HandyFTP, but I need to switch locations... so committing unfinished. diff -r 76d876c441c9 -r 7101b5692601 android/DWindows.kt --- a/android/DWindows.kt Tue Aug 31 09:35:36 2021 +0000 +++ b/android/DWindows.kt Tue Sep 14 05:53:51 2021 +0000 @@ -42,6 +42,8 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.AppCompatEditText import androidx.collection.SimpleArrayMap +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.constraintlayout.widget.ConstraintSet import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.content.res.ResourcesCompat @@ -1976,6 +1978,160 @@ } } + fun splitBarNew(type: Int, topleft: View?, bottomright: View?, cid: Int): ConstraintLayout? + { + var splitbar: ConstraintLayout? = null + + waitOnUiThread { + splitbar = ConstraintLayout(this) + + if(splitbar != null) { + val constraintSet = ConstraintSet() + constraintSet.clone(splitbar) + + splitbar!!.id = cid + + // Place the top/left item + if(topleft != null) { + if(topleft.id == 0) { + topleft.id = View.generateViewId() + } + splitbar!!.addView(topleft) + constraintSet.connect( + topleft.id, + ConstraintLayout.LayoutParams.TOP, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.TOP + ) + constraintSet.connect( + topleft.id, + ConstraintLayout.LayoutParams.LEFT, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.LEFT + ) + + if (type == 0) { + // Horizontal + constraintSet.connect( + topleft.id, + ConstraintLayout.LayoutParams.BOTTOM, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.BOTTOM + ) + constraintSet.constrainPercentWidth(topleft.id, 0.5F) + } else { + // Vertical + constraintSet.connect( + topleft.id, + ConstraintLayout.LayoutParams.RIGHT, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.RIGHT + ) + constraintSet.constrainPercentHeight(topleft.id, 0.5F) + } + } + + // Place the bottom/right item + if(bottomright != null) { + if (bottomright.id == 0) { + bottomright.id = View.generateViewId() + } + splitbar!!.addView(bottomright) + constraintSet.connect( + bottomright.id, + ConstraintLayout.LayoutParams.BOTTOM, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.BOTTOM + ) + constraintSet.connect( + bottomright.id, + ConstraintLayout.LayoutParams.RIGHT, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.RIGHT + ) + + if (type == 0) { + // Horizontal + constraintSet.connect( + bottomright.id, + ConstraintLayout.LayoutParams.TOP, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.TOP + ) + constraintSet.constrainPercentWidth(bottomright.id, 0.5F) + } else { + // Vertical + constraintSet.connect( + bottomright.id, + ConstraintLayout.LayoutParams.LEFT, + ConstraintLayout.LayoutParams.PARENT_ID, + ConstraintLayout.LayoutParams.LEFT + ) + constraintSet.constrainPercentHeight(bottomright.id, 0.5F) + } + } + + // finally, apply the constraint set to layout + constraintSet.applyTo(splitbar) + } + } + return splitbar + } + + fun splitBarGet(splitbar: ConstraintLayout): Float { + var position: Float = 50.0F + + waitOnUiThread { + val topleft: View? = splitbar.getChildAt(0) + val bottomright: View? = splitbar.getChildAt(1) + + if(splitbar.width > 0 && splitbar.height > 0) { + if (topleft != null) { + if (splitbar.width == topleft.width) { + position = (topleft.height / splitbar.height) * 100.0F + } else { + position = (topleft.width / splitbar.width) * 100.0F + } + } else if (bottomright != null) { + if (splitbar.width == bottomright.width) { + position = 100.0F - ((bottomright.height / splitbar.height) * 100.0F) + } else { + position = 100.0F - ((bottomright.width / splitbar.width) * 100.0F) + } + } + } + } + return position + } + + fun splitBarSet(splitbar: ConstraintLayout, position: Float) { + waitOnUiThread { + val topleft: View? = splitbar.getChildAt(0) + val bottomright: View? = splitbar.getChildAt(1) + + if(splitbar.width > 0 && splitbar.height > 0) { + val constraintSet = ConstraintSet() + constraintSet.clone(splitbar) + if (topleft != null) { + if (splitbar.width == topleft.width) { + constraintSet.constrainPercentHeight(topleft.id, position / 100.0F) + } else { + constraintSet.constrainPercentWidth(topleft.id, position / 100.0F) + } + } + if (bottomright != null) { + val altper: Float = (100.0F - position) / 100.0F + if (splitbar.width == bottomright.width) { + constraintSet.constrainPercentHeight(bottomright.id, altper) + } else { + constraintSet.constrainPercentWidth(bottomright.id, altper) + } + } + constraintSet.applyTo(splitbar) + } + } + } + fun sliderNew(vertical: Int, increments: Int, cid: Int): SeekBar? { var slider: SeekBar? = null diff -r 76d876c441c9 -r 7101b5692601 android/dw.cpp --- a/android/dw.cpp Tue Aug 31 09:35:36 2021 +0000 +++ b/android/dw.cpp Tue Sep 14 05:53:51 2021 +0000 @@ -4104,6 +4104,19 @@ */ HWND API dw_splitbar_new(int type, HWND topleft, HWND bottomright, unsigned long 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 splitBarNew = env->GetMethodID(clazz, "splitBarNew", + "(ILandroid/view/View;Landroid/view/View;I)Landroidx/constraintlayout/widget/ConstraintLayout;"); + // Call the method on the object + jobject result = _dw_jni_check_result(env, env->CallObjectMethod(_dw_obj, splitBarNew, type, topleft, bottomright, (int)cid), _DW_REFERENCE_WEAK); + return result; + } return nullptr; } @@ -4115,6 +4128,20 @@ */ void API dw_splitbar_set(HWND handle, float percent) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + jfloat position = (jfloat)percent; + // 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 splitBarSet = env->GetMethodID(clazz, "splitBarSet", + "(Landroidx/constraintlayout/widget/ConstraintLayout;F)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, splitBarSet, handle, position); + _dw_jni_check_exception(env); + } } /* @@ -4126,7 +4153,22 @@ */ float API dw_splitbar_get(HWND handle) { - return 0; + JNIEnv *env; + float retval = 0; + + 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 splitBarGet = env->GetMethodID(clazz, "splitBarGet", + "(Landroidx/constraintlayout/widget/ConstraintLayout;)F"); + // Call the method on the object + retval = (float)env->CallFloatMethod(_dw_obj, splitBarGet, handle); + if(_dw_jni_check_exception(env)) + retval = 0; + } + return retval; } /*