comparison android/DWindows.kt @ 2677:c90b2d7057c8

Android: Implement dw_window_set_color() on Containers and Listboxes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 22 Oct 2021 18:49:10 +0000
parents a43cf048ff17
children c1482518b643
comparison
equal deleted inserted replaced
2676:a43cf048ff17 2677:c90b2d7057c8
248 } 248 }
249 249
250 class DWListBox(context: Context) : ListView(context), OnItemClickListener { 250 class DWListBox(context: Context) : ListView(context), OnItemClickListener {
251 var list = mutableListOf<String>() 251 var list = mutableListOf<String>()
252 var selected: Int = -1 252 var selected: Int = -1
253 var colorFore: Int? = null
254 var colorBack: Int? = null
253 255
254 init { 256 init {
255 setAdapter( 257 setAdapter(
256 ArrayAdapter( 258 object : ArrayAdapter<String>(
257 context, 259 context,
258 R.layout.simple_list_item_1, list 260 R.layout.simple_list_item_1, list
259 ) 261 ) {
262 override fun getView(pos: Int, view: View?, parent: ViewGroup): View {
263 val thisview = super.getView(pos, view, parent)
264 val textview = thisview as TextView
265 if (colorFore != null) {
266 textview.setTextColor(colorFore!!)
267 }
268 if (colorBack != null) {
269 textview.setBackgroundColor(colorBack!!)
270 }
271 return thisview
272 }
273 }
260 ) 274 )
261 onItemClickListener = this 275 onItemClickListener = this
262 } 276 }
263 277
264 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { 278 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
671 var model = DWContainerModel() 685 var model = DWContainerModel()
672 var selectedItem: Int = -1 686 var selectedItem: Int = -1
673 var simpleMode: Boolean = true 687 var simpleMode: Boolean = true
674 var oddColor: Int? = null 688 var oddColor: Int? = null
675 var evenColor: Int? = null 689 var evenColor: Int? = null
690 var foreColor: Int? = null
691 var backColor: Int? = null
676 var lastClick: Long = 0 692 var lastClick: Long = 0
677 var lastClickRow: Int = -1 693 var lastClickRow: Int = -1
678 694
679 override fun getCount(): Int { 695 override fun getCount(): Int {
680 return model.numberOfRows() 696 return model.numberOfRows()
761 if (content is String) { 777 if (content is String) {
762 textview.text = content 778 textview.text = content
763 } else if (content is Int) { 779 } else if (content is Int) {
764 textview.text = content.toString() 780 textview.text = content.toString()
765 } 781 }
782 if(foreColor != null) {
783 textview.setTextColor(foreColor!!)
784 }
766 } 785 }
767 } 786 }
768 } 787 }
769 } 788 }
770 // Handle row stripe 789 // Handle row stripe
771 if (position % 2 == 0) { 790 if (position % 2 == 0) {
772 if(evenColor != null) { 791 if(evenColor != null) {
773 rowView.setBackgroundColor(evenColor!!) 792 rowView.setBackgroundColor(evenColor!!)
793 } else if(backColor != null) {
794 rowView.setBackgroundColor(backColor!!)
774 } 795 }
775 } else { 796 } else {
776 if(oddColor != null) { 797 if(oddColor != null) {
777 rowView.setBackgroundColor(oddColor!!) 798 rowView.setBackgroundColor(oddColor!!)
799 } else if(backColor != null) {
800 rowView.setBackgroundColor(backColor!!)
778 } 801 }
779 } 802 }
780 return rowView 803 return rowView
781 } 804 }
782 } 805 }
1357 button.setBackgroundColor(colorback) 1380 button.setBackgroundColor(colorback)
1358 } else if(window is LinearLayout) { 1381 } else if(window is LinearLayout) {
1359 val box: LinearLayout = window 1382 val box: LinearLayout = window
1360 1383
1361 box.setBackgroundColor(colorback) 1384 box.setBackgroundColor(colorback)
1385 } else if(window is DWListBox) {
1386 val listbox = window as DWListBox
1387
1388 // Handle DW_CLR_DEFAULT
1389 if(fore == 16) {
1390 val value = TypedValue()
1391 this.theme.resolveAttribute(R.attr.editTextColor, value, true)
1392 colorfore = value.data
1393 }
1394
1395 listbox.colorFore = colorfore
1396 listbox.colorBack = colorback
1397
1398 listbox.setBackgroundColor(colorback)
1399 } else if(window is ListView) {
1400 val cont = window as ListView
1401 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1402
1403 // Handle DW_CLR_DEFAULT
1404 if(fore == 16) {
1405 val value = TypedValue()
1406 this.theme.resolveAttribute(R.attr.editTextColor, value, true)
1407 colorfore = value.data
1408 }
1409
1410 adapter.foreColor = colorfore
1411 adapter.backColor = colorback
1412
1413 cont.setBackgroundColor(colorback)
1362 } 1414 }
1363 } 1415 }
1364 } 1416 }
1365 1417
1366 fun windowSetText(window: View, text: String) { 1418 fun windowSetText(window: View, text: String) {