diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..0d383352
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,43 @@
+# Created by .ignore support plugin (hsz.mobi)
+### Android template
+# Built application files
+*.apk
+*.ap_
+
+# Files for the ART/Dalvik VM
+*.dex
+
+# Java class files
+*.class
+
+# Generated files
+bin/
+gen/
+out/
+
+# Gradle files
+.gradle/
+build/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Proguard folder generated by Eclipse
+proguard/
+
+# Log Files
+*.log
+
+# Android Studio Navigation editor temp files
+.navigation/
+
+# Android Studio captures folder
+captures/
+
+# Intellij
+*.iml
+.idea/
+
+# Keystore files
+*.jks
+
diff --git a/README.md b/README.md
index d4567296..ca8c453a 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,36 @@ Sweet Alert Dialog
===================
SweetAlert for Android, a beautiful and clever alert dialog
+#### This is the most advanced and contemporary fork of the apparently dead project
+**Added:**
+- Ability to set custom view
+- More convenient interface to bind listeners (like in AlertDialog)
+- Third neutral button with own listener, colors, methods and etc.
+- Ability to disable buttons
+- Ability to set buttons stroke width
+- Dark style of dialogs
+- Ability to make dialogs without buttons
+- Support of HTML tags
+- Ability to set text size
+- Ability to set buttons color
+
+Some screenshots of the new features:
+
+
+
+
+
+#### Known issues:
+- [ ] Bug with buttons height if custom view too big and need scrollview
+- [ ] Buttons can handle only one line strings
+
[](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)
+[Demo Download](https://github.com/F0RIS/sweet-alert-dialog/releases/download/1.5.3/sample-v1.5.3.apk)
## ScreenShot

@@ -19,9 +42,9 @@ The simplest way to use SweetAlertDialog is to add the library as aar dependency
**Maven**
- cn.pedant.sweetalert
+ com.github.f0ris.sweetalert
library
- 1.3
+ 1.6.2
aar
@@ -32,7 +55,7 @@ The simplest way to use SweetAlertDialog is to add the library as aar dependency
}
dependencies {
- compile 'cn.pedant.sweetalert:library:1.3'
+ implementation 'com.github.f0ris.sweetalert:library:1.6.2'
}
## Usage
@@ -115,7 +138,17 @@ A message with a custom icon:
.setCustomImage(R.drawable.custom_img)
.show();
-Bind the listener to confirm button:
+A message with a custom view:
+
+ final EditText editText = new EditText(this);
+ new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Custom view")
+ .setConfirmText("Ok")
+ .setCustomView(editText)
+ .show();
+
+
+Different ways to bind the listener to button:
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure?")
@@ -127,24 +160,32 @@ Bind the listener to confirm button:
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() {
+ .setCancelButton("Cancel", new SweetAlertDialog.OnSweetClickListener() {
@Override
public void onClick(SweetAlertDialog sDialog) {
- sDialog.cancel();
+ sDialog.dismissWithAnimation();
}
})
.show();
+
+Disable button
+
+ final SweetAlertDialog disabledBtnDialog = new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Title")
+ .setContentText("Disabled button dialog")
+ .setConfirmText("Confirm")
+ .setCancelText("Cancel")
+
+ disabledBtnDialog.setOnShowListener(new DialogInterface.OnShowListener() {
+ @Override
+ public void onShow(DialogInterface dialog) {
+ disabledBtnDialog.getButton(SweetAlertDialog.BUTTON_CONFIRM).setEnabled(false);
+ }
+ });
+ disabledBtnDialog.show();
+
+
**Change** the dialog style upon confirming:
new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
diff --git a/README.zh.md b/README.zh.md
deleted file mode 100644
index d114fbf1..00000000
--- a/README.zh.md
+++ /dev/null
@@ -1,192 +0,0 @@
-Sweet Alert Dialog
-===================
-Android版的SweetAlert,清新文艺,快意灵动的甜心弹框
-
-[](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)
-
-## 运行示意图
-
-
-## 安装
-使用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();
-
-
-
-你可以通过**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.
-
-
diff --git a/build.gradle b/build.gradle
index 88583e9d..977f0849 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,19 +1,28 @@
buildscript {
repositories {
mavenCentral()
+ jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
dependencies {
- classpath 'com.android.tools.build:gradle:0.14.1'
+ classpath 'com.android.tools.build:gradle:3.5.3'
}
}
ext {
- compileSdkVersion = 21
- buildToolsVersion = "19.1.0"
+ compileSdkVersion = 28
}
allprojects {
repositories {
mavenCentral()
+ jcenter()
+ maven {
+ url 'https://maven.google.com/'
+ name 'Google'
+ }
}
}
diff --git a/gradle.properties b/gradle.properties
index f62a8f4b..9a5eee07 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,14 +1,14 @@
-VERSION_NAME=1.3
-VERSION_CODE=4
-GROUP=cn.pedant.sweetalert
+VERSION_NAME=1.6.2
+VERSION_CODE=14
+GROUP=com.github.f0ris.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_URL=https://github.com/F0RIS/sweet-alert-dialog
+POM_SCM_URL=https://github.com/F0RIS/sweet-alert-dialog
+POM_SCM_CONNECTION=scm:git@github.com:F0RIS/sweet-alert-dialog.git
+POM_SCM_DEV_CONNECTION=scm:git@github.com:F0RIS/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
+POM_DEVELOPER_ID=f0ris
+POM_DEVELOPER_NAME=F0RIS
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 8a6b0613..c60b14f7 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Tue Dec 02 17:43:17 CET 2014
+#Sat Feb 15 19:36:06 IRST 2020
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
\ No newline at end of file
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index 8e4eabc6..da2d790d 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -5,7 +5,6 @@ group = GROUP
android {
compileSdkVersion rootProject.ext.compileSdkVersion
- buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion 9
@@ -17,7 +16,10 @@ android {
}
dependencies {
- compile 'com.pnikosis:materialish-progress:1.0'
+ implementation 'com.pnikosis:materialish-progress:1.7'
}
-apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
\ No newline at end of file
+apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
+/* upload command:
+ gradlew -p library clean build uploadArchives --info
+ */
\ No newline at end of file
diff --git a/library/gradle.properties b/library/gradle.properties
index b989904e..65f52fe9 100644
--- a/library/gradle.properties
+++ b/library/gradle.properties
@@ -1,3 +1,5 @@
-POM_NAME=SweetAlertDialog-Library
+POM_NAME=sweetalert
POM_ARTIFACT_ID=library
-POM_PACKAGING=aar
\ No newline at end of file
+POM_PACKAGING=jar
+RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
+SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots
\ No newline at end of file
diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml
index 6426f3f4..a5303d6f 100644
--- a/library/src/main/AndroidManifest.xml
+++ b/library/src/main/AndroidManifest.xml
@@ -1,10 +1,9 @@
+ package="cn.pedant.SweetAlert"
+ android:versionCode="14"
+ android:versionName="1.6.2">
-
-
-
+
+
\ No newline at end of file
diff --git a/library/src/main/java/cn/pedant/SweetAlert/Constants.java b/library/src/main/java/cn/pedant/SweetAlert/Constants.java
new file mode 100644
index 00000000..a6994529
--- /dev/null
+++ b/library/src/main/java/cn/pedant/SweetAlert/Constants.java
@@ -0,0 +1,30 @@
+package cn.pedant.SweetAlert;
+
+import android.graphics.PorterDuff;
+import android.graphics.drawable.Drawable;
+import android.view.MotionEvent;
+import android.view.View;
+
+public class Constants {
+ //make bg a little bit darker
+ public static final View.OnTouchListener FOCUS_TOUCH_LISTENER = new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ Drawable drawable = v.getBackground();
+ switch (event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ case MotionEvent.ACTION_BUTTON_PRESS:
+
+ drawable.setColorFilter(0x20000000, PorterDuff.Mode.SRC_ATOP);
+ v.invalidate();
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ drawable.clearColorFilter();
+ v.invalidate();
+ break;
+ }
+ return false;
+ }
+ };
+}
diff --git a/library/src/main/java/cn/pedant/SweetAlert/OptAnimationLoader.java b/library/src/main/java/cn/pedant/SweetAlert/OptAnimationLoader.java
index 371b35f9..6d441fa1 100644
--- a/library/src/main/java/cn/pedant/SweetAlert/OptAnimationLoader.java
+++ b/library/src/main/java/cn/pedant/SweetAlert/OptAnimationLoader.java
@@ -59,23 +59,30 @@ private static Animation createAnimationFromXml(Context c, XmlPullParser parser,
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());
- }
+ switch (name) {
+ case "set":
+ anim = new AnimationSet(c, attrs);
+ createAnimationFromXml(c, parser, (AnimationSet) anim, attrs);
+ break;
+ case "alpha":
+ anim = new AlphaAnimation(c, attrs);
+ break;
+ case "scale":
+ anim = new ScaleAnimation(c, attrs);
+ break;
+ case "rotate":
+ anim = new RotateAnimation(c, attrs);
+ break;
+ case "translate":
+ anim = new TranslateAnimation(c, attrs);
+ break;
+ default:
+ 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());
+ }
+ break;
}
if (parent != null) {
@@ -86,4 +93,4 @@ private static Animation createAnimationFromXml(Context c, XmlPullParser parser,
return anim;
}
-}
+}
\ No newline at end of file
diff --git a/library/src/main/java/cn/pedant/SweetAlert/Rotate3dAnimation.java b/library/src/main/java/cn/pedant/SweetAlert/Rotate3dAnimation.java
index d71473b0..30aaf41e 100644
--- a/library/src/main/java/cn/pedant/SweetAlert/Rotate3dAnimation.java
+++ b/library/src/main/java/cn/pedant/SweetAlert/Rotate3dAnimation.java
@@ -69,11 +69,11 @@ public Rotate3dAnimation (Context context, AttributeSet attrs) {
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));
+ Description d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_customPivotX));
mPivotXType = d.type;
mPivotXValue = d.value;
- d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_pivotY));
+ d = parseValue(a.peekValue(R.styleable.Rotate3dAnimation_customPivotY));
mPivotYType = d.type;
mPivotYValue = d.value;
diff --git a/library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java b/library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
index 77be52dd..916641ca 100644
--- a/library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
+++ b/library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
@@ -1,20 +1,31 @@
package cn.pedant.SweetAlert;
+import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
+import android.text.Html;
+import android.util.TypedValue;
import android.view.View;
+import android.view.ViewGroup;
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.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
import com.pnikosis.materialishprogress.ProgressWheel;
@@ -32,12 +43,19 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private Animation mSuccessBowAnim;
private TextView mTitleTextView;
private TextView mContentTextView;
+ private FrameLayout mCustomViewContainer;
+ private View mCustomView;
private String mTitleText;
private String mContentText;
private boolean mShowCancel;
private boolean mShowContent;
private String mCancelText;
private String mConfirmText;
+ private int mTitleSize;
+ private int mContentSize;
+ private int mButtonsSize;
+ private Typeface mTf;
+ private String mNeutralText;
private int mAlertType;
private FrameLayout mErrorFrame;
private FrameLayout mSuccessFrame;
@@ -48,13 +66,25 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private View mSuccessRightMask;
private Drawable mCustomImgDrawable;
private ImageView mCustomImage;
+ private LinearLayout mButtonsContainer;
private Button mConfirmButton;
+ private boolean mHideConfirmButton = false;
private Button mCancelButton;
+ private Button mNeutralButton;
+ private Integer mConfirmButtonBackgroundColor;
+ private Integer mConfirmButtonTextColor;
+ private Integer mNeutralButtonBackgroundColor;
+ private Integer mNeutralButtonTextColor;
+ private Integer mCancelButtonBackgroundColor;
+ private Integer mCancelButtonTextColor;
private ProgressHelper mProgressHelper;
private FrameLayout mWarningFrame;
private OnSweetClickListener mCancelClickListener;
private OnSweetClickListener mConfirmClickListener;
+ private OnSweetClickListener mNeutralClickListener;
private boolean mCloseFromCancel;
+ private boolean mHideKeyBoardOnDismiss = true;
+ private int contentTextSize = 0;
public static final int NORMAL_TYPE = 0;
public static final int ERROR_TYPE = 1;
@@ -63,8 +93,24 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
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 static boolean DARK_STYLE = false;
+
+ //aliases
+ public final static int BUTTON_CONFIRM = DialogInterface.BUTTON_POSITIVE;
+ public final static int BUTTON_CANCEL = DialogInterface.BUTTON_NEGATIVE;
+
+ private final float defStrokeWidth;
+ private float strokeWidth = 0;
+
+
+ public SweetAlertDialog hideConfirmButton() {
+ this.mHideConfirmButton = true;
+ return this;
+ }
+
+ public interface OnSweetClickListener {
+ void onClick(SweetAlertDialog sweetAlertDialog);
}
public SweetAlertDialog(Context context) {
@@ -72,19 +118,23 @@ public SweetAlertDialog(Context context) {
}
public SweetAlertDialog(Context context, int alertType) {
- super(context, R.style.alert_dialog);
+ super(context, DARK_STYLE ? R.style.alert_dialog_dark : R.style.alert_dialog_light);
setCancelable(true);
- setCanceledOnTouchOutside(false);
+ setCanceledOnTouchOutside(true); //TODO was false
+
+ defStrokeWidth = getContext().getResources().getDimension(R.dimen.buttons_stroke_width);
+ strokeWidth = defStrokeWidth;
+
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);
+ 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++) {
+ for (; idx < childAnims.size(); idx++) {
if (childAnims.get(idx) instanceof AlphaAnimation) {
break;
}
@@ -94,7 +144,7 @@ public SweetAlertDialog(Context context, int alertType) {
}
}
mSuccessBowAnim = OptAnimationLoader.loadAnimation(getContext(), R.anim.success_bow_roate);
- mSuccessLayoutAnimSet = (AnimationSet)OptAnimationLoader.loadAnimation(getContext(), R.anim.success_mask_layout);
+ 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() {
@@ -106,6 +156,9 @@ public void onAnimationStart(Animation animation) {
@Override
public void onAnimationEnd(Animation animation) {
mDialogView.setVisibility(View.GONE);
+ if (mHideKeyBoardOnDismiss) {
+ hideSoftKeyboard();
+ }
mDialogView.post(new Runnable() {
@Override
public void run() {
@@ -140,40 +193,63 @@ protected void onCreate(Bundle 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);
+ mTitleTextView = findViewById(R.id.title_text);
+ mContentTextView = findViewById(R.id.content_text);
+ mCustomViewContainer = findViewById(R.id.custom_view_container);
+ mErrorFrame = findViewById(R.id.error_frame);
+ mErrorX = mErrorFrame.findViewById(R.id.error_x);
+ mSuccessFrame = findViewById(R.id.success_frame);
+ mProgressFrame = findViewById(R.id.progress_dialog);
+ mSuccessTick = 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));
+ mCustomImage = findViewById(R.id.custom_image);
+ mWarningFrame = findViewById(R.id.warning_frame);
+ mButtonsContainer = findViewById(R.id.buttons_container);
+ mConfirmButton = findViewById(R.id.confirm_button);
mConfirmButton.setOnClickListener(this);
+ mConfirmButton.setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER);
+ mCancelButton = findViewById(R.id.cancel_button);
mCancelButton.setOnClickListener(this);
+ mCancelButton.setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER);
+ mNeutralButton = findViewById(R.id.neutral_button);
+ mNeutralButton.setOnClickListener(this);
+ mNeutralButton.setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER);
+ mProgressHelper.setProgressWheel((ProgressWheel) findViewById(R.id.progressWheel));
setTitleText(mTitleText);
setContentText(mContentText);
+ setCustomView(mCustomView);
setCancelText(mCancelText);
setConfirmText(mConfirmText);
+ setTitleTextSize(mTitleSize);
+ setContentTextSize(mContentSize);
+ setButtonsTextSize(mButtonsSize);
+ setTypeface(mTf);
+ setNeutralText(mNeutralText);
+ applyStroke();
+ setConfirmButtonBackgroundColor(mConfirmButtonBackgroundColor);
+ setConfirmButtonTextColor(mConfirmButtonTextColor);
+ setCancelButtonBackgroundColor(mCancelButtonBackgroundColor);
+ setCancelButtonTextColor(mCancelButtonTextColor);
+ setNeutralButtonBackgroundColor(mNeutralButtonBackgroundColor);
+ setNeutralButtonTextColor(mNeutralButtonTextColor);
changeAlertType(mAlertType, true);
}
- private void restore () {
+ 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);
+ mConfirmButton.setVisibility(mHideConfirmButton ? View.GONE : View.VISIBLE);
+
+ adjustButtonContainerVisibility();
+
+ mConfirmButton.setBackgroundResource(R.drawable.green_button_background);
mErrorFrame.clearAnimation();
mErrorX.clearAnimation();
mSuccessTick.clearAnimation();
@@ -181,7 +257,75 @@ private void restore () {
mSuccessRightMask.clearAnimation();
}
- private void playAnimation () {
+
+ public SweetAlertDialog setTitleTextSize(int sps){
+ mTitleSize = sps;
+ if (mTitleTextView != null && mTitleSize != 0) {
+ mTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sps);
+ }
+
+
+ return this;
+ }
+
+ public SweetAlertDialog setContentTextSize(int sps){
+ mContentSize = sps;
+ if (mContentTextView != null && mContentSize != 0) {
+ mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, sps);
+ }
+
+ return this;
+ }
+
+ public SweetAlertDialog setButtonsTextSize(int sps){
+ mButtonsSize = sps;
+ if (mCancelButton != null && mButtonsSize != 0) {
+ mCancelButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, sps);
+ }
+
+ if (mConfirmButton != null && mButtonsSize != 0) {
+ mConfirmButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, sps);
+ }
+
+ return this;
+ }
+
+ public SweetAlertDialog setTypeface(Typeface tf){
+ mTf = tf;
+ if (mTitleTextView != null && mTf != null) {
+ mTitleTextView.setTypeface(tf);
+ }
+ if (mContentTextView != null && mTf != null) {
+ mContentTextView.setTypeface(tf);
+ }
+
+ if (mCancelButton != null && mTf != null) {
+ mCancelButton.setTypeface(tf);
+ }
+
+ if (mConfirmButton != null && mTf != null) {
+ mConfirmButton.setTypeface(tf);
+ }
+ return this;
+ }
+
+ /**
+ * Hides buttons container if all buttons are invisible or gone.
+ * This deletes useless margins
+ */
+ private void adjustButtonContainerVisibility() {
+ boolean showButtonsContainer = false;
+ for (int i = 0; i < mButtonsContainer.getChildCount(); i++) {
+ View view = mButtonsContainer.getChildAt(i);
+ if (view instanceof Button && view.getVisibility() == View.VISIBLE) {
+ showButtonsContainer = true;
+ break;
+ }
+ }
+ mButtonsContainer.setVisibility(showButtonsContainer ? View.VISIBLE : View.GONE);
+ }
+
+ private void playAnimation() {
if (mAlertType == ERROR_TYPE) {
mErrorFrame.startAnimation(mErrorInAnim);
mErrorX.startAnimation(mErrorXInAnim);
@@ -199,6 +343,7 @@ private void changeAlertType(int alertType, boolean fromCreate) {
// restore all of views state before switching alert type
restore();
}
+ mConfirmButton.setVisibility(mHideConfirmButton ? View.GONE : View.VISIBLE);
switch (mAlertType) {
case ERROR_TYPE:
mErrorFrame.setVisibility(View.VISIBLE);
@@ -210,7 +355,7 @@ private void changeAlertType(int alertType, boolean fromCreate) {
mSuccessRightMask.startAnimation(mSuccessLayoutAnimSet.getAnimations().get(1));
break;
case WARNING_TYPE:
- mConfirmButton.setBackgroundResource(R.drawable.red_button_background);
+// mConfirmButton.setBackgroundResource(R.drawable.red_button_background);
mWarningFrame.setVisibility(View.VISIBLE);
break;
case CUSTOM_IMAGE_TYPE:
@@ -219,15 +364,17 @@ private void changeAlertType(int alertType, boolean fromCreate) {
case PROGRESS_TYPE:
mProgressFrame.setVisibility(View.VISIBLE);
mConfirmButton.setVisibility(View.GONE);
+// mButtonsContainer.setVisibility(View.GONE);
break;
}
+ adjustButtonContainerVisibility();
if (!fromCreate) {
playAnimation();
}
}
}
- public int getAlerType () {
+ public int getAlertType() {
return mAlertType;
}
@@ -236,19 +383,28 @@ public void changeAlertType(int alertType) {
}
- public String getTitleText () {
+ public String getTitleText() {
return mTitleText;
}
- public SweetAlertDialog setTitleText (String text) {
+ public SweetAlertDialog setTitleText(String text) {
mTitleText = text;
if (mTitleTextView != null && mTitleText != null) {
- mTitleTextView.setText(mTitleText);
+ if (text.isEmpty()) {
+ mTitleTextView.setVisibility(View.GONE);
+ } else {
+ mTitleTextView.setVisibility(View.VISIBLE);
+ mTitleTextView.setText(Html.fromHtml(mTitleText));
+ }
}
return this;
}
- public SweetAlertDialog setCustomImage (Drawable drawable) {
+ public SweetAlertDialog setTitleText(int resId) {
+ return setTitleText(getContext().getResources().getString(resId));
+ }
+
+ public SweetAlertDialog setCustomImage(Drawable drawable) {
mCustomImgDrawable = drawable;
if (mCustomImage != null && mCustomImgDrawable != null) {
mCustomImage.setVisibility(View.VISIBLE);
@@ -257,28 +413,57 @@ public SweetAlertDialog setCustomImage (Drawable drawable) {
return this;
}
- public SweetAlertDialog setCustomImage (int resourceId) {
+ public SweetAlertDialog setCustomImage(int resourceId) {
return setCustomImage(getContext().getResources().getDrawable(resourceId));
}
- public String getContentText () {
+ public String getContentText() {
return mContentText;
}
- public SweetAlertDialog setContentText (String text) {
+ /**
+ * @param text text which can contain html tags.
+ */
+ public SweetAlertDialog setContentText(String text) {
mContentText = text;
if (mContentTextView != null && mContentText != null) {
showContentText(true);
- mContentTextView.setText(mContentText);
+ if (contentTextSize != 0) {
+ mContentTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, spToPx(contentTextSize, getContext()));
+ }
+ mContentTextView.setText(Html.fromHtml(mContentText));
+ mContentTextView.setVisibility(View.VISIBLE);
+ mCustomViewContainer.setVisibility(View.GONE);
}
return this;
}
- public boolean isShowCancelButton () {
+ public static int spToPx(float sp, Context context) {
+ return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
+ }
+
+ /**
+ * @param width in SP
+ */
+ public SweetAlertDialog setStrokeWidth(float width) {
+ this.strokeWidth = spToPx(width, getContext());
+ return this;
+ }
+
+ private void applyStroke() {
+ if (Float.compare(defStrokeWidth, strokeWidth) != 0) {
+ Resources r = getContext().getResources();
+ setButtonBackgroundColor(mConfirmButton, r.getColor(R.color.main_green_color));
+ setButtonBackgroundColor(mNeutralButton, r.getColor(R.color.main_disabled_color));
+ setButtonBackgroundColor(mCancelButton, r.getColor(R.color.red_btn_bg_color));
+ }
+ }
+
+ public boolean isShowCancelButton() {
return mShowCancel;
}
- public SweetAlertDialog showCancelButton (boolean isShow) {
+ public SweetAlertDialog showCancelButton(boolean isShow) {
mShowCancel = isShow;
if (mCancelButton != null) {
mCancelButton.setVisibility(mShowCancel ? View.VISIBLE : View.GONE);
@@ -286,11 +471,11 @@ public SweetAlertDialog showCancelButton (boolean isShow) {
return this;
}
- public boolean isShowContentText () {
+ public boolean isShowContentText() {
return mShowContent;
}
- public SweetAlertDialog showContentText (boolean isShow) {
+ public SweetAlertDialog showContentText(boolean isShow) {
mShowContent = isShow;
if (mContentTextView != null) {
mContentTextView.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
@@ -298,11 +483,11 @@ public SweetAlertDialog showContentText (boolean isShow) {
return this;
}
- public String getCancelText () {
+ public String getCancelText() {
return mCancelText;
}
- public SweetAlertDialog setCancelText (String text) {
+ public SweetAlertDialog setCancelText(String text) {
mCancelText = text;
if (mCancelButton != null && mCancelText != null) {
showCancelButton(true);
@@ -311,11 +496,11 @@ public SweetAlertDialog setCancelText (String text) {
return this;
}
- public String getConfirmText () {
+ public String getConfirmText() {
return mConfirmText;
}
- public SweetAlertDialog setConfirmText (String text) {
+ public SweetAlertDialog setConfirmText(String text) {
mConfirmText = text;
if (mConfirmButton != null && mConfirmText != null) {
mConfirmButton.setText(mConfirmText);
@@ -323,21 +508,200 @@ public SweetAlertDialog setConfirmText (String text) {
return this;
}
- public SweetAlertDialog setCancelClickListener (OnSweetClickListener listener) {
+ public SweetAlertDialog setConfirmButtonBackgroundColor(Integer color) {
+ mConfirmButtonBackgroundColor = color;
+ setButtonBackgroundColor(mConfirmButton, color);
+ return this;
+ }
+
+ public Integer getConfirmButtonBackgroundColor() {
+ return mConfirmButtonBackgroundColor;
+ }
+
+ public SweetAlertDialog setNeutralButtonBackgroundColor(Integer color) {
+ mNeutralButtonBackgroundColor = color;
+ setButtonBackgroundColor(mNeutralButton, color);
+ return this;
+ }
+
+ public Integer getNeutralButtonBackgroundColor() {
+ return mNeutralButtonBackgroundColor;
+ }
+
+ public SweetAlertDialog setCancelButtonBackgroundColor(Integer color) {
+ mCancelButtonBackgroundColor = color;
+ setButtonBackgroundColor(mCancelButton, color);
+ return this;
+ }
+
+ public Integer getCancelButtonBackgroundColor() {
+ return mCancelButtonBackgroundColor;
+ }
+
+ private void setButtonBackgroundColor(Button btn, Integer color) {
+ if (btn != null && color != null) {
+ Drawable[] drawableItems = ViewUtils.getDrawable(btn);
+ if (drawableItems != null) {
+ GradientDrawable gradientDrawableUnChecked = (GradientDrawable) drawableItems[1];
+ //solid color
+ gradientDrawableUnChecked.setColor(color);
+ //stroke
+ gradientDrawableUnChecked.setStroke((int) strokeWidth, genStrokeColor(color));
+ }
+ }
+ }
+
+ private int genStrokeColor(int color) {
+ float hsv[] = new float[3];
+ Color.colorToHSV(color, hsv);
+ hsv[2] *= 0.7f; // decrease value component
+ return Color.HSVToColor(hsv);
+ }
+
+ public SweetAlertDialog setConfirmButtonTextColor(Integer color) {
+ mConfirmButtonTextColor = color;
+ if (mConfirmButton != null && color != null) {
+ mConfirmButton.setTextColor(mConfirmButtonTextColor);
+ }
+ return this;
+ }
+
+ public Integer getConfirmButtonTextColor() {
+ return mConfirmButtonTextColor;
+ }
+
+ public SweetAlertDialog setNeutralButtonTextColor(Integer color) {
+ mNeutralButtonTextColor = color;
+ if (mNeutralButton != null && color != null) {
+ mNeutralButton.setTextColor(mNeutralButtonTextColor);
+ }
+ return this;
+ }
+
+ public Integer getNeutralButtonTextColor() {
+ return mNeutralButtonTextColor;
+ }
+
+ public SweetAlertDialog setCancelButtonTextColor(Integer color) {
+ mCancelButtonTextColor = color;
+ if (mCancelButton != null && color != null) {
+ mCancelButton.setTextColor(mCancelButtonTextColor);
+ }
+ return this;
+ }
+
+ public Integer getCancelButtonTextColor() {
+ return mCancelButtonTextColor;
+ }
+
+ public SweetAlertDialog setCancelClickListener(OnSweetClickListener listener) {
mCancelClickListener = listener;
return this;
}
- public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener) {
+ public SweetAlertDialog setConfirmClickListener(OnSweetClickListener listener) {
mConfirmClickListener = listener;
return this;
}
+ public SweetAlertDialog setNeutralText(String text) {
+ mNeutralText = text;
+ if (mNeutralButton != null && mNeutralText != null && !text.isEmpty()) {
+ mNeutralButton.setVisibility(View.VISIBLE);
+ mNeutralButton.setText(mNeutralText);
+ }
+ return this;
+ }
+
+ public SweetAlertDialog setNeutralClickListener(OnSweetClickListener listener) {
+ mNeutralClickListener = listener;
+ return this;
+ }
+
+ @Override
+ public void setTitle(CharSequence title) {
+ this.setTitleText(title.toString());
+ }
+
+ @Override
+ public void setTitle(int titleId) {
+ this.setTitleText(getContext().getResources().getString(titleId));
+ }
+
+ public Button getButton(int buttonType) {
+ switch (buttonType) {
+ default:
+ case BUTTON_CONFIRM:
+ return mConfirmButton;
+ case BUTTON_CANCEL:
+ return mCancelButton;
+ case BUTTON_NEUTRAL:
+ return mNeutralButton;
+ }
+ }
+
+ public SweetAlertDialog setConfirmButton(String text, OnSweetClickListener listener) {
+ this.setConfirmText(text);
+ this.setConfirmClickListener(listener);
+ return this;
+ }
+
+ public SweetAlertDialog setConfirmButton(int resId, OnSweetClickListener listener) {
+ String text = getContext().getResources().getString(resId);
+ setConfirmButton(text, listener);
+ return this;
+ }
+
+
+ public SweetAlertDialog setCancelButton(String text, OnSweetClickListener listener) {
+ this.setCancelText(text);
+ this.setCancelClickListener(listener);
+ return this;
+ }
+
+ public SweetAlertDialog setCancelButton(int resId, OnSweetClickListener listener) {
+ String text = getContext().getResources().getString(resId);
+ setCancelButton(text, listener);
+ return this;
+ }
+
+ public SweetAlertDialog setNeutralButton(String text, OnSweetClickListener listener) {
+ this.setNeutralText(text);
+ this.setNeutralClickListener(listener);
+ return this;
+ }
+
+ public SweetAlertDialog setNeutralButton(int resId, OnSweetClickListener listener) {
+ String text = getContext().getResources().getString(resId);
+ setNeutralButton(text, listener);
+ return this;
+ }
+
+
+ public int getContentTextSize() {
+ return contentTextSize;
+ }
+
protected void onStart() {
mDialogView.startAnimation(mModalInAnim);
playAnimation();
}
+ /**
+ * set custom view instead of message
+ *
+ * @param view
+ */
+ public SweetAlertDialog setCustomView(View view) {
+ mCustomView = view;
+ if (mCustomView != null && mCustomViewContainer != null) {
+ mCustomViewContainer.addView(view);
+ mCustomViewContainer.setVisibility(View.VISIBLE);
+ mContentTextView.setVisibility(View.GONE);
+ }
+ return this;
+ }
+
/**
* The real Dialog.cancel() will be invoked async-ly after the animation finishes.
*/
@@ -355,8 +719,9 @@ public void dismissWithAnimation() {
private void dismissWithAnimation(boolean fromCancel) {
mCloseFromCancel = fromCancel;
- mConfirmButton.startAnimation(mOverlayOutAnim);
- mDialogView.startAnimation(mModalOutAnim);
+ //several view animations can't be launched at one view, that's why apply alpha animation on child
+ ((ViewGroup) mDialogView).getChildAt(0).startAnimation(mOverlayOutAnim); //alpha animation
+ mDialogView.startAnimation(mModalOutAnim); //scale animation
}
@Override
@@ -373,10 +738,35 @@ public void onClick(View v) {
} else {
dismissWithAnimation();
}
+ } else if (v.getId() == R.id.neutral_button) {
+ if (mNeutralClickListener != null) {
+ mNeutralClickListener.onClick(SweetAlertDialog.this);
+ } else {
+ dismissWithAnimation();
+ }
}
}
- public ProgressHelper getProgressHelper () {
+ public ProgressHelper getProgressHelper() {
return mProgressHelper;
}
+
+ public SweetAlertDialog setHideKeyBoardOnDismiss(boolean hide) {
+ this.mHideKeyBoardOnDismiss = hide;
+ return this;
+ }
+
+ public boolean isHideKeyBoardOnDismiss() {
+ return this.mHideKeyBoardOnDismiss;
+ }
+
+ private void hideSoftKeyboard() {
+ Activity activity = getOwnerActivity();
+ if (activity != null) {
+ InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
+ if (inputMethodManager != null && activity.getCurrentFocus() != null) {
+ inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/library/src/main/java/cn/pedant/SweetAlert/ViewUtils.java b/library/src/main/java/cn/pedant/SweetAlert/ViewUtils.java
new file mode 100644
index 00000000..3a0cdad0
--- /dev/null
+++ b/library/src/main/java/cn/pedant/SweetAlert/ViewUtils.java
@@ -0,0 +1,19 @@
+package cn.pedant.SweetAlert;
+
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.DrawableContainer;
+import android.graphics.drawable.StateListDrawable;
+import android.view.View;
+
+public class ViewUtils {
+
+ static Drawable[] getDrawable(View view) {
+ StateListDrawable drawable = (StateListDrawable) view.getBackground();
+ DrawableContainer.DrawableContainerState dcs = (DrawableContainer.DrawableContainerState) drawable.getConstantState();
+ if (dcs != null) {
+ return dcs.getChildren();
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/library/src/main/res/anim/error_frame_in.xml b/library/src/main/res/anim/error_frame_in.xml
index f777451a..cfd5f473 100644
--- a/library/src/main/res/anim/error_frame_in.xml
+++ b/library/src/main/res/anim/error_frame_in.xml
@@ -14,7 +14,7 @@
sweet:rollType="x"
sweet:fromDeg="100"
sweet:toDeg="0"
- sweet:pivotX="50%"
- sweet:pivotY="50%"
+ sweet:customPivotX="50%"
+ sweet:customPivotY="50%"
android:duration="400"/>
\ No newline at end of file
diff --git a/library/src/main/res/drawable/blue_button_background.xml b/library/src/main/res/drawable/blue_button_background.xml
index 0e597b42..d768b563 100644
--- a/library/src/main/res/drawable/blue_button_background.xml
+++ b/library/src/main/res/drawable/blue_button_background.xml
@@ -1,15 +1,17 @@
- -
+
-
-
-
+
+
+
-
+
-
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/dialog_background.xml b/library/src/main/res/drawable/dialog_background.xml
index 4c4a5e72..6dbf1b8c 100644
--- a/library/src/main/res/drawable/dialog_background.xml
+++ b/library/src/main/res/drawable/dialog_background.xml
@@ -1,5 +1,5 @@
-
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/dialog_background_dark.xml b/library/src/main/res/drawable/dialog_background_dark.xml
new file mode 100644
index 00000000..1957d110
--- /dev/null
+++ b/library/src/main/res/drawable/dialog_background_dark.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/gray_button_background.xml b/library/src/main/res/drawable/gray_button_background.xml
index 04e807d0..14d2051b 100644
--- a/library/src/main/res/drawable/gray_button_background.xml
+++ b/library/src/main/res/drawable/gray_button_background.xml
@@ -1,15 +1,17 @@
- -
+
-
-
-
+
+
+
-
+
-
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/green_button_background.xml b/library/src/main/res/drawable/green_button_background.xml
new file mode 100644
index 00000000..1102b403
--- /dev/null
+++ b/library/src/main/res/drawable/green_button_background.xml
@@ -0,0 +1,17 @@
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/drawable/red_button_background.xml b/library/src/main/res/drawable/red_button_background.xml
index a0ef0823..16b16f04 100644
--- a/library/src/main/res/drawable/red_button_background.xml
+++ b/library/src/main/res/drawable/red_button_background.xml
@@ -1,15 +1,17 @@
- -
+
-
-
-
+
+
+
-
+
-
+
\ No newline at end of file
diff --git a/library/src/main/res/layout/alert_dialog.xml b/library/src/main/res/layout/alert_dialog.xml
index 7972157f..c705a433 100644
--- a/library/src/main/res/layout/alert_dialog.xml
+++ b/library/src/main/res/layout/alert_dialog.xml
@@ -1,160 +1,213 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:background="?attr/sweet_alert_bg_drawable"
+ android:layoutDirection="ltr">
-
-
-
-
-
-
-
-
+ android:minWidth="@dimen/alert_width"
+ android:orientation="vertical"
+ android:paddingBottom="15dp"
+ android:paddingLeft="30dp"
+ android:paddingRight="30dp"
+ android:paddingTop="10dp">
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+ tools:text="message \n message \n message"
+ tools:visibility="visible">
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
\ No newline at end of file
+
diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml
index 1bf0493f..ac3f2c69 100644
--- a/library/src/main/res/values/attrs.xml
+++ b/library/src/main/res/values/attrs.xml
@@ -8,7 +8,11 @@
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml
index 8cf71f4a..d8bc778b 100644
--- a/library/src/main/res/values/colors.xml
+++ b/library/src/main/res/values/colors.xml
@@ -1,7 +1,13 @@
#00000000
+
+ #F27474
+
#FFFFFF
+
+ #e6222222
+
#FFFFFF
#D0D0D0
#B6B6B6
@@ -19,4 +25,24 @@
#ff21272b
#ff80cbc4
#ff009688
+
+ #575757
+ #fff
+ #797979
+ #fff
+
+
+ #6bd505
+ #60bf04
+ #f77805
+ #e66f04
+ #f7b90d
+ #e4ab0c
+ #2469df
+ #205ec7
+ #05d9f7
+ #05c7e2
+
+ #838383
+ #707070
\ No newline at end of file
diff --git a/library/src/main/res/values/dimen.xml b/library/src/main/res/values/dimens.xml
similarity index 67%
rename from library/src/main/res/values/dimen.xml
rename to library/src/main/res/values/dimens.xml
index 454ef6bb..87ff4bff 100644
--- a/library/src/main/res/values/dimen.xml
+++ b/library/src/main/res/values/dimens.xml
@@ -3,4 +3,7 @@
290dp
3dp
34dp
+
+ 53dp
+ 0sp
\ No newline at end of file
diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml
index 3bb566c8..7de6c66c 100644
--- a/library/src/main/res/values/styles.xml
+++ b/library/src/main/res/values/styles.xml
@@ -1,6 +1,7 @@
-
+
+
+
\ No newline at end of file
diff --git a/sample/build.gradle b/sample/build.gradle
index 93b52a19..1dc3636c 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -5,11 +5,10 @@ group = GROUP
android {
compileSdkVersion rootProject.ext.compileSdkVersion
- buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
- minSdkVersion 9
- targetSdkVersion 21
+ minSdkVersion 13
+ targetSdkVersion 28
}
lintOptions {
@@ -27,5 +26,5 @@ android {
dependencies {
//compile 'cn.pedant.sweetalert:library:1.3'
- compile project(':library')
+ implementation project(':library')
}
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index c773687a..e5ac8bf9 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -1,15 +1,17 @@
-
-
-
+ package="cn.pedant.SweetAlert.sample">
+
+
+
-
-
+
+
diff --git a/sample/src/main/java/cn/pedant/SweetAlert/sample/SampleActivity.java b/sample/src/main/java/cn/pedant/SweetAlert/sample/SampleActivity.java
index ea7f2cd6..4c9d6b3c 100644
--- a/sample/src/main/java/cn/pedant/SweetAlert/sample/SampleActivity.java
+++ b/sample/src/main/java/cn/pedant/SweetAlert/sample/SampleActivity.java
@@ -1,10 +1,16 @@
package cn.pedant.SweetAlert.sample;
import android.app.Activity;
+import android.content.DialogInterface;
+import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import cn.pedant.SweetAlert.Constants;
import cn.pedant.SweetAlert.SweetAlertDialog;
public class SampleActivity extends Activity implements View.OnClickListener {
@@ -15,31 +21,51 @@ public class SampleActivity extends Activity implements View.OnClickListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity);
- findViewById(R.id.basic_test).setOnClickListener(this);
- findViewById(R.id.under_text_test).setOnClickListener(this);
- findViewById(R.id.error_text_test).setOnClickListener(this);
- findViewById(R.id.success_text_test).setOnClickListener(this);
- findViewById(R.id.warning_confirm_test).setOnClickListener(this);
- findViewById(R.id.warning_cancel_test).setOnClickListener(this);
- findViewById(R.id.custom_img_test).setOnClickListener(this);
- findViewById(R.id.progress_dialog).setOnClickListener(this);
+
+ int[] btnIds = {
+ R.id.basic_test, R.id.styled_text_and_stroke, R.id.basic_test_without_buttons, R.id.under_text_test,
+ R.id.error_text_test, R.id.success_text_test, R.id.warning_confirm_test, R.id.warning_cancel_test,
+ R.id.custom_img_test, R.id.progress_dialog, R.id.neutral_btn_test, R.id.disabled_btn_test, R.id.dark_style,
+ R.id.custom_view_test, R.id.custom_btn_colors_test
+ };
+ for (Integer id : btnIds) {
+ findViewById(id).setOnClickListener(this);
+ findViewById(id).setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER);
+ }
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.basic_test:
- // default title "Here's a message!"
SweetAlertDialog sd = new SweetAlertDialog(this);
sd.setCancelable(true);
sd.setCanceledOnTouchOutside(true);
+ sd.setContentText("Here's a message");
sd.show();
break;
+ case R.id.basic_test_without_buttons:
+ SweetAlertDialog sd2 = new SweetAlertDialog(this);
+ sd2.setCancelable(true);
+ sd2.setCanceledOnTouchOutside(true);
+ sd2.setContentText("Here's a message");
+ sd2.hideConfirmButton();
+ sd2.show();
+ break;
case R.id.under_text_test:
new SweetAlertDialog(this)
+ .setTitleText("Title")
.setContentText("It's pretty, isn't it?")
.show();
break;
+ case R.id.styled_text_and_stroke:
+ new SweetAlertDialog(this)
+ .setTitleText("Red title")
+ .setContentText("Big green bold")
+ .setContentTextSize(21)
+ .setStrokeWidth(2)
+ .show();
+ break;
case R.id.error_text_test:
new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Oops...")
@@ -56,17 +82,15 @@ public void onClick(View v) {
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) {
- // reuse previous dialog instance
- sDialog.setTitleText("Deleted!")
- .setContentText("Your imaginary file has been deleted!")
- .setConfirmText("OK")
- .setConfirmClickListener(null)
- .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
- }
+ .setCancelButton("Yes, delete it!", new SweetAlertDialog.OnSweetClickListener() {
+ @Override
+ public void onClick(SweetAlertDialog sweetAlertDialog) {
+ // reuse previous dialog instance
+ sweetAlertDialog.setTitleText("Deleted!")
+ .setContentText("Your imaginary file has been deleted!")
+ .setConfirmClickListener(null)
+ .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
+ }
})
.show();
break;
@@ -74,8 +98,8 @@ public void onClick(SweetAlertDialog sDialog) {
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!")
+ .setCancelText("No, cancel pls!")
+ .setConfirmText("Yes, delete it!")
.showCancelButton(true)
.setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
@Override
@@ -128,7 +152,7 @@ public void onClick(SweetAlertDialog sDialog) {
public void onTick(long millisUntilFinished) {
// you can change the progress bar color by ProgressHelper every 800 millis
i++;
- switch (i){
+ switch (i) {
case 0:
pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.blue_btn_bg_color));
break;
@@ -161,6 +185,78 @@ public void onFinish() {
}
}.start();
break;
+
+ case R.id.neutral_btn_test:
+ new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Title")
+ .setContentText("Three buttons dialog")
+ .setConfirmText("Confirm")
+ .setCancelText("Cancel")
+ .setNeutralText("Neutral")
+ .show();
+ break;
+
+ case R.id.disabled_btn_test:
+ final SweetAlertDialog disabledBtnDialog = new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Title")
+ .setContentText("Disabled button dialog")
+ .setConfirmText("OK")
+ .setCancelText("Cancel")
+ .setNeutralText("Neutral");
+
+ disabledBtnDialog.setOnShowListener(new DialogInterface.OnShowListener() {
+ @Override
+ public void onShow(DialogInterface dialog) {
+ disabledBtnDialog.getButton(SweetAlertDialog.BUTTON_CONFIRM).setEnabled(false);
+ }
+ });
+ disabledBtnDialog.show();
+ break;
+
+ case R.id.dark_style:
+ if (((CheckBox) v).isChecked()) {
+ SweetAlertDialog.DARK_STYLE = true;
+ } else {
+ SweetAlertDialog.DARK_STYLE = false;
+ }
+ break;
+
+ case R.id.custom_view_test:
+ final EditText editText = new EditText(this);
+ final CheckBox checkBox = new CheckBox(this);
+ editText.setText("Some edit text");
+ checkBox.setChecked(true);
+ checkBox.setText("Some checkbox");
+
+ if (SweetAlertDialog.DARK_STYLE) {
+ editText.setTextColor(Color.WHITE);
+ checkBox.setTextColor(Color.WHITE);
+ }
+
+ LinearLayout linearLayout = new LinearLayout(getApplicationContext());
+ linearLayout.setOrientation(LinearLayout.VERTICAL);
+ linearLayout.addView(editText);
+ linearLayout.addView(checkBox);
+
+ SweetAlertDialog dialog = new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Custom view")
+ .hideConfirmButton();
+
+ dialog.setCustomView(linearLayout);
+ dialog.show();
+ break;
+ case R.id.custom_btn_colors_test:
+ new SweetAlertDialog(this, SweetAlertDialog.NORMAL_TYPE)
+ .setTitleText("Custom view")
+ .setCancelButton("red", null)
+ .setCancelButtonBackgroundColor(Color.RED)
+ .setNeutralButton("cyan", null)
+ .setNeutralButtonBackgroundColor(Color.CYAN)
+ .setConfirmButton("blue", null)
+ .setConfirmButtonBackgroundColor(Color.BLUE)
+ .show();
+ break;
+
}
}
}
diff --git a/sample/src/main/res/layout/sample_activity.xml b/sample/src/main/res/layout/sample_activity.xml
index bc3fe382..59c9f5f2 100644
--- a/sample/src/main/res/layout/sample_activity.xml
+++ b/sample/src/main/res/layout/sample_activity.xml
@@ -1,181 +1,197 @@
-
+
+
+
-
-
-
-
-
-
-
+
+
+ android:layout_toRightOf="@id/logo_img"
+ android:scaleX="0.8"
+ android:scaleY="0.8"
+ android:text="Dark style"
+ android:textColor="@android:color/black" />
-
+ android:gravity="center"
+ android:orientation="vertical">
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
+
+
+ android:text="Try me!" />
+
+
+
+
-
-
-
+
+
+ android:text="Try me!" />
-
-
-
+
+
+ android:text="Try me!" />
-
-
-
+
+
+ android:text="Try me!" />
-
-
-
+
+
+ android:text="Try me!" />
-
-
-
+
+
+ android:text="Try me!" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml
new file mode 100644
index 00000000..0d75dd63
--- /dev/null
+++ b/sample/src/main/res/values/styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file