changeset 2655:5b63a3ed8e10

Android: Code path cleanup, basically only try one image load... the only exception being android native resources... try those first and then load any other possible paths.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 15 Sep 2021 08:36:21 +0000
parents fe186c9318cc
children 2bdbd5e83654
files android/DWindows.kt
diffstat 1 files changed, 19 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Wed Sep 15 08:05:39 2021 +0000
+++ b/android/DWindows.kt	Wed Sep 15 08:36:21 2021 +0000
@@ -3015,7 +3015,8 @@
 
                     imageview.setImageResource(resID)
                 }
-            } else if(data != null) {
+            }
+            if(data != null) {
                 val b = BitmapFactory.decodeByteArray(data, 0, length)
 
                 if (window is ImageButton) {
@@ -3036,11 +3037,22 @@
         var icon: Drawable? = null
 
         waitOnUiThread {
-            var filename: String? = file
+            var filename: String? = null
 
             // Handle Dynamic Windows resource IDs
             if(resID > 0 && resID < 65536) {
                 filename = resID.toString()
+            // Handle Android resource IDs
+            } else if(resID != 0) {
+                try {
+                    icon = ResourcesCompat.getDrawable(resources, resID, null)
+                } catch (e: Resources.NotFoundException) {
+                }
+            // Handle bitmap data
+            } else if(data != null) {
+                icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length))
+            } else {
+                filename = file
             }
             // Handle filename or DW resource IDs
             // these will be located in the assets folder
@@ -3058,15 +3070,6 @@
                         break
                     }
                 }
-            // Handle Android resource IDs
-            } else if(resID != 0) {
-                try {
-                    icon = ResourcesCompat.getDrawable(resources, resID, null)
-                } catch (e: Resources.NotFoundException) {
-                }
-            // Handle bitmap data
-            } else if(data != null) {
-                icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length))
             }
         }
         return icon
@@ -3077,7 +3080,7 @@
         var pixmap: Bitmap? = null
 
         waitOnUiThread {
-            var filename: String? = file
+            var filename: String? = null
 
             if(width > 0 && height > 0) {
                 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888)
@@ -3085,6 +3088,10 @@
                 filename = resID.toString()
             } else if(resID != 0) {
                 pixmap = BitmapFactory.decodeResource(resources, resID)
+            } else if(data != null) {
+                pixmap = BitmapFactory.decodeByteArray(data, 0, length)
+            } else {
+                filename = file
             }
             if(filename != null) {
                 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
@@ -3100,8 +3107,6 @@
                         break
                     }
                 }
-            } else if(data != null) {
-                pixmap = BitmapFactory.decodeByteArray(data, 0, length)
             }
         }
         return pixmap