Since Erel posted the really useful snippet "CSBuilder with leading margin" I've got curious if there were more styles possible to use with Erel's method.
As the "android.text.style.LeadingMarginSpan.Standard" is well documented on developer.android.com I looked for a quote-solution and found the "QuoteSpan" style.
But my attempt to imitate the wrapped SpannableStringBuilder
led to a RuntimeException:
As it seems, my modest quarter-knowledge how JAVA and Android works under the hood is not enough to find a solution myself.
So what would be the right way to add "QuoteSpan" or "BulletSpan" to CSBuilder textstyle?
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
Sleep(0)
Dim cs As CSBuilder
cs.Initialize
CallSub3(Me, "AddLeadingMarginSpan", cs, Array As Int(0dip, 30dip))
cs.Append("1) First do text text text, text text text text text text text").PopAll
CallSub3(Me, "AddLeadingMarginSpan", cs, Array As Int(0dip, 30dip))
cs.Append(CRLF).Append("2) Second do text text text, text text text text text text text").PopAll
Label1.Text = cs
End Sub
Sub AddLeadingMarginSpan(cs As Object, FirstAndRest() As Int)
Dim span As JavaObject
span.InitializeNewInstance("android.text.style.LeadingMarginSpan.Standard", Array(FirstAndRest(0), FirstAndRest(1)))
Dim jo As JavaObject = cs
jo.RunMethod("open", Array(span))
End Sub
As the "android.text.style.LeadingMarginSpan.Standard" is well documented on developer.android.com I looked for a quote-solution and found the "QuoteSpan" style.
But my attempt to imitate the wrapped SpannableStringBuilder
B4X:
...
CallSub3(Me, "AddQuoteSpan", cs, Array As Int(Colors.Green, 20dip, 40dip))
cs.Append(CRLF).Append("Quote:").Append(CRLF).Append("Second do text text text, text text text text text text text").PopAll
...
Sub AddQuoteSpan(cs As Object, intColorGapwidthStripewidth() As Int)
Dim span As JavaObject
'
' --------------- --------------- --------------- ---------------
'Not working:
span.InitializeNewInstance("android.text.style.QuoteSpan", Array(intColorGapwidthStripewidth(0), intColorGapwidthStripewidth(1), intColorGapwidthStripewidth(2)))
' --------------- --------------- --------------- ---------------
'
Dim jo As JavaObject = cs
jo.RunMethod("open", Array(span))
End Sub
led to a RuntimeException:
~e:java.lang.RuntimeException: Constructor not found.
~e: at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
As it seems, my modest quarter-knowledge how JAVA and Android works under the hood is not enough to find a solution myself.
So what would be the right way to add "QuoteSpan" or "BulletSpan" to CSBuilder textstyle?