comparison android/DWindows.kt @ 2653:297456a381e4

Android: Similar resource change for bitmap buttons. Could be another few of these still in the source to change.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 14 Sep 2021 19:39:07 +0000
parents 42151fd096d4
children fe186c9318cc
comparison
equal deleted inserted replaced
2652:42151fd096d4 2653:297456a381e4
1464 fun bitmapButtonNew(text: String, resid: Int): ImageButton? { 1464 fun bitmapButtonNew(text: String, resid: Int): ImageButton? {
1465 var button: ImageButton? = null 1465 var button: ImageButton? = null
1466 waitOnUiThread { 1466 waitOnUiThread {
1467 button = ImageButton(this) 1467 button = ImageButton(this)
1468 val dataArrayMap = SimpleArrayMap<String, Long>() 1468 val dataArrayMap = SimpleArrayMap<String, Long>()
1469 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
1470 var filename: String? = null
1469 1471
1470 button!!.tag = dataArrayMap 1472 button!!.tag = dataArrayMap
1471 button!!.id = resid 1473 button!!.id = resid
1472 button!!.setImageResource(resid) 1474 button!!.setImageResource(resid)
1473 button!!.setOnClickListener { 1475 button!!.setOnClickListener {
1474 lastClickView = button!! 1476 lastClickView = button!!
1475 eventHandlerSimple(button!!, DWEvent.CLICKED) 1477 eventHandlerSimple(button!!, DWEvent.CLICKED)
1478 }
1479
1480 if(resid > 0 && resid < 65536) {
1481 filename = resid.toString()
1482 }
1483
1484 if(filename != null) {
1485 for (ext in exts) {
1486 // Try to load the image, and protect against exceptions
1487 try {
1488 val f = this.assets.open(filename + ext)
1489 val b = BitmapFactory.decodeStream(f)
1490
1491 if (b != null) {
1492 button!!.setImageBitmap(b)
1493 break
1494 }
1495 } catch (e: IOException) {
1496 }
1497 }
1476 } 1498 }
1477 } 1499 }
1478 return button 1500 return button
1479 } 1501 }
1480 1502