Repository: pedant/sweet-alert-dialog Branch: master Commit: 770bb183fb4f Files: 45 Total size: 85.7 KB Directory structure: gitextract_j7agdo7h/ ├── README.md ├── README.zh.md ├── build.gradle ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── library/ │ ├── build.gradle │ ├── gradle.properties │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── cn/ │ │ └── pedant/ │ │ └── SweetAlert/ │ │ ├── OptAnimationLoader.java │ │ ├── ProgressHelper.java │ │ ├── Rotate3dAnimation.java │ │ ├── SuccessTickView.java │ │ └── SweetAlertDialog.java │ └── res/ │ ├── anim/ │ │ ├── error_frame_in.xml │ │ ├── error_x_in.xml │ │ ├── modal_in.xml │ │ ├── modal_out.xml │ │ ├── success_bow_roate.xml │ │ └── success_mask_layout.xml │ ├── drawable/ │ │ ├── blue_button_background.xml │ │ ├── dialog_background.xml │ │ ├── error_center_x.xml │ │ ├── error_circle.xml │ │ ├── gray_button_background.xml │ │ ├── red_button_background.xml │ │ ├── success_bow.xml │ │ ├── success_circle.xml │ │ ├── warning_circle.xml │ │ └── warning_sigh.xml │ ├── layout/ │ │ └── alert_dialog.xml │ └── values/ │ ├── attrs.xml │ ├── colors.xml │ ├── dimen.xml │ ├── strings.xml │ └── styles.xml ├── sample/ │ ├── build.gradle │ ├── proguard-android.txt │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── cn/ │ │ └── pedant/ │ │ └── SweetAlert/ │ │ └── sample/ │ │ └── SampleActivity.java │ └── res/ │ ├── layout/ │ │ └── sample_activity.xml │ └── values/ │ └── strings.xml └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: README.md ================================================ Sweet Alert Dialog =================== SweetAlert for Android, a beautiful and clever alert dialog [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Sweet%20Alert%20Dialog-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1065) [中文版](https://github.com/pedant/sweet-alert-dialog/blob/master/README.zh.md) Inspired by JavaScript [SweetAlert](http://tristanedwards.me/sweetalert) [Demo Download](https://github.com/pedant/sweet-alert-dialog/releases/download/v1.1/sweet-alert-sample-v1.1.apk) ## ScreenShot ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/change_type.gif) ## Setup The simplest way to use SweetAlertDialog is to add the library as aar dependency to your build. **Maven** cn.pedant.sweetalert library 1.3 aar **Gradle** repositories { mavenCentral() } dependencies { compile 'cn.pedant.sweetalert:library:1.3' } ## Usage show material progress SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE); pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); pDialog.setTitleText("Loading"); pDialog.setCancelable(false); pDialog.show(); ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/play_progress.gif) You can customize progress bar dynamically with materialish-progress methods via **SweetAlertDialog.getProgressHelper()**: - resetCount() - isSpinning() - spin() - stopSpinning() - getProgress() - setProgress(float progress) - setInstantProgress(float progress) - getCircleRadius() - setCircleRadius(int circleRadius) - getBarWidth() - setBarWidth(int barWidth) - getBarColor() - setBarColor(int barColor) - getRimWidth() - setRimWidth(int rimWidth) - getRimColor() - setRimColor(int rimColor) - getSpinSpeed() - setSpinSpeed(float spinSpeed) thanks to the project [materialish-progress](https://github.com/pnikosis/materialish-progress) and [@croccio](https://github.com/croccio) participation. more usages about progress, please see the sample. A basic message: new SweetAlertDialog(this) .setTitleText("Here's a message!") .show(); A title with a text under: new SweetAlertDialog(this) .setTitleText("Here's a message!") .setContentText("It's pretty, isn't it?") .show(); A error message: new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .show(); A warning message: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .show(); A success message: new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Good job!") .setContentText("You clicked the button!") .show(); A message with a custom icon: new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Sweet!") .setContentText("Here's a custom image.") .setCustomImage(R.drawable.custom_img) .show(); Bind the listener to confirm button: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.dismissWithAnimation(); } }) .show(); Show the cancel button and bind listener to it: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setCancelText("No,cancel plx!") .setConfirmText("Yes,delete it!") .showCancelButton(true) .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.cancel(); } }) .show(); **Change** the dialog style upon confirming: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog .setTitleText("Deleted!") .setContentText("Your imaginary file has been deleted!") .setConfirmText("OK") .setConfirmClickListener(null) .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); } }) .show(); [more android tech shares: pedant.cn](http://www.pedant.cn) ## 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. ================================================ FILE: README.zh.md ================================================ Sweet Alert Dialog =================== Android版的SweetAlert,清新文艺,快意灵动的甜心弹框 [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Sweet%20Alert%20Dialog-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1065) [English Version](https://github.com/pedant/sweet-alert-dialog/blob/master/README.md) 灵感来源于JS版[SweetAlert](http://tristanedwards.me/sweetalert) [Demo下载](https://github.com/pedant/sweet-alert-dialog/releases/download/v1.1/sweet-alert-sample-v1.1.apk) ## 运行示意图 ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/change_type.gif) ## 安装 使用SweetAlertDialog最简单的办法就是像下面这样添加项目依赖。 **Maven** cn.pedant.sweetalert library 1.3 aar **Gradle** repositories { mavenCentral() } dependencies { compile 'cn.pedant.sweetalert:library:1.3' } ## 如何开始 显示Material进度样式 SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE); pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86")); pDialog.setTitleText("Loading"); pDialog.setCancelable(false); pDialog.show(); ![image](https://github.com/pedant/sweet-alert-dialog/raw/master/play_progress.gif) 你可以通过**SweetAlertDialog.getProgressHelper()**调用materialish-progress中下面这些方法,来动态改变进度条的样式 - resetCount() - isSpinning() - spin() - stopSpinning() - getProgress() - setProgress(float progress) - setInstantProgress(float progress) - getCircleRadius() - setCircleRadius(int circleRadius) - getBarWidth() - setBarWidth(int barWidth) - getBarColor() - setBarColor(int barColor) - getRimWidth() - setRimWidth(int rimWidth) - getRimColor() - setRimColor(int rimColor) - getSpinSpeed() - setSpinSpeed(float spinSpeed) 感谢[materialish-progress](https://github.com/pnikosis/materialish-progress)项目以及[@croccio](https://github.com/croccio)的参与。 更多关于进度条的用法,请参见样例代码。 只显示标题: new SweetAlertDialog(this) .setTitleText("Here's a message!") .show(); 显示标题和内容: new SweetAlertDialog(this) .setTitleText("Here's a message!") .setContentText("It's pretty, isn't it?") .show(); 显示异常样式: new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE) .setTitleText("Oops...") .setContentText("Something went wrong!") .show(); 显示警告样式: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .show(); 显示成功完成样式: new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE) .setTitleText("Good job!") .setContentText("You clicked the button!") .show(); 自定义头部图像: new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE) .setTitleText("Sweet!") .setContentText("Here's a custom image.") .setCustomImage(R.drawable.custom_img) .show(); 确认事件绑定: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.dismissWithAnimation(); } }) .show(); 显示取消按钮及事件绑定: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setCancelText("No,cancel plx!") .setConfirmText("Yes,delete it!") .showCancelButton(true) .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog.cancel(); } }) .show(); 确认后**切换**对话框样式: new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE) .setTitleText("Are you sure?") .setContentText("Won't be able to recover this file!") .setConfirmText("Yes,delete it!") .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sDialog) { sDialog .setTitleText("Deleted!") .setContentText("Your imaginary file has been deleted!") .setConfirmText("OK") .setConfirmClickListener(null) .changeAlertType(SweetAlertDialog.SUCCESS_TYPE); } }) .show(); [更多Android原创技术分享见: pedant.cn](http://www.pedant.cn) ## 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. ================================================ FILE: build.gradle ================================================ buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.14.1' } } ext { compileSdkVersion = 21 buildToolsVersion = "19.1.0" } allprojects { repositories { mavenCentral() } } ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Tue Dec 02 17:43:17 CET 2014 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip ================================================ FILE: gradle.properties ================================================ VERSION_NAME=1.3 VERSION_CODE=4 GROUP=cn.pedant.sweetalert POM_DESCRIPTION=SweetAlert for Android, a beautiful and clever alert dialog. POM_URL=https://github.com/pedant/sweet-alert-dialog POM_SCM_URL=https://github.com/pedant/sweet-alert-dialog POM_SCM_CONNECTION=scm:git@github.com:pedant/sweet-alert-dialog.git POM_SCM_DEV_CONNECTION=scm:git@github.com:pedant/sweet-alert-dialog.git POM_LICENCE_NAME=The MIT License POM_LICENCE_URL=http://opensource.org/licenses/MIT POM_LICENCE_DIST=repo POM_DEVELOPER_ID=pedant POM_DEVELOPER_NAME=Pedant ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # For Cygwin, ensure paths are in UNIX format before anything is touched. if $cygwin ; then [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` fi # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >&- APP_HOME="`pwd -P`" cd "$SAVED" >&- CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: library/build.gradle ================================================ apply plugin: 'com.android.library' version = VERSION_NAME group = GROUP android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion 9 } lintOptions { abortOnError false } } dependencies { compile 'com.pnikosis:materialish-progress:1.0' } apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' ================================================ FILE: library/gradle.properties ================================================ POM_NAME=SweetAlertDialog-Library POM_ARTIFACT_ID=library POM_PACKAGING=aar ================================================ FILE: library/src/main/AndroidManifest.xml ================================================ ================================================ FILE: library/src/main/java/cn/pedant/SweetAlert/OptAnimationLoader.java ================================================ package cn.pedant.SweetAlert; import android.content.Context; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.util.AttributeSet; import android.util.Xml; import android.view.animation.*; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; public class OptAnimationLoader { public static Animation loadAnimation(Context context, int id) throws Resources.NotFoundException { XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createAnimationFromXml(context, parser); } catch (XmlPullParserException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { if (parser != null) parser.close(); } } private static Animation createAnimationFromXml(Context c, XmlPullParser parser) throws XmlPullParserException, IOException { return createAnimationFromXml(c, parser, null, Xml.asAttributeSet(parser)); } private static Animation createAnimationFromXml(Context c, XmlPullParser parser, AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException { Animation anim = null; // Make sure we are on a start tag. int type; int depth = parser.getDepth(); while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } String name = parser.getName(); if (name.equals("set")) { anim = new AnimationSet(c, attrs); createAnimationFromXml(c, parser, (AnimationSet)anim, attrs); } else if (name.equals("alpha")) { anim = new AlphaAnimation(c, attrs); } else if (name.equals("scale")) { anim = new ScaleAnimation(c, attrs); } else if (name.equals("rotate")) { anim = new RotateAnimation(c, attrs); } else if (name.equals("translate")) { anim = new TranslateAnimation(c, attrs); } else { try { anim = (Animation) Class.forName(name).getConstructor(Context.class, AttributeSet.class).newInstance(c, attrs); } catch (Exception te) { throw new RuntimeException("Unknown animation name: " + parser.getName() + " error:" + te.getMessage()); } } if (parent != null) { parent.addAnimation(anim); } } return anim; } } ================================================ FILE: library/src/main/java/cn/pedant/SweetAlert/ProgressHelper.java ================================================ package cn.pedant.SweetAlert; import android.content.Context; import com.pnikosis.materialishprogress.ProgressWheel; public class ProgressHelper { private ProgressWheel mProgressWheel; private boolean mToSpin; private float mSpinSpeed; private int mBarWidth; private int mBarColor; private int mRimWidth; private int mRimColor; private boolean mIsInstantProgress; private float mProgressVal; private int mCircleRadius; public ProgressHelper(Context ctx) { mToSpin = true; mSpinSpeed = 0.75f; mBarWidth = ctx.getResources().getDimensionPixelSize(R.dimen.common_circle_width) + 1; mBarColor = ctx.getResources().getColor(R.color.success_stroke_color); mRimWidth = 0; mRimColor = 0x00000000; mIsInstantProgress = false; mProgressVal = -1; mCircleRadius = ctx.getResources().getDimensionPixelOffset(R.dimen.progress_circle_radius); } public ProgressWheel getProgressWheel () { return mProgressWheel; } public void setProgressWheel (ProgressWheel progressWheel) { mProgressWheel = progressWheel; updatePropsIfNeed(); } private void updatePropsIfNeed () { if (mProgressWheel != null) { if (!mToSpin && mProgressWheel.isSpinning()) { mProgressWheel.stopSpinning(); } else if (mToSpin && !mProgressWheel.isSpinning()) { mProgressWheel.spin(); } if (mSpinSpeed != mProgressWheel.getSpinSpeed()) { mProgressWheel.setSpinSpeed(mSpinSpeed); } if (mBarWidth != mProgressWheel.getBarWidth()) { mProgressWheel.setBarWidth(mBarWidth); } if (mBarColor != mProgressWheel.getBarColor()) { mProgressWheel.setBarColor(mBarColor); } if (mRimWidth != mProgressWheel.getRimWidth()) { mProgressWheel.setRimWidth(mRimWidth); } if (mRimColor != mProgressWheel.getRimColor()) { mProgressWheel.setRimColor(mRimColor); } if (mProgressVal != mProgressWheel.getProgress()) { if (mIsInstantProgress) { mProgressWheel.setInstantProgress(mProgressVal); } else { mProgressWheel.setProgress(mProgressVal); } } if (mCircleRadius != mProgressWheel.getCircleRadius()) { mProgressWheel.setCircleRadius(mCircleRadius); } } } public void resetCount() { if (mProgressWheel != null) { mProgressWheel.resetCount(); } } public boolean isSpinning() { return mToSpin; } public void spin() { mToSpin = true; updatePropsIfNeed(); } public void stopSpinning() { mToSpin = false; updatePropsIfNeed(); } public float getProgress() { return mProgressVal; } public void setProgress(float progress) { mIsInstantProgress = false; mProgressVal = progress; updatePropsIfNeed(); } public void setInstantProgress(float progress) { mProgressVal = progress; mIsInstantProgress = true; updatePropsIfNeed(); } public int getCircleRadius() { return mCircleRadius; } /** * @param circleRadius units using pixel * **/ public void setCircleRadius(int circleRadius) { mCircleRadius = circleRadius; updatePropsIfNeed(); } public int getBarWidth() { return mBarWidth; } public void setBarWidth(int barWidth) { mBarWidth = barWidth; updatePropsIfNeed(); } public int getBarColor() { return mBarColor; } public void setBarColor(int barColor) { mBarColor = barColor; updatePropsIfNeed(); } public int getRimWidth() { return mRimWidth; } public void setRimWidth(int rimWidth) { mRimWidth = rimWidth; updatePropsIfNeed(); } public int getRimColor() { return mRimColor; } public void setRimColor(int rimColor) { mRimColor = rimColor; updatePropsIfNeed(); } public float getSpinSpeed() { return mSpinSpeed; } public void setSpinSpeed(float spinSpeed) { mSpinSpeed = spinSpeed; updatePropsIfNeed(); } } ================================================ FILE: library/src/main/java/cn/pedant/SweetAlert/Rotate3dAnimation.java ================================================ package cn.pedant.SweetAlert; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Camera; import android.graphics.Matrix; import android.util.AttributeSet; import android.util.TypedValue; import android.view.animation.Animation; import android.view.animation.Transformation; public class Rotate3dAnimation extends Animation { private int mPivotXType = ABSOLUTE; private int mPivotYType = ABSOLUTE; private float mPivotXValue = 0.0f; private float mPivotYValue = 0.0f; private float mFromDegrees; private float mToDegrees; private float mPivotX; private float mPivotY; private Camera mCamera; private int mRollType; public static final int ROLL_BY_X = 0; public static final int ROLL_BY_Y = 1; public static final int ROLL_BY_Z = 2; protected static class Description { public int type; public float value; } Description parseValue(TypedValue value) { Description d = new Description(); if (value == null) { d.type = ABSOLUTE; d.value = 0; } else { if (value.type == TypedValue.TYPE_FRACTION) { d.type = (value.data & TypedValue.COMPLEX_UNIT_MASK) == TypedValue.COMPLEX_UNIT_FRACTION_PARENT ? RELATIVE_TO_PARENT : RELATIVE_TO_SELF; d.value = TypedValue.complexToFloat(value.data); return d; } else if (value.type == TypedValue.TYPE_FLOAT) { d.type = ABSOLUTE; d.value = value.getFloat(); return d; } else if (value.type >= TypedValue.TYPE_FIRST_INT && value.type <= TypedValue.TYPE_LAST_INT) { d.type = ABSOLUTE; d.value = value.data; return d; } } d.type = ABSOLUTE; d.value = 0.0f; return d; } public Rotate3dAnimation (Context context, AttributeSet attrs) { super(context, attrs); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Rotate3dAnimation); mFromDegrees = a.getFloat(R.styleable.Rotate3dAnimation_fromDeg, 0.0f); mToDegrees = a.getFloat(R.styleable.Rotate3dAnimation_toDeg, 0.0f); mRollType = a.getInt(R.styleable.Rotate3dAnimation_rollType, ROLL_BY_X); Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotX)); mPivotXType = d.type; mPivotXValue = d.value; d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY)); mPivotYType = d.type; mPivotYValue = d.value; a.recycle(); initializePivotPoint(); } public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees) { mRollType = rollType; mFromDegrees = fromDegrees; mToDegrees = toDegrees; mPivotX = 0.0f; mPivotY = 0.0f; } public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, float pivotX, float pivotY) { mRollType = rollType; mFromDegrees = fromDegrees; mToDegrees = toDegrees; mPivotXType = ABSOLUTE; mPivotYType = ABSOLUTE; mPivotXValue = pivotX; mPivotYValue = pivotY; initializePivotPoint(); } public Rotate3dAnimation (int rollType, float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) { mRollType = rollType; mFromDegrees = fromDegrees; mToDegrees = toDegrees; mPivotXValue = pivotXValue; mPivotXType = pivotXType; mPivotYValue = pivotYValue; mPivotYType = pivotYType; initializePivotPoint(); } private void initializePivotPoint() { if (mPivotXType == ABSOLUTE) { mPivotX = mPivotXValue; } if (mPivotYType == ABSOLUTE) { mPivotY = mPivotYValue; } } @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); mCamera = new Camera(); mPivotX = resolveSize(mPivotXType, mPivotXValue, width, parentWidth); mPivotY = resolveSize(mPivotYType, mPivotYValue, height, parentHeight); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final float fromDegrees = mFromDegrees; float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); final Matrix matrix = t.getMatrix(); mCamera.save(); switch (mRollType) { case ROLL_BY_X: mCamera.rotateX(degrees); break; case ROLL_BY_Y: mCamera.rotateY(degrees); break; case ROLL_BY_Z: mCamera.rotateZ(degrees); break; } mCamera.getMatrix(matrix); mCamera.restore(); matrix.preTranslate(-mPivotX, -mPivotY); matrix.postTranslate(mPivotX, mPivotY); } } ================================================ FILE: library/src/main/java/cn/pedant/SweetAlert/SuccessTickView.java ================================================ package cn.pedant.SweetAlert; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; import android.view.animation.Animation; import android.view.animation.Transformation; public class SuccessTickView extends View { private float mDensity = -1; private Paint mPaint; private final float CONST_RADIUS = dip2px(1.2f); private final float CONST_RECT_WEIGHT = dip2px(3); private final float CONST_LEFT_RECT_W = dip2px(15); private final float CONST_RIGHT_RECT_W = dip2px(25); private final float MIN_LEFT_RECT_W = dip2px(3.3f); private final float MAX_RIGHT_RECT_W = CONST_RIGHT_RECT_W + dip2px(6.7f); private float mMaxLeftRectWidth; private float mLeftRectWidth; private float mRightRectWidth; private boolean mLeftRectGrowMode; public SuccessTickView(Context context) { super(context); init(); } public SuccessTickView(Context context, AttributeSet attrs){ super(context,attrs); init(); } private void init () { mPaint = new Paint(); mPaint.setColor(getResources().getColor(R.color.success_stroke_color)); mLeftRectWidth = CONST_LEFT_RECT_W; mRightRectWidth = CONST_RIGHT_RECT_W; mLeftRectGrowMode = false; } @Override public void draw(Canvas canvas) { super.draw(canvas); int totalW = getWidth(); int totalH = getHeight(); // rotate canvas first canvas.rotate(45, totalW / 2, totalH / 2); totalW /= 1.2; totalH /= 1.4; mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; RectF leftRect = new RectF(); if (mLeftRectGrowMode) { leftRect.left = 0; leftRect.right = leftRect.left + mLeftRectWidth; leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2; leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT; } else { leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; leftRect.left = leftRect.right - mLeftRectWidth; leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2; leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT; } canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint); RectF rightRect = new RectF(); rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1; rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2; rightRect.right = rightRect.left + CONST_RECT_WEIGHT; rightRect.top = rightRect.bottom - mRightRectWidth; canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint); } public float dip2px(float dpValue) { if(mDensity == -1) { mDensity = getResources().getDisplayMetrics().density; } return dpValue * mDensity + 0.5f; } public void startTickAnim () { // hide tick mLeftRectWidth = 0; mRightRectWidth = 0; invalidate(); Animation tickAnim = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); if (0.54 < interpolatedTime && 0.7 >= interpolatedTime) { // grow left and right rect to right mLeftRectGrowMode = true; mLeftRectWidth = mMaxLeftRectWidth * ((interpolatedTime - 0.54f) / 0.16f); if (0.65 < interpolatedTime) { mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f); } invalidate(); } else if (0.7 < interpolatedTime && 0.84 >= interpolatedTime) { // shorten left rect from right, still grow right rect mLeftRectGrowMode = false; mLeftRectWidth = mMaxLeftRectWidth * (1 - ((interpolatedTime - 0.7f) / 0.14f)); mLeftRectWidth = mLeftRectWidth < MIN_LEFT_RECT_W ? MIN_LEFT_RECT_W : mLeftRectWidth; mRightRectWidth = MAX_RIGHT_RECT_W * ((interpolatedTime - 0.65f) / 0.19f); invalidate(); } else if (0.84 < interpolatedTime && 1 >= interpolatedTime) { // restore left rect width, shorten right rect to const mLeftRectGrowMode = false; mLeftRectWidth = MIN_LEFT_RECT_W + (CONST_LEFT_RECT_W - MIN_LEFT_RECT_W) * ((interpolatedTime - 0.84f) / 0.16f); mRightRectWidth = CONST_RIGHT_RECT_W + (MAX_RIGHT_RECT_W - CONST_RIGHT_RECT_W) * (1 - ((interpolatedTime - 0.84f) / 0.16f)); invalidate(); } } }; tickAnim.setDuration(750); tickAnim.setStartOffset(100); startAnimation(tickAnim); } } ================================================ FILE: library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java ================================================ package cn.pedant.SweetAlert; import android.app.Dialog; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.AnimationSet; import android.view.animation.Transformation; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import com.pnikosis.materialishprogress.ProgressWheel; import java.util.List; public class SweetAlertDialog extends Dialog implements View.OnClickListener { private View mDialogView; private AnimationSet mModalInAnim; private AnimationSet mModalOutAnim; private Animation mOverlayOutAnim; private Animation mErrorInAnim; private AnimationSet mErrorXInAnim; private AnimationSet mSuccessLayoutAnimSet; private Animation mSuccessBowAnim; private TextView mTitleTextView; private TextView mContentTextView; private String mTitleText; private String mContentText; private boolean mShowCancel; private boolean mShowContent; private String mCancelText; private String mConfirmText; private int mAlertType; private FrameLayout mErrorFrame; private FrameLayout mSuccessFrame; private FrameLayout mProgressFrame; private SuccessTickView mSuccessTick; private ImageView mErrorX; private View mSuccessLeftMask; private View mSuccessRightMask; private Drawable mCustomImgDrawable; private ImageView mCustomImage; private Button mConfirmButton; private Button mCancelButton; private ProgressHelper mProgressHelper; private FrameLayout mWarningFrame; private OnSweetClickListener mCancelClickListener; private OnSweetClickListener mConfirmClickListener; private boolean mCloseFromCancel; public static final int NORMAL_TYPE = 0; public static final int ERROR_TYPE = 1; public static final int SUCCESS_TYPE = 2; public static final int WARNING_TYPE = 3; public static final int CUSTOM_IMAGE_TYPE = 4; public static final int PROGRESS_TYPE = 5; public static interface OnSweetClickListener { public void onClick (SweetAlertDialog sweetAlertDialog); } public SweetAlertDialog(Context context) { this(context, NORMAL_TYPE); } public SweetAlertDialog(Context context, int alertType) { super(context, R.style.alert_dialog); setCancelable(true); setCanceledOnTouchOutside(false); mProgressHelper = new ProgressHelper(context); mAlertType = alertType; mErrorInAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.error_frame_in); mErrorXInAnim = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.error_x_in); // 2.3.x system don't support alpha-animation on layer-list drawable // remove it from animation set if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { List childAnims = mErrorXInAnim.getAnimations(); int idx = 0; for (;idx < childAnims.size();idx++) { if (childAnims.get(idx) instanceof AlphaAnimation) { break; } } if (idx < childAnims.size()) { childAnims.remove(idx); } } mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate); mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout); mModalInAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_in); mModalOutAnim = (AnimationSet) OptAnimationLoader.loadAnimation(getContext(), R.anim.modal_out); mModalOutAnim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mDialogView.setVisibility(View.GONE); mDialogView.post(new Runnable() { @Override public void run() { if (mCloseFromCancel) { SweetAlertDialog.super.cancel(); } else { SweetAlertDialog.super.dismiss(); } } }); } @Override public void onAnimationRepeat(Animation animation) { } }); // dialog overlay fade out mOverlayOutAnim = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { WindowManager.LayoutParams wlp = getWindow().getAttributes(); wlp.alpha = 1 - interpolatedTime; getWindow().setAttributes(wlp); } }; mOverlayOutAnim.setDuration(120); } protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.alert_dialog); mDialogView = getWindow().getDecorView().findViewById(android.R.id.content); mTitleTextView = (TextView)findViewById(R.id.title_text); mContentTextView = (TextView)findViewById(R.id.content_text); mErrorFrame = (FrameLayout)findViewById(R.id.error_frame); mErrorX = (ImageView)mErrorFrame.findViewById(R.id.error_x); mSuccessFrame = (FrameLayout)findViewById(R.id.success_frame); mProgressFrame = (FrameLayout)findViewById(R.id.progress_dialog); mSuccessTick = (SuccessTickView)mSuccessFrame.findViewById(R.id.success_tick); mSuccessLeftMask = mSuccessFrame.findViewById(R.id.mask_left); mSuccessRightMask = mSuccessFrame.findViewById(R.id.mask_right); mCustomImage = (ImageView)findViewById(R.id.custom_image); mWarningFrame = (FrameLayout)findViewById(R.id.warning_frame); mConfirmButton = (Button)findViewById(R.id.confirm_button); mCancelButton = (Button)findViewById(R.id.cancel_button); mProgressHelper.setProgressWheel((ProgressWheel)findViewById(R.id.progressWheel)); mConfirmButton.setOnClickListener(this); mCancelButton.setOnClickListener(this); setTitleText(mTitleText); setContentText(mContentText); setCancelText(mCancelText); setConfirmText(mConfirmText); changeAlertType(mAlertType, true); } private void restore () { mCustomImage.setVisibility(View.GONE); mErrorFrame.setVisibility(View.GONE); mSuccessFrame.setVisibility(View.GONE); mWarningFrame.setVisibility(View.GONE); mProgressFrame.setVisibility(View.GONE); mConfirmButton.setVisibility(View.VISIBLE); mConfirmButton.setBackgroundResource(R.drawable.blue_button_background); mErrorFrame.clearAnimation(); mErrorX.clearAnimation(); mSuccessTick.clearAnimation(); mSuccessLeftMask.clearAnimation(); mSuccessRightMask.clearAnimation(); } private void playAnimation () { if (mAlertType == ERROR_TYPE) { mErrorFrame.startAnimation(mErrorInAnim); mErrorX.startAnimation(mErrorXInAnim); } else if (mAlertType == SUCCESS_TYPE) { mSuccessTick.startTickAnim(); mSuccessRightMask.startAnimation(mSuccessBowAnim); } } private void changeAlertType(int alertType, boolean fromCreate) { mAlertType = alertType; // call after created views if (mDialogView != null) { if (!fromCreate) { // restore all of views state before switching alert type restore(); } switch (mAlertType) { case ERROR_TYPE: mErrorFrame.setVisibility(View.VISIBLE); break; case SUCCESS_TYPE: mSuccessFrame.setVisibility(View.VISIBLE); // initial rotate layout of success mask mSuccessLeftMask.startAnimation(mSuccessLayoutAnimSet.getAnimations().get(0)); mSuccessRightMask.startAnimation(mSuccessLayoutAnimSet.getAnimations().get(1)); break; case WARNING_TYPE: mConfirmButton.setBackgroundResource(R.drawable.red_button_background); mWarningFrame.setVisibility(View.VISIBLE); break; case CUSTOM_IMAGE_TYPE: setCustomImage(mCustomImgDrawable); break; case PROGRESS_TYPE: mProgressFrame.setVisibility(View.VISIBLE); mConfirmButton.setVisibility(View.GONE); break; } if (!fromCreate) { playAnimation(); } } } public int getAlerType () { return mAlertType; } public void changeAlertType(int alertType) { changeAlertType(alertType, false); } public String getTitleText () { return mTitleText; } public SweetAlertDialog setTitleText (String text) { mTitleText = text; if (mTitleTextView != null && mTitleText != null) { mTitleTextView.setText(mTitleText); } return this; } public SweetAlertDialog setCustomImage (Drawable drawable) { mCustomImgDrawable = drawable; if (mCustomImage != null && mCustomImgDrawable != null) { mCustomImage.setVisibility(View.VISIBLE); mCustomImage.setImageDrawable(mCustomImgDrawable); } return this; } public SweetAlertDialog setCustomImage (int resourceId) { return setCustomImage(getContext().getResources().getDrawable(resourceId)); } public String getContentText () { return mContentText; } public SweetAlertDialog setContentText (String text) { mContentText = text; if (mContentTextView != null && mContentText != null) { showContentText(true); mContentTextView.setText(mContentText); } return this; } public boolean isShowCancelButton () { return mShowCancel; } public SweetAlertDialog showCancelButton (boolean isShow) { mShowCancel = isShow; if (mCancelButton != null) { mCancelButton.setVisibility(mShowCancel ? View.VISIBLE : View.GONE); } return this; } public boolean isShowContentText () { return mShowContent; } public SweetAlertDialog showContentText (boolean isShow) { mShowContent = isShow; if (mContentTextView != null) { mContentTextView.setVisibility(mShowContent ? View.VISIBLE : View.GONE); } return this; } public String getCancelText () { return mCancelText; } public SweetAlertDialog setCancelText (String text) { mCancelText = text; if (mCancelButton != null && mCancelText != null) { showCancelButton(true); mCancelButton.setText(mCancelText); } return this; } public String getConfirmText () { return mConfirmText; } public SweetAlertDialog setConfirmText (String text) { mConfirmText = text; if (mConfirmButton != null && mConfirmText != null) { mConfirmButton.setText(mConfirmText); } return this; } public SweetAlertDialog setCancelClickListener (OnSweetClickListener listener) { mCancelClickListener = listener; return this; } public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener) { mConfirmClickListener = listener; return this; } protected void onStart() { mDialogView.startAnimation(mModalInAnim); playAnimation(); } /** * The real Dialog.cancel() will be invoked async-ly after the animation finishes. */ @Override public void cancel() { dismissWithAnimation(true); } /** * The real Dialog.dismiss() will be invoked async-ly after the animation finishes. */ public void dismissWithAnimation() { dismissWithAnimation(false); } private void dismissWithAnimation(boolean fromCancel) { mCloseFromCancel = fromCancel; mConfirmButton.startAnimation(mOverlayOutAnim); mDialogView.startAnimation(mModalOutAnim); } @Override public void onClick(View v) { if (v.getId() == R.id.cancel_button) { if (mCancelClickListener != null) { mCancelClickListener.onClick(SweetAlertDialog.this); } else { dismissWithAnimation(); } } else if (v.getId() == R.id.confirm_button) { if (mConfirmClickListener != null) { mConfirmClickListener.onClick(SweetAlertDialog.this); } else { dismissWithAnimation(); } } } public ProgressHelper getProgressHelper () { return mProgressHelper; } } ================================================ FILE: library/src/main/res/anim/error_frame_in.xml ================================================ ================================================ FILE: library/src/main/res/anim/error_x_in.xml ================================================ ================================================ FILE: library/src/main/res/anim/modal_in.xml ================================================ ================================================ FILE: library/src/main/res/anim/modal_out.xml ================================================ ================================================ FILE: library/src/main/res/anim/success_bow_roate.xml ================================================ ================================================ FILE: library/src/main/res/anim/success_mask_layout.xml ================================================ ================================================ FILE: library/src/main/res/drawable/blue_button_background.xml ================================================ ================================================ FILE: library/src/main/res/drawable/dialog_background.xml ================================================ ================================================ FILE: library/src/main/res/drawable/error_center_x.xml ================================================ ================================================ FILE: library/src/main/res/drawable/error_circle.xml ================================================ ================================================ FILE: library/src/main/res/drawable/gray_button_background.xml ================================================ ================================================ FILE: library/src/main/res/drawable/red_button_background.xml ================================================ ================================================ FILE: library/src/main/res/drawable/success_bow.xml ================================================ ================================================ FILE: library/src/main/res/drawable/success_circle.xml ================================================ ================================================ FILE: library/src/main/res/drawable/warning_circle.xml ================================================ ================================================ FILE: library/src/main/res/drawable/warning_sigh.xml ================================================ ================================================ FILE: library/src/main/res/layout/alert_dialog.xml ================================================