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,116
  • Screenshot_20160430-104923.png
    Screenshot_20160430-104923.png
    130.9 KB · Views: 1,739
  • libSweetAlertDialogV1.1.0.zip
    40.8 KB · Views: 790
  • SweetAlertDialogV1.2.zip
    34.8 KB · Views: 947
Last edited:

DonManfred

Expert
Licensed User
Longtime User
android.content.res.Resources$NotFoundException: Resource ID #0x0
You did forgot to add the additionalres lines? Or the res folders???
See Example-Code...

The res-Folders are in the example zip.
The #additionalres lines are in the project-code too.

Make sure to use them
 

Jaco vd Walt

Member
Licensed User
Longtime User
Thank you for a great lib / wrap. I use it as standard with all my apps. I was wondering if someone might have had the following scenario : Whenever the wait wheel is turning (Progress Type), I want to prevent the user from pressing the back button and in effect canceling the dialog. I tried catching the back key, but it is ignored since sweetalert consumes the event. I dont think it is possible, was just wondering :)

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
How to use the ProgressHelper? Could you
explain it please?
- You should always start a new thread for your questions.
- See the example in #1. It is using it and showing how you can update the progress. It is using a timer but you can implement your own progress for sure.
 
Last edited:

BarryW

Active Member
Licensed User
Longtime User
????? WHAT exactly is the question?
Additionally you should ALWAYS create a new thread for any question you have.

B4X:
Sweet.Initialize("Sweet")
Sweet.AlertType = Sweet.TypeInfo

'---------------------- OR 

Sweet.Initialize("Sweet")
Sweet.AlertType = Sweet.TypeConfirmation

Like that
 

SMR

New Member
Hi dear,
Please Update Lib by below feature:
1- Replace CharSequence instead of string for (message & title & buttons)
2- add text size feature
3- add html text for message & title
4- can add custom view(panel) instead of message

thanks
 

Nestor Castro Jr

Member
Licensed User
Hello there,

I made a very simple example to explain my problem. In this code, I show one alert every time that user clicks on Activity. It works in the first time, but in the second time, the app freezes and do not show the alert box.

Sample:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

'
' WARNING!!!!
' The order of the following #AdditionalRes-lines
' must be exact like this
#AdditionalRes: ..\res.MaterialIshProgress
#AdditionalRes: ..\res.SweetAlertDialog

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

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 sweet As SweetAlertDialog
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")
    sweet.Initialize("Alert")
    sweet.AlertType = sweet.TypeWarning
    
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Click
    sweet.showCancelButton(True).showContentText(True).withCancelText("Not yet").withConfirmText("Yo man").withContentText("Bla bla bla bla").withTitleText("DonManfred present").show   
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
 

mangojack

Well-Known Member
Licensed User
Longtime User
@Nestor Castro Jr , Please do not make duplicate posts. Your issue has been solved here...
 

Nestor Castro Jr

Member
Licensed User
@Nestor Castro Jr , Please do not make duplicate posts. Your issue has been solved here...
Sorry! I only did this because I had no answer to my question in Library Forum for one week.
 
Top