B4A Library [B4X] BCToast - Cross platform custom toast message

BCToast is a custom "toast" message implementation based on BCTextEngine: https://www.b4x.com/android/forum/t...-bbcode-parser-rich-text-view.106207/#content

It requires BCTextEngine v1.65+.

java_Vr5tF2Iymf.png


Note that unlike B4A built-in toast message feature, this toast message can only be displayed from an Activity.

Usage example:
B4X:
Sub Globals
   Private toast As BCToast
End Sub

Sub Activity_Create(FirstTime As Boolean)
   toast.Initialize(Activity) 'Use Page1.RootPanel in B4i or MainForm.RootPane in B4J.
End Sub

Sub Activity_Click
   toast.Show($"The time now is [b]$Time{DateTime.Now}[/b]"$)
End Sub

Default duration is set to 3000 ms. It can be changed with the DurationMs field.
The text itself is highly customizable. See BCTextEngine for more information.

Tip: use the plain tag if you are showing error messages or any other unsanitized text:
B4X:
Toast.Show($"[plain]${LastException.Message}[/plain]"$)
Otherwise the text might include square brackets which will be treated as invalid bbcode.


V1.01 - Adds support for images.
New fields:
B4X:
Public PaddingSides As Int = 15dip
Public PaddingTopBottom As Int = 10dip
Public MaxHeight As Int = 100dip
Public VerticalCenterPercentage As Int = 85
 

Attachments

  • BCToast.b4xlib
    4.5 KB · Views: 1,751
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
I remember that one day you said that if it works at least for two platforms [B4X] is OK.
But I don't remember the thread.
in this thread

But I think Erel's concept is that if it isn't specified that it only affects 2 platforms (obviously indicating which ones) then it is meant for 3.
 
Last edited:

Jorge M A

Well-Known Member
Licensed User
Longtime User
[B4X] B4XDrawer - sliding drawer
Works only with B4A and B4i, but not with B4J !?
eeeeeemmmmm.....
Updates:

- 1.53 - Adds support for B4J (without gestures). No need to update if using with B4A or B4i.
 

klaus

Expert
Licensed User
Longtime User
But I think Erel's concept is that if it isn't specified that it only affects 2 platforms (obviously indicating which ones) then it is meant for 3.
I totally agree with this too!
I'm afraid that I didn't read carefully enough the [B4X] B4XDrawer - sliding drawer thread where it is written that the B4J version was added.
 

bocker77

Active Member
Licensed User
Longtime User
Is there a way to change the width of the toast panel. I tried changing the width as such but with no effect.
"toast.pnl.Width = Activity.Width - 100dip" and many other values. When I show it it fills the whole width of the screen. I would like to limit the width and it looks as if I can implement wordwrap with BB1 if the text is too long.

Thanks
 

bocker77

Active Member
Licensed User
Longtime User
Not to sound too stupid but I am not quite sure I understand what you mean. Here is my code surrounding this issue. pnlMain is the panel that the toast is being shown over if that comes into play in any way. Is this what you mean by parent view?

B4X:
    Private toast As BCToast
    Dim xui As XUI
... 
    Private pnlMain As Panel
...
        ' Setup Custom Toast Message
        toast.Initialize(Activity)
        toast.VerticalCenterPercentage = 65
        toast.pnl.Width = Activity.Width - 100dip
        toast.BB1.TextEngine.Initialize(Activity)
        toast.BB1.WordWrap = True
        toast.BB1.TextEngine.CustomFonts.Put("normal",xui.CreateFont(Typeface. _
                                             CreateNew(Typeface.SERIF, Typeface.STYLE_NORMAL), 10))
...
        ' The maximum width = the width of the parent view. You can add it to a panel
        ' instead of the root view and make it thinner.
        toast.pnl.Color = Color
        toast.DurationMs = Duration
        toast.MaxHeight = 100dip
        toast.Show("[Alignment=Center][img FileName=SmallKanga.png width=24 vertical=12/][/Alignment]" & _
                "[Font=normal] [TextSize=14][Color=" & TextColor & "][Alignment=Left]" & CRLF & Text & _
                "[/Alignment][/Color][/TextSize][/Font]")
 

LucaMs

Expert
Licensed User
Longtime User
toast.Initialize(Activity) 'Use Page1.RootPanel in B4i or MainForm.RootPane in B4J.
Just a little clarification:

1 - you should change MainForm declaration to Public
2 - for B4Xpages other than B4XMainPage you shoud use something like:
B4X:
Dim frm As Form = B4XPages.GetNativeParent(Me)
toast.Initialize(frm.RootPane)
 
Top