B4J Library ToastMessageShow Library

Hi guys, I am pleased to introduce ToastMessageShow for B4J.

In to the zip is included the library and the demo.

The library Include:

Below is the commons where you wish to display the Toast:


jCustomToast
Author:
GiuseppeSalvi
Version: 1.1
  • ToastMessageShow
    Fields:
    • TOAST_ERROR_ICON As Image
    • TOAST_INFO_ICON As Image
    • TOAST_SUCCESS_ICON As Image
    • TOAST_WARNING_ICON As Image
    • TEXT_CENTER As Int
    • TEXT_LEFT As Int
    • TEXT_RIGHT As Int
    • TOAST_BOTTOM_CENTER As Pos
    • TOAST_BOTTOM_LEFT As Pos
    • TOAST_BOTTOM_RIGHT As Pos
    • TOAST_CENTER As Pos
    • TOAST_CENTER_LEFT As Pos
    • TOAST_CENTER_RIGHT As Pos
    • TOAST_ERROR_ICON As Image
    • TOAST_INFO_ICON As Image
    • TOAST_LONG_DELAY As Double
    • TOAST_SHORT_DELAY As Double
    • TOAST_SUCCESS_ICON As Image
    • TOAST_TOP_CENTER As Pos
    • TOAST_TOP_LEFT As Pos
    • TOAST_TOP_RIGHT As Pos
    • TOAST_WARNING_ICON As Image
    Methods:
    • Initialize (EventName As String)
      Initialize the Objct
    • ToastIconSize16x16
      Set the icon 16 x 16
    • ToastIconSize24x24
      Set the icon 24 x 24
    • ToastIconSize32x32
      Set the icon 32 x 32
    • ToastIconSize40x40
      Set the icon 40 x 40
    • ToastIconSize48x48
      Set the icon 48 x 48
    • ToastShow (message As String)
      Show message
    • ToastShow2 (title As String, message As String)
      Show title and message
    • ToastShow3 (message As String, icon As Image)
      Show message and icon
    • ToastShow4 (title As String, message As String, icon As Image)
      Show title, message and icon
    • ToastShow5 (title As String, icon As Image)
      Show title and icon
    • ToastShow6 (icon As Image)
      Show icon
    • ToastStop
      Stop the toast
    Properties:
    • ToastDuration As Double [write only]
      Set the delay
    • ToastLocation As Pos [write only]
      Set the position of the toast
    • ToastMessageColor As Color [write only]
      Set color to the message
    • ToastNotificationOwner As Form [write only]
      Set MainForm to Anchor the Toast Inside own Window
    • ToastTextLocation As Int [write only]
      Set the position of the text
    • ToastTitleColor As Color [write only]
      Set color to the title
    • Version As String [read only]
      Return Author and Version of this library



How it work:
B4X:
#Region  Project Attributes
   #MainFormWidth: -1
   #MainFormHeight: -1
#End Region

Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private b1 As Button
   Private b2 As Button
   Private b3 As Button
   Private b4 As Button
   Private b5 As Button
   Private b6 As Button
   Private Toast As ToastMessageShow
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("CutomToast") 'Load the layout file.
   Toast.Initialize("Toast")
   Toast.ToastIconSize32x32
   Toast.ToastDuration = 6 'Toast.TOAST_LONG_DELAY
   Toast.ToastTextLocation = Toast.TEXT_CENTER
   Toast.ToastLocation= Toast.TOAST_CENTER_RIGHT
 
   '******************************************
 
   Toast.ToastNotificationOwner = MainForm 'this declaration Important
 
   '******************************************
 
   MainForm.Show
End Sub

Sub b1_MouseClicked (EventData As MouseEvent)
   Toast.ToastMessageColor = fx.Colors.White
   Toast.ToastShow("This is a Toast with message")
End Sub

Sub b2_MouseClicked (EventData As MouseEvent)
   Toast.ToastTitleColor = fx.Colors.Red
   Toast.ToastMessageColor = fx.Colors.Yellow
   Toast.ToastShow2("Title","This is a Toast with title and message")
End Sub

Sub b3_MouseClicked (EventData As MouseEvent)
   Dim icon As Image
   icon.Initialize(File.DirAssets,"info.png")
   Toast.ToastMessageColor = fx.Colors.Green
   Toast.ToastShow3("This is a Toast with message and icon",icon)
End Sub

Sub b4_MouseClicked (EventData As MouseEvent)
Toast.ToastTitleColor = fx.Colors.Cyan
Toast.ToastMessageColor = fx.Colors.Yellow
   Toast.ToastShow4("Title","This is a Toast with title, message and icon",Toast.TOAST_SUCCESS_ICON)
End Sub

Sub b5_MouseClicked (EventData As MouseEvent)
Toast.ToastTitleColor = fx.Colors.Blue
   Toast.ToastShow5("Title and icon",Toast.TOAST_ERROR_ICON)
End Sub

Sub b6_MouseClicked (EventData As MouseEvent)
   Toast.ToastShow6(Toast.TOAST_INFO_ICON)
End Sub

Sub MainForm_CloseRequest (EventData As Event)
   Toast.ToastStop
End Sub

Any comment or any suggestion will be appreciated.


Author of the original class is (Gerrit Grunwald)

I made a lot of changes to make it the same like android Toast.


Any error u find please report to me.
 

Attachments

  • CustomToast v1.0.zip
    31.6 KB · Views: 1,760
  • toast_only_message.png
    toast_only_message.png
    31.5 KB · Views: 1,645
  • toast_title_and_message.png
    toast_title_and_message.png
    39.7 KB · Views: 1,522
  • toast_message_and_icon.png
    toast_message_and_icon.png
    31.1 KB · Views: 1,437
  • toast_title_message_and_icon.png
    toast_title_message_and_icon.png
    34.8 KB · Views: 1,503
  • toast_title_and_icon.png
    toast_title_and_icon.png
    37.5 KB · Views: 1,483
  • toast_only_icon.png
    toast_only_icon.png
    30.5 KB · Views: 1,439
  • CustomToast v1.1.zip
    22.2 KB · Views: 1,765
  • ToastMessage_1.jpg
    ToastMessage_1.jpg
    46.2 KB · Views: 1,243
  • ToastMessage_2.jpg
    ToastMessage_2.jpg
    43.3 KB · Views: 1,365
Last edited:

joseluis

Active Member
Licensed User
Longtime User
Hi lonleystar, I'm testing your library in linux and each toast also displays a white rectangle over the GUI.

before clicking:
before-clicking.jpg

after clicking:
after-clicking.jpg
 

lonleystar

Well-Known Member
Licensed User
Longtime User

joseluis

Active Member
Licensed User
Longtime User
Thanks for the quick response. The system I'm using for testing is Lubuntu 14.10 64bit using LXDE (openbox) as a desktop manager.
 

FabioRome

Member
Licensed User
Longtime User
I have the same problem, using Debian 64Bit with MATE (as a Desktop manager porting of Gnome2)
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Found this 3 years after this nice lib was published. The library works well on Windows 10, even on a topmost pane. However when I run my B4J application on Mac the toastmessage shows under the application which means I have to display the messages on either side of the program. I would also like an automatic wordwrap function to support any type of resolutions these days. On my Mac the resolution is smaller which means all text in toastmessage is not visible because text simply won't fit on the screen.
Overall a very useful toastmessage lib. Maybe you can update it to v1.2 so it is showing correctly on Mac OS X El Capitan.

Cheers, Roger
 
Last edited:
Top