Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, ItemHeight2 As Int, Value As Object, blnMenu As Boolean, blnSelection As Boolean, SelectionColor As String)
'add click pressed for selection type
If blnSelection = True Then
Dim sd As StateListDrawable
sd.Initialize
'User color
If SelectionColor = "" Then
sd.AddState(sd.State_Pressed, pressedDrawable)
Else
Dim cdColor As ColorDrawable
cdColor.Initialize(SelectionColor, 0)
sd.AddState(sd.State_Pressed, cdColor)
End If
sd.AddCatchAllState(Pnl.Background)
End If
'create another panel to handle the click event
Dim p As Panel
Dim cd As ColorDrawable
'highlight type
If blnSelection = True Then
p.Initialize("panel") 'click sound and event
p.Background = sd
cd.Initialize(Colors.Transparent, 0)
'no highlight
Else
p.Initialize("") 'no click sound
If blnMenu = True Then
cd.Initialize(DefaultTextBackgroundMenuColor, 0)
Else
cd.Initialize(DefaultTextBackgroundColor, 0)
End If
End If
Pnl.Background = cd
'ripple effect
If blnSelection = True Then
Dim AC As AppCompat
AC.SetClickEffect(Pnl, False)
End If
p.AddView(Pnl, 0, 0, sv.Width, ItemHeight + ItemHeight2)
p.Tag = Index
If blnMenu = True Then
If blnDividerColorMargin = True Then
p.Elevation = 0
Else
p.Elevation = 25
End If
End If
'LAST PANEL
If Index = items.Size Then
items.Add(Value)
panels.Add(p)
Dim Top As Int
If Index = 0 Then
Top = DefaultDividerHeight
Else
Top = sv.Panel.Height
End If
sv.Panel.AddView(p, 0, Top, sv.Width, ItemHeight + ItemHeight2)
'ANY PANELS BEFORE LAST
Else
Dim Top As Int
If Index = 0 Then
Top = DefaultDividerHeight
Else
Dim previousPanel As Panel
previousPanel = panels.Get(Index - 1)
Top = previousPanel.Top + previousPanel.Height + DefaultDividerHeight
End If
Dim p2 As Panel
For i = Index To panels.Size - 1
p2 = panels.Get(i)
p2.Top = p2.Top + ItemHeight + ItemHeight2 + DefaultDividerHeight
p2.Tag = i + 1
Next
items.InsertAt(Index, Value)
panels.InsertAt(Index, p)
sv.Panel.AddView(p, 0, Top, sv.Width, ItemHeight + ItemHeight2)
End If
sv.Panel.Height = sv.Panel.Height + ItemHeight + ItemHeight2 + DefaultDividerHeight
If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + DefaultDividerHeight
If sv.Panel.Height < sv.Height Then
InsertMaskPanel(items.Size, "*Mask*")
End If
End Sub