'#Event: ItemClicked(Index As Int, Value As Object)
#DesignerProperty: Key: OpenId, DisplayName: ID to show, FieldType: Int, DefaultValue: 0, Description: ID of Parent and Child ID to be shown.
#DesignerProperty: Key: TitleHeight, DisplayName: Title Text Height, FieldType: Int, DefaultValue: 20, Description: Textheight of the Title.
#DesignerProperty: Key: IntendWidth, DisplayName: Intend Width, FieldType: Int, DefaultValue: 50, Description: Width of the Child intend form the left.
#DesignerProperty: Key: ParentTextSize, DisplayName: Parent Text Height, FieldType: Int, DefaultValue: 18, Description: Textheight of the Menuparent (Branch).
#DesignerProperty: Key: ChildTextSize, DisplayName: Child Text Height, FieldType: Int, DefaultValue: 14, Description: Textheight of the Child (Leaf).
#DesignerProperty: Key: BackgroundColor, DisplayName: Background color, FieldType: color, DefaultValue:0xFFFFFFFF, Description: Controls Background color.
#DesignerProperty: Key: TitelBackgroundColor, DisplayName: Titel Background color, FieldType: color, DefaultValue:0xFFFFFFFF, Description: Title Background color.
#DesignerProperty: Key: TitelTextColor, DisplayName: Titel Text color, FieldType: color, DefaultValue:0xFF000000, Description: Title Text color.
#DesignerProperty: Key: ParentTextColor, DisplayName: Parent Text Color, FieldType: color, DefaultValue: 0xFF000000, Description: Textcolor of the Parent.
#DesignerProperty: Key: ChildTextColor, DisplayName: Child Text Color, FieldType: color, DefaultValue: 0xFF000000, Description: Textcolor of the Parent.
#DesignerProperty: Key: ParentColor, DisplayName: Parent Background Color, FieldType: color, DefaultValue: 0xFFFFFFFF, Description: Backgroundcolor of the Parent Panel.
#DesignerProperty: Key: ChildColor, DisplayName: Child Background Color, FieldType: color, DefaultValue: 0xFFFFFFFF, Description: Backgroundcolor of the Child Panel.
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Public Tag As Object
'Public Scv As ScrollView
Type TMI ( _
ID As Int, _
ParentID As Int, _
BM As Bitmap, _
Txt As String, _
Show As Boolean, _
HasChildren As Boolean)
Private clv As CustomListView
Public ItemList As List
Private props1 As Map
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
'Scv.Initialize(100dip)
clv.Initialize(mCallBack,"clv")
ItemList.Initialize
props1.Initialize
End Sub
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, props As Map)
mBase = Base
Tag = mBase.Tag
mBase.Tag = Me
props1 = props
' set parameters
'clv.Width=mBase.Width
'clv.height= mBase.height
mBase.AddView(clv.AsView,0,0,mBase.Width,mBase.Height)
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
End Sub
' # build the panel for one item
Sub buildItem(item As TMI) As Panel
Try
Dim t As Label ' Branch label
t.Initialize("MenuItemClicked")
t.Text = item.txt
If item.ParentID = 0 Then
t.Textcolor = props1.Get("ParentTextColor")
t.TextSize = props1.Get("ParentTextSize")
t.Typeface = Typeface.DEFAULT_BOLD
Else
t.Textcolor = props1.Get("ChildTextColor")
t.TextSize = props1.Get("ChildTextSize")
End If
t.Height = t.TextSize + 10
If item.ParentID <> 0 Then t.Tag = item.parentid
Dim ind As Label ' Intend
ind.Initialize("MenuItemClicked")
ind.Width = props1.Get("IntendWidth")
ind.Height = t.height
If item.ParentID <> 0 Then ind.tag = item.parentid
Dim i As ImageView ' Branch Image
i.Initialize("MenuItemClicked")
i.Height = t.Height
i.Width = i.Height
If item.ParentID <> 0 Then i.Tag=item.parentid
If item.bm.isinitialized Then i.Bitmap=item.bm
' stretch label to full width
t.Width =clv.asview.Width -10 - i.Width -10 -10
Dim p As Panel ' Main Branchpanel
p.Initialize("p")
p.RemoveAllViews
p.Height = t.height
If item.ParentID <> 0 Then p.Tag = item.parentid
If p.Height < i.Height Then p.Height=i.height
If p.Height < t.Height Then p.Height=t.height
If item.ParentID=0 Then
p.Color = props1.Get("ParentColor")
Else
p.Color = props1.Get("ChildColor")
End If
' add views to the panel
If item.ParentID = 0 Then
p.addview(i,10,0,i.Width,i.Height)
p.AddView(t,10 + i.Width + 10,0,t.Width,t.height)
p.Width = 10 + i.Width + 10 + t.width
Else
p.addview(ind,10,0,ind.width,ind.height)
p.addview(i,10 + ind.Width +10,0,i.Width,i.Height)
p.AddView(t,10 + ind.width + 10 + i.Width +10,0,t.Width,t.height)
p.Width = 10 + ind.Width + 10 + i.Width+10+t.width
End If
' return panel as tree row
Return p
Catch
xui.Msgbox2Async(LastException,"Error FTM1","OK","","",Null)
Return Null
End Try
End Sub
' # add the items to the customlistview
public Sub buildTree
Try
Dim item As TMI
Dim p As Panel
p.Initialize("p")
clv.clear
For x = 0 To ItemList.Size-1
item = ItemList.Get(x)
'Log("V" & r & " " & item.Txt & " " & Scv.height)
p = buildItem(item)
'Scv.Panel.AddView(p,0,r,p.Width,p.Height)
If item.Show = True Then clv.Add(p,p.Height,item.id)
Next
Catch
xui.Msgbox2Async(LastException,"Error FTM2","OK","","",Null)
End Try
End Sub
' # listview item click event
Sub clv_ItemClick (Index As Int, Value As Object)
Try
Log(Sender)
' Get the menu item via ID = Value
Dim p As Panel = clv.GetPanel(Index).GetView(0)
Dim item As TMI
item = ItemList.Get(Value)
If item.HasChildren = False Then ' single Branch or child
Select Case Value
Case 1
' action
End Select
Else
' Toggle show/hide
For x = 0 To ItemList.Size-1
item = ItemList.Get(x)
If item.ID = Value Or item.ParentID = Value Then
item.Show = Not(item.show) ' switch
ItemList.Set(x,item) ' change the value
End If
Next
' rebuild the tree
buildTree
End If
Catch
xui.Msgbox2Async(LastException,"Error FTM3","OK","","",Null)
End Try
End Sub
'Private Sub Xclv_ItemClick(Index As Int, Value As Object)
' If SubExists(mCallBack, mEventName & "_ItemClick") Then
' 'raise the Click event , passing selected parameters
' CallSub3(mCallBack, mEventName & "_ItemClick", Index, Value)
' End If
'End Sub