Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
2527:eec926265888 | 2528:03f6870bcfcc |
---|---|
1624 fun calendarNew(cid: Int): CalendarView? | 1624 fun calendarNew(cid: Int): CalendarView? |
1625 { | 1625 { |
1626 var calendar: CalendarView? = null | 1626 var calendar: CalendarView? = null |
1627 | 1627 |
1628 waitOnUiThread { | 1628 waitOnUiThread { |
1629 var dataArrayMap = SimpleArrayMap<String, Long>() | |
1630 | |
1629 calendar = CalendarView(this) | 1631 calendar = CalendarView(this) |
1632 calendar!!.tag = dataArrayMap | |
1633 calendar!!.id = cid | |
1630 calendar!!.setOnDateChangeListener { calendar, year, month, day -> | 1634 calendar!!.setOnDateChangeListener { calendar, year, month, day -> |
1631 val c: Calendar = Calendar.getInstance(); | 1635 val c: Calendar = Calendar.getInstance(); |
1632 c.set(year, month, day); | 1636 c.set(year, month, day); |
1633 calendar.date = c.timeInMillis | 1637 calendar.date = c.timeInMillis |
1634 } | 1638 } |
1652 waitOnUiThread { | 1656 waitOnUiThread { |
1653 // Convert from milliseconds to seconds | 1657 // Convert from milliseconds to seconds |
1654 date = calendar.date / 1000 | 1658 date = calendar.date / 1000 |
1655 } | 1659 } |
1656 return date | 1660 return date |
1661 } | |
1662 | |
1663 fun bitmapNew(cid: Int): ImageView? | |
1664 { | |
1665 var imageview: ImageView? = null | |
1666 | |
1667 waitOnUiThread { | |
1668 var dataArrayMap = SimpleArrayMap<String, Long>() | |
1669 | |
1670 imageview = ImageView(this) | |
1671 imageview!!.tag = dataArrayMap | |
1672 imageview!!.id = cid | |
1673 } | |
1674 | |
1675 return imageview | |
1676 } | |
1677 | |
1678 fun windowSetBitmap(window: View, resID: Int, filename: String?) | |
1679 { | |
1680 waitOnUiThread { | |
1681 if(resID != 0) { | |
1682 if(window is ImageButton) { | |
1683 val button = window | |
1684 | |
1685 button.setImageResource(resID) | |
1686 } else if(window is ImageView) { | |
1687 val imageview = window | |
1688 | |
1689 imageview.setImageResource(resID) | |
1690 } | |
1691 } else if(filename != null) { | |
1692 // Try to load the image, and protect against exceptions | |
1693 try { | |
1694 val f = File(filename) | |
1695 val b = BitmapFactory.decodeStream(FileInputStream(f)) | |
1696 if(window is ImageButton) { | |
1697 val button = window | |
1698 | |
1699 button.setImageBitmap(b) | |
1700 } else if(window is ImageView) { | |
1701 val imageview = window | |
1702 | |
1703 imageview.setImageBitmap(b) | |
1704 } | |
1705 } catch (e: FileNotFoundException) { | |
1706 } | |
1707 } | |
1708 } | |
1709 } | |
1710 | |
1711 fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int) | |
1712 { | |
1713 waitOnUiThread { | |
1714 if(resID != 0) { | |
1715 if (window is ImageButton) { | |
1716 val button = window | |
1717 | |
1718 button.setImageResource(resID) | |
1719 } else if (window is ImageView) { | |
1720 val imageview = window | |
1721 | |
1722 imageview.setImageResource(resID) | |
1723 } | |
1724 } else if(data != null) { | |
1725 val b = BitmapFactory.decodeByteArray(data, 0, length) | |
1726 | |
1727 if (window is ImageButton) { | |
1728 val button = window | |
1729 | |
1730 button.setImageBitmap(b) | |
1731 } else if (window is ImageView) { | |
1732 val imageview = window | |
1733 | |
1734 imageview.setImageBitmap(b) | |
1735 } | |
1736 } | |
1737 } | |
1657 } | 1738 } |
1658 | 1739 |
1659 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer | 1740 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer |
1660 { | 1741 { |
1661 // creating timer task, timer | 1742 // creating timer task, timer |