# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1639050779 0 # Node ID cacde852e2db1e8b32e40d49a7aad0c942e99e09 # Parent c0be289068391f5f174030e6bc1320e875e227ce Android: Add dialog dismiss and color change handlers to the color chooser. dw_color_choose() now blocks and waits for the user to pick a color.... previously it opened the dialog and returned the original color. Probably need to add a GradientBar for the brightness... maybe some buttons to apply or cancel, but for now the Android < button closes it. diff -r c0be28906839 -r cacde852e2db android/DWindows.kt --- a/android/DWindows.kt Thu Dec 09 04:52:01 2021 +0000 +++ b/android/DWindows.kt Thu Dec 09 11:52:59 2021 +0000 @@ -66,6 +66,10 @@ import kotlin.math.* import android.content.ContentUris import androidx.appcompat.widget.AppCompatSeekBar +import android.content.DialogInterface + + + // Color Wheel section @@ -1685,6 +1689,9 @@ private var fileURI: Uri? = null private var fileLock = ReentrantLock() private var fileCond = fileLock.newCondition() + private var colorLock = ReentrantLock() + private var colorCond = colorLock.newCondition() + private var colorChosen: Int = 0 // Lists of data for our Windows private var windowTitles = mutableListOf() private var windowMenuBars = mutableListOf() @@ -5247,19 +5254,29 @@ // This can't be called from the main thread if(Looper.getMainLooper() != Looper.myLooper()) { + colorLock.lock() waitOnUiThread { val dialog = Dialog(this) val colorWheel = ColorWheel(this, null, 0) dialog.setContentView(colorWheel) colorWheel.rgb = Color.rgb(red, green, blue) + colorChosen = colorWheel.rgb + colorWheel.colorChangeListener = { rgb: Int -> colorChosen = rgb } dialog.window?.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) + dialog.setOnDismissListener { + colorLock.lock() + colorCond.signal() + colorLock.unlock() + } dialog.show() - retval = colorWheel.rgb } + colorCond.await() + retval = colorChosen + colorLock.unlock() } return retval } diff -r c0be28906839 -r cacde852e2db android/dw.cpp --- a/android/dw.cpp Thu Dec 09 04:52:01 2021 +0000 +++ b/android/dw.cpp Thu Dec 09 11:52:59 2021 +0000 @@ -2986,6 +2986,8 @@ if((env = (JNIEnv *)pthread_getspecific(_dw_env_key))) { unsigned long _value = _dw_get_color(value); + int r, g, b; + jint ac; // First get the class that contains the method you need to call jclass clazz = _dw_find_class(env, DW_CLASS_NAME); @@ -2993,10 +2995,15 @@ jmethodID colorChoose = env->GetMethodID(clazz, "colorChoose", "(IIIII)I"); // Call the method on the object - newcolor = (unsigned long)env->CallIntMethod(_dw_obj, colorChoose, (jint)value, 0, + ac = env->CallIntMethod(_dw_obj, colorChoose, (jint)value, 0, (jint)DW_RED_VALUE(_value), (jint)DW_GREEN_VALUE(_value), (jint)DW_BLUE_VALUE(_value)); - if(!_dw_jni_check_exception(env)) + if(_dw_jni_check_exception(env)) return value; + // Convert from Android Color to RGB back to Dynamic Windows + b = ac & 0xff; + g = (ac >> 8) & 0xff; + r = (ac >> 16) & 0xff; + newcolor = DW_RGB(r, g, b); } return newcolor; }