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

Added the ability to set margins and set padding on the button container #50

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.gradle
build
local.properties
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.1.0'
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}

dependencies {
compile 'com.pnikosis:materialish-progress:1.0'
compile 'com.pnikosis:materialish-progress:1.5'
}

apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
95 changes: 95 additions & 0 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?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="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<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" 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/generated/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/generated/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/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-22.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
<orderEntry type="library" exported="" name="materialish-progress-1.5" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
</component>
</module>
Binary file added library/src/main/assets/noasarck.otf
Binary file not shown.
160 changes: 156 additions & 4 deletions library/src/main/java/cn/pedant/SweetAlert/SweetAlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@

import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
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.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.*;

import com.pnikosis.materialishprogress.ProgressWheel;

Expand All @@ -38,10 +39,15 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private boolean mShowContent;
private String mCancelText;
private String mConfirmText;
private int mTitleSize;
private int mContentSize;
private int mButtonsSize;
private Typeface mTf;
private int mAlertType;
private FrameLayout mErrorFrame;
private FrameLayout mSuccessFrame;
private FrameLayout mProgressFrame;
private LinearLayout mButtonContainer;
private SuccessTickView mSuccessTick;
private ImageView mErrorX;
private View mSuccessLeftMask;
Expand All @@ -55,13 +61,23 @@ public class SweetAlertDialog extends Dialog implements View.OnClickListener {
private OnSweetClickListener mCancelClickListener;
private OnSweetClickListener mConfirmClickListener;
private boolean mCloseFromCancel;
private MediaPlayer mp;

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;
private int mButtonsPaddingLeft;
private int mButtonsPaddingTop;
private int mButtonsPaddingRight;
private int mButtonsPaddingBottom;
private int mButtonContainerMarginLeft;
private int mButtonContainerMarginTop;
private int mButtonContainerMarginRight;
private int mButtonContainerMarginBottom;
private int mButtonHeight;

public static interface OnSweetClickListener {
public void onClick (SweetAlertDialog sweetAlertDialog);
Expand Down Expand Up @@ -153,6 +169,7 @@ 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);
mButtonContainer = (LinearLayout)findViewById(R.id.button_container);
mProgressHelper.setProgressWheel((ProgressWheel)findViewById(R.id.progressWheel));
mConfirmButton.setOnClickListener(this);
mCancelButton.setOnClickListener(this);
Expand All @@ -161,6 +178,14 @@ protected void onCreate(Bundle savedInstanceState) {
setContentText(mContentText);
setCancelText(mCancelText);
setConfirmText(mConfirmText);
setTitleTextSize(mTitleSize);
setContentTextSize(mContentSize);
setButtonsTextSize(mButtonsSize);
setButtonPadding(mButtonsPaddingLeft, mButtonsPaddingTop, mButtonsPaddingRight, mButtonsPaddingBottom);
setButtonContainerMargins(mButtonContainerMarginLeft, mButtonContainerMarginTop, mButtonContainerMarginRight,
mButtonContainerMarginBottom);
setButtonHeight(mButtonHeight);
setTypeface(mTf);
changeAlertType(mAlertType, true);

}
Expand Down Expand Up @@ -248,6 +273,121 @@ public SweetAlertDialog setTitleText (String text) {
return this;
}

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;
}

/**
* Sets the margins for the button container on the bottom.
* @param left The left in pixels
* @param top The top in pixels
* @param right The right in pixels
* @param bottom The bottom in pixels
* @return
*/
public SweetAlertDialog setButtonContainerMargins(int left, int top, int right, int bottom) {
mButtonContainerMarginLeft = left;
mButtonContainerMarginTop = top;
mButtonContainerMarginRight = right;
mButtonContainerMarginBottom = bottom;

if (mButtonContainer != null) {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mButtonContainer.getLayoutParams();
params.setMargins(mButtonContainerMarginLeft, mButtonContainerMarginTop, mButtonContainerMarginRight, mButtonContainerMarginBottom);
mButtonContainer.setLayoutParams(params);
}
return this;
}

/**
* Sets the padding for both the cancel and confirm buttons.
* @param left
* @param top
* @param right
* @param bottom
* @return
*/
public SweetAlertDialog setButtonPadding(int left, int top, int right, int bottom) {
mButtonsPaddingLeft = left;
mButtonsPaddingTop = top;
mButtonsPaddingRight = right;
mButtonsPaddingBottom = bottom;

if (mCancelButton != null) {
mCancelButton.setPadding(mButtonsPaddingLeft, mButtonsPaddingTop, mButtonsPaddingRight, mButtonsPaddingBottom);
}

if (mConfirmButton != null) {
mConfirmButton.setPadding(mButtonsPaddingLeft, mButtonsPaddingTop, mButtonsPaddingRight, mButtonsPaddingBottom);
}

return this;
}

public SweetAlertDialog setButtonHeight(int pixels) {
mButtonHeight = pixels;
if (mCancelButton != null && mButtonHeight != 0) {
ViewGroup.LayoutParams layoutParams = mCancelButton.getLayoutParams();
layoutParams.height = pixels;
mCancelButton.setLayoutParams(layoutParams);
}

if (mConfirmButton != null && mButtonHeight != 0) {
ViewGroup.LayoutParams layoutParams = mConfirmButton.getLayoutParams();
layoutParams.height = pixels;
mConfirmButton.setLayoutParams(layoutParams);
}

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;
}

public SweetAlertDialog setCustomImage (Drawable drawable) {
mCustomImgDrawable = drawable;
if (mCustomImage != null && mCustomImgDrawable != null) {
Expand Down Expand Up @@ -333,6 +473,13 @@ public SweetAlertDialog setConfirmClickListener (OnSweetClickListener listener)
return this;
}

public SweetAlertDialog setMediaPlayer(MediaPlayer mp){
this.mp = mp;

return this;
}


protected void onStart() {
mDialogView.startAnimation(mModalInAnim);
playAnimation();
Expand Down Expand Up @@ -361,6 +508,11 @@ private void dismissWithAnimation(boolean fromCancel) {

@Override
public void onClick(View v) {

if(mp != null){
mp.start();
}

if (v.getId() == R.id.cancel_button) {
if (mCancelClickListener != null) {
mCancelClickListener.onClick(SweetAlertDialog.this);
Expand Down
4 changes: 2 additions & 2 deletions library/src/main/res/drawable/blue_button_background.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/blue_btn_bg_pressed_color" />
<corners android:radius="6dp"/>
<corners android:radius="2dp"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/blue_btn_bg_color" />
<corners android:radius="6dp"/>
<corners android:radius="2dp"/>
</shape>
</item>
</selector>
2 changes: 1 addition & 1 deletion library/src/main/res/drawable/dialog_background.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/sweet_dialog_bg_color" />
<corners android:radius="6dp"/>
<corners android:radius="2dp"/>
</shape>
4 changes: 2 additions & 2 deletions library/src/main/res/drawable/error_center_x.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<rotate android:fromDegrees="45" android:toDegrees="45" android:pivotX="50%" android:pivotY="50%">
<shape android:shape="rectangle">
<solid android:color="@color/error_stroke_color"/>
<corners android:radius="4dp"/>
<corners android:radius="2dp"/>
<size android:height="3dp" android:width="28dp"/>
</shape>
</rotate>
Expand All @@ -14,7 +14,7 @@
<rotate android:fromDegrees="315" android:toDegrees="315" android:pivotX="50%" android:pivotY="50%">
<shape android:shape="rectangle">
<solid android:color="@color/error_stroke_color"/>
<corners android:radius="4dp"/>
<corners android:radius="2dp"/>
<size android:height="3dp" android:width="28dp"/>
</shape>
</rotate>
Expand Down
Loading