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:

Mashiane

Expert
Licensed User
Longtime User
T
This is a wrap for this github project.

SweetAlertDialog
Author:
DonManfred (wrapper)
Version: 1.1
  • 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 )
    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
To avoid having multiple sweet dialog variables, is it possible for you to add a Tag property. Then onCancel and onConfirm methods, one can determine the tag and then process accordingly? Just a thought?
 

Mashiane

Expert
Licensed User
Longtime User
Hi there

I want to implement this on Activity_KeyPress to confirm if an activity can be closed so that I can run Activity.Finish and ExitApplication. This does not show the dialog, can you please advise? Thanks

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Dim Txt As String
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        sweet.Initialize("sweetmsgbox")
        modMashiane.SetConfirm(sweet,"Confirm Exit", "Are you sure that you want to close the app?")
    End If
End Sub


Sub sweetmsgbox_onCancel()   
   sweet.dismissWithAnimation
End Sub

Sub sweetmsgbox_onConfirm()   
   sweet.dismissWithAnimation
   Activity.finish
  ExitApplication
End Sub
 

samperizal

Active Member
Licensed User
Longtime User
Greetings.
I 'm testing the linbreria SweetAlertDialog

with this code
sweet.Initialize ( " Alert" )
sweet.AlertType = sweet.TypeWarning
sweet.showCancelButton(True).showContentText(True).withCancelText("No").withConfirmText("Si").withContentText("Desea leaving the application " ) . withTitleText ( " Exit " ) . show

Sub Alert_onCancel ()
sweet.dismissWithAnimation
End Sub

Sub Alert_onConfirm ()
sweet.dismissWithAnimation
Activity.finish
ExitApplication
End Sub

the application does not expect any button being pressed

Thank you
 

samperizal

Active Member
Licensed User
Longtime User
If KeyCode = KeyCodes.KEYCODE_BACK Then

sweet.Initialize("Alert")

sweet.showCancelButton(True).showContentText(True).withCancelText("No").withConfirmText("Si").withContentText("Desea abandonar la aplicación").withTitleText("Salir").show
Return True
End If
 

Anser

Well-Known Member
Licensed User
Longtime User
Hi,

This lib looks good. A good substitute for MsgBox/ToastMessageShow

I am just testing this lib to find out whether it will suit my requirements and while testing got stuck in the below given situation.

In an Alert Type "Success", usually there will not be a Cancel button, it will be just "OK" button that will be used to inform the user about the status of an action.

As this Lib works async way, we need to control the flow of the code accordingly.

When the Sweet Dialog is displayed, if the user press a back key, how do we trap that ? Or How do we execute something, if the user press the Back button

In my situation,when a SweetAlertDialog is displayed, even if the user press the back key, I need to do Activity.Finish

For Eg
B4X:
Sub Globals
   Dim SweetAD As SweetAlertDialog
End Sub

Sub SMTP_MessageSent(Success As Boolean)
 
    SweetAD.Initialize("SweetAD")         
    SweetAD.AlertType = SweetAD.TypeSuccess

    'As It is just an information to the user, I don't need the cancel button here.
    'So I have used showCancelButton(False)

    SweetAD.showCancelButton(False).showContentText(True).withConfirmText("OK").withContentText("Your request has been submitted.").withTitleText("Done").show     
End Sub

Sub SweetAD_onConfirm ()
    SweetAD.dismissWithAnimation
    Activity.finish
End Sub

'The following sub will not get executed because SweetAD.showCancelButton(False) is used
' So the Activity does not get finished.
' If the user press back button, the following sub will not get executed
Sub SweetAD_onCancel ()
    SweetAD.dismissWithAnimation
    Activity.finish
End Sub
Is there a way in this lib, so that when a SweetAlert is displayed, if the user presses the BACK key, the onCancel Event of the lib is executed ?

Is there a way in this lib, so that the SweetAlert will get dismissed automatically after a specified time and the onCancel or onConfirm events gets triggered/fired

I understand that the following Sub can also be used to achieve what I wanted, but wanted to know whether any other elegant way is there in this library to trap the BACK key pressed considered as onCancel event.

Unfortunately, even the following code is failing, don't know why
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
   If KeyCode = KeyCodes.KEYCODE_BACK Then
     Activity.Finish   
   End If
   Return True   
End Sub

Any input will be appreciated.

Regards
Anser
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Is there a way in this lib, so that the SweetAlert will get dismissed automatically after a specified time and the onCancel or onConfirm events gets triggered/fired
No. The lib does not implement such a feature. Hint: The version you have ;)

See updated lib in post #1 (V1.2)

I´ve added a onDismissListener.

B4X:
Sub Alert_onDismiss()
    Log($"Alert_onDismiss()"$)
   
End Sub
It is triggered when you cancel the dialog with backkey...
 

Anser

Well-Known Member
Licensed User
Longtime User
I was using v1.10

Now I tested with v1.20 and is working fine as expected. Thank you.
 

zani

Member
Licensed User
Longtime User
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
e:\b4asource\test\res.sweetalertdialog\layout\alert_dialog.xml:129: error: No resource identifier found for attribute 'textAlignment' in package 'android'
i have this error
 

tpakis

Active Member
Licensed User
Longtime User
I have a problem, i have a button that when pressed the sweet dialog shows and works fine. But after the user dismiss it with .dismissWithAnimation after clicking the cancel button on the dialog, i have this problem:
When i click the first button that shows the dialog (for the second time the first time works fine) the screen dims - fades but the dialog doesn't show up. Any ideas?

Found the problem: I initialized the dialog on activity_create, but i should initialize it every time in button_click
 
Last edited:

Keith Flanagan

Member
Licensed User
I get the following error when compiling the example

B4A version: 6.31
Parsing code. (0.00s)
Compiling code. (0.02s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Generating R file. Error
..\res.sweetalertdialog\layout\alert_dialog.xml:129: error: No resource identifier found for attribute 'textAlignment' in package 'android'

Any thoughts on how to resolve this issue?


Thanks
 

Keith Flanagan

Member
Licensed User
Thanks for the prompt response DonManfred.

The setting is as follows:

C:\Android\android-sdk\platforms\android-15\android.jar

So i need to download the latest JAR through the SDK manager?
 

Phayao

Active Member
Licensed User
Longtime User
Thanks Manfred for this great lib, it works in your example
(v.6.50 beta - android.jar v.25):
BUT sorry to say I got a silly error message on the line: sweet.initialize("Alert")
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:2060)
at android.content.res.Resources.getDimensionPixelSize(Resources.java:1545)
at cn.pedant.SweetAlert.ProgressHelper.<init>(ProgressHelper.java:22)
at cn.pedant.SweetAlert.SweetAlertDialog.<init>(SweetAlertDialog.java:78)
at cn.pedant.SweetAlert.SweetAlertDialog.<init>(SweetAlertDialog.java:71)
at de.donmanfred.SweetAlertDialogWrapper.Initialize(SweetAlertDialogWrapper.java:35)

I cannot post the whole code, because it's too complex and lengthy - i put the initialize command in the activity.create or .resume part:
B4X:
Sub Activity_Resume
    ' add progress dialog for crossreference:
    sweet.Initialize("Alert")
    sweet.AlertType = sweet.TypeProgress
    ' 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

Anybody got an idea what I'm doing wrong here ?
Thanks,
Chris
 
Top