comparison android/DWindows.kt @ 2722:cacde852e2db

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.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 09 Dec 2021 11:52:59 +0000
parents 9ce1649b0fbd
children bf585f375286
comparison
equal deleted inserted replaced
2721:c0be28906839 2722:cacde852e2db
64 import android.util.* 64 import android.util.*
65 import android.util.Base64 65 import android.util.Base64
66 import kotlin.math.* 66 import kotlin.math.*
67 import android.content.ContentUris 67 import android.content.ContentUris
68 import androidx.appcompat.widget.AppCompatSeekBar 68 import androidx.appcompat.widget.AppCompatSeekBar
69 import android.content.DialogInterface
70
71
72
69 73
70 74
71 // Color Wheel section 75 // Color Wheel section
72 private val HUE_COLORS = intArrayOf( 76 private val HUE_COLORS = intArrayOf(
73 Color.RED, 77 Color.RED,
1683 private var paint = Paint() 1687 private var paint = Paint()
1684 private var bgcolor: Int? = null 1688 private var bgcolor: Int? = null
1685 private var fileURI: Uri? = null 1689 private var fileURI: Uri? = null
1686 private var fileLock = ReentrantLock() 1690 private var fileLock = ReentrantLock()
1687 private var fileCond = fileLock.newCondition() 1691 private var fileCond = fileLock.newCondition()
1692 private var colorLock = ReentrantLock()
1693 private var colorCond = colorLock.newCondition()
1694 private var colorChosen: Int = 0
1688 // Lists of data for our Windows 1695 // Lists of data for our Windows
1689 private var windowTitles = mutableListOf<String?>() 1696 private var windowTitles = mutableListOf<String?>()
1690 private var windowMenuBars = mutableListOf<DWMenu?>() 1697 private var windowMenuBars = mutableListOf<DWMenu?>()
1691 private var windowStyles = mutableListOf<Int>() 1698 private var windowStyles = mutableListOf<Int>()
1692 private var windowDefault = mutableListOf<View?>() 1699 private var windowDefault = mutableListOf<View?>()
5245 { 5252 {
5246 var retval: Int = color 5253 var retval: Int = color
5247 5254
5248 // This can't be called from the main thread 5255 // This can't be called from the main thread
5249 if(Looper.getMainLooper() != Looper.myLooper()) { 5256 if(Looper.getMainLooper() != Looper.myLooper()) {
5257 colorLock.lock()
5250 waitOnUiThread { 5258 waitOnUiThread {
5251 val dialog = Dialog(this) 5259 val dialog = Dialog(this)
5252 val colorWheel = ColorWheel(this, null, 0) 5260 val colorWheel = ColorWheel(this, null, 0)
5253 5261
5254 dialog.setContentView(colorWheel) 5262 dialog.setContentView(colorWheel)
5255 colorWheel.rgb = Color.rgb(red, green, blue) 5263 colorWheel.rgb = Color.rgb(red, green, blue)
5264 colorChosen = colorWheel.rgb
5265 colorWheel.colorChangeListener = { rgb: Int -> colorChosen = rgb }
5256 dialog.window?.setLayout( 5266 dialog.window?.setLayout(
5257 ViewGroup.LayoutParams.MATCH_PARENT, 5267 ViewGroup.LayoutParams.MATCH_PARENT,
5258 ViewGroup.LayoutParams.MATCH_PARENT 5268 ViewGroup.LayoutParams.MATCH_PARENT
5259 ) 5269 )
5270 dialog.setOnDismissListener {
5271 colorLock.lock()
5272 colorCond.signal()
5273 colorLock.unlock()
5274 }
5260 dialog.show() 5275 dialog.show()
5261 retval = colorWheel.rgb 5276 }
5262 } 5277 colorCond.await()
5278 retval = colorChosen
5279 colorLock.unlock()
5263 } 5280 }
5264 return retval 5281 return retval
5265 } 5282 }
5266 5283
5267 fun messageBox(title: String, body: String, flags: Int): Int 5284 fun messageBox(title: String, body: String, flags: Int): Int