B4A Library SweetAlertDialog

Mashiane

Expert
Licensed User
Longtime User
T
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
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
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…