GithubHelp home page GithubHelp logo

x3rocode / sweetlottiealertdialog Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 2.61 MB

:sparkles: SweetAlertDialog with lottie! :sparkles:

Kotlin 27.03% Java 72.97%
android android-alert alert android-dialog-alert android-modal android-popup android-popupwindow android-ui android-widget dialog

sweetlottiealertdialog's Introduction

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.

sweetlottiealertdialog's People

Contributors

x3rocode avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

sweetlottiealertdialog's Issues

Customize Buttons

Hello, first of all thank you for the lib! I want to customize the button text size etc. But when I try to get the cancel button for example I can't. Is there any other way?

Button cancel = dialog.findViewById(R.id.cancel_button);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.