comparison android/DWindows.kt @ 2690:755d9ad07aaf

Android: Fix state exception by calling notifyDataSetChanged() on DWListBox. Avoid warnings creating bitmaps from resources by not calling setImageResource() unless the resource ID is greater than 65535. Use App ID when logging messages.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 31 Oct 2021 12:59:45 +0000
parents 7127de139acf
children e13607b87517
comparison
equal deleted inserted replaced
2689:7127de139acf 2690:755d9ad07aaf
809 var threadLock = ReentrantLock() 809 var threadLock = ReentrantLock()
810 var threadCond = threadLock.newCondition() 810 var threadCond = threadLock.newCondition()
811 var notificationID: Int = 0 811 var notificationID: Int = 0
812 var darkMode: Int = -1 812 var darkMode: Int = -1
813 var lastClickView: View? = null 813 var lastClickView: View? = null
814 private var appID: String? = null
814 private var paint = Paint() 815 private var paint = Paint()
815 private var bgcolor: Int? = null 816 private var bgcolor: Int? = null
816 private var fileURI: Uri? = null 817 private var fileURI: Uri? = null
817 private var fileLock = ReentrantLock() 818 private var fileLock = ReentrantLock()
818 private var fileCond = threadLock.newCondition() 819 private var fileCond = threadLock.newCondition()
1907 val dataArrayMap = SimpleArrayMap<String, Long>() 1908 val dataArrayMap = SimpleArrayMap<String, Long>()
1908 var filename: String? = null 1909 var filename: String? = null
1909 1910
1910 button!!.tag = dataArrayMap 1911 button!!.tag = dataArrayMap
1911 button!!.id = resid 1912 button!!.id = resid
1912 button!!.setImageResource(resid)
1913 button!!.setOnClickListener { 1913 button!!.setOnClickListener {
1914 lastClickView = button!! 1914 lastClickView = button!!
1915 eventHandlerSimple(button!!, DWEvent.CLICKED) 1915 eventHandlerSimple(button!!, DWEvent.CLICKED)
1916 } 1916 }
1917 1917
1918 if(resid > 0 && resid < 65536) { 1918 if(resid > 0 && resid < 65536) {
1919 filename = resid.toString() 1919 filename = resid.toString()
1920 } else {
1921 button!!.setImageResource(resid)
1920 } 1922 }
1921 1923
1922 if(filename != null) { 1924 if(filename != null) {
1923 for (ext in DWImageExts) { 1925 for (ext in DWImageExts) {
1924 // Try to load the image, and protect against exceptions 1926 // Try to load the image, and protect against exceptions
3153 combobox.list.add(text) 3155 combobox.list.add(text)
3154 } else if(window is DWListBox) { 3156 } else if(window is DWListBox) {
3155 val listbox = window 3157 val listbox = window
3156 3158
3157 listbox.list.add(text) 3159 listbox.list.add(text)
3160 val adapter = listbox.adapter as ArrayAdapter<String>
3161 adapter.notifyDataSetChanged()
3158 } 3162 }
3159 } 3163 }
3160 } 3164 }
3161 3165
3162 fun listOrComboBoxInsert(window: View, text: String, pos: Int) 3166 fun listOrComboBoxInsert(window: View, text: String, pos: Int)
3168 combobox.list.add(pos, text) 3172 combobox.list.add(pos, text)
3169 } else if(window is DWListBox) { 3173 } else if(window is DWListBox) {
3170 val listbox = window 3174 val listbox = window
3171 3175
3172 listbox.list.add(pos, text) 3176 listbox.list.add(pos, text)
3177 val adapter = listbox.adapter as ArrayAdapter<String>
3178 adapter.notifyDataSetChanged()
3173 } 3179 }
3174 } 3180 }
3175 } 3181 }
3176 3182
3177 fun listOrComboBoxClear(window: View) 3183 fun listOrComboBoxClear(window: View)
3183 combobox.list.clear() 3189 combobox.list.clear()
3184 } else if(window is DWListBox) { 3190 } else if(window is DWListBox) {
3185 val listbox = window 3191 val listbox = window
3186 3192
3187 listbox.list.clear() 3193 listbox.list.clear()
3194 val adapter = listbox.adapter as ArrayAdapter<String>
3195 adapter.notifyDataSetChanged()
3188 } 3196 }
3189 } 3197 }
3190 } 3198 }
3191 3199
3192 fun listOrComboBoxCount(window: View): Int 3200 fun listOrComboBoxCount(window: View): Int
3216 if(index > -1 && index < combobox.list.count()) 3224 if(index > -1 && index < combobox.list.count())
3217 combobox.list[index] = text 3225 combobox.list[index] = text
3218 } else if(window is DWListBox) { 3226 } else if(window is DWListBox) {
3219 val listbox = window 3227 val listbox = window
3220 3228
3221 if(index > -1 && index < listbox.list.count()) 3229 if(index > -1 && index < listbox.list.count()) {
3222 listbox.list[index] = text 3230 listbox.list[index] = text
3231 val adapter = listbox.adapter as ArrayAdapter<String>
3232 adapter.notifyDataSetChanged()
3233 }
3223 } 3234 }
3224 } 3235 }
3225 } 3236 }
3226 3237
3227 fun listOrComboBoxGetText(window: View, index: Int): String? 3238 fun listOrComboBoxGetText(window: View, index: Int): String?
3299 } else if(window is DWListBox) { 3310 } else if(window is DWListBox) {
3300 val listbox = window 3311 val listbox = window
3301 3312
3302 if(index < listbox.list.count()) { 3313 if(index < listbox.list.count()) {
3303 listbox.list.removeAt(index) 3314 listbox.list.removeAt(index)
3315 val adapter = listbox.adapter as ArrayAdapter<String>
3316 adapter.notifyDataSetChanged()
3304 } 3317 }
3305 } 3318 }
3306 } 3319 }
3307 } 3320 }
3308 3321
3989 }, (duration + 50).toLong()) 4002 }, (duration + 50).toLong())
3990 } 4003 }
3991 4004
3992 fun debugMessage(text: String) 4005 fun debugMessage(text: String)
3993 { 4006 {
3994 Log.d(null, text) 4007 Log.d(appID, text)
3995 } 4008 }
3996 4009
3997 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 4010 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
3998 super.onActivityResult(requestCode, resultCode, data) 4011 super.onActivityResult(requestCode, resultCode, data)
3999 if(requestCode == 100) { 4012 if(requestCode == 100) {
4177 } 4190 }
4178 } 4191 }
4179 4192
4180 fun dwInit(appid: String, appname: String): Int 4193 fun dwInit(appid: String, appname: String): Int
4181 { 4194 {
4195 appID = appid
4196
4182 waitOnUiThread { 4197 waitOnUiThread {
4183 // Create the notification channel in dw_init() 4198 // Create the notification channel in dw_init()
4184 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 4199 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4185 // Create the NotificationChannel 4200 // Create the NotificationChannel
4186 val importance = NotificationManager.IMPORTANCE_DEFAULT 4201 val importance = NotificationManager.IMPORTANCE_DEFAULT