comparison android/DWindows.kt @ 2777:7d7eac751f7d

Android: Connect the C API to the Kotlin tree implementation.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 22 Jun 2022 07:13:32 +0000
parents 858155527b05
children c28602443759
comparison
equal deleted inserted replaced
2776:858155527b05 2777:7d7eac751f7d
67 import java.util.zip.ZipFile 67 import java.util.zip.ZipFile
68 import kotlin.math.* 68 import kotlin.math.*
69 69
70 70
71 // Tree View section 71 // Tree View section
72 class DWTreeItem(value: Any, layoutId: Int) { 72 class DWTreeItem(title: String, icon: Drawable?, data: Long, parent: DWTreeItem?) {
73 private var value: Any 73 private var title: String
74 private var parent: DWTreeItem? 74 private var parent: DWTreeItem?
75 private val children: LinkedList<DWTreeItem> 75 private val children: LinkedList<DWTreeItem>
76 private val layoutId: Int
77 private var level: Int 76 private var level: Int
78 private var isExpanded: Boolean 77 private var isExpanded: Boolean
79 private var isSelected: Boolean 78 private var isSelected: Boolean
80 var itemData: Long = 0 79 private var data: Long = 0
81 var itemIcon: Drawable? = null 80 private var icon: Drawable? = null
82 var parentItem: DWTreeItem? = null
83 81
84 fun addChild(child: DWTreeItem) { 82 fun addChild(child: DWTreeItem) {
85 child.setParent(this) 83 child.setParent(this)
86 child.setLevel(level + 1) 84 child.setLevel(level + 1)
87 children.add(child) 85 children.add(child)
88 updateNodeChildrenDepth(child) 86 updateNodeChildrenDepth(child)
89 } 87 }
90 88
91 fun setValue(value: Any) { 89 fun setTitle(title: String) {
92 this.value = value 90 this.title = title
93 } 91 }
94 92
95 fun getValue(): Any { 93 fun getTitle(): String {
96 return value 94 return title
95 }
96
97 fun setIcon(icon: Drawable?) {
98 this.icon = icon
99 }
100
101 fun getIcon(): Drawable? {
102 return icon
103 }
104
105 fun setData(data: Long) {
106 this.data = data
107 }
108
109 fun getData(): Long {
110 return data
111 }
112
113 fun getParent(): DWTreeItem? {
114 return parent
97 } 115 }
98 116
99 fun setParent(parent: DWTreeItem?) { 117 fun setParent(parent: DWTreeItem?) {
100 this.parent = parent 118 this.parent = parent
101 } 119 }
102 120
103 fun getParent(): DWTreeItem? {
104 return parent
105 }
106
107 fun getChildren(): LinkedList<DWTreeItem> { 121 fun getChildren(): LinkedList<DWTreeItem> {
108 return children 122 return children
109 }
110
111 fun getLayoutId(): Int {
112 return layoutId
113 } 123 }
114 124
115 fun setLevel(level: Int) { 125 fun setLevel(level: Int) {
116 this.level = level 126 this.level = level
117 } 127 }
142 child.setLevel(node.getLevel() + 1) 152 child.setLevel(node.getLevel() + 1)
143 } 153 }
144 } 154 }
145 155
146 init { 156 init {
147 this.value = value 157 this.title = title
148 parent = null 158 this.icon = icon
159 this.data = data
160 this.parent = parent
149 children = LinkedList() 161 children = LinkedList()
150 this.layoutId = layoutId
151 level = 0 162 level = 0
152 isExpanded = false 163 isExpanded = false
153 isSelected = false 164 isSelected = false
154 } 165 }
155 } 166 }
167
156 class DWTreeItemManager { 168 class DWTreeItemManager {
157 // Collection to save the current tree nodes 169 // Collection to save the current tree nodes
158 private val rootsNodes: LinkedList<DWTreeItem> 170 private val rootsNodes: LinkedList<DWTreeItem>
159 171
160 // Get DWTreeItem from the current nodes by index 172 // Get DWTreeItem from the current nodes by index
455 true 467 true
456 } 468 }
457 } 469 }
458 470
459 override fun getItemViewType(position: Int): Int { 471 override fun getItemViewType(position: Int): Int {
460 return treeItemManager.get(position).getLayoutId() 472 // TODO: Fix this with no layoutId
473 return 0
461 } 474 }
462 475
463 override fun getItemCount(): Int { 476 override fun getItemCount(): Int {
464 return treeItemManager.size() 477 return treeItemManager.size()
465 } 478 }
526 // Update the list of tree nodes 539 // Update the list of tree nodes
527 // @param treeItems The new tree nodes 540 // @param treeItems The new tree nodes
528 fun updateTreeItems(treeItems: List<DWTreeItem>) { 541 fun updateTreeItems(treeItems: List<DWTreeItem>) {
529 treeItemManager.updateItems(treeItems) 542 treeItemManager.updateItems(treeItems)
530 notifyItemRangeInserted(0, treeItems.size) 543 notifyItemRangeInserted(0, treeItems.size)
544 }
545
546 // Clear all the items from the tree
547 fun clear() {
548 treeItemManager.clearItems()
531 } 549 }
532 550
533 // Register a callback to be invoked when this DWTreeItem is clicked 551 // Register a callback to be invoked when this DWTreeItem is clicked
534 // @param listener The callback that will run 552 // @param listener The callback that will run
535 fun setTreeItemClickListener(listener: OnTreeItemClickListener?) { 553 fun setTreeItemClickListener(listener: OnTreeItemClickListener?) {
4528 var treeitem: DWTreeItem? = null 4546 var treeitem: DWTreeItem? = null
4529 4547
4530 waitOnUiThread { 4548 waitOnUiThread {
4531 var treeViewAdapter = tree.adapter as DWTreeViewAdapter 4549 var treeViewAdapter = tree.adapter as DWTreeViewAdapter
4532 4550
4533 treeitem = DWTreeItem(title, 0) 4551 treeitem = DWTreeItem(title, icon, itemdata, parent)
4534 if(parent == null) { 4552 if(parent == null) {
4535 tree.roots.add(treeitem!!) 4553 tree.roots.add(treeitem!!)
4536 } else { 4554 } else {
4537 parent.addChild(treeitem!!) 4555 parent.addChild(treeitem!!)
4538 treeitem!!.parentItem = parent 4556 }
4539 }
4540 treeitem!!.itemData = itemdata
4541 treeitem!!.itemIcon = icon
4542 } 4557 }
4543 return treeitem 4558 return treeitem
4559 }
4560
4561 fun treeGetTitle(tree: DWTree, item: DWTreeItem): String?
4562 {
4563 var retval: String? = null
4564
4565 waitOnUiThread {
4566 retval = item.getTitle()
4567 }
4568 return retval
4569 }
4570
4571 fun treeGetParent(tree: DWTree, item: DWTreeItem): DWTreeItem?
4572 {
4573 var retval: DWTreeItem? = null
4574
4575 waitOnUiThread {
4576 retval = item.getParent()
4577 }
4578 return retval
4579 }
4580
4581 fun treeItemChange(tree: DWTree, item: DWTreeItem, title: String?, icon: Drawable?)
4582 {
4583 waitOnUiThread {
4584 if(title != null) {
4585 item.setTitle(title)
4586 }
4587 if(icon != null) {
4588 item.setIcon(icon)
4589 }
4590 }
4591 }
4592
4593 fun treeItemSetData(tree: DWTree, item: DWTreeItem, data: Long)
4594 {
4595 waitOnUiThread {
4596 item.setData(data)
4597 }
4598 }
4599
4600 fun treeItemGetData(tree: DWTree, item: DWTreeItem): Long
4601 {
4602 var retval: Long = 0
4603
4604 waitOnUiThread {
4605 retval = item.getData()
4606 }
4607 return retval
4608 }
4609
4610 fun treeItemSelect(tree: DWTree, item: DWTreeItem)
4611 {
4612 waitOnUiThread {
4613 item.setSelected(true)
4614 }
4615 }
4616
4617 fun treeItemExpand(tree: DWTree, item: DWTreeItem, state: Int)
4618 {
4619 waitOnUiThread {
4620 val treeViewAdapter = tree.adapter as DWTreeViewAdapter
4621
4622 if(state != 0) {
4623 treeViewAdapter.expandNode(item)
4624 } else {
4625 treeViewAdapter.collapseNode(item)
4626 }
4627 }
4628 }
4629
4630 fun treeItemDelete(tree: DWTree, item: DWTreeItem)
4631 {
4632 // TODO: Implement this
4633 }
4634
4635 fun treeClear(tree: DWTree)
4636 {
4637 waitOnUiThread {
4638 val treeViewAdapter = tree.adapter as DWTreeViewAdapter
4639 treeViewAdapter.clear()
4640 }
4544 } 4641 }
4545 4642
4546 fun containerNew(cid: Int, multi: Int): ListView? 4643 fun containerNew(cid: Int, multi: Int): ListView?
4547 { 4644 {
4548 var cont: ListView? = null 4645 var cont: ListView? = null