B4A Library SweetAlertDialog

This is a wrap for this github project.

SweetAlertDialog
Author:
DonManfred (wrapper)
Version: 1.2
  • ProgressHelper
    Methods:
    • Initialize
    • IsInitialized As Boolean
    • isSpinning As Boolean
    • resetCount
    • spin
    • stopSpinning
    Properties:
    • BarColor As Int
    • BarWidth As Int
    • CircleRadius As Int
    • InstantProgress As Float [write only]
    • Progress As Float
    • ProgressWheel As ProgressWheel
    • RimColor As Int
    • RimWidth As Int
    • SpinSpeed As Float
  • SweetAlertDialog
    Events:
    • onCancel ( As )
    • onConfirm ( As )
    • ondismiss ( As )
    Methods:
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • cancel
      The real Dialog.cancel() will be invoked async-ly after the animation finishes.
    • dismissWithAnimation
      The real Dialog.dismiss() will be invoked async-ly after the animation finishes.
    • isShowCancelButton As Boolean
    • isShowContentText As Boolean
    • show
    • showCancelButton (isShow As Boolean) As SweetAlertDialogWrapper
    • showContentText (isShow As Boolean) As SweetAlertDialogWrapper
    • withCancelText (text As String) As SweetAlertDialogWrapper
    • withConfirmText (text As String) As SweetAlertDialogWrapper
    • withContentText (text As String) As SweetAlertDialogWrapper
    • withCustomImage (drawable As Drawable) As SweetAlertDialogWrapper
    • withCustomImageResource (resource As String) As SweetAlertDialogWrapper
    • withTitleText (text As String) As SweetAlertDialogWrapper
    Properties:
    • AlertType As Int
    • CancelText As String [read only]
    • ConfirmText As String [read only]
    • ContentText As String [read only]
    • ProgressHelper As ProgressHelper [read only]
    • TitleText As String [read only]
    • TypeCustomImage As Int [read only]
    • TypeError As Int [read only]
    • TypeNormal As Int [read only]
    • TypeProgress As Int [read only]
    • TypeSuccess As Int [read only]
    • TypeWarning As Int [read only]

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 sweet As SweetAlertDialog
    Dim t As Timer
    Dim count As Int
    Dim helper As ProgressHelper
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")
    count = 0
    t.Initialize("Timer",200)
    sweet.Initialize("Alert")
    sweet.AlertType = sweet.TypeCustomImage

    ' Get Progresshelper object.
    ' With the ProgressHelper you can change the Properties
    ' of the ProgressWheel. Start, stop spinning and so on...
    helper = sweet.ProgressHelper


End Sub
Sub Activity_Resume
    sweet.showCancelButton(False).showContentText(True).withConfirmText("I love it!").withContentText("SweetAlertDialogs Library").withTitleText("DonManfred present").withCustomImageResource("donmanfred").show
    't.Enabled = True
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Alert_onCancel()
    Log($"Alert_onCancel()"$)
    sweet.AlertType = sweet.TypeError
    'sweet.withContentText("BLA bla BLA bla BLA")
    sweet.dismissWithAnimation
End Sub
Sub Alert_onConfirm()
    Log($"Alert_onConfirm()"$)

    sweet.dismissWithAnimation
End Sub
Sub Timer_Tick
    count = count +1

    If count < 100 Then
        sweet.withContentText($"Downloadfinished... ${count}"$)
    Else
        sweet.withContentText($"Downloading finished!"$)
        sweet.AlertType = sweet.TypeSuccess
        t.Enabled = False
    End If

End Sub
 

Attachments

  • SweetAlertDialogEx.zip
    18.7 KB · Views: 1,207
  • Screenshot_20160430-104923.png
    Screenshot_20160430-104923.png
    130.9 KB · Views: 1,848
  • libSweetAlertDialogV1.1.0.zip
    40.8 KB · Views: 878
  • SweetAlertDialogV1.2.zip
    34.8 KB · Views: 1,039
Last edited:

itgirl

Active Member
Licensed User
Longtime User
thanks for this one actually im trying to replace all my msgboxes with this cool and sweet one . but Cant we use
B4X:
Sub exit_dialog_onCancel()
    Dim sweet As SweetAlertDialog = Sender
    sweet .dismissWithAnimation
End Sub
throws en error
B4X:
java.lang.ClassCastException: de.donmanfred.SweetAlertDialogWrapper$1 cannot be cast to cn.pedant.SweetAlert.SweetAlertDialog

or maybe what would be more nice if we can check the value without the need of going to another sub i mean like msgbox but i guess its different than how msgbox works

B4X:
dim anw as int = exit_dialog.show
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
or maybe what would be more nice if we can check the value without the need of going to another sub i mean like msgbox but i guess its different than how msgbox works
This library does not provide such functionality.
You can treat it more likely async calls with httputils.
That´s how the lib works.
 

itgirl

Active Member
Licensed User
Longtime User
you dont need to cast the object again. just use your global sweet

B4X:
Sub exit_dialog_onCancel()
    sweet.dismissWithAnimation
End Sub
yes you are right but in case of i dim the sweet not in a global sub which is my case and there's alot of "Sweets" in my activity ... so my solution was to dim only one sweet in the globals and then re-Initialize it inside my code multiple times , you think this way has any problems ?
 

so27

Active Member
Licensed User
Longtime User
Hello DonManfred,

how do I change the code, if I want to use their own icon. My code does not, because bitmap.
B4X:
sweet.withCustomImage(LoadBitmap(File.DirAssets,"info.png"))
 

so27

Active Member
Licensed User
Longtime User
Okay, understand. How then, can I pass an existing PNG as a drawable? :eek:
 

so27

Active Member
Licensed User
Longtime User
Sorry in the above code I can't find the donmanfred.png and in the example, the file is not used. Or i was blind o_O
 

so27

Active Member
Licensed User
Longtime User
I found it. You could tell but quiet.:D The PNG file must be copied into the directory: \res.SweetAlertDialog\drawable
 

so27

Active Member
Licensed User
Longtime User
I can understand you. Thanks for the great library.
 

Mashiane

Expert
Licensed User
Longtime User
This is very impressive, have added some example methods for play.

Usage...
B4X:
SetError("Mashy Error", "This is an error message!")
    SetConfirm("Confirm Delete", "Are you sure you want to delete this record?")
    SetInform("Done", "The download was succesful.")
    SetCustom("Custom Image", "This is a custom image resource sweet alert.", "Ok", "", "question")

Them methods....
B4X:
Sub SetError(sTitle As String, sMessage As String)
    sweet.AlertType = sweet.TypeError
    sweet.showCancelButton(False).showContentText(True).withConfirmText("Ok").withContentText(sMessage).withTitleText(sTitle).show
End Sub

Sub SetConfirm(sTitle As String, sMessage As String)
    sweet.AlertType = sweet.TypeWarning
    sweet.showCancelButton(True).showContentText(True).withCancelText("No").withConfirmText("Yes").withContentText(sMessage).withTitleText(sTitle).show
End Sub

Sub SetInform(sTitle As String, sMessage As String)
    sweet.AlertType = sweet.TypeSuccess
    sweet.showCancelButton(False).showContentText(True).withConfirmText("Ok").withContentText(sMessage).withTitleText(sTitle).show
End Sub

Sub SetCustom(sTitle As String, sMessage As String, sConfirm As String, sCancel As String, sImage As String)
    ' you need to put the image file e.g. image.png on res.SweetAlertDialog\drawable folder
    Dim bCancel As Boolean = True
    Dim bContent As Boolean = True
    If sCancel.Length = 0 Then
        bCancel = False
    Else
        sweet.withCancelText(sCancel)
    End If
    If sMessage.Length = 0 Then bContent = False
    If sImage.Length <> 0 Then
        sweet.AlertType = sweet.TypeCustomImage
        sweet.withCustomImageResource(sImage)
    Else
        sweet.AlertType = sweet.TypeNormal
    End If
    sweet.showCancelButton(bCancel).showContentText(bContent).withConfirmText(sConfirm).withContentText(sMessage).withTitleText(sTitle).show
End Sub
 

Attachments

  • BottomNavigationExample.zip
    16.8 KB · Views: 549
Top