# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1631617965 0 # Node ID 42151fd096d49037baef8f59cdb7fd29cb7bae51 # Parent 7700c8022af32a0b9b853b8abd54b6d7c21c0203 Android: Switch to loading resource images like we do on iOS. Instead of using the Android resource ID, which is created automatically... Try to load the resource ID as the filename from the assets folder. If the Resource ID is outside the 1 to 65535 range, try Android resource loading, in case it actually is a native Android resource ID. diff -r 7700c8022af3 -r 42151fd096d4 android/DWindows.kt --- a/android/DWindows.kt Tue Sep 14 06:58:40 2021 +0000 +++ b/android/DWindows.kt Tue Sep 14 11:12:45 2021 +0000 @@ -3004,17 +3004,20 @@ } } - fun iconNew(filename: String?, data: ByteArray?, length: Int, resID: Int): Drawable? + fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable? { var icon: Drawable? = null waitOnUiThread { - if(resID != 0) { - try { - icon = ResourcesCompat.getDrawable(resources, resID, null) - } catch(e: Resources.NotFoundException) { - } - } else if(filename != null) { + var filename: String? = file + + // Handle Dynamic Windows resource IDs + if(resID > 0 && resID < 65536) { + filename = resID.toString() + } + // Handle filename or DW resource IDs + // these will be located in the assets folder + if(filename != null) { val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") for (ext in exts) { @@ -3024,10 +3027,17 @@ icon = Drawable.createFromStream(f, null) } catch (e: IOException) { } - if(icon != null) { + if (icon != null) { 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)) }