Mercurial > dwindows
changeset 2652:42151fd096d4
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 14 Sep 2021 11:12:45 +0000 |
parents | 7700c8022af3 |
children | 297456a381e4 |
files | android/DWindows.kt |
diffstat | 1 files changed, 18 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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)) }