comparison android/DWindows.kt @ 2520:167af4b0004b

Android: Implement spinbuttons and callbacks.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 08 May 2021 23:22:52 +0000
parents 551313c064f2
children 5f92284e2b08
comparison
equal deleted inserted replaced
2519:551313c064f2 2520:167af4b0004b
82 } 82 }
83 83
84 external fun eventHandlerHTMLChanged(obj1: View, message: Int, URI: String, status: Int) 84 external fun eventHandlerHTMLChanged(obj1: View, message: Int, URI: String, status: Int)
85 } 85 }
86 86
87 class DWSpinButton(context: Context) : AppCompatEditText(context), OnTouchListener {
88 var value: Long = 0
89 var minimum: Long = 0
90 var maximum: Long = 65535
91
92 init {
93 setCompoundDrawablesWithIntrinsicBounds(android.R.drawable.ic_media_previous, 0, android.R.drawable.ic_media_next, 0);
94 setOnTouchListener(this)
95 }
96
97 override fun onTouch(v: View, event: MotionEvent): Boolean {
98 val DRAWABLE_RIGHT = 2
99 val DRAWABLE_LEFT = 0
100
101 if (event.action == MotionEvent.ACTION_UP) {
102 if (event.x >= v.width - (v as EditText)
103 .compoundDrawables[DRAWABLE_RIGHT].bounds.width()
104 ) {
105 value += 1
106 if(value > maximum) {
107 value = maximum
108 }
109 setText(value.toString())
110 eventHandlerInt(14, value.toInt(), 0, 0, 0)
111 return true
112 } else if (event.x <= (v as EditText)
113 .compoundDrawables[DRAWABLE_LEFT].bounds.width()
114 ) {
115 value -= 1
116 if(value < minimum) {
117 value = minimum
118 }
119 setText(value.toString())
120 eventHandlerInt(14, value.toInt(), 0, 0, 0)
121 return true
122 }
123 }
124 return false
125 }
126
127 external fun eventHandlerInt(
128 message: Int,
129 inta: Int,
130 intb: Int,
131 intc: Int,
132 intd: Int
133 )
134 }
135
87 class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener { 136 class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener {
88 var lpw: ListPopupWindow? = null 137 var lpw: ListPopupWindow? = null
89 var list = mutableListOf<String>() 138 var list = mutableListOf<String>()
90 var selected: Int = -1 139 var selected: Int = -1
91 140
112 eventHandlerInt(11, position, 0, 0, 0) 161 eventHandlerInt(11, position, 0, 0, 0)
113 } 162 }
114 163
115 override fun onTouch(v: View, event: MotionEvent): Boolean { 164 override fun onTouch(v: View, event: MotionEvent): Boolean {
116 val DRAWABLE_RIGHT = 2 165 val DRAWABLE_RIGHT = 2
166
117 if (event.action == MotionEvent.ACTION_UP) { 167 if (event.action == MotionEvent.ACTION_UP) {
118 if (event.x >= v.width - (v as EditText) 168 if (event.x >= v.width - (v as EditText)
119 .compoundDrawables[DRAWABLE_RIGHT].bounds.width() 169 .compoundDrawables[DRAWABLE_RIGHT].bounds.width()
120 ) { 170 ) {
121 lpw!!.show() 171 lpw!!.show()
1056 2 -> html.loadUrl("http://dwindows.netlabs.org") 1106 2 -> html.loadUrl("http://dwindows.netlabs.org")
1057 4 -> html.reload() 1107 4 -> html.reload()
1058 5 -> html.stopLoading() 1108 5 -> html.stopLoading()
1059 } 1109 }
1060 } 1110 }
1111 }
1112
1113 fun spinButtonNew(text: String, cid: Int): DWSpinButton?
1114 {
1115 var spinbutton: DWSpinButton? = null
1116
1117 waitOnUiThread {
1118 var dataArrayMap = SimpleArrayMap<String, Long>()
1119 val newval = text.toLongOrNull()
1120
1121 spinbutton = DWSpinButton(this)
1122 spinbutton!!.tag = dataArrayMap
1123 spinbutton!!.id = cid
1124 spinbutton!!.setText(text)
1125 if(newval != null) {
1126 spinbutton!!.value = newval
1127 }
1128 }
1129 return spinbutton
1130 }
1131
1132 fun spinButtonSetPos(spinbutton: DWSpinButton, position: Long)
1133 {
1134 waitOnUiThread {
1135 spinbutton.value = position
1136 spinbutton.setText(position.toString())
1137 }
1138 }
1139
1140 fun spinButtonSetLimits(spinbutton: DWSpinButton, upper: Long, lower: Long)
1141 {
1142 waitOnUiThread {
1143 spinbutton.maximum = upper
1144 spinbutton.minimum = lower
1145 if(spinbutton.value > upper) {
1146 spinbutton.value = upper
1147 }
1148 if(spinbutton.value < lower) {
1149 spinbutton.value = lower
1150 }
1151 spinbutton.setText(spinbutton.value.toString())
1152 }
1153 }
1154
1155 fun spinButtonGetPos(spinbutton: DWSpinButton): Long
1156 {
1157 var retval: Long = 0
1158
1159 waitOnUiThread {
1160 val newvalue = spinbutton.text.toString().toLongOrNull()
1161
1162 if(newvalue == null) {
1163 retval = spinbutton.value
1164 } else {
1165 retval = newvalue
1166 }
1167 }
1168 return retval
1061 } 1169 }
1062 1170
1063 fun comboBoxNew(text: String, cid: Int): DWComboBox? 1171 fun comboBoxNew(text: String, cid: Int): DWComboBox?
1064 { 1172 {
1065 var combobox: DWComboBox? = null 1173 var combobox: DWComboBox? = null