changeset 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
files android/DWindows.kt
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Tue Sep 14 11:12:45 2021 +0000
+++ b/android/DWindows.kt	Tue Sep 14 19:39:07 2021 +0000
@@ -1466,6 +1466,8 @@
         waitOnUiThread {
             button = ImageButton(this)
             val dataArrayMap = SimpleArrayMap<String, Long>()
+            val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
+            var filename: String? = null
 
             button!!.tag = dataArrayMap
             button!!.id = resid
@@ -1474,6 +1476,26 @@
                 lastClickView = button!!
                 eventHandlerSimple(button!!, DWEvent.CLICKED)
             }
+
+            if(resid > 0 && resid < 65536) {
+                filename = resid.toString()
+            }
+
+            if(filename != null) {
+                for (ext in exts) {
+                    // Try to load the image, and protect against exceptions
+                    try {
+                        val f = this.assets.open(filename + ext)
+                        val b = BitmapFactory.decodeStream(f)
+
+                        if (b != null) {
+                            button!!.setImageBitmap(b)
+                            break
+                        }
+                    } catch (e: IOException) {
+                    }
+                }
+            }
         }
         return button
     }