Using this class you can build CharSequences (the output of CSBuilder) and save the information required to build those styled strings. This allows to later load the information and create the same CharSequences.
1. Create a class named PCSBuilder (Persistent CSBuilder):
Usage example:
Save and load bytes: [B4X] Bytes To File
Or use KVS2.
The class is not complete. You should add the other methods as well.
1. Create a class named PCSBuilder (Persistent CSBuilder):
B4X:
Sub Class_Globals
Private cs As CSBuilder
Private data As List
Private ser As B4XSerializator
End Sub
Public Sub Initialize As PCSBuilder
cs.Initialize
data.Initialize
If False Then
'to avoid obfuscation issues.
CallSub(Me, "Color")
CallSub(Me, "Append")
CallSub(Me, "Pop")
CallSub(Me, "PopAll")
End If
Return Me
End Sub
Public Sub FromBytes(b() As Byte) As PCSBuilder
Dim list As List = ser.ConvertBytesToObject(b)
For Each o() As Object In list
If o.Length = 1 Then
CallSub(Me, o(0))
Else
CallSub2(Me, o(0), o(1))
End If
Next
Return Me
End Sub
Public Sub ToBytes As Byte()
Return ser.ConvertObjectToBytes(data)
End Sub
Public Sub Color (clr As Int) As PCSBuilder
cs.Color(clr)
data.Add(Array("color", clr))
Return Me
End Sub
Public Sub Append (Text As Object) As PCSBuilder
cs.Append(Text)
data.Add(Array("append", Text))
Return Me
End Sub
Public Sub Pop As PCSBuilder
cs.Pop
data.Add(Array("pop"))
Return Me
End Sub
Public Sub PopAll As PCSBuilder
cs.PopAll
data.Add(Array("popall"))
Return Me
End Sub
Public Sub ToCharSequence As Object
Return cs
End Sub
Usage example:
B4X:
Dim p As PCSBuilder
Activity.Title = p.Initialize.Append("hello ").Color(Colors.Red).Append("world").PopAll.ToCharSequence
Dim b() As Byte = p.ToBytes
Label.Text = p.Initialize.FromBytes(b).ToCharSequence
Save and load bytes: [B4X] Bytes To File
Or use KVS2.
The class is not complete. You should add the other methods as well.