Android Question replace text in label with b4xgifview

Addo

Well-Known Member
Licensed User
I am planning to use xclv as a chatbox with supporting of animated gifs in it like animated smilyes ..


i have followed this tutorial that posted previously by using regex and csbuilder



B4X:
Sub ReplaceSmilies(s As String) As CSBuilder
   
    Dim baseSmiley() As String
   
    baseSmiley = smileysStringarray

   
    Dim rb As RegexBuilder
    rb.Initialize
    For Each smiley As String In baseSmiley
        If rb.Pattern <> "" Then rb.AppendOr
        rb.StartNonCapture.AppendEscaped(smiley).EndNonCapture
    Next
    Return MarkPattern(s, rb.Pattern, 0)
End Sub

Sub MarkPattern(Input As String, Pattern As String, GroupNumber As Int) As CSBuilder
    Dim cs As CSBuilder
    cs.Initialize

    Dim lastMatchEnd As Int = 0
    Dim m As Matcher = Regex.Matcher(Pattern, Input)
    Do While m.Find
        Dim currentStart As Int = m.GetStart(GroupNumber)
        cs.Append(Input.SubString2(lastMatchEnd, currentStart))
        lastMatchEnd = m.GetEnd(GroupNumber)
        'apply styling here
        Log(m.Group(GroupNumber))
        Dim smgif As b4xgifview
       
        smgif.Initialize(Me,"")
        smgif.DesignerCreateView(Activity,Null,Null) ' not sure in that case what i have to create as a base
        smgif.SetGif(File.DirAssets, 1.gif")
       
        cs.Image(smgif, 30dip, 30dip, True)

    Loop
    If lastMatchEnd < Input.Length Then cs.Append(Input.SubString(lastMatchEnd))
    Return cs
End Sub


the thing is cs.Image(smgif, 30dip, 30dip, True) accepts only bitmaps in the parameter can i do any workaround to add the b4xgifview

also since those smilyes are diffrent Gifs based on user text input i am not sure what should i place during creatingdesignerview in b4xgifview
 
Last edited:
Solution

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 1
Solution

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Addo

Well-Known Member
Licensed User
Thank you Erel, i got the part of adding the view but still the struggle in my brain is now using csbuilder or BBCodeView i am lost in this part since i am trying to use b4xgifview within the label to replace the smile operator with the gifview its looks like my question is stupid but can i find any example that use b4xgifview to achieve the same goal maybe its easier than i think
 
Upvote 0

Addo

Well-Known Member
Licensed User
hey Erel i tried to use code view and impacted into an error

B4X:
Service started in the background. Trying to start again in foreground mode.
*** Service (starter) Create ***
** Service (starter) Start **
Service started in foreground mode.
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
bbcodeparser_vvvvvvvvvvvv4 (java line: 921)
java.lang.ClassCastException: b4a.example.b4xgifview cannot be cast to android.view.View
    at b4a.example.bbcodeparser._vvvvvvvvvvvv4(bbcodeparser.java:921)
    at b4a.example.bbcodeparser._vvvvvvvvvv5(bbcodeparser.java:142)
    at b4a.example.bbcodeview._vvvvvvvvvvvvvv6(bbcodeview.java:487)
    at b4a.example.bbcodeview._setvvvvvvvvvvvvvvv3(bbcodeview.java:542)
    at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:421)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1773)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8387)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

here is my code

B4X:
Dim firsgif As b4xgifview

Private Sub CreateGif(GLeft As Int, GTop As Int, Gwidth As Int, Gheight As Int) As b4xgifview
 
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0, 0, 0, 102dip, 102dip)
    pnl.LoadLayout("smileLayout")
    SmileGifView.mBase.Left = GLeft
    SmileGifView.mBase.Top = GTop
    SmileGifView.mBase.Width = Gwidth
    SmileGifView.mBase.Height = Gheight
 
    Return SmileGifView
End Sub


Usage

B4X:
Dim firsgif As b4xgifview

firsgif = CreateGif(0, 0, DipToCurrent(30), DipToCurrent(30))
firsgif.SetGif(File.DirAssets, "1.gif")
BBCodeView1.Views.Put("1", firsgif)

BBCodeView1.text = "Hi [View="1" Vertical=10/], This is a test [View="1" Vertical=10/]"
 
Last edited:
Upvote 0

Addo

Well-Known Member
Licensed User
Solved by adding

B4X:
BBCodeView1.Views.Put("1", firsgif.mBase)

but i have encountered in a different error why when there is 2 similar gifviews in the bbCodeview it raises this error

B4X:
** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
bbcodeparser_vvvvvvvvvvvv4 (java line: 921)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    at android.view.ViewGroup.addViewInner(ViewGroup.java:5327)
    at android.view.ViewGroup.addView(ViewGroup.java:5156)
    at android.view.ViewGroup.addView(ViewGroup.java:5128)
    at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
    at anywheresoftware.b4a.objects.B4XViewWrapper.AddView(B4XViewWrapper.java:326)
    at b4a.example.bbcodeparser._vvvvvvvvvvvv4(bbcodeparser.java:921)
    at b4a.example.bbcodeparser._vvvvvvvvvv5(bbcodeparser.java:142)
    at b4a.example.bbcodeview._vvvvvvvvvvvvvv6(bbcodeview.java:487)
    at b4a.example.bbcodeview._setvvvvvvvvvvvvvvv3(bbcodeview.java:542)
    at b4a.example.main$ResumableSub_Activity_Create.resume(main.java:418)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1773)
    at android.os.Handler.handleCallback(Handler.java:900)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:219)
    at android.app.ActivityThread.main(ActivityThread.java:8387)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1055)

Also BBCodeView Does not Support RTL language i cant use it in this case hopefully we can find a similar approach with labels
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
but i have encountered in a different error why when there is 2 similar gifviews in the bbCodeview it raises this error
You are adding the same view twice. As I said, you should use SMM to simplify things.

Also BBCodeView Does not Support RTL language
It does. Make sure to set BBCodeView.RTL = True.
 
Upvote 0

Addo

Well-Known Member
Licensed User
You are adding the same view twice. As I said, you should use SMM to simplify things.
i meant if the user puts multi smile operator in the same string as example " hello :) :) :) "
it will be replaced with
"hello [View=":)" Vertical=10/] [View=":)" Vertical=10/] [View=":)" Vertical=10/]"
I will try to see how to use SMM to reach the same approach
 
Upvote 0
Top