' In the Class Global added these and modify some
Public DefaultTextColor As Int = xui.Color_Black
Public DefaultTextBackgroundColor As Int = xui.Color_White
Public DefaultFontSize As Int = 14
Private itemList As List
' in The Class Create initialise that list
Public Sub Initialize (vCallBack As Object, vEventName As String)
itemList.initialize
' and some other stuff before or after the initialize
End Sub
Public Sub AddTextItem(Text As Object, Value As Object, Alignment As Object,Autosize As Boolean)
InsertAtTextItem(items.Size, Text, Value, Alignment,Autosize)
End Sub
' Inserts a text item at the specified index.
' NOTE added alignment in the format "VERTICAL,HORIZONTAL"
Public Sub InsertAtTextItem(Index As Int, Text As Object, Value As Object, Alignment As Object,Autosize As Boolean)
Dim align() As String
Dim lblGravity(2) As Int
If Alignment = "" Or Alignment = Null Then
lblGravity(0) = Gravity.NO_GRAVITY ' that can be changed to CENTER_VERTICAL
lblGravity(1) = Gravity.NO_GRAVITY ' that can be changed to CENTER_HORIZONTAL
Else
align = Regex.Split(",",Alignment)
End If
' this is the default value if set as "Default,Default"
If align(0).ToLowerCase = "default" Then lblGravity(0) = Gravity.CENTER_VERTICAL
If align(1).ToLowerCase = "default" Then lblGravity(1) = Gravity.LEFT
For i = 0 To 1
Select Case align(i)
Case "TOP" : lblGravity(i) = Gravity.TOP : Exit
Case "LEFT" : lblGravity(i) = Gravity.LEFT : Exit
Case "RIGHT" : lblGravity(i) = Gravity.RIGHT : Exit
Case "CENTER" : lblGravity(i) = Gravity.CENTER : Exit
Case "CENTER_HORIZONTAL" : lblGravity(i) = Gravity.CENTER_HORIZONTAL : Exit
Case "CENTER_VERTICAL" : lblGravity(i) = Gravity.CENTER_VERTICAL : Exit
Case "BOTTOM" : lblGravity(i) = Gravity.BOTTOM : Exit
Case "FILL" : lblGravity(i) = Gravity.FILL : Exit
End Select
Next
If horizontal Then
Log("AddTextItem is only supported in vertical orientation.")
Return
End If
Dim pnl As B4XView = CreatePanel("")
#if B4A
Dim lbl As Label = CreateLabel("")
#else if B4I
' i'm not shure what to put here
#else if B4J
' neither here
#end if
lbl.Height = Max(50dip, lbl.Height)
lbl.Width = sv.ScrollViewContentWidth -10dip
lbl.TextSize = DefaultFontSize
lbl.Text = Text
'If Autosize Then ' can only be changed after it insertion in panel
' lbl.Height=-2 ' and is currently not used
' lbl.Width=-2 ' cause this only works with B4XView i think
' End If
#if B4J
lbl.SetTextAlignment(lblGravity(0),lblGravity(1))
#else if B4A
lbl.Gravity = Bit.Or(lblGravity(1), lblGravity(0))
#end if
' set the text gravity based on Alignment string
' 0 is vertical 1 is Horizontal for lblGravity()
pnl.AddView(lbl, 5dip, 2dip, sv.ScrollViewContentWidth - 10dip, lbl.Height)
If xui.IsB4i = False Then
lbl.TextColor = DefaultTextColor
End If
itemList.Add(lbl)
' Modified to add alignment of label just created that is inserted in panel
pnl.Color = DefaultTextBackgroundColor
pnl.Height = lbl.Height + 2dip
InsertAt(Index, pnl, Value)
Dim item As CLVItem = GetRawListItem(Index)
item.TextItem = True
End Sub
' Only used with addTextItem only
' this is used to retreive a specific item in the list by it's index
' and change values directly to the selected label in the list
Public Sub getItemFromList(Index As Int) As Label
' extract the label value from the list
If Index > itemList.Size-1 Then
Return itemList.Get((itemList.Size-1))
Else
Return itemList.Get(Index)
End If
End Sub
' Here are some code to setup the values of each textItem inside the Main activity
' the cs setup was use before so i let it there if needed.
If oPos.nodeType="F" Then ' This for me is a title no link centered
cs.Initialize.Size(20).Typeface(Typeface.CreateNew(Typeface.FONTAWESOME,Typeface.STYLE_NORMAL)).Color(convertGreenColor(oPos.Color)).Alignment("ALIGN_CENTER").Append(oPos.Texte.Replace("2014","2020")).popall
TableView1.DefaultTextColor = convertGreenColor(oPos.Color)
TableView1.DefaultTextBackgroundColor = Colors.White
TableView1.DefaultFontSize = 20 ' this is new
TableView1.AsView.Width=-2
TableView1.AsView.Height=-2
TableView1.AddTextItem(oPos.Texte, oPos.Link,"CENTER_VERTICAL,CENTER_HORIZONTAL",True)
else if oPos.nodeType = "D" Then ' this for me is a link document
cs.Initialize.Size(18).Typeface(Typeface.CreateNew(Typeface.FONTAWESOME,Typeface.STYLE_NORMAL)).Color(convertGreenColor(oPos.Color)).Alignment("ALIGN_LEFT").Append(" " & Chr(0xF03C) & " " & oPos.Texte).popall
TableView1.DefaultTextColor = convertGreenColor(oPos.Color)
TableView1.DefaultTextBackgroundColor = Colors.White
TableView1.DefaultFontSize = 20
TableView1.AsView.Width=-2
TableView1.AsView.Height=-2
TableView1.AddTextItem(" " & Chr(0xF03C) & " " & oPos.Texte, oPos.Link,"TOP,LEFT",True)
End If
' NOTE the new itemList as list that keep track of each individual item in the list defined in the Class Global
' also modify the clear method to clear all the items from the list
'Clears all items.
Public Sub Clear
items.Clear
itemList.Clear ' this clear the items in list but do not reinitialize the list
sv.ScrollViewInnerPanel.RemoveAllViews
SetScrollViewContentSize(0)
ResetVisibles
End Sub