Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button changes #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.gradle
/local.properties
/.idea
.DS_Store
/build
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sweet Alert Dialog
Sweet Alert Dialog
===================
SweetAlert for Android, a beautiful and clever alert dialog

Expand Down Expand Up @@ -76,20 +76,23 @@ A basic message:

new SweetAlertDialog(this)
.setTitleText("Here's a message!")
.setConfirmText("OK")
.show();

A title with a text under:

new SweetAlertDialog(this)
.setTitleText("Here's a message!")
.setContentText("It's pretty, isn't it?")
.setConfirmText("OK")
.show();

A error message:

new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
.setTitleText("Oops...")
.setContentText("Something went wrong!")
.setConfirmText("OK")
.show();

A warning message:
Expand All @@ -105,6 +108,7 @@ A success message:
new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.setConfirmText("OK")
.show();

A message with a custom icon:
Expand All @@ -113,6 +117,7 @@ A message with a custom icon:
.setTitleText("Sweet!")
.setContentText("Here's a custom image.")
.setCustomImage(R.drawable.custom_img)
.setConfirmText("OK")
.show();

Bind the listener to confirm button:
Expand Down Expand Up @@ -164,6 +169,23 @@ Show the cancel button and bind listener to it:
})
.show();

Show a dialog without buttons:

new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Congratulations!")
.setContentText("You created a dialog without buttons!")
.show();

Dialog with **three** buttons! Neutral, cancel, confirm.

new SweetAlertDialog(this)
.setTitleText("Three buttons!")
.setContentText("There's never enough buttons. I like buttons.")
.setNeutralText("Maybe")
.setCancelText("No")
.setConfirmText("Yes")
.show();

[more android tech shares: pedant.cn](http://www.pedant.cn)

## License
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.1'
classpath 'com.android.tools.build:gradle:1.3.0'
}
}

Expand Down
1 change: 1 addition & 0 deletions library/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
100 changes: 100 additions & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="cn.pedant.sweetalert" external.system.module.version="1.3" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":library" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<afterSyncTasks>
<task>generateDebugAndroidTestSources</task>
<task>generateDebugSources</task>
</afterSyncTasks>
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
<option name="LIBRARY_PROJECT" value="true" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/21.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.pnikosis/materialish-progress/1.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-21.0.0" level="project" />
<orderEntry type="library" exported="" name="materialish-progress-1.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
</component>
</module>
59 changes: 57 additions & 2 deletions library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private String mTitleText;
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;
Expand All @@ -50,10 +53,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;
Expand Down Expand Up @@ -153,13 +158,16 @@ 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);

Expand All @@ -171,7 +179,6 @@ private void restore () {
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();
Expand Down Expand Up @@ -218,7 +225,6 @@ private void changeAlertType(int alertType, boolean fromCreate) {
break;
case PROGRESS_TYPE:
mProgressFrame.setVisibility(View.VISIBLE);
mConfirmButton.setVisibility(View.GONE);
break;
}
if (!fromCreate) {
Expand Down Expand Up @@ -278,6 +284,14 @@ 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) {
Expand All @@ -286,6 +300,22 @@ public SweetAlertDialog showCancelButton (boolean isShow) {
return this;
}

public SweetAlertDialog showConfirmButton (boolean isShow) {
mShowConfirm = isShow;
if (mConfirmButton != null) {
mConfirmButton.setVisibility(mShowConfirm ? View.VISIBLE : View.GONE);
}
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;
}
Expand Down Expand Up @@ -315,9 +345,23 @@ 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) {
showConfirmButton(true);
mConfirmButton.setText(mConfirmText);
}
return this;
Expand All @@ -333,6 +377,11 @@ public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener)
return this;
}

public SweetAlertDialog setNeutralClickListener (OnSweetClickListener listener) {
mNeutralClickListener = listener;
return this;
}

protected void onStart() {
mDialogView.startAnimation(mModalInAnim);
playAnimation();
Expand Down Expand Up @@ -373,6 +422,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();
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion library/src/main/res/layout/alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
android:layout_height="wrap_content"
android:gravity="center">

<Button
android:id="@+id/neutral_button"
style="@style/dialog_blue_button"
android:background="@drawable/gray_button_background"
android:layout_marginRight="10dp"
android:visibility="gone"
android:text="@string/dialog_neutral" />

<Button
android:id="@+id/cancel_button"
style="@style/dialog_blue_button"
Expand All @@ -155,6 +163,7 @@
<Button
android:id="@+id/confirm_button"
style="@style/dialog_blue_button"
android:text="@string/dialog_ok" />
android:text="@string/dialog_ok"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
1 change: 1 addition & 0 deletions library/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<string name="dialog_default_title">Here\'s a message!</string>
<string name="dialog_ok">OK</string>
<string name="dialog_cancel">Cancel</string>
<string name="dialog_neutral">Neutral</string>
<string name="LOADING">Loading...</string>
</resources>
1 change: 1 addition & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading