B4A Library Linker

A wrap for this https://github.com/Gaineyj0349/Linker ( not fully tested)


linker.png

Linker
Author:
SMM
Version: 0.01
  • Linker
    Events:
    • _onlinkclick (charSequenceClicked as String As )
    Methods:
    • update As void
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, EventName As java.lang.String, tv As android.widget.TextView) As void
    • clearLinksList As void
    • addStrings (list As anywheresoftware.b4a.objects.collections.List) As void
    • addProfiles (plist As anywheresoftware.b4a.objects.collections.List) As void
    • setLinkColorForCharSequence (charSequenceIn As java.lang.String, color As int) As void
    • setUnderlineModeForCharSequence (charSequenceIn As java.lang.String, whether As boolean) As void
    Properties:
    • AllLinkUnderline As boolean [write only]
    • Profiles As anywheresoftware.b4a.objects.collections.List [read only]
    • AllLinkColors As int [write only]
  • LinkProfile
    Methods:
    • isUnderlineMode As boolean
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, charSequence As java.lang.String, linkColor As int, underlineMode As boolean) As void
    Properties:
    • UnderlineMode As boolean [write only]
    • LinkColor As int
  • SpanLocation
    Methods:
    • IsInitialized As boolean
    • Initialize (ba As anywheresoftware.b4a.BA, startIndex As int, endIndex As int) As void
    Properties:
    • startIndex As int
    • EndIndex As int


Sample

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim linker As Linker
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim tv As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    tv.Initialize("tv")
    Activity.AddView(tv,0,0,100%x,100%y)
    tv.Text= "This is a text for test purpose only , you can't use it in commercial projects without permission"
    linker.Initialize("linker",tv)
    linker.addStrings(Array As String("only","permission"))
    Dim prof As LinkProfile
    prof.Initialize("purpose",Colors.Red,False)
    linker.addProfiles(Array As LinkProfile(prof))
    linker.update
End Sub
Sub linker_onlinkclick(clicked As String)
    Log(clicked&" was clicked")
End Sub
 

Attachments

  • linker.zip
    27.4 KB · Views: 212

MarcoRome

Expert
Licensed User
Longtime User
Hi @somed3v3loper and thank you for this library.
But why this new library if in CSBuilder you have already this:


B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Dim cs As CSBuilder
   cs.Initialize.Size(30).Append("Some ").Append(CreateClickableWord("words"))
   cs.Append(" are ").Append(CreateClickableWord("clickable")).Append(".").PopAll
   Label1.Text = cs
   cs.EnableClickEvents(Label1)
End Sub

Sub CreateClickableWord(Text As String) As CSBuilder
   Dim cs As CSBuilder
   Return cs.Initialize.Underline.Color(0xFF00D0FF).Clickable("word", Text).Append(Text).PopAll
End Sub

Sub Word_Click (Tag As Object)
   Log($"You have clicked on word: ${Tag}"$)
End Sub
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
Hi @somed3v3loper and thank you for this library.
But why this new library if in CSBuilder you have already this:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("1")
   Dim cs As CSBuilder
   cs.Initialize.Size(30).Append("Some ").Append(CreateClickableWord("words"))
   cs.Append(" are ").Append(CreateClickableWord("clickable")).Append(".").PopAll
   Label1.Text = cs
   cs.EnableClickEvents(Label1)
End Sub

Sub CreateClickableWord(Text As String) As CSBuilder
   Dim cs As CSBuilder
   Return cs.Initialize.Underline.Color(0xFF00D0FF).Clickable("word", Text).Append(Text).PopAll
End Sub

Sub Word_Click (Tag As Object)
   Log($"You have clicked on word: ${Tag}"$)
End Sub
I don't know :D
 

jimmyF

Active Member
Licensed User
Longtime User
I may well be missing something here but I believe the difference is that this new library can handle existing text and does not need to create it.
 
Top