Skip to content

x3rocode/SweetLottieAlertDialog

Repository files navigation

SweetLottieAlertDialog ✨

✨ SweetAlertDialog with lottie! ✨

SweetAlert for Android, a beautiful and clever alert dialog with lottie animation effect!

Origin repo : https://github.com/pedant/sweet-alert-dialog

ezgif-2-374eab3d3c

feature

You can setup Lottie animation in 2parts.

NO Explanation Example
1. Lottie Icon in alert loop

no loop
2. Full Screen Lottie
Lottie behind alert

Lottie cover alert

Using Gradle 🚀

In your top-level build.gradle file:

repositories {
  ...
  mavenCentral()
}

In your app build.gradle file:

dependencies {
    implementation 'com.github.fascinate98:SweetLottieAlertDialog:[latest_version]'
}

How to Use ⚡

Check here BASIC USAGE

  1. Go https://lottiefiles.com/

  2. Search Lottie animation you want.

  3. Download lottie json file.

  1. (option) Change the downloaded file name.

  1. Make res -> New -> Android Resource Directory

  1. Make raw folder. (Resource type -> raw)

  1. Move json file downloaded to raw folder.

  1. In your Code

Make simple button for example.

In your xml file:

<Button
    android:id="@+id/button1"
    android:layout_margin="10dp"
    android:text="Try me!" />

How to set lottie Icon in alert

In your Activity file:

//lottie icon in alert
 button1.setOnClickListener {
                //1. you have to set type SweetLottieAlertDialog.LOTTIE_ID_TYPE.
                val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
                //2. setLottieImagebyId(your_lottie_res, isLoop(boolean), listner)
                lsd2.setLottieImagebyId(R.raw.lottie_cryingface, true, null)
                lsd2.contentText = "Try Again!"
                lsd2.show()
            }

If you want set listner,

//lottie icon in alert
button1.setOnClickListener {
                val lsd2 = SweetLottieAlertDialog(this, SweetLottieAlertDialog.LOTTIE_ID_TYPE)
                //isLoop is false!
                lsd2.setLottieImagebyId(R.raw.ok_btn_lottie, false, object : Animator.AnimatorListener {

                    override fun onAnimationStart(animation: Animator) {

                    }

                    override fun onAnimationEnd(animation: Animator) {
                    //this will be executed when lottie animation end.
                        lsd2.dismissWithAnimation()
                    }

                    override fun onAnimationCancel(animation: Animator) {
                    }

                    override fun onAnimationRepeat(animation: Animator) {
                    }
                })
                lsd2.contentText = "Success!"
                lsd2.setCancelable(true)
                lsd2.setCanceledOnTouchOutside(true)
                lsd2.show()
            }


How to set Full screen lottie

//full screen - Lottie cover alert
 button1.setOnClickListener {
            val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
            //text in alert
            lsd.contentText = "Congratulation!"
            //set full screen lottie. It will cover your alert.  
            //setPopupLottieAnimation(your_lottie_res, isLoop(boolean), elevation);
            lsd.setPopupLottieAnimation(R.raw.bg_lottie, false, 999f)
            lsd.show()
        }

if you want lottie behind alert,

//full screen - Lottie behind alert
 button1.setOnClickListener {
            val lsd = SweetLottieAlertDialog(this, SweetLottieAlertDialog.NORMAL_TYPE)
            //text in alert
            lsd.contentText = "Congratulation!"
            //set full screen lottie behind alert.
            //set elevation 0f.                                 v here!
            lsd.setPopupLottieAnimation(R.raw.bg_lottie, false, 0f)
            lsd.show()
        }

License

The MIT License (MIT)

Copyright (c) 2014 Pedant(http://pedant.cn)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.