comparison android/DWindows.kt @ 2654:fe186c9318cc

Android: More resource changes, for windowSetBitmap and pixmapNew.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 15 Sep 2021 08:05:39 +0000
parents 297456a381e4
children 5b63a3ed8e10
comparison
equal deleted inserted replaced
2653:297456a381e4 2654:fe186c9318cc
2954 } 2954 }
2955 2955
2956 return imageview 2956 return imageview
2957 } 2957 }
2958 2958
2959 fun windowSetBitmap(window: View, resID: Int, filename: String?) 2959 fun windowSetBitmap(window: View, resID: Int, file: String?)
2960 { 2960 {
2961 waitOnUiThread { 2961 waitOnUiThread {
2962 if(resID != 0) { 2962 var filename: String? = file
2963 if(window is ImageButton) { 2963
2964 if(resID > 0 && resID < 65536) {
2965 filename = resID.toString()
2966 } else if(resID != 0) {
2967 if (window is ImageButton) {
2964 val button = window 2968 val button = window
2965 2969
2966 button.setImageResource(resID) 2970 button.setImageResource(resID)
2967 } else if(window is ImageView) { 2971 } else if (window is ImageView) {
2968 val imageview = window 2972 val imageview = window
2969 2973
2970 imageview.setImageResource(resID) 2974 imageview.setImageResource(resID)
2971 } 2975 }
2972 } else if(filename != null) { 2976 }
2977 if(filename != null) {
2973 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") 2978 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
2974 2979
2975 for (ext in exts) { 2980 for (ext in exts) {
2976 // Try to load the image, and protect against exceptions 2981 // Try to load the image, and protect against exceptions
2977 try { 2982 try {
3065 } 3070 }
3066 } 3071 }
3067 return icon 3072 return icon
3068 } 3073 }
3069 3074
3070 fun pixmapNew(width: Int, height: Int, filename: String?, data: ByteArray?, length: Int, resID: Int): Bitmap? 3075 fun pixmapNew(width: Int, height: Int, file: String?, data: ByteArray?, length: Int, resID: Int): Bitmap?
3071 { 3076 {
3072 var pixmap: Bitmap? = null 3077 var pixmap: Bitmap? = null
3073 3078
3074 waitOnUiThread { 3079 waitOnUiThread {
3080 var filename: String? = file
3081
3075 if(width > 0 && height > 0) { 3082 if(width > 0 && height > 0) {
3076 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888) 3083 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888)
3084 } else if(resID > 0 && resID < 65536) {
3085 filename = resID.toString()
3077 } else if(resID != 0) { 3086 } else if(resID != 0) {
3078 pixmap = BitmapFactory.decodeResource(resources, resID) 3087 pixmap = BitmapFactory.decodeResource(resources, resID)
3079 } else if(filename != null) { 3088 }
3089 if(filename != null) {
3080 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") 3090 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
3081 3091
3082 for (ext in exts) { 3092 for (ext in exts) {
3083 // Try to load the image, and protect against exceptions 3093 // Try to load the image, and protect against exceptions
3084 try { 3094 try {