Mercurial > dwindows
comparison android/DWindows.kt @ 2517:d746323f2841
Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
Eliminate some kotlin code warnings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 08 May 2021 08:11:51 +0000 |
parents | 8f5d064b7054 |
children | 551313c064f2 |
comparison
equal
deleted
inserted
replaced
2516:8f5d064b7054 | 2517:d746323f2841 |
---|---|
85 } | 85 } |
86 | 86 |
87 class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener { | 87 class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener { |
88 var lpw: ListPopupWindow? = null | 88 var lpw: ListPopupWindow? = null |
89 var list = mutableListOf<String>() | 89 var list = mutableListOf<String>() |
90 var selected: Int = -1 | |
90 | 91 |
91 init { | 92 init { |
92 setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.arrow_down_float, 0); | 93 setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.arrow_down_float, 0); |
93 setOnTouchListener(this) | 94 setOnTouchListener(this) |
94 lpw = ListPopupWindow(context) | 95 lpw = ListPopupWindow(context) |
103 lpw!!.setOnItemClickListener(this) | 104 lpw!!.setOnItemClickListener(this) |
104 } | 105 } |
105 | 106 |
106 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { | 107 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { |
107 val item = list[position] | 108 val item = list[position] |
109 selected = position | |
108 setText(item) | 110 setText(item) |
109 lpw!!.dismiss() | 111 lpw!!.dismiss() |
112 eventHandlerInt(11, position, 0, 0, 0) | |
110 } | 113 } |
111 | 114 |
112 override fun onTouch(v: View, event: MotionEvent): Boolean { | 115 override fun onTouch(v: View, event: MotionEvent): Boolean { |
113 val DRAWABLE_RIGHT = 2 | 116 val DRAWABLE_RIGHT = 2 |
114 if (event.action == MotionEvent.ACTION_UP) { | 117 if (event.action == MotionEvent.ACTION_UP) { |
119 return true | 122 return true |
120 } | 123 } |
121 } | 124 } |
122 return false | 125 return false |
123 } | 126 } |
127 | |
128 external fun eventHandlerInt( | |
129 message: Int, | |
130 inta: Int, | |
131 intb: Int, | |
132 intc: Int, | |
133 intd: Int | |
134 ) | |
124 } | 135 } |
125 | 136 |
126 class DWindows : AppCompatActivity() { | 137 class DWindows : AppCompatActivity() { |
127 var firstWindow: Boolean = true | 138 var firstWindow: Boolean = true |
128 var windowLayout: LinearLayout? = null | 139 var windowLayout: LinearLayout? = null |
364 var box: LinearLayout? = null | 375 var box: LinearLayout? = null |
365 | 376 |
366 // Handle scrollboxes by pulling the LinearLayout | 377 // Handle scrollboxes by pulling the LinearLayout |
367 // out of the ScrollView to pack into | 378 // out of the ScrollView to pack into |
368 if (boxview is LinearLayout) { | 379 if (boxview is LinearLayout) { |
369 box = boxview as LinearLayout | 380 box = boxview |
370 } else if (boxview is ScrollView) { | 381 } else if (boxview is ScrollView) { |
371 var sv: ScrollView = boxview | 382 var sv: ScrollView = boxview |
372 | 383 |
373 if (sv.getChildAt(0) is LinearLayout) { | 384 if (sv.getChildAt(0) is LinearLayout) { |
374 box = sv.getChildAt(0) as LinearLayout | 385 box = sv.getChildAt(0) as LinearLayout |
613 | 624 |
614 fun mleSetEditable(mle: EditText, state: Int) | 625 fun mleSetEditable(mle: EditText, state: Int) |
615 { | 626 { |
616 waitOnUiThread { | 627 waitOnUiThread { |
617 if (state != 0) { | 628 if (state != 0) { |
618 mle!!.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) | 629 mle.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) |
619 } else { | 630 } else { |
620 mle!!.inputType = InputType.TYPE_NULL | 631 mle.inputType = InputType.TYPE_NULL |
621 } | 632 } |
622 } | 633 } |
623 } | 634 } |
624 | 635 |
625 fun mleSetCursor(mle: EditText, point: Int) | 636 fun mleSetCursor(mle: EditText, point: Int) |
1029 var dataArrayMap = SimpleArrayMap<String, Long>() | 1040 var dataArrayMap = SimpleArrayMap<String, Long>() |
1030 | 1041 |
1031 combobox = DWComboBox(this) | 1042 combobox = DWComboBox(this) |
1032 combobox!!.tag = dataArrayMap | 1043 combobox!!.tag = dataArrayMap |
1033 combobox!!.id = cid | 1044 combobox!!.id = cid |
1045 combobox!!.setText(text) | |
1034 } | 1046 } |
1035 return combobox | 1047 return combobox |
1036 } | 1048 } |
1037 | 1049 |
1038 fun listOrComboBoxAppend(window: View, text: String) | 1050 fun listOrComboBoxAppend(window: View, text: String) |
1039 { | 1051 { |
1040 waitOnUiThread { | 1052 waitOnUiThread { |
1041 if(window is DWComboBox) { | 1053 if(window is DWComboBox) { |
1042 val combobox = window as DWComboBox | 1054 val combobox = window |
1043 | 1055 |
1044 combobox.list.add(text) | 1056 combobox.list.add(text) |
1057 } | |
1058 } | |
1059 } | |
1060 | |
1061 fun listOrComboBoxInsert(window: View, text: String, pos: Int) | |
1062 { | |
1063 waitOnUiThread { | |
1064 if(window is DWComboBox) { | |
1065 val combobox = window | |
1066 | |
1067 combobox.list.add(pos, text) | |
1068 } | |
1069 } | |
1070 } | |
1071 | |
1072 fun listOrComboBoxClear(window: View) | |
1073 { | |
1074 waitOnUiThread { | |
1075 if(window is DWComboBox) { | |
1076 val combobox = window | |
1077 | |
1078 combobox.list.clear() | |
1079 } | |
1080 } | |
1081 } | |
1082 | |
1083 fun listOrComboBoxCount(window: View): Int | |
1084 { | |
1085 var retval: Int = 0 | |
1086 | |
1087 waitOnUiThread { | |
1088 if(window is DWComboBox) { | |
1089 val combobox = window | |
1090 | |
1091 retval = combobox.list.count() | |
1092 } | |
1093 } | |
1094 return retval | |
1095 } | |
1096 | |
1097 fun listOrComboBoxSetText(window: View, index: Int, text: String) | |
1098 { | |
1099 waitOnUiThread { | |
1100 if(window is DWComboBox) { | |
1101 val combobox = window | |
1102 | |
1103 if(index < combobox.list.count()) | |
1104 combobox.list[index] = text | |
1105 } | |
1106 } | |
1107 } | |
1108 | |
1109 fun listOrComboBoxGetText(window: View, index: Int): String? | |
1110 { | |
1111 var retval: String? = null | |
1112 | |
1113 waitOnUiThread { | |
1114 if(window is DWComboBox) { | |
1115 val combobox = window | |
1116 | |
1117 if(index < combobox.list.count()) | |
1118 retval = combobox.list[index] | |
1119 } | |
1120 } | |
1121 return retval | |
1122 } | |
1123 | |
1124 fun listOrComboBoxGetSelected(window: View): Int | |
1125 { | |
1126 var retval: Int = -1 | |
1127 | |
1128 waitOnUiThread { | |
1129 if(window is DWComboBox) { | |
1130 val combobox = window | |
1131 | |
1132 retval = combobox.selected | |
1133 } | |
1134 } | |
1135 return retval | |
1136 } | |
1137 | |
1138 fun listOrComboBoxSelect(window: View, index: Int, state: Int) | |
1139 { | |
1140 waitOnUiThread { | |
1141 if(window is DWComboBox) { | |
1142 val combobox = window | |
1143 | |
1144 if(index < combobox.list.count() && state != 0) { | |
1145 combobox.selected = index | |
1146 combobox.setText(combobox.list[index]) | |
1147 } | |
1148 } | |
1149 } | |
1150 } | |
1151 | |
1152 fun listOrComboBoxDelete(window: View, index: Int) | |
1153 { | |
1154 waitOnUiThread { | |
1155 if(window is DWComboBox) { | |
1156 val combobox = window | |
1157 | |
1158 if(index < combobox.list.count()) { | |
1159 combobox.list.removeAt(index) | |
1160 } | |
1045 } | 1161 } |
1046 } | 1162 } |
1047 } | 1163 } |
1048 | 1164 |
1049 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer | 1165 fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer |