diff android/DWindows.kt @ 2852:5018df4f952e

Win/Android/Template: Add return values to dw_window_set_bitmap(_from_data). Also update the readme regarding this change.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2022 00:34:20 +0000
parents 6790bea27685
children edb4307ac7ce
line wrap: on
line diff
--- a/android/DWindows.kt	Mon Nov 14 22:00:47 2022 +0000
+++ b/android/DWindows.kt	Tue Nov 15 00:34:20 2022 +0000
@@ -5782,8 +5782,10 @@
         return imageview
     }
 
-    fun windowSetBitmap(window: View, resID: Int, file: String?)
-    {
+    fun windowSetBitmap(window: View, resID: Int, file: String?): Int
+    {
+        var retval: Int = -1
+
         waitOnUiThread {
             var filename: String? = file
 
@@ -5794,10 +5796,12 @@
                     val button = window
 
                     button.setImageResource(resID)
+                    retval = 0
                 } else if (window is ImageView) {
                     val imageview = window
 
                     imageview.setImageResource(resID)
+                    retval = 0
                 }
             }
             if(filename != null) {
@@ -5812,48 +5816,64 @@
                                 val button = window
 
                                 button.setImageBitmap(b)
+                                retval = 0
                             } else if (window is ImageView) {
                                 val imageview = window
 
                                 imageview.setImageBitmap(b)
+                                retval = 0
                             }
                             break
+                        } else {
+                            retval = 1
                         }
                     } catch (e: IOException) {
                     }
                 }
             }
         }
-    }
-
-    fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int)
-    {
+        return retval
+    }
+
+    fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int): Int
+    {
+        var retval: Int = -1
+
         waitOnUiThread {
             if(resID != 0) {
                 if (window is ImageButton) {
                     val button = window
 
                     button.setImageResource(resID)
+                    retval = 0
                 } else if (window is ImageView) {
                     val imageview = window
 
                     imageview.setImageResource(resID)
+                    retval = 0
                 }
             }
             if(data != null) {
                 val b = BitmapFactory.decodeByteArray(data, 0, length)
 
-                if (window is ImageButton) {
-                    val button = window
-
-                    button.setImageBitmap(b)
-                } else if (window is ImageView) {
-                    val imageview = window
-
-                    imageview.setImageBitmap(b)
+                if(b != null) {
+                    if (window is ImageButton) {
+                        val button = window
+
+                        button.setImageBitmap(b)
+                        retval = 0
+                    } else if (window is ImageView) {
+                        val imageview = window
+
+                        imageview.setImageBitmap(b)
+                        retval = 0
+                    }
+                } else {
+                    retval = 1
                 }
             }
         }
+        return retval
     }
 
     fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable?