comparison android/DWindows.kt @ 2752:d355c6abbba6

Android: Add a DWContainerRow class implmenting LinearLayout and Checkable. Use this new class instead of LinearLayout when creating container rows. This is an attempt get multiple selection working in the container.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 31 Dec 2021 23:21:44 +0000
parents ee1cfa7d645e
children 2ac361d3a837
comparison
equal deleted inserted replaced
2751:ee1cfa7d645e 2752:d355c6abbba6
69 import androidx.appcompat.widget.AppCompatSeekBar 69 import androidx.appcompat.widget.AppCompatSeekBar
70 import android.content.DialogInterface 70 import android.content.DialogInterface
71 import android.graphics.pdf.PdfDocument 71 import android.graphics.pdf.PdfDocument
72 import android.print.* 72 import android.print.*
73 import android.print.pdf.PrintedPdfDocument 73 import android.print.pdf.PrintedPdfDocument
74 import android.widget.Checkable
75
76 import android.widget.LinearLayout
77
78
79
74 80
75 81
76 // Color Wheel section 82 // Color Wheel section
77 private val HUE_COLORS = intArrayOf( 83 private val HUE_COLORS = intArrayOf(
78 Color.RED, 84 Color.RED,
1639 rowdata.clear() 1645 rowdata.clear()
1640 rowtitle.clear() 1646 rowtitle.clear()
1641 } 1647 }
1642 } 1648 }
1643 1649
1650 class DWContainerRow : LinearLayout, Checkable {
1651 private var mChecked = false
1652
1653 constructor(context: Context?) : super(context) {}
1654 constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
1655 constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {}
1656
1657 override fun setChecked(b: Boolean) {
1658 mChecked = b
1659 refreshDrawableState()
1660 }
1661
1662 override fun isChecked(): Boolean {
1663 return mChecked
1664 }
1665
1666 override fun toggle() {
1667 mChecked = !mChecked
1668 refreshDrawableState()
1669 }
1670
1671 override fun onCreateDrawableState(extraSpace: Int): IntArray {
1672 val states = super.onCreateDrawableState(extraSpace + 1)
1673 if (mChecked) {
1674 mergeDrawableStates(states, CHECKED_STATE)
1675 }
1676 return states
1677 }
1678
1679 companion object {
1680 val CHECKED_STATE = intArrayOf(R.attr.state_checked)
1681 }
1682 }
1683
1644 class DWContainerAdapter(c: Context) : BaseAdapter() 1684 class DWContainerAdapter(c: Context) : BaseAdapter()
1645 { 1685 {
1646 private var context = c 1686 private var context = c
1647 var model = DWContainerModel() 1687 var model = DWContainerModel()
1648 var selectedItem: Int = -1 1688 var selectedItem: Int = -1
1665 override fun getItemId(position: Int): Long { 1705 override fun getItemId(position: Int): Long {
1666 return position.toLong() 1706 return position.toLong()
1667 } 1707 }
1668 1708
1669 override fun getView(position: Int, view: View?, parent: ViewGroup): View { 1709 override fun getView(position: Int, view: View?, parent: ViewGroup): View {
1670 var rowView: LinearLayout? = view as LinearLayout? 1710 var rowView: DWContainerRow? = view as DWContainerRow?
1671 var displayColumns = model.numberOfColumns() 1711 var displayColumns = model.numberOfColumns()
1672 1712
1673 // In simple mode, limit the columns to 1 or 2 1713 // In simple mode, limit the columns to 1 or 2
1674 if(simpleMode == true) { 1714 if(simpleMode == true) {
1675 // If column 1 is bitmap and column 2 is text... 1715 // If column 1 is bitmap and column 2 is text...
1681 } 1721 }
1682 } 1722 }
1683 1723
1684 // If the view passed in is null we need to create the layout 1724 // If the view passed in is null we need to create the layout
1685 if(rowView == null) { 1725 if(rowView == null) {
1686 rowView = LinearLayout(context) 1726 rowView = DWContainerRow(context)
1687 rowView.orientation = LinearLayout.HORIZONTAL 1727 rowView.orientation = LinearLayout.HORIZONTAL
1688 1728
1689 for(i in 0 until displayColumns) { 1729 for(i in 0 until displayColumns) {
1690 val content = model.getRowAndColumn(position, i) 1730 val content = model.getRowAndColumn(position, i)
1691 1731
3955 } 3995 }
3956 cont!!.setOnItemClickListener { parent, view, position, id -> 3996 cont!!.setOnItemClickListener { parent, view, position, id ->
3957 val title = adapter.model.getRowTitle(position) 3997 val title = adapter.model.getRowTitle(position)
3958 val data = adapter.model.getRowData(position) 3998 val data = adapter.model.getRowData(position)
3959 val now = System.currentTimeMillis() 3999 val now = System.currentTimeMillis()
4000 val rowView: DWContainerRow = view as DWContainerRow
3960 4001
3961 view.isSelected = !view.isSelected 4002 view.isSelected = !view.isSelected
4003 rowView.isChecked = !rowView.isChecked
3962 adapter.selectedItem = position 4004 adapter.selectedItem = position
3963 lastClickView = cont!! 4005 lastClickView = cont!!
3964 // If we are single select or we got a double tap... 4006 // If we are single select or we got a double tap...
3965 // Generate an ENTER event 4007 // Generate an ENTER event
3966 if(cont!!.choiceMode != ListView.CHOICE_MODE_MULTIPLE || 4008 if(cont!!.choiceMode != ListView.CHOICE_MODE_MULTIPLE ||