Mercurial > dwindows
changeset 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 |
files | android/DWindows.kt |
diffstat | 1 files changed, 44 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/android/DWindows.kt Tue Dec 28 13:53:59 2021 +0000 +++ b/android/DWindows.kt Fri Dec 31 23:21:44 2021 +0000 @@ -71,6 +71,12 @@ import android.graphics.pdf.PdfDocument import android.print.* import android.print.pdf.PrintedPdfDocument +import android.widget.Checkable + +import android.widget.LinearLayout + + + // Color Wheel section @@ -1641,6 +1647,40 @@ } } +class DWContainerRow : LinearLayout, Checkable { + private var mChecked = false + + constructor(context: Context?) : super(context) {} + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} + constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {} + + override fun setChecked(b: Boolean) { + mChecked = b + refreshDrawableState() + } + + override fun isChecked(): Boolean { + return mChecked + } + + override fun toggle() { + mChecked = !mChecked + refreshDrawableState() + } + + override fun onCreateDrawableState(extraSpace: Int): IntArray { + val states = super.onCreateDrawableState(extraSpace + 1) + if (mChecked) { + mergeDrawableStates(states, CHECKED_STATE) + } + return states + } + + companion object { + val CHECKED_STATE = intArrayOf(R.attr.state_checked) + } +} + class DWContainerAdapter(c: Context) : BaseAdapter() { private var context = c @@ -1667,7 +1707,7 @@ } override fun getView(position: Int, view: View?, parent: ViewGroup): View { - var rowView: LinearLayout? = view as LinearLayout? + var rowView: DWContainerRow? = view as DWContainerRow? var displayColumns = model.numberOfColumns() // In simple mode, limit the columns to 1 or 2 @@ -1683,7 +1723,7 @@ // If the view passed in is null we need to create the layout if(rowView == null) { - rowView = LinearLayout(context) + rowView = DWContainerRow(context) rowView.orientation = LinearLayout.HORIZONTAL for(i in 0 until displayColumns) { @@ -3957,8 +3997,10 @@ val title = adapter.model.getRowTitle(position) val data = adapter.model.getRowData(position) val now = System.currentTimeMillis() + val rowView: DWContainerRow = view as DWContainerRow view.isSelected = !view.isSelected + rowView.isChecked = !rowView.isChecked adapter.selectedItem = position lastClickView = cont!! // If we are single select or we got a double tap...