Mercurial > dwindows
comparison android/DWindows.kt @ 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 |
comparison
equal
deleted
inserted
replaced
2654:fe186c9318cc | 2655:5b63a3ed8e10 |
---|---|
3013 } else if (window is ImageView) { | 3013 } else if (window is ImageView) { |
3014 val imageview = window | 3014 val imageview = window |
3015 | 3015 |
3016 imageview.setImageResource(resID) | 3016 imageview.setImageResource(resID) |
3017 } | 3017 } |
3018 } else if(data != null) { | 3018 } |
3019 if(data != null) { | |
3019 val b = BitmapFactory.decodeByteArray(data, 0, length) | 3020 val b = BitmapFactory.decodeByteArray(data, 0, length) |
3020 | 3021 |
3021 if (window is ImageButton) { | 3022 if (window is ImageButton) { |
3022 val button = window | 3023 val button = window |
3023 | 3024 |
3034 fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable? | 3035 fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable? |
3035 { | 3036 { |
3036 var icon: Drawable? = null | 3037 var icon: Drawable? = null |
3037 | 3038 |
3038 waitOnUiThread { | 3039 waitOnUiThread { |
3039 var filename: String? = file | 3040 var filename: String? = null |
3040 | 3041 |
3041 // Handle Dynamic Windows resource IDs | 3042 // Handle Dynamic Windows resource IDs |
3042 if(resID > 0 && resID < 65536) { | 3043 if(resID > 0 && resID < 65536) { |
3043 filename = resID.toString() | 3044 filename = resID.toString() |
3045 // Handle Android resource IDs | |
3046 } else if(resID != 0) { | |
3047 try { | |
3048 icon = ResourcesCompat.getDrawable(resources, resID, null) | |
3049 } catch (e: Resources.NotFoundException) { | |
3050 } | |
3051 // Handle bitmap data | |
3052 } else if(data != null) { | |
3053 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length)) | |
3054 } else { | |
3055 filename = file | |
3044 } | 3056 } |
3045 // Handle filename or DW resource IDs | 3057 // Handle filename or DW resource IDs |
3046 // these will be located in the assets folder | 3058 // these will be located in the assets folder |
3047 if(filename != null) { | 3059 if(filename != null) { |
3048 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") | 3060 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") |
3056 } | 3068 } |
3057 if (icon != null) { | 3069 if (icon != null) { |
3058 break | 3070 break |
3059 } | 3071 } |
3060 } | 3072 } |
3061 // Handle Android resource IDs | |
3062 } else if(resID != 0) { | |
3063 try { | |
3064 icon = ResourcesCompat.getDrawable(resources, resID, null) | |
3065 } catch (e: Resources.NotFoundException) { | |
3066 } | |
3067 // Handle bitmap data | |
3068 } else if(data != null) { | |
3069 icon = BitmapDrawable(resources, BitmapFactory.decodeByteArray(data, 0, length)) | |
3070 } | 3073 } |
3071 } | 3074 } |
3072 return icon | 3075 return icon |
3073 } | 3076 } |
3074 | 3077 |
3075 fun pixmapNew(width: Int, height: Int, file: String?, data: ByteArray?, length: Int, resID: Int): Bitmap? | 3078 fun pixmapNew(width: Int, height: Int, file: String?, data: ByteArray?, length: Int, resID: Int): Bitmap? |
3076 { | 3079 { |
3077 var pixmap: Bitmap? = null | 3080 var pixmap: Bitmap? = null |
3078 | 3081 |
3079 waitOnUiThread { | 3082 waitOnUiThread { |
3080 var filename: String? = file | 3083 var filename: String? = null |
3081 | 3084 |
3082 if(width > 0 && height > 0) { | 3085 if(width > 0 && height > 0) { |
3083 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888) | 3086 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888) |
3084 } else if(resID > 0 && resID < 65536) { | 3087 } else if(resID > 0 && resID < 65536) { |
3085 filename = resID.toString() | 3088 filename = resID.toString() |
3086 } else if(resID != 0) { | 3089 } else if(resID != 0) { |
3087 pixmap = BitmapFactory.decodeResource(resources, resID) | 3090 pixmap = BitmapFactory.decodeResource(resources, resID) |
3091 } else if(data != null) { | |
3092 pixmap = BitmapFactory.decodeByteArray(data, 0, length) | |
3093 } else { | |
3094 filename = file | |
3088 } | 3095 } |
3089 if(filename != null) { | 3096 if(filename != null) { |
3090 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") | 3097 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") |
3091 | 3098 |
3092 for (ext in exts) { | 3099 for (ext in exts) { |
3098 } | 3105 } |
3099 if(pixmap != null) { | 3106 if(pixmap != null) { |
3100 break | 3107 break |
3101 } | 3108 } |
3102 } | 3109 } |
3103 } else if(data != null) { | |
3104 pixmap = BitmapFactory.decodeByteArray(data, 0, length) | |
3105 } | 3110 } |
3106 } | 3111 } |
3107 return pixmap | 3112 return pixmap |
3108 } | 3113 } |
3109 | 3114 |