diff --git a/.idea/modules.xml b/.idea/modules.xml
index 68a39ce..dca0d95 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,9 +2,12 @@
+
+
-
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index dd3153a..c596039 100644
--- a/README.md
+++ b/README.md
@@ -22,8 +22,8 @@ The simplest way to use SweetAlertDialog is to add the library as aar dependency
```
dependencies {
- compile 'com.github.cazaea:sweet-alert-dialog:1.0.0'
- }
+ implementation 'com.github.yuxiaohui78:SweetAlertDialog:1.1.1'
+ }
```
**Gradle**(Project)
@@ -74,11 +74,46 @@ You can customize progress bar dynamically with materialish-progress methods via
- setRimColor(int rimColor)
- getSpinSpeed()
- setSpinSpeed(float spinSpeed)
+
+ - setDialogWidth (int dpWidth)
+ - setDialogHeight (int dpHeight)
+ - setDialogLayout (int dpWidth, int dpHeight)
+
thanks to the project [materialish-progress](https://github.com/pnikosis/materialish-progress) and [@pedant](https://github.com/pedant) participation.
more usages about progress, please see the sample.
+Touch the outside to cancel the dialog :
+
+ SweetAlertDialog sd = new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
+ .setCustomImage(R.drawable.pill_icon)
+ .setTitleText("3:00PM")
+ .setContentText("Asprin 50 mg. Take 2 pills")
+ .setNeutralText("Later")
+ .setCancelText("Skip it")
+ .setConfirmText("Take it!");
+
+ sd.setCancelable(true);
+ sd.setCanceledOnTouchOutside(true);
+ sd.show();
+ sd.setDialogWidth (300); //dynamically to change the dialog width (unit is dp)
+
+
+
+Add a neutral button :
+
+ new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
+ .setCustomImage(R.drawable.pill_icon)
+ .setTitleText("3:00PM")
+ .setContentText("Asprin 50 mg. Take 2 pills")
+ .setNeutralText("Later")
+ .setCancelText("Skip it")
+ .setConfirmText("Take it!")
+ .show();
+
+
+
A basic message:
new SweetAlertDialog(this)
@@ -173,6 +208,8 @@ Show the cancel button and bind listener to it:
}
})
.show();
+
+
[more android tech shares: cazaea.com](http://www.cazaea.com)
diff --git a/app/src/main/java/com/cazaea/sweetalert/sample/SampleActivity.java b/app/src/main/java/com/cazaea/sweetalert/sample/SampleActivity.java
index 7760917..6613d66 100644
--- a/app/src/main/java/com/cazaea/sweetalert/sample/SampleActivity.java
+++ b/app/src/main/java/com/cazaea/sweetalert/sample/SampleActivity.java
@@ -6,6 +6,7 @@
import android.os.Handler;
import android.view.View;
import android.widget.Switch;
+import android.widget.Toast;
import com.cazaea.sweetalert.SweetAlertDialog;
@@ -25,11 +26,48 @@ public void onCreate(Bundle savedInstanceState) {
findViewById(R.id.warning_cancel_test).setOnClickListener(this);
findViewById(R.id.custom_img_test).setOnClickListener(this);
findViewById(R.id.progress_dialog).setOnClickListener(this);
+ findViewById(R.id.three_button).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
+ case R.id.three_button:
+ SweetAlertDialog sd1 = new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
+ .setCustomImage(R.drawable.pill_icon)
+ .setTitleText("3:00PM")
+ .setContentText("Asprin 50 mg. Take 2 pills")
+ .setNeutralText("Later")
+ .setCancelText("Skip it")
+
+ .setConfirmText("Take it!")
+ .setNeutralClickListener(new SweetAlertDialog.OnSweetClickListener() {
+ @Override
+ public void onClick(SweetAlertDialog sweetAlertDialog) {
+ Toast.makeText(SampleActivity.this, "Take it later!", Toast.LENGTH_SHORT).show();
+ sweetAlertDialog.dismiss();
+ }
+ })
+ .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
+ @Override
+ public void onClick(SweetAlertDialog sweetAlertDialog) {
+ Toast.makeText(SampleActivity.this, "Skip it!", Toast.LENGTH_SHORT).show();
+ sweetAlertDialog.dismiss();
+ }
+ })
+ .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
+ @Override
+ public void onClick(SweetAlertDialog sweetAlertDialog) {
+ Toast.makeText(SampleActivity.this, "Take it now!", Toast.LENGTH_SHORT).show();
+ sweetAlertDialog.dismiss();
+ }
+ });
+
+ sd1.setCancelable(true);
+ sd1.setCanceledOnTouchOutside(true);
+ sd1.show();
+ sd1.setDialogLayout(320, 200);
+ break;
case R.id.basic_test:
// default title "Here's a message!"
SweetAlertDialog sd = new SweetAlertDialog(this);
@@ -84,7 +122,7 @@ public void onClick(SweetAlertDialog sDialog) {
.show();
break;
case R.id.warning_cancel_test:
- new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
+ SweetAlertDialog sdd = new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
.setTitleText("Are you sure?")
.setContentText("Won't be able to recover this file!")
.setCancelText("No,cancel plx!")
@@ -122,8 +160,11 @@ public void onClick(SweetAlertDialog sDialog) {
.setConfirmClickListener(null)
.changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
}
- })
- .show();
+ });
+
+
+ sdd.show();
+ sdd.setDialogWidth(300);
break;
case R.id.custom_img_test:
new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
diff --git a/app/src/main/res/drawable/pill_icon.png b/app/src/main/res/drawable/pill_icon.png
new file mode 100644
index 0000000..e8ab98e
Binary files /dev/null and b/app/src/main/res/drawable/pill_icon.png differ
diff --git a/app/src/main/res/layout/sample_activity.xml b/app/src/main/res/layout/sample_activity.xml
index 9d42335..c495df6 100644
--- a/app/src/main/res/layout/sample_activity.xml
+++ b/app/src/main/res/layout/sample_activity.xml
@@ -19,6 +19,8 @@
android:contentDescription="@string/app_name"
android:src="@drawable/logo_big" />
+
+
+
+
+
+
diff --git a/library/src/main/java/com/cazaea/sweetalert/SweetAlertDialog.java b/library/src/main/java/com/cazaea/sweetalert/SweetAlertDialog.java
index 7830ea6..f9d6269 100644
--- a/library/src/main/java/com/cazaea/sweetalert/SweetAlertDialog.java
+++ b/library/src/main/java/com/cazaea/sweetalert/SweetAlertDialog.java
@@ -5,6 +5,7 @@
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
+import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
@@ -14,6 +15,7 @@
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.TextView;
import com.cazaea.materialishprogress.ProgressWheel;
@@ -35,9 +37,11 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private String mContentText;
private boolean mShowCancel;
private boolean mShowConfirm;
+ private boolean mShowNeutral;
private boolean mShowContent;
private String mCancelText;
private String mConfirmText;
+ private String mNeutralText;
private int mAlertType;
private FrameLayout mErrorFrame;
private FrameLayout mSuccessFrame;
@@ -50,10 +54,12 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private ImageView mCustomImage;
private Button mConfirmButton;
private Button mCancelButton;
+ private Button mNeutralButton;
private ProgressHelper mProgressHelper;
private FrameLayout mWarningFrame;
private OnSweetClickListener mCancelClickListener;
private OnSweetClickListener mConfirmClickListener;
+ private OnSweetClickListener mNeutralClickListener;
private boolean mCloseFromCancel;
public static final int NORMAL_TYPE = 0;
@@ -153,16 +159,41 @@ protected void onCreate(Bundle savedInstanceState) {
mWarningFrame = (FrameLayout)findViewById(R.id.warning_frame);
mConfirmButton = (Button)findViewById(R.id.confirm_button);
mCancelButton = (Button)findViewById(R.id.cancel_button);
+ mNeutralButton = (Button)findViewById(R.id.neutral_button);
mProgressHelper.setProgressWheel((ProgressWheel)findViewById(R.id.progressWheel));
mConfirmButton.setOnClickListener(this);
mCancelButton.setOnClickListener(this);
+ mNeutralButton.setOnClickListener(this);
setTitleText(mTitleText);
setContentText(mContentText);
setCancelText(mCancelText);
+ setNeutralText(mNeutralText);
setConfirmText(mConfirmText);
changeAlertType(mAlertType, true);
+ }
+
+ public static float convertDpToPixel(float dp, Context context) {
+ return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
+ }
+
+ public void setDialogLayout (int dpWidth, int dpHeight){
+ LinearLayout ly = findViewById(R.id.loading);
+ ly.getLayoutParams().width = (int)convertDpToPixel(dpWidth, getContext());
+ ly.getLayoutParams().height = (int)convertDpToPixel(dpHeight, getContext());
+ ly.setLayoutParams(ly.getLayoutParams());
+ }
+
+ public void setDialogWidth (int dpWidth){
+ LinearLayout ly = findViewById(R.id.loading);
+ ly.getLayoutParams().width = (int)convertDpToPixel(dpWidth, getContext());
+ ly.setLayoutParams(ly.getLayoutParams());
+ }
+ public void setDialogHeight (int dpHeight){
+ LinearLayout ly = findViewById(R.id.loading);
+ ly.getLayoutParams().height = (int)convertDpToPixel(dpHeight, getContext());
+ ly.setLayoutParams(ly.getLayoutParams());
}
private void restore () {
@@ -274,6 +305,18 @@ public SweetAlertDialog setContentText (String text) {
return this;
}
+ public boolean isShowCancelButton () {
+ return mShowCancel;
+ }
+
+ public boolean isShowNeutralButton () {
+ return mShowNeutral;
+ }
+
+ public boolean isShowConfirmButton () {
+ return mShowConfirm;
+ }
+
public SweetAlertDialog showCancelButton (boolean isShow) {
mShowCancel = isShow;
if (mCancelButton != null) {
@@ -290,6 +333,18 @@ public SweetAlertDialog showConfirmButton (boolean isShow) {
return this;
}
+ public SweetAlertDialog showNeutralButton (boolean isShow) {
+ mShowNeutral = isShow;
+ if (mNeutralButton != null) {
+ mNeutralButton.setVisibility(mShowNeutral ? View.VISIBLE : View.GONE);
+ }
+ return this;
+ }
+
+ public boolean isShowContentText () {
+ return mShowContent;
+ }
+
public SweetAlertDialog showContentText (boolean isShow) {
mShowContent = isShow;
if (mContentTextView != null) {
@@ -315,6 +370,19 @@ public String getConfirmText () {
return mConfirmText;
}
+ public SweetAlertDialog setNeutralText (String text) {
+ mNeutralText = text;
+ if (mNeutralButton != null && mNeutralText != null) {
+ showNeutralButton(true);
+ mNeutralButton.setText(mNeutralText);
+ }
+ return this;
+ }
+
+ public String getNeutralText() {
+ return mNeutralText;
+ }
+
public SweetAlertDialog setConfirmText (String text) {
mConfirmText = text;
if (mConfirmButton != null && mConfirmText != null) {
@@ -334,6 +402,11 @@ public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener)
return this;
}
+ public SweetAlertDialog setNeutralClickListener (OnSweetClickListener listener) {
+ mNeutralClickListener = listener;
+ return this;
+ }
+
protected void onStart() {
mDialogView.startAnimation(mModalInAnim);
playAnimation();
@@ -374,6 +447,12 @@ public void onClick(View v) {
} else {
dismissWithAnimation();
}
+ } else if (v.getId() == R.id.neutral_button) {
+ if (mNeutralClickListener != null) {
+ mNeutralClickListener.onClick(SweetAlertDialog.this);
+ } else {
+ dismissWithAnimation();
+ }
}
}
diff --git a/library/src/main/res/layout/alert_dialog.xml b/library/src/main/res/layout/alert_dialog.xml
index 5cca431..d69c8cf 100644
--- a/library/src/main/res/layout/alert_dialog.xml
+++ b/library/src/main/res/layout/alert_dialog.xml
@@ -153,6 +153,14 @@
android:text="@string/dialog_cancel"
android:visibility="gone" />
+
+