B4A Library SuperToasts

This was asked here as a Wish . Enjoy it @fredo and all friends here :)

A wrap for this https://github.com/JohnPersano/SuperToasts

SuperToasts_Banner (Medium).png



Please note :
1-
B4X:
@DependsOn(values={"android-support-v4"})
2- Not the whole project have been wrapped but I think the most important stuff .


SuperToasts
Author:
SMM
Version: 0.01
  • SuperToasts
    Events:
    • _click
    • _dismiss
    Fields:
    • ANIMATIONS_FADE As Int
    • ANIMATIONS_FLY As Int
    • ANIMATIONS_POP As Int
    • ANIMATIONS_SCALE As Int
    • DURATION_LONG As Int
    • DURATION_MEDIUM As Int
    • DURATION_SHORT As Int
    • DURATION_VERY_LONG As Int
    • DURATION_VERY_SHORT As Int
    • FRAME_KITKAT As Int
    • FRAME_LOLLIPOP As Int
    • FRAME_STANDARD As Int
    • ICONPOSITION_BOTTOM As Int
    • ICONPOSITION_LEFT As Int
    • ICONPOSITION_RIGHT As Int
    • ICONPOSITION_TOP As Int
    • MATERIAL_AMBER As String
    • MATERIAL_BLUE As String
    • MATERIAL_BLUE_GREY As String
    • MATERIAL_BROWN As String
    • MATERIAL_CYAN As String
    • MATERIAL_DEEP_ORANGE As String
    • MATERIAL_DEEP_PURPLE As String
    • MATERIAL_GREEN As String
    • MATERIAL_GREY As String
    • MATERIAL_INDIGO As String
    • MATERIAL_LIGHT_BLUE As String
    • MATERIAL_LIGHT_GREEN As String
    • MATERIAL_LIME As String
    • MATERIAL_ORANGE As String
    • MATERIAL_PINK As String
    • MATERIAL_PURPLE As String
    • MATERIAL_RED As String
    • MATERIAL_TEAL As String
    • MATERIAL_YELLOW As String
    • TYPE_BUTTON As Int
    • TYPE_PROGRESS_BAR As Int
    • TYPE_PROGRESS_CIRCLE As Int
    • TYPE_STANDARD As Int
    Methods:
    • Initialize (EventName As String)
    • SuperActivityToast (type As Int, buttontext As String, drawable As String, tag As String, ProgressBarColor As Int, text As String, duration As Int, frame As Int, color As String, animation As Int)
    • SuperToast (type As Int, drawable As String, tag As String, text As String, duration As Int, frame As Int, color As String, animation As Int)


Sample

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim st As SuperToasts
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")
'    Activity.Finish
'    CallSubDelayed(testbg,"display_toast")
    st.Initialize("st")
    'baicon is the name of image drawable
    st.SuperActivityToast(st.TYPE_BUTTON,"Done","baicon","my own tag",Colors.Red,"Well done",st.DURATION_VERY_LONG,st.FRAME_STANDARD,st.MATERIAL_BROWN,st.ANIMATIONS_FLY)
End Sub
Sub st_click(tag As String)
    Log(tag)
End Sub

This is testbg service code if you want to test toasts from services

B4X:
#Region  Service Attributes
    #StartAtBoot: False

#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim sts As SuperToasts
End Sub

Sub Service_Create
    sts.Initialize("sts")
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub
Sub display_toast
    sts.SuperToast(sts.TYPE_BUTTON,"baicon","my own toast tag","Well done",sts.DURATION_VERY_LONG,sts.FRAME_STANDARD,sts.MATERIAL_BROWN,sts.ANIMATIONS_FLY)

End Sub
Sub sts_dismiss(tag As String)
    Log(tag)
End Sub




UPDATE : Really sorry :) I forgot to upload resources folder now it is uploaded .


UPDATE : version 2 fixes issue reported here thanks @kkkpe and sorry for taking too much time .

Please note that now we have two different objects SuperActivityToast which is an ActivityObject as its name shows and SuperToast which can be used from a service .


SuperToasts
Author:
SMM
Version: 0.02
  • SuperActivityToast
    Events:
    • _click
    Fields:
    • ANIMATIONS_FADE As Int
    • ANIMATIONS_FLY As Int
    • ANIMATIONS_POP As Int
    • ANIMATIONS_SCALE As Int
    • DURATION_LONG As Int
    • DURATION_MEDIUM As Int
    • DURATION_SHORT As Int
    • DURATION_VERY_LONG As Int
    • DURATION_VERY_SHORT As Int
    • FRAME_KITKAT As Int
    • FRAME_LOLLIPOP As Int
    • FRAME_STANDARD As Int
    • ICONPOSITION_BOTTOM As Int
    • ICONPOSITION_LEFT As Int
    • ICONPOSITION_RIGHT As Int
    • ICONPOSITION_TOP As Int
    • MATERIAL_AMBER As String
    • MATERIAL_BLUE As String
    • MATERIAL_BLUE_GREY As String
    • MATERIAL_BROWN As String
    • MATERIAL_CYAN As String
    • MATERIAL_DEEP_ORANGE As String
    • MATERIAL_DEEP_PURPLE As String
    • MATERIAL_GREEN As String
    • MATERIAL_GREY As String
    • MATERIAL_INDIGO As String
    • MATERIAL_LIGHT_BLUE As String
    • MATERIAL_LIGHT_GREEN As String
    • MATERIAL_LIME As String
    • MATERIAL_ORANGE As String
    • MATERIAL_PINK As String
    • MATERIAL_PURPLE As String
    • MATERIAL_RED As String
    • MATERIAL_TEAL As String
    • MATERIAL_YELLOW As String
    • TYPE_BUTTON As Int
    • TYPE_PROGRESS_BAR As Int
    • TYPE_PROGRESS_CIRCLE As Int
    • TYPE_STANDARD As Int
    Methods:
    • Initialize (EventName As String)
    • SuperActivityToast (type As Int, buttontext As String, drawable As String, tag As String, ProgressBarColor As Int, text As String, duration As Int, frame As Int, color As String, animation As Int)
  • SuperToast
    Events:
    • _dismiss
    Fields:
    • ANIMATIONS_FADE As Int
    • ANIMATIONS_FLY As Int
    • ANIMATIONS_POP As Int
    • ANIMATIONS_SCALE As Int
    • DURATION_LONG As Int
    • DURATION_MEDIUM As Int
    • DURATION_SHORT As Int
    • DURATION_VERY_LONG As Int
    • DURATION_VERY_SHORT As Int
    • FRAME_KITKAT As Int
    • FRAME_LOLLIPOP As Int
    • FRAME_STANDARD As Int
    • ICONPOSITION_BOTTOM As Int
    • ICONPOSITION_LEFT As Int
    • ICONPOSITION_RIGHT As Int
    • ICONPOSITION_TOP As Int
    • MATERIAL_AMBER As String
    • MATERIAL_BLUE As String
    • MATERIAL_BLUE_GREY As String
    • MATERIAL_BROWN As String
    • MATERIAL_CYAN As String
    • MATERIAL_DEEP_ORANGE As String
    • MATERIAL_DEEP_PURPLE As String
    • MATERIAL_GREEN As String
    • MATERIAL_GREY As String
    • MATERIAL_INDIGO As String
    • MATERIAL_LIGHT_BLUE As String
    • MATERIAL_LIGHT_GREEN As String
    • MATERIAL_LIME As String
    • MATERIAL_ORANGE As String
    • MATERIAL_PINK As String
    • MATERIAL_PURPLE As String
    • MATERIAL_RED As String
    • MATERIAL_TEAL As String
    • MATERIAL_YELLOW As String
    • TYPE_BUTTON As Int
    • TYPE_PROGRESS_BAR As Int
    • TYPE_PROGRESS_CIRCLE As Int
    • TYPE_STANDARD As Int
    Methods:
    • Initialize (EventName As String)
    • SuperToast (type As Int, drawable As String, tag As String, text As String, duration As Int, frame As Int, color As String, animation As Int)
 

Attachments

  • SuperToasts.zip
    35.7 KB · Views: 398
  • res.zip
    9.4 KB · Views: 481
  • SuperToasts2.zip
    41.3 KB · Views: 454
Last edited:

kkkpe

Active Member
Licensed User
Longtime User
to me, it returns this error:

B4X:
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_button1_click (java line: 383)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
    at com.github.johnpersano.supertoasts.library.SuperToast.<init>(SuperToast.java:126)
    at com.github.johnpersano.supertoasts.library.SuperActivityToast.<init>(SuperActivityToast.java:150)
    at com.github.johnpersano.supertoasts.library.SuperActivityToast.create(SuperActivityToast.java:965)
    at smm.supertoastwrapperp.supertoastwrapper.SuperActivityToast(supertoastwrapper.java:84)
    at b4a.example.main._button1_click(main.java:383)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:5242)
    at android.widget.TextView.performClick(TextView.java:10573)
    at android.view.View$PerformClick.run(View.java:21196)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
 

somed3v3loper

Well-Known Member
Licensed User
Longtime User
to me, it returns this error:

B4X:
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
PackageAdded: package:b4a.example
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_button1_click (java line: 383)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
    at com.github.johnpersano.supertoasts.library.SuperToast.<init>(SuperToast.java:126)
    at com.github.johnpersano.supertoasts.library.SuperActivityToast.<init>(SuperActivityToast.java:150)
    at com.github.johnpersano.supertoasts.library.SuperActivityToast.create(SuperActivityToast.java:965)
    at smm.supertoastwrapperp.supertoastwrapper.SuperActivityToast(supertoastwrapper.java:84)
    at b4a.example.main._button1_click(main.java:383)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:5242)
    at android.widget.TextView.performClick(TextView.java:10573)
    at android.view.View$PerformClick.run(View.java:21196)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6938)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
** Service (service_aggiungi_coordinate) Start **
Passo in GPS
Also similar crash happened to me when I used Activity.Finish before these lines
B4X:
st.Initialize("st")
    'baicon is the name of image drawable
    st.SuperActivityToast(st.TYPE_BUTTON,"Done","baicon","my own tag",Colors.Red,"Well done",st.DURATION_VERY_LONG,st.FRAME_STANDARD,st.MATERIAL_BROWN,st.ANIMATIONS_FLY)
 

kkkpe

Active Member
Licensed User
Longtime User
I put the folder in the directory of my project, I tried with #additionalres: .. \ res I have the same problem.
 

MarcoRome

Expert
Licensed User
Longtime User
The Service work without problem in Activity i have problem. The Log error is:

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_btn_normal_click (B4A line: 53)
st.SuperActivityToast(st.TYPE_BUTTON,"Done","baic
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at com.github.johnpersano.supertoasts.library.SuperToast.<init>(SuperToast.java:126)
at com.github.johnpersano.supertoasts.library.SuperActivityToast.<init>(SuperActivityToast.java:150)
at com.github.johnpersano.supertoasts.library.SuperActivityToast.create(SuperActivityToast.java:965)
at smm.supertoastwrapperp.supertoastwrapper.SuperActivityToast(supertoastwrapper.java:84)
at b4a.example.supertoast.main._btn_normal_click(main.java:424)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10814)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Example in attachment ( Device with Android 6 )
 

Attachments

  • SuperToast.zip
    21.2 KB · Views: 320

somed3v3loper

Well-Known Member
Licensed User
Longtime User
to me, it returns this error:


Same thing.
Maybe @somed3v3loper do you forget value folder ??

Version 2 is now uploaded and should fix this issue please test and feedback .
Note that two types SuperActivityToast and SuperToast are now two different objects you declare them separately .
like
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim st As SuperToast
   
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 sts As SuperActivityToast
End Sub
 

MarcoRome

Expert
Licensed User
Longtime User
Perfect... work both.
In attachment new example for library 0.02
 

Attachments

  • SuperToast.zip
    19.9 KB · Views: 323
Top