comparison android/DWindows.kt @ 2579:68ee9a89e0f0

Android: Code cleanup, fix all warnings except for unused function/parameters.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 22 May 2021 23:48:08 +0000
parents a36448beb7f7
children 473eb9ff3f04
comparison
equal deleted inserted replaced
2578:a36448beb7f7 2579:68ee9a89e0f0
37 import android.widget.SeekBar.OnSeekBarChangeListener 37 import android.widget.SeekBar.OnSeekBarChangeListener
38 import androidx.appcompat.app.AlertDialog 38 import androidx.appcompat.app.AlertDialog
39 import androidx.appcompat.app.AppCompatActivity 39 import androidx.appcompat.app.AppCompatActivity
40 import androidx.appcompat.widget.AppCompatEditText 40 import androidx.appcompat.widget.AppCompatEditText
41 import androidx.collection.SimpleArrayMap 41 import androidx.collection.SimpleArrayMap
42 import androidx.constraintlayout.widget.ConstraintLayout
43 import androidx.constraintlayout.widget.ConstraintSet
44 import androidx.core.app.NotificationCompat 42 import androidx.core.app.NotificationCompat
45 import androidx.core.app.NotificationManagerCompat 43 import androidx.core.app.NotificationManagerCompat
46 import androidx.core.content.res.ResourcesCompat 44 import androidx.core.content.res.ResourcesCompat
47 import androidx.core.view.MenuCompat 45 import androidx.core.view.MenuCompat
48 import androidx.recyclerview.widget.RecyclerView 46 import androidx.recyclerview.widget.RecyclerView
49 import androidx.viewpager2.widget.ViewPager2 47 import androidx.viewpager2.widget.ViewPager2
50 import com.google.android.material.tabs.TabLayout 48 import com.google.android.material.tabs.TabLayout
51 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener 49 import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
52 import com.google.android.material.tabs.TabLayoutMediator 50 import com.google.android.material.tabs.TabLayoutMediator
53 import java.io.File 51 import java.io.File
54 import java.io.FileInputStream
55 import java.io.FileNotFoundException
56 import java.io.IOException 52 import java.io.IOException
57 import java.util.* 53 import java.util.*
58 import java.util.concurrent.locks.ReentrantLock 54 import java.util.concurrent.locks.ReentrantLock
59 55
60 56
69 override fun getItemCount() = viewList.count() 65 override fun getItemCount() = viewList.count()
70 override fun getItemViewType(position: Int): Int { 66 override fun getItemViewType(position: Int): Int {
71 return position 67 return position
72 } 68 }
73 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) { 69 override fun onBindViewHolder(holder: DWEventViewHolder, position: Int) {
74 holder.setIsRecyclable(false); 70 holder.setIsRecyclable(false)
75 } 71 }
76 72
77 class DWEventViewHolder(var view: View) : RecyclerView.ViewHolder(view) 73 class DWEventViewHolder(var view: View) : RecyclerView.ViewHolder(view)
78 } 74 }
79 75
101 var value: Long = 0 97 var value: Long = 0
102 var minimum: Long = 0 98 var minimum: Long = 0
103 var maximum: Long = 65535 99 var maximum: Long = 65535
104 100
105 init { 101 init {
106 setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_media_previous, 0, android.R.drawable.ic_media_next, 0); 102 setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_media_previous, 0, R.drawable.ic_media_next, 0)
107 setOnTouchListener(this) 103 setOnTouchListener(this)
108 } 104 }
109 105
110 override fun onTouch(v: View, event: MotionEvent): Boolean { 106 override fun onTouch(v: View, event: MotionEvent): Boolean {
111 val DRAWABLE_RIGHT = 2 107 val DRAWABLE_RIGHT = 2
129 value = minimum 125 value = minimum
130 } 126 }
131 setText(value.toString()) 127 setText(value.toString())
132 eventHandlerInt(14, value.toInt(), 0, 0, 0) 128 eventHandlerInt(14, value.toInt(), 0, 0, 0)
133 return true 129 return true
134 } else if (event.x <= (v as EditText) 130 } else if (event.x <= v.compoundDrawables[DRAWABLE_LEFT].bounds.width()) {
135 .compoundDrawables[DRAWABLE_LEFT].bounds.width()
136 ) {
137 val newvalue = this.text.toString().toLongOrNull() 131 val newvalue = this.text.toString().toLongOrNull()
138 132
139 if(newvalue != null) { 133 if(newvalue != null) {
140 value = newvalue - 1 134 value = newvalue - 1
141 } else { 135 } else {
168 var lpw: ListPopupWindow? = null 162 var lpw: ListPopupWindow? = null
169 var list = mutableListOf<String>() 163 var list = mutableListOf<String>()
170 var selected: Int = -1 164 var selected: Int = -1
171 165
172 init { 166 init {
173 setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.arrow_down_float, 0); 167 setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.arrow_down_float, 0)
174 setOnTouchListener(this) 168 setOnTouchListener(this)
175 lpw = ListPopupWindow(context) 169 lpw = ListPopupWindow(context)
176 lpw!!.setAdapter( 170 lpw!!.setAdapter(
177 ArrayAdapter( 171 ArrayAdapter(
178 context, 172 context,
179 android.R.layout.simple_list_item_1, list 173 R.layout.simple_list_item_1, list
180 ) 174 )
181 ) 175 )
182 lpw!!.anchorView = this 176 lpw!!.anchorView = this
183 lpw!!.isModal = true 177 lpw!!.isModal = true
184 lpw!!.setOnItemClickListener(this) 178 lpw!!.setOnItemClickListener(this)
221 215
222 init { 216 init {
223 setAdapter( 217 setAdapter(
224 ArrayAdapter( 218 ArrayAdapter(
225 context, 219 context,
226 android.R.layout.simple_list_item_1, list 220 R.layout.simple_list_item_1, list
227 ) 221 )
228 ) 222 )
229 onItemClickListener = this 223 onItemClickListener = this
230 } 224 }
231 225
426 fun createMenu(newmenu: Menu?) { 420 fun createMenu(newmenu: Menu?) {
427 if(menu == null) { 421 if(menu == null) {
428 menu = newmenu 422 menu = newmenu
429 } 423 }
430 if(menu != null) { 424 if(menu != null) {
431 var group: Int = 0 425 var group = 0
432 426
433 // Enable group dividers for separators 427 // Enable group dividers for separators
434 MenuCompat.setGroupDividerEnabled(menu, true); 428 MenuCompat.setGroupDividerEnabled(menu, true)
435 429
436 for (menuitem in children) { 430 for (menuitem in children) {
437 // Submenus on Android can't have submenus, so stop at depth 1 431 // Submenus on Android can't have submenus, so stop at depth 1
438 if (menuitem.submenu != null && menu !is SubMenu) { 432 if (menuitem.submenu != null && menu !is SubMenu) {
439 if(menuitem.submenuitem == null) { 433 if(menuitem.submenuitem == null) {
446 } else if(menuitem.menuitem == null) { 440 } else if(menuitem.menuitem == null) {
447 menuitem.menuitem = menu?.add(group, menuitem.id, 0, menuitem.title) 441 menuitem.menuitem = menu?.add(group, menuitem.id, 0, menuitem.title)
448 menuitem.menuitem!!.isCheckable = menuitem.check 442 menuitem.menuitem!!.isCheckable = menuitem.check
449 menuitem.menuitem!!.isChecked = menuitem.checked 443 menuitem.menuitem!!.isChecked = menuitem.checked
450 menuitem.menuitem!!.isEnabled = menuitem.enabled 444 menuitem.menuitem!!.isEnabled = menuitem.enabled
451 menuitem.menuitem!!.setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener { item: MenuItem? -> 445 menuitem.menuitem!!.setOnMenuItemClickListener { item: MenuItem? ->
452 eventHandlerSimple(menuitem, 8) 446 eventHandlerSimple(menuitem, 8)
453 true 447 true
454 }) 448 }
455 } 449 }
456 } 450 }
457 } 451 }
458 } 452 }
459 } 453 }
656 } 650 }
657 651
658 // If the view passed in is null we need to create the layout 652 // If the view passed in is null we need to create the layout
659 if(rowView == null) { 653 if(rowView == null) {
660 rowView = LinearLayout(context) 654 rowView = LinearLayout(context)
661 var lastView: View? = null
662
663 rowView.orientation = LinearLayout.HORIZONTAL 655 rowView.orientation = LinearLayout.HORIZONTAL
664 656
665 for(i in 0 until displayColumns) { 657 for(i in 0 until displayColumns) {
666 val content = model.getRowAndColumn(position, i) 658 val content = model.getRowAndColumn(position, i)
667 659
673 LinearLayout.LayoutParams.WRAP_CONTENT) 665 LinearLayout.LayoutParams.WRAP_CONTENT)
674 if (content is Drawable) { 666 if (content is Drawable) {
675 imageview.setImageDrawable(content) 667 imageview.setImageDrawable(content)
676 } 668 }
677 rowView.addView(imageview) 669 rowView.addView(imageview)
678 lastView = imageview
679 } else { 670 } else {
680 // Everything else id displayed as text 671 // Everything else id displayed as text
681 val textview = TextView(context) 672 val textview = TextView(context)
682 textview.id = View.generateViewId() 673 textview.id = View.generateViewId()
683 textview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 674 textview.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
686 textview.text = content 677 textview.text = content
687 } else if(content is Int) { 678 } else if(content is Int) {
688 textview.text = content.toString() 679 textview.text = content.toString()
689 } 680 }
690 rowView.addView(textview) 681 rowView.addView(textview)
691 lastView = textview
692 } 682 }
693 } 683 }
694 // TODO: Add code to optionally add other columns 684 // TODO: Add code to optionally add other columns
695 } else { 685 } else {
696 // Otherwise we just need to update the existing layout 686 // Otherwise we just need to update the existing layout
935 925
936 fun windowSetStyle(window: View, style: Int, mask: Int) 926 fun windowSetStyle(window: View, style: Int, mask: Int)
937 { 927 {
938 waitOnUiThread { 928 waitOnUiThread {
939 if (window is TextView && window !is EditText) { 929 if (window is TextView && window !is EditText) {
940 val text = window as TextView 930 val text = window
941 val ourmask = (Gravity.HORIZONTAL_GRAVITY_MASK or Gravity.VERTICAL_GRAVITY_MASK) and mask 931 val ourmask = (Gravity.HORIZONTAL_GRAVITY_MASK or Gravity.VERTICAL_GRAVITY_MASK) and mask
942 932
943 if (ourmask != 0) { 933 if (ourmask != 0) {
944 // Gravity with the masked parts zeroed out 934 // Gravity with the masked parts zeroed out
945 val newgravity = style and ourmask 935 val newgravity = style and ourmask
965 } 955 }
966 } 956 }
967 } 957 }
968 958
969 fun windowGetData(window: View, name: String): Long { 959 fun windowGetData(window: View, name: String): Long {
970 var retval: Long = 0L 960 var retval = 0L
971 961
972 if (window.tag != null) { 962 if (window.tag != null) {
973 val dataArrayMap: SimpleArrayMap<String, Long> = window.tag as SimpleArrayMap<String, Long> 963 val dataArrayMap: SimpleArrayMap<String, Long> = window.tag as SimpleArrayMap<String, Long>
974 964
975 if(dataArrayMap.containsKey(name)) { 965 if(dataArrayMap.containsKey(name)) {
990 if(fontname != null) { 980 if(fontname != null) {
991 val bold: Boolean = fontname.contains(" Bold") 981 val bold: Boolean = fontname.contains(" Bold")
992 val italic: Boolean = fontname.contains(" Italic") 982 val italic: Boolean = fontname.contains(" Italic")
993 val font = fontname.substringAfter('.') 983 val font = fontname.substringAfter('.')
994 var fontFamily = font 984 var fontFamily = font
995 var typeface: Typeface? = null 985 val typeface: Typeface?
996 986
997 if (bold) { 987 if (bold) {
998 fontFamily = font.substringBefore(" Bold") 988 fontFamily = font.substringBefore(" Bold")
999 } else if (italic) { 989 } else if (italic) {
1000 fontFamily = font.substringBefore(" Italic") 990 fontFamily = font.substringBefore(" Italic")
1014 } 1004 }
1015 return Typeface.DEFAULT 1005 return Typeface.DEFAULT
1016 } 1006 }
1017 1007
1018 fun windowSetFont(window: View, fontname: String?) { 1008 fun windowSetFont(window: View, fontname: String?) {
1019 var typeface: Typeface? = typefaceFromFontName(fontname) 1009 val typeface: Typeface? = typefaceFromFontName(fontname)
1020 var size: Float? = null 1010 var size: Float? = null
1021 1011
1022 if(fontname != null) { 1012 if(fontname != null) {
1023 size = fontname.substringBefore('.').toFloatOrNull() 1013 size = fontname.substringBefore('.').toFloatOrNull()
1024 } 1014 }
1226 box = sv.getChildAt(0) as LinearLayout 1216 box = sv.getChildAt(0) as LinearLayout
1227 } 1217 }
1228 } 1218 }
1229 1219
1230 if (box != null) { 1220 if (box != null) {
1231 var weight: Float = 1F 1221 var weight = 1F
1232 1222
1233 // If it is a box, match parent based on direction 1223 // If it is a box, match parent based on direction
1234 if ((item is LinearLayout) || (item is ScrollView)) { 1224 if ((item is LinearLayout) || (item is ScrollView)) {
1235 if (box.orientation == LinearLayout.VERTICAL) { 1225 if (box.orientation == LinearLayout.VERTICAL) {
1236 if (hsize != 0) { 1226 if (hsize != 0) {
1486 } 1476 }
1487 } 1477 }
1488 1478
1489 fun checkOrRadioGetChecked(control: View): Boolean 1479 fun checkOrRadioGetChecked(control: View): Boolean
1490 { 1480 {
1491 var retval: Boolean = false 1481 var retval = false
1492 1482
1493 waitOnUiThread { 1483 waitOnUiThread {
1494 if (control is CheckBox) { 1484 if (control is CheckBox) {
1495 val checkbox: CheckBox = control 1485 val checkbox: CheckBox = control
1496 retval = checkbox.isChecked 1486 retval = checkbox.isChecked
1790 1780
1791 // Make sure the box is MATCH_PARENT 1781 // Make sure the box is MATCH_PARENT
1792 box.layoutParams = LinearLayout.LayoutParams( 1782 box.layoutParams = LinearLayout.LayoutParams(
1793 LinearLayout.LayoutParams.MATCH_PARENT, 1783 LinearLayout.LayoutParams.MATCH_PARENT,
1794 LinearLayout.LayoutParams.MATCH_PARENT 1784 LinearLayout.LayoutParams.MATCH_PARENT
1795 ); 1785 )
1796 1786
1797 adapter.viewList[index] = box 1787 adapter.viewList[index] = box
1798 } 1788 }
1799 } 1789 }
1800 } 1790 }
1801 1791
1802 fun notebookPageGet(notebook: RelativeLayout): Long 1792 fun notebookPageGet(notebook: RelativeLayout): Long
1803 { 1793 {
1804 var retval: Long = 0L 1794 var retval = 0L
1805 1795
1806 waitOnUiThread { 1796 waitOnUiThread {
1807 var pager: ViewPager2? = null 1797 var pager: ViewPager2? = null
1808 var tabs: TabLayout? = null 1798 var tabs: TabLayout? = null
1809 1799
1891 return percent 1881 return percent
1892 } 1882 }
1893 1883
1894 fun percentGetPos(percent: ProgressBar): Int 1884 fun percentGetPos(percent: ProgressBar): Int
1895 { 1885 {
1896 var retval: Int = 0 1886 var retval = 0
1897 1887
1898 waitOnUiThread { 1888 waitOnUiThread {
1899 retval = percent.progress 1889 retval = percent.progress
1900 } 1890 }
1901 return retval 1891 return retval
1973 fun spinButtonNew(text: String, cid: Int): DWSpinButton? 1963 fun spinButtonNew(text: String, cid: Int): DWSpinButton?
1974 { 1964 {
1975 var spinbutton: DWSpinButton? = null 1965 var spinbutton: DWSpinButton? = null
1976 1966
1977 waitOnUiThread { 1967 waitOnUiThread {
1978 var dataArrayMap = SimpleArrayMap<String, Long>() 1968 val dataArrayMap = SimpleArrayMap<String, Long>()
1979 val newval = text.toLongOrNull() 1969 val newval = text.toLongOrNull()
1980 1970
1981 spinbutton = DWSpinButton(this) 1971 spinbutton = DWSpinButton(this)
1982 spinbutton!!.tag = dataArrayMap 1972 spinbutton!!.tag = dataArrayMap
1983 spinbutton!!.id = cid 1973 spinbutton!!.id = cid
2031 fun comboBoxNew(text: String, cid: Int): DWComboBox? 2021 fun comboBoxNew(text: String, cid: Int): DWComboBox?
2032 { 2022 {
2033 var combobox: DWComboBox? = null 2023 var combobox: DWComboBox? = null
2034 2024
2035 waitOnUiThread { 2025 waitOnUiThread {
2036 var dataArrayMap = SimpleArrayMap<String, Long>() 2026 val dataArrayMap = SimpleArrayMap<String, Long>()
2037 2027
2038 combobox = DWComboBox(this) 2028 combobox = DWComboBox(this)
2039 combobox!!.tag = dataArrayMap 2029 combobox!!.tag = dataArrayMap
2040 combobox!!.id = cid 2030 combobox!!.id = cid
2041 combobox!!.setText(text) 2031 combobox!!.setText(text)
2054 cont = ListView(this) 2044 cont = ListView(this)
2055 cont!!.tag = dataArrayMap 2045 cont!!.tag = dataArrayMap
2056 cont!!.id = cid 2046 cont!!.id = cid
2057 cont!!.adapter = adapter 2047 cont!!.adapter = adapter
2058 if(multi != 0) { 2048 if(multi != 0) {
2059 cont!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE; 2049 cont!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE
2060 } 2050 }
2061 cont!!.setOnItemClickListener { parent, view, position, id -> 2051 cont!!.setOnItemClickListener { parent, view, position, id ->
2062 val title = adapter.model.getRowTitle(position) 2052 val title = adapter.model.getRowTitle(position)
2063 val data = adapter.model.getRowData(position) 2053 val data = adapter.model.getRowData(position)
2064 2054
2286 } 2276 }
2287 } 2277 }
2288 2278
2289 fun containerGetColumnType(cont: ListView, column: Int): Int 2279 fun containerGetColumnType(cont: ListView, column: Int): Int
2290 { 2280 {
2291 var type: Int = 0 2281 var type = 0
2292 2282
2293 waitOnUiThread { 2283 waitOnUiThread {
2294 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter 2284 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
2295 2285
2296 type = adapter.model.getColumnType(column) 2286 type = adapter.model.getColumnType(column)
2343 2333
2344 listbox = DWListBox(this) 2334 listbox = DWListBox(this)
2345 listbox!!.tag = dataArrayMap 2335 listbox!!.tag = dataArrayMap
2346 listbox!!.id = cid 2336 listbox!!.id = cid
2347 if(multi != 0) { 2337 if(multi != 0) {
2348 listbox!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE; 2338 listbox!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE
2349 } 2339 }
2350 } 2340 }
2351 return listbox 2341 return listbox
2352 } 2342 }
2353 2343
2396 } 2386 }
2397 } 2387 }
2398 2388
2399 fun listOrComboBoxCount(window: View): Int 2389 fun listOrComboBoxCount(window: View): Int
2400 { 2390 {
2401 var retval: Int = 0 2391 var retval = 0
2402 2392
2403 waitOnUiThread { 2393 waitOnUiThread {
2404 if(window is DWComboBox) { 2394 if(window is DWComboBox) {
2405 val combobox = window 2395 val combobox = window
2406 2396
2483 val listbox = window 2473 val listbox = window
2484 2474
2485 if(index < listbox.list.count()) { 2475 if(index < listbox.list.count()) {
2486 if(state != 0) { 2476 if(state != 0) {
2487 listbox.selected = index 2477 listbox.selected = index
2488 listbox.setItemChecked(index, true); 2478 listbox.setItemChecked(index, true)
2489 } else { 2479 } else {
2490 listbox.setItemChecked(index, false); 2480 listbox.setItemChecked(index, false)
2491 } 2481 }
2492 } 2482 }
2493 } 2483 }
2494 } 2484 }
2495 } 2485 }
2565 2555
2566 calendar = CalendarView(this) 2556 calendar = CalendarView(this)
2567 calendar!!.tag = dataArrayMap 2557 calendar!!.tag = dataArrayMap
2568 calendar!!.id = cid 2558 calendar!!.id = cid
2569 calendar!!.setOnDateChangeListener { calendar, year, month, day -> 2559 calendar!!.setOnDateChangeListener { calendar, year, month, day ->
2570 val c: Calendar = Calendar.getInstance(); 2560 val c: Calendar = Calendar.getInstance()
2571 c.set(year, month, day); 2561 c.set(year, month, day)
2572 calendar.date = c.timeInMillis 2562 calendar.date = c.timeInMillis
2573 } 2563 }
2574 } 2564 }
2575 2565
2576 return calendar 2566 return calendar
2684 { 2674 {
2685 var icon: Drawable? = null 2675 var icon: Drawable? = null
2686 2676
2687 waitOnUiThread { 2677 waitOnUiThread {
2688 if(resID != 0) { 2678 if(resID != 0) {
2689 icon = ResourcesCompat.getDrawable(resources, resID, null); 2679 icon = ResourcesCompat.getDrawable(resources, resID, null)
2690 } else if(filename != null) { 2680 } else if(filename != null) {
2691 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") 2681 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
2692 2682
2693 for (ext in exts) { 2683 for (ext in exts) {
2694 // Try to load the image, and protect against exceptions 2684 // Try to load the image, and protect against exceptions
2715 2705
2716 waitOnUiThread { 2706 waitOnUiThread {
2717 if(width > 0 && height > 0) { 2707 if(width > 0 && height > 0) {
2718 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888) 2708 pixmap = Bitmap.createBitmap(null, width, height, Bitmap.Config.ARGB_8888)
2719 } else if(resID != 0) { 2709 } else if(resID != 0) {
2720 pixmap = BitmapFactory.decodeResource(resources, resID); 2710 pixmap = BitmapFactory.decodeResource(resources, resID)
2721 } else if(filename != null) { 2711 } else if(filename != null) {
2722 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif") 2712 val exts = arrayOf("", ".png", ".webp", ".jpg", ".jpeg", ".gif")
2723 2713
2724 for (ext in exts) { 2714 for (ext in exts) {
2725 // Try to load the image, and protect against exceptions 2715 // Try to load the image, and protect against exceptions
2779 fun pixmapBitBlt(dstr: DWRender?, dstp: Bitmap?, dstx: Int, dsty: Int, dstw: Int, dsth: Int, 2769 fun pixmapBitBlt(dstr: DWRender?, dstp: Bitmap?, dstx: Int, dsty: Int, dstw: Int, dsth: Int,
2780 srcr: DWRender?, srcp: Bitmap?, srcy: Int, srcx: Int, srcw: Int, srch: Int): Int 2770 srcr: DWRender?, srcp: Bitmap?, srcy: Int, srcx: Int, srcw: Int, srch: Int): Int
2781 { 2771 {
2782 val dst = Rect(dstx, dsty, dstx + dstw, dsty + dsth) 2772 val dst = Rect(dstx, dsty, dstx + dstw, dsty + dsth)
2783 val src = Rect(srcx, srcy, srcx + srcw, srcy + srch) 2773 val src = Rect(srcx, srcy, srcx + srcw, srcy + srch)
2784 var retval: Int = 1 2774 var retval = 1
2785 2775
2786 if(srcw == -1) { 2776 if(srcw == -1) {
2787 src.right = srcx + dstw 2777 src.right = srcx + dstw
2788 } 2778 }
2789 if(srch == -1) { 2779 if(srch == -1) {
2875 paint.typeface = typeface 2865 paint.typeface = typeface
2876 if (fontsize > 0) { 2866 if (fontsize > 0) {
2877 paint.textSize = fontsize.toFloat() 2867 paint.textSize = fontsize.toFloat()
2878 } 2868 }
2879 } else if (window != null && window is DWRender) { 2869 } else if (window != null && window is DWRender) {
2880 val secondary: DWRender = window as DWRender 2870 val secondary: DWRender = window
2881 2871
2882 if (secondary.typeface != null) { 2872 if (secondary.typeface != null) {
2883 paint.typeface = secondary.typeface 2873 paint.typeface = secondary.typeface
2884 if (secondary.fontsize != null && secondary.fontsize!! > 0F) { 2874 if (secondary.fontsize != null && secondary.fontsize!! > 0F) {
2885 paint.textSize = secondary.fontsize!! 2875 paint.textSize = secondary.fontsize!!
2915 paint.typeface = typeface 2905 paint.typeface = typeface
2916 if(fontsize > 0) { 2906 if(fontsize > 0) {
2917 paint.textSize = fontsize.toFloat() 2907 paint.textSize = fontsize.toFloat()
2918 } 2908 }
2919 } else if(window != null && window is DWRender) { 2909 } else if(window != null && window is DWRender) {
2920 val secondary: DWRender = window as DWRender 2910 val secondary: DWRender = window
2921 2911
2922 if(secondary.typeface != null) { 2912 if(secondary.typeface != null) {
2923 paint.typeface = secondary.typeface 2913 paint.typeface = secondary.typeface
2924 if(secondary.fontsize != null && secondary.fontsize!! > 0F) { 2914 if(secondary.fontsize != null && secondary.fontsize!! > 0F) {
2925 paint.textSize = secondary.fontsize!! 2915 paint.textSize = secondary.fontsize!!
3173 return retval 3163 return retval
3174 } 3164 }
3175 3165
3176 fun messageBox(title: String, body: String, flags: Int): Int 3166 fun messageBox(title: String, body: String, flags: Int): Int
3177 { 3167 {
3178 var retval: Int = 0 3168 var retval = 0
3179 3169
3180 waitOnUiThread { 3170 waitOnUiThread {
3181 // make a text input dialog and show it 3171 // make a text input dialog and show it
3182 val alert = AlertDialog.Builder(this) 3172 val alert = AlertDialog.Builder(this)
3183 3173
3184 alert.setTitle(title) 3174 alert.setTitle(title)
3185 alert.setMessage(body) 3175 alert.setMessage(body)
3186 if ((flags and (1 shl 3)) != 0) { 3176 if ((flags and (1 shl 3)) != 0) {
3187 alert.setPositiveButton("Yes", 3177 alert.setPositiveButton("Yes"
3188 //android.R.string.yes, 3178 )
3189 DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 3179 //R.string.yes,
3190 retval = 1 3180 { _: DialogInterface, _: Int ->
3191 throw java.lang.RuntimeException() 3181 retval = 1
3192 }); 3182 throw java.lang.RuntimeException()
3183 }
3193 } 3184 }
3194 if ((flags and ((1 shl 1) or (1 shl 2))) != 0) { 3185 if ((flags and ((1 shl 1) or (1 shl 2))) != 0) {
3195 alert.setNegativeButton( 3186 alert.setNegativeButton(
3196 android.R.string.ok, 3187 R.string.ok
3197 DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 3188 ) { _: DialogInterface, _: Int ->
3198 retval = 0 3189 retval = 0
3199 throw java.lang.RuntimeException() 3190 throw java.lang.RuntimeException()
3200 }); 3191 }
3201 } 3192 }
3202 if ((flags and ((1 shl 3) or (1 shl 4))) != 0) { 3193 if ((flags and ((1 shl 3) or (1 shl 4))) != 0) {
3203 alert.setNegativeButton("No", 3194 alert.setNegativeButton("No"
3204 //android.R.string.no, 3195 )
3205 DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 3196 //R.string.no,
3206 retval = 0 3197 { _: DialogInterface, _: Int ->
3207 throw java.lang.RuntimeException() 3198 retval = 0
3208 }); 3199 throw java.lang.RuntimeException()
3200 }
3209 } 3201 }
3210 if ((flags and ((1 shl 2) or (1 shl 4))) != 0) { 3202 if ((flags and ((1 shl 2) or (1 shl 4))) != 0) {
3211 alert.setNeutralButton( 3203 alert.setNeutralButton(
3212 android.R.string.cancel, 3204 R.string.cancel
3213 DialogInterface.OnClickListener { _: DialogInterface, _: Int -> 3205 ) { _: DialogInterface, _: Int ->
3214 retval = 2 3206 retval = 2
3215 throw java.lang.RuntimeException() 3207 throw java.lang.RuntimeException()
3216 }); 3208 }
3217 } 3209 }
3218 alert.setCancelable(false) 3210 alert.setCancelable(false)
3219 alert.show(); 3211 alert.show()
3220 3212
3221 // loop till a runtime exception is triggered. 3213 // loop till a runtime exception is triggered.
3222 try { 3214 try {
3223 Looper.loop() 3215 Looper.loop()
3224 } catch (e2: RuntimeException) { 3216 } catch (e2: RuntimeException) {