Mercurial > dwindows
diff android/DWindows.kt @ 2528:03f6870bcfcc
Android: Implement dw_bitmap_new(), dw_dwindow_set_bitmap() and dw_window_set_bitmap_from_data().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 10 May 2021 09:29:51 +0000 |
parents | eec926265888 |
children | 060fdb2d807d |
line wrap: on
line diff
--- a/android/DWindows.kt Mon May 10 02:24:52 2021 +0000 +++ b/android/DWindows.kt Mon May 10 09:29:51 2021 +0000 @@ -1626,7 +1626,11 @@ var calendar: CalendarView? = null waitOnUiThread { + var dataArrayMap = SimpleArrayMap<String, Long>() + calendar = CalendarView(this) + calendar!!.tag = dataArrayMap + calendar!!.id = cid calendar!!.setOnDateChangeListener { calendar, year, month, day -> val c: Calendar = Calendar.getInstance(); c.set(year, month, day); @@ -1656,6 +1660,83 @@ return date } + fun bitmapNew(cid: Int): ImageView? + { + var imageview: ImageView? = null + + waitOnUiThread { + var dataArrayMap = SimpleArrayMap<String, Long>() + + imageview = ImageView(this) + imageview!!.tag = dataArrayMap + imageview!!.id = cid + } + + return imageview + } + + fun windowSetBitmap(window: View, resID: Int, filename: String?) + { + waitOnUiThread { + if(resID != 0) { + if(window is ImageButton) { + val button = window + + button.setImageResource(resID) + } else if(window is ImageView) { + val imageview = window + + imageview.setImageResource(resID) + } + } else if(filename != null) { + // Try to load the image, and protect against exceptions + try { + val f = File(filename) + val b = BitmapFactory.decodeStream(FileInputStream(f)) + if(window is ImageButton) { + val button = window + + button.setImageBitmap(b) + } else if(window is ImageView) { + val imageview = window + + imageview.setImageBitmap(b) + } + } catch (e: FileNotFoundException) { + } + } + } + } + + fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int) + { + waitOnUiThread { + if(resID != 0) { + if (window is ImageButton) { + val button = window + + button.setImageResource(resID) + } else if (window is ImageView) { + val imageview = window + + imageview.setImageResource(resID) + } + } else 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) + } + } + } + } + fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer { // creating timer task, timer