B4A Library [B4X] [BETA] BCTextEngine / BBCodeView - Text engine + BBCode parser + Rich Text View

Discussion in 'Additional libraries, classes and official updates' started by Erel, May 28, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    If you just want to show some (rich) content to the user then you should indeed create a web page, not a native app.

    BCTextEngine allows you to build your layout based on the text. The result is made of a ScrollView, an ImageView and the additional views that you added. I assume that your app should also include some logic. Otherwise go with a web page...
    jimmyF likes this.
  2. Sandman

    Sandman Well-Known Member Licensed User

    Oh, absolutely! :) I was just considering the possibility to have a certain place in the app (that sometimes get updates that needs to be pushed out on the app stores) to instead use this solution.
  3. ThRuST

    ThRuST Well-Known Member Licensed User

    @Sandman Apple secures their financial wealth from memberships so they don't care about a few people updating their apps through webpages :)
    Unless any development tool "interferes" with their business strategy. Otherwise, business as usual and your chicks for free :D
  4. peacemaker

    peacemaker Well-Known Member Licensed User

    I think the text engine can parse one more tag [Logic], that is ... code block to run, where added views can be referenced and used.
  5. Mahares

    Mahares Well Known Member Licensed User

    1. Using Erel's B4A example, why is it that the customlistview does not scroll beyond items 1 and 2 unless the text in the next sentense is removed:
    'We can also download an image here: [img url="https://b4x-4c17.kxcdn.com/android/forum/data/avatars/l/42/42649.jpg?1432374732" width=60 height=60/]
    Note that you must explicitly set the dimensions of such images.'

    PLease that I have read this from Erel's first post: 'The example adds a CustomListView to the layout. This can cause an issue in B4A if the layout becomes scrollable'

    2. I saved to a text file the text generated from: BBCodeView1.Text. Is there a viewer on the Android device or PC that can display the text as shown in the UI?
    Dim rp As RuntimePermissions
    Dim s As String=BBCodeView1.Text
    3. Is this going to make RichString and CSBuilder a thing of the past in future enhancement and improvements to the lib?

    Attached Files:

    • bbc.txt
      File size:
      843 bytes
    Last edited: May 29, 2019
  6. jimmyF

    jimmyF Active Member Licensed User

    See post #18

    ImageView1.Bitmap = BBCodeView1.mBase.Snapshot
    3. I think this is pretty exciting. I can imagine transferring data between apps as just one of many possibilities.:)

  7. Mahares

    Mahares Well Known Member Licensed User

    1. I have read post#1 and #18 of Erel and yours of #16 prior to posting. I want to know what Erel has in mind to overcome this limitation.

    2. Your answer for question 2 is not what I was looking for. I would like to know if there is a program that can allow viewing the text like for example a pdf viewer the way is it formatted in the UI, not an image file.
    jimmyF likes this.
  8. Erel

    Erel Administrator Staff Member Licensed User

    The limitation has nothing to do with BBCodeView. Nesting scrollable elements is problematic in Android. Either make sure that the text is short enough not to be scrollable or don't add a scrollable element. You can for example use B4XDialog with B4XListTemplate instead.

    Yes. BBCodeView. You can use it on both Android and PC.
  9. xulihang

    xulihang Active Member Licensed User

    Should BCTextEngine be used in priority over CSBulder for B4A and TextFlow for B4J?
  10. Erel

    Erel Administrator Staff Member Licensed User

    It depends on your requirements. There is nothing bad with using CSBuilder or TextFlow.
  11. Mahares

    Mahares Well Known Member Licensed User

    I know you can use it with B4A and B4J, but that was not my question.
    I would like to know if I save the text generated by BBCodeView to a file, if there is a viewer (for Android and on PC) I can use to open the text file and see the formatted text with its images and text.
  12. jimmyF

    jimmyF Active Member Licensed User

    Sounds like a great idea for my next project! Thanks! :D
  13. Erel

    Erel Administrator Staff Member Licensed User

    Create a B4J program with BBCodeText and set its text property.
  14. Erel

    Erel Administrator Staff Member Licensed User


    Another B4J example.

    The views are created with the designer and are loaded to a panel that is not part of the layout. Note that in B4i and B4J you need to make sure that the Handle Resize Event is unchecked in this layout.

    Edit: Example updated with the changes required for BCTextEngine v1.50.

    Attached Files:

    • 1.zip
      File size:
      16.3 KB
    Last edited: Jun 17, 2019
    fredo, asales and Johan Hormaza like this.
  15. Erel

    Erel Administrator Staff Member Licensed User

    V1.02 - New BBCodeView.Padding field. Can be used to change the padding.
  16. mcqueccu

    mcqueccu Active Member Licensed User

    Skip unsupported tags
    Hello, please I want to find out if there is a way to skip contents that are formatted with square brackets example [hello] without crashing the app? I was displaying some longs strings from a database and i get crash error.

    Error (position - 197) Invalid tag: hello
    bbcodeview_createruns (java line: 
    java.lang.RuntimeException: Object should first be initialized (
  17. Erel

    Erel Administrator Staff Member Licensed User

    Should the text from the database be formatted? Is it BBCode?
    If not then wrap it with the 'plain' tag.
    jimmyF likes this.
  18. mcqueccu

    mcqueccu Active Member Licensed User

    The text is not supposed to be formatted, it's not needed I just realised that some of them had that square bracket around them for emphasis and it's random.

    I will try and wrap it with the 'plain' and if it doesn't work then I will just find and replace all before setting it to the bbcodeview
  19. Erel

    Erel Administrator Staff Member Licensed User

    The Plain tag is intended exactly for this use case. If you encounter any problem then post it and it will be fixed.
  20. William Lancee

    William Lancee Member Licensed User

    I really like this development. However, on my device (Samsung Galaxy 10.5 Tab S2) the text is broken up.

    Toky Olivier likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice