comparison android/DWindows.kt @ 2852:5018df4f952e

Win/Android/Template: Add return values to dw_window_set_bitmap(_from_data). Also update the readme regarding this change.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2022 00:34:20 +0000
parents 6790bea27685
children edb4307ac7ce
comparison
equal deleted inserted replaced
2851:fdd21139c07f 2852:5018df4f952e
5780 } 5780 }
5781 5781
5782 return imageview 5782 return imageview
5783 } 5783 }
5784 5784
5785 fun windowSetBitmap(window: View, resID: Int, file: String?) 5785 fun windowSetBitmap(window: View, resID: Int, file: String?): Int
5786 { 5786 {
5787 var retval: Int = -1
5788
5787 waitOnUiThread { 5789 waitOnUiThread {
5788 var filename: String? = file 5790 var filename: String? = file
5789 5791
5790 if(resID > 0 && resID < 65536) { 5792 if(resID > 0 && resID < 65536) {
5791 filename = resID.toString() 5793 filename = resID.toString()
5792 } else if(resID != 0) { 5794 } else if(resID != 0) {
5793 if (window is ImageButton) { 5795 if (window is ImageButton) {
5794 val button = window 5796 val button = window
5795 5797
5796 button.setImageResource(resID) 5798 button.setImageResource(resID)
5799 retval = 0
5797 } else if (window is ImageView) { 5800 } else if (window is ImageView) {
5798 val imageview = window 5801 val imageview = window
5799 5802
5800 imageview.setImageResource(resID) 5803 imageview.setImageResource(resID)
5804 retval = 0
5801 } 5805 }
5802 } 5806 }
5803 if(filename != null) { 5807 if(filename != null) {
5804 for (ext in DWImageExts) { 5808 for (ext in DWImageExts) {
5805 // Try to load the image, and protect against exceptions 5809 // Try to load the image, and protect against exceptions
5810 if(b != null) { 5814 if(b != null) {
5811 if (window is ImageButton) { 5815 if (window is ImageButton) {
5812 val button = window 5816 val button = window
5813 5817
5814 button.setImageBitmap(b) 5818 button.setImageBitmap(b)
5819 retval = 0
5815 } else if (window is ImageView) { 5820 } else if (window is ImageView) {
5816 val imageview = window 5821 val imageview = window
5817 5822
5818 imageview.setImageBitmap(b) 5823 imageview.setImageBitmap(b)
5824 retval = 0
5819 } 5825 }
5820 break 5826 break
5827 } else {
5828 retval = 1
5821 } 5829 }
5822 } catch (e: IOException) { 5830 } catch (e: IOException) {
5823 } 5831 }
5824 } 5832 }
5825 } 5833 }
5826 } 5834 }
5827 } 5835 return retval
5828 5836 }
5829 fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int) 5837
5830 { 5838 fun windowSetBitmapFromData(window: View, resID: Int, data: ByteArray?, length: Int): Int
5839 {
5840 var retval: Int = -1
5841
5831 waitOnUiThread { 5842 waitOnUiThread {
5832 if(resID != 0) { 5843 if(resID != 0) {
5833 if (window is ImageButton) { 5844 if (window is ImageButton) {
5834 val button = window 5845 val button = window
5835 5846
5836 button.setImageResource(resID) 5847 button.setImageResource(resID)
5848 retval = 0
5837 } else if (window is ImageView) { 5849 } else if (window is ImageView) {
5838 val imageview = window 5850 val imageview = window
5839 5851
5840 imageview.setImageResource(resID) 5852 imageview.setImageResource(resID)
5853 retval = 0
5841 } 5854 }
5842 } 5855 }
5843 if(data != null) { 5856 if(data != null) {
5844 val b = BitmapFactory.decodeByteArray(data, 0, length) 5857 val b = BitmapFactory.decodeByteArray(data, 0, length)
5845 5858
5846 if (window is ImageButton) { 5859 if(b != null) {
5847 val button = window 5860 if (window is ImageButton) {
5848 5861 val button = window
5849 button.setImageBitmap(b) 5862
5850 } else if (window is ImageView) { 5863 button.setImageBitmap(b)
5851 val imageview = window 5864 retval = 0
5852 5865 } else if (window is ImageView) {
5853 imageview.setImageBitmap(b) 5866 val imageview = window
5854 } 5867
5855 } 5868 imageview.setImageBitmap(b)
5856 } 5869 retval = 0
5870 }
5871 } else {
5872 retval = 1
5873 }
5874 }
5875 }
5876 return retval
5857 } 5877 }
5858 5878
5859 fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable? 5879 fun iconNew(file: String?, data: ByteArray?, length: Int, resID: Int): Drawable?
5860 { 5880 {
5861 var icon: Drawable? = null 5881 var icon: Drawable? = null