Sub Process_Globals
End Sub
Sub Globals
Dim ClickableLabel As Label
Dim LabelExtras1 As LabelExtras
Dim LogLabel As Label
Dim Html1 As Html
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
' Dim the objects from the LabelExtras library
Dim LinkMovementMethod1 As LinkMovementMethod
Dim SpannableStringBuilder1 As SpannableStringBuilder
Dim StyleSpans() As StyleSpan
' this is the String which contains HTML elements that we want to make clickable
' note that the Html FromHtml method parses the String as HTML so if you try to use the CRLF constant in this String it will not create a new line, instead the HTML <br> element can be used
Dim HtmlString As String="<b>Any</b> text that you want to detect <b><i>clicks</i></b> on must be within an <spans>HTML</span> <b>BOLD</b> element, the <u>StyleSpanClick</u> event is passed SelectionStart and SelectionEnd parameters.<br><br>Click <b>HERE</b> to <myTag>continue</myTag>.<br><br>bogus_filename.png does not exist <img src='bogus_filename.png' /><br><br>What is a question <img src='question-mark.gif' /><br><br>This is a <tag>tag</tag> <img src='tag.png' />"
' test the new FromHtml2 method
SpannableStringBuilder1.Initialize(Html1.FromHtml2(HtmlString, "ImageGetter", "TagHandler"))
StyleSpans=SpannableStringBuilder1.GetStyleSpans(0, SpannableStringBuilder1.Length)
For Each StyleSpan1 As StyleSpan In StyleSpans
If StyleSpan1.GetStyle=Typeface.STYLE_BOLD Then
Dim SpanStart As Int=SpannableStringBuilder1.GetSpanStart(StyleSpan1)
Dim SpanEnd As Int=SpannableStringBuilder1.GetSpanEnd(StyleSpan1)
Dim SpanFlags As Int=SpannableStringBuilder1.GetSpanFlags(StyleSpan1)
Dim ClickableSpan1 As ClickableSpan
ClickableSpan1.Initialize("ClickableSpan1", Colors.Red, False)
SpannableStringBuilder1.SetSpan(ClickableSpan1, SpanStart, SpanEnd, SpanFlags)
End If
Next
ClickableLabel.Text=SpannableStringBuilder1
LabelExtras1.SetMovementMethod(ClickableLabel, LinkMovementMethod1.GetInstance)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ClickableSpan1_Click(SelectionStart As Int, SelectionEnd As Int)
Dim LogText As StringBuilder
LogText.Initialize
LogText.Append("ClickableSpan1_Click: "&DateTime.Now&CRLF)
LogText.Append("SelectionStart="&SelectionStart&CRLF)
LogText.Append("SelectionEnd="&SelectionEnd&CRLF)
Dim SelectedText As String=ClickableLabel.Text.SubString2(SelectionStart, SelectionEnd)
LogText.Append("Selected (clicked) text='"&SelectedText&"'")
LogLabel.Text=LogText.ToString
If SelectedText="HERE" Then
StartActivity(ActivityTwo)
End If
End Sub
Sub ImageGetter_GetDrawable(Source As String) As Object
Log("ImageGetter1_GetDrawable: "&Source)
If File.Exists(File.DirAssets, Source) Then
Dim Bitmap1 As Bitmap
Bitmap1=LoadBitmap(File.DirAssets, Source)
Dim BitmapDrawable1 As BitmapDrawable
BitmapDrawable1.Initialize(Bitmap1)
' LabelExtras Object now contains a SetDrawableBounds helper method to enable setting of a Drawable Bounds
LabelExtras1.SetDrawableBounds(BitmapDrawable1, 0, 0, Bitmap1.Width, Bitmap1.Height)
Return BitmapDrawable1
Else
' the default placeholder image will be used if Null is returned by this Sub
Return Null
End If
End Sub
Sub TagHandler_HandleTag(Opening As Boolean, Tag As String, SpannableStringBuilder1 As SpannableStringBuilder)
Log("TagHandler_HandleTag: "&Opening&", "&Tag)
' i've made unknown HTML tags into BB type tags
If Opening Then
SpannableStringBuilder1.Append("[").Append(Tag).Append("]")
Else
SpannableStringBuilder1.Append("[/").Append(Tag).Append("]")
End If
End Sub