comparison android/DWindows.kt @ 2556:d2d8c66ad062

Android: Initial container implementation... getting a NullPointerException crash in dwtest... But I wanted to get this code committed while I work on it more.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 16 May 2021 22:41:50 +0000
parents d7d163d70763
children 756331246f94
comparison
equal deleted inserted replaced
2555:d7d163d70763 2556:d2d8c66ad062
9 import android.content.ClipboardManager 9 import android.content.ClipboardManager
10 import android.content.Context 10 import android.content.Context
11 import android.content.DialogInterface 11 import android.content.DialogInterface
12 import android.content.pm.ActivityInfo 12 import android.content.pm.ActivityInfo
13 import android.content.res.Configuration 13 import android.content.res.Configuration
14 import android.content.res.Resources
15 import android.graphics.* 14 import android.graphics.*
16 import android.graphics.drawable.BitmapDrawable 15 import android.graphics.drawable.BitmapDrawable
17 import android.graphics.drawable.Drawable 16 import android.graphics.drawable.Drawable
18 import android.graphics.drawable.GradientDrawable 17 import android.graphics.drawable.GradientDrawable
19 import android.media.AudioManager 18 import android.media.AudioManager
224 ArrayAdapter( 223 ArrayAdapter(
225 context, 224 context,
226 android.R.layout.simple_list_item_1, list 225 android.R.layout.simple_list_item_1, list
227 ) 226 )
228 ) 227 )
229 setOnItemClickListener(this) 228 onItemClickListener = this
230 } 229 }
231 230
232 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { 231 override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) {
233 selected = position 232 selected = position
234 eventHandlerInt(11, position, 0, 0, 0) 233 eventHandlerInt(11, position, 0, 0, 0)
472 return columns.size 471 return columns.size
473 } 472 }
474 473
475 fun numberOfRows(): Int 474 fun numberOfRows(): Int
476 { 475 {
477 return data.size / columns.size 476 if(columns.size > 0) {
477 return data.size / columns.size
478 }
479 return 0
478 } 480 }
479 481
480 fun getColumnType(column: Int): Int 482 fun getColumnType(column: Int): Int
481 { 483 {
482 if(column < types.size) { 484 if(column < types.size) {
515 types.add(type) 517 types.add(type)
516 // If we change the columns we have to invalidate the data 518 // If we change the columns we have to invalidate the data
517 data.clear() 519 data.clear()
518 } 520 }
519 521
520 fun addRows(count: Int) 522 fun addRows(count: Int): Long
521 { 523 {
524 var startRow: Long = numberOfRows().toLong()
525
522 for(i in 0 until (count * columns.size)) 526 for(i in 0 until (count * columns.size))
523 { 527 {
524 // Fill in with nulls to be set later 528 // Fill in with nulls to be set later
525 data.add(null) 529 data.add(null)
526 } 530 }
531 return startRow
527 } 532 }
528 533
529 fun clear() 534 fun clear()
530 { 535 {
531 data.clear() 536 data.clear()
580 rowView.addView(textview) 585 rowView.addView(textview)
581 set.clone(rowView) 586 set.clone(rowView)
582 set.connect(imageview.id, ConstraintSet.LEFT, textview.id, ConstraintSet.RIGHT) 587 set.connect(imageview.id, ConstraintSet.LEFT, textview.id, ConstraintSet.RIGHT)
583 set.applyTo(rowView) 588 set.applyTo(rowView)
584 589
590 // TODO: Add code to optionally add other columns
585 return rowView 591 return rowView
586 } 592 }
587 } 593 }
588 594
589 class DWindows : AppCompatActivity() { 595 class DWindows : AppCompatActivity() {
744 { 750 {
745 for(menuitem in menu.children) { 751 for(menuitem in menu.children) {
746 if(menuitem.id == cid) { 752 if(menuitem.id == cid) {
747 // Handle DW_MIS_ENABLED/DISABLED 753 // Handle DW_MIS_ENABLED/DISABLED
748 if((state and (1 or (1 shl 1))) != 0) { 754 if((state and (1 or (1 shl 1))) != 0) {
749 var enabled: Boolean = false 755 var enabled = false
750 756
751 // Handle DW_MIS_ENABLED 757 // Handle DW_MIS_ENABLED
752 if ((state and 1) != 0) { 758 if ((state and 1) != 0) {
753 enabled = true 759 enabled = true
754 } 760 }
759 } 765 }
760 } 766 }
761 767
762 // Handle DW_MIS_CHECKED/UNCHECKED 768 // Handle DW_MIS_CHECKED/UNCHECKED
763 if((state and ((1 shl 2) or (1 shl 3))) != 0) { 769 if((state and ((1 shl 2) or (1 shl 3))) != 0) {
764 var checked: Boolean = false 770 var checked = false
765 771
766 // Handle DW_MIS_CHECKED 772 // Handle DW_MIS_CHECKED
767 if ((state and (1 shl 2)) != 0) { 773 if ((state and (1 shl 2)) != 0) {
768 checked = true 774 checked = true
769 } 775 }
1876 combobox!!.tag = dataArrayMap 1882 combobox!!.tag = dataArrayMap
1877 combobox!!.id = cid 1883 combobox!!.id = cid
1878 combobox!!.setText(text) 1884 combobox!!.setText(text)
1879 } 1885 }
1880 return combobox 1886 return combobox
1887 }
1888
1889 fun containerNew(cid: Int, multi: Int): ListView?
1890 {
1891 var cont: ListView? = null
1892
1893 waitOnUiThread {
1894 var dataArrayMap = SimpleArrayMap<String, Long>()
1895
1896 cont = ListView(this)
1897 cont!!.tag = dataArrayMap
1898 cont!!.id = cid
1899 cont!!.adapter = DWContainerAdapter(this)
1900 if(multi != 0) {
1901 cont!!.choiceMode = ListView.CHOICE_MODE_MULTIPLE;
1902 }
1903 }
1904 return cont
1905 }
1906
1907 fun containerAddColumn(cont: ListView, title: String, flags: Int)
1908 {
1909 waitOnUiThread {
1910 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1911
1912 adapter.model.addColumn(title, flags)
1913 }
1914 }
1915
1916 fun containerAlloc(cont: ListView, rowcount: Int): ListView
1917 {
1918 waitOnUiThread {
1919 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1920 val rowStart = adapter.model.addRows(rowcount)
1921
1922 windowSetData(cont, "_dw_rowstart", rowStart)
1923 }
1924 return cont
1925 }
1926
1927 fun containerChangeItemString(cont: ListView, column: Int, row: Int, text: String)
1928 {
1929 waitOnUiThread {
1930 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1931
1932 adapter.model.setRowAndColumn(row, column, text)
1933 }
1934 }
1935
1936 fun containerChangeItemIcon(cont: ListView, column: Int, row: Int, icon: Drawable)
1937 {
1938 waitOnUiThread {
1939 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1940
1941 adapter.model.setRowAndColumn(row, column, icon)
1942 }
1943 }
1944
1945 fun containerChangeItemInt(cont: ListView, column: Int, row: Int, num: Int)
1946 {
1947 waitOnUiThread {
1948 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1949
1950 adapter.model.setRowAndColumn(row, column, num)
1951 }
1952 }
1953
1954 fun containerGetColumnType(cont: ListView, column: Int): Int
1955 {
1956 var type: Int = 0
1957
1958 waitOnUiThread {
1959 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1960
1961 type = adapter.model.getColumnType(column)
1962 }
1963 return type
1964 }
1965
1966 fun containerClear(cont: ListView)
1967 {
1968 waitOnUiThread {
1969 val adapter: DWContainerAdapter = cont.adapter as DWContainerAdapter
1970
1971 adapter.model.clear()
1972 }
1881 } 1973 }
1882 1974
1883 fun listBoxNew(cid: Int, multi: Int): DWListBox? 1975 fun listBoxNew(cid: Int, multi: Int): DWListBox?
1884 { 1976 {
1885 var listbox: DWListBox? = null 1977 var listbox: DWListBox? = null