Skip to content

Commit

Permalink
Feat: Andreid color removed from button background & test color. Hexa…
Browse files Browse the repository at this point in the history
… value is required now
  • Loading branch information
taimoorsultani committed Jun 24, 2021
1 parent c0cfcc7 commit 660e66e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 52 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The simplest way to use Sweetalert is to add the library as aar dependency to yo
<dependency>
<groupId>com.github.taimoorsultani</groupId>
<artifactId>android-sweetalert2</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>

**Gradle**
Expand All @@ -73,7 +73,7 @@ The simplest way to use Sweetalert is to add the library as aar dependency to yo
}

dependencies {
implementation 'com.github.taimoorsultani:android-sweetalert2:1.2.0'
implementation 'com.github.taimoorsultani:android-sweetalert2:1.3.0'
}

## Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -270,11 +272,14 @@ public void onFinish() {
.showCancelButton(true)
.showConfirmButton(true)
.setCancelButton("red", null)
.setCancelButtonBackgroundColor(Color.RED)
.setCancelButtonBackgroundColor("#5B2C6F")
.setCancelButtonTextColor("#D35400")
.setNeutralButton("cyan", null)
.setNeutralButtonBackgroundColor(Color.CYAN)
.setNeutralButtonBackgroundColor("#21618C")
.setNeutralButtonTextColor("#2ECC71")
.setConfirmButton("blue", null)
.setConfirmButtonBackgroundColor(Color.BLUE)
.setConfirmButtonBackgroundColor("#117864")
.setConfirmButtonTextColor("#EC7063")
.show();
break;

Expand Down
28 changes: 14 additions & 14 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
style="@style/description_style"
android:text="@string/show_material_progress" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/progress_dialog"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -52,7 +52,7 @@
style="@style/description_style"
android:text="@string/a_basic_message" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/basic_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -63,7 +63,7 @@
style="@style/description_style"
android:text="@string/a_basic_message_nwithout_buttons" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/basic_test_without_buttons"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -74,7 +74,7 @@
style="@style/description_style"
android:text="@string/a_title_with_a_text_under" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/under_text_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -84,7 +84,7 @@
style="@style/description_style"
android:text="@string/styled_text_and_stroke" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/styled_text_and_stroke"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -95,7 +95,7 @@
style="@style/description_style"
android:text="@string/show_error_message" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/error_text_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -106,7 +106,7 @@
style="@style/description_style"
android:text="@string/a_success_message" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/success_text_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -118,7 +118,7 @@
style="@style/description_style"
android:text="@string/a_warning_message_with_a_listener_bind_to_the_confirm_button" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/warning_confirm_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -129,7 +129,7 @@
style="@style/description_style"
android:text="@string/a_warning_message_with_listeners_bind_to_cancel_and_confirm_button" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/warning_cancel_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -140,7 +140,7 @@
style="@style/description_style"
android:text="@string/a_message_with_a_custom_icon" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/custom_img_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -151,7 +151,7 @@
style="@style/description_style"
android:text="@string/a_message_with_neutral_button" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/neutral_btn_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -162,7 +162,7 @@
style="@style/description_style"
android:text="@string/disabled_ok_button" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/disabled_btn_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -173,7 +173,7 @@
style="@style/description_style"
android:text="@string/custom_view" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/custom_view_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand All @@ -184,7 +184,7 @@
style="@style/description_style"
android:text="@string/custom_btn_colors" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/custom_btn_colors_test"
style="@style/dialog_blue_button"
android:layout_margin="@dimen/mp10"
Expand Down
5 changes: 3 additions & 2 deletions sweetalert2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 3
versionName "1.2.0"
versionCode 4
versionName "1.3.0"
}

buildTypes {
Expand All @@ -25,5 +25,6 @@ android {
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.pnikosis:materialish-progress:1.7'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
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.Log;
Expand Down Expand Up @@ -64,12 +66,12 @@ public class Sweetalert extends Dialog implements View.OnClickListener {
private boolean mShowConfirm = 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 String mConfirmButtonBackgroundColor;
private String mConfirmButtonTextColor;
private String mNeutralButtonBackgroundColor;
private String mNeutralButtonTextColor;
private String mCancelButtonBackgroundColor;
private String mCancelButtonTextColor;
private final ProgressHelper mProgressHelper;
private FrameLayout mWarningFrame;
private OnSweetClickListener mCancelClickListener;
Expand Down Expand Up @@ -379,9 +381,9 @@ public Sweetalert setStrokeWidth(float width) {
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));
setButtonBackgroundColor(mConfirmButton, "#6bd505");
setButtonBackgroundColor(mNeutralButton, "#838383");
setButtonBackgroundColor(mCancelButton, "#DD6B55");
}
}

Expand Down Expand Up @@ -442,45 +444,45 @@ public Sweetalert setConfirmText(String text) {
return this;
}

public Sweetalert setConfirmButtonBackgroundColor(Integer color) {
public Sweetalert setConfirmButtonBackgroundColor(String color) {
mConfirmButtonBackgroundColor = color;
setButtonBackgroundColor(mConfirmButton, color);
return this;
}

public Integer getConfirmButtonBackgroundColor() {
public String getConfirmButtonBackgroundColor() {
return mConfirmButtonBackgroundColor;
}

public Sweetalert setNeutralButtonBackgroundColor(Integer color) {
public Sweetalert setNeutralButtonBackgroundColor(String color) {
mNeutralButtonBackgroundColor = color;
setButtonBackgroundColor(mNeutralButton, color);
return this;
}

public Integer getNeutralButtonBackgroundColor() {
public String getNeutralButtonBackgroundColor() {
return mNeutralButtonBackgroundColor;
}

public Sweetalert setCancelButtonBackgroundColor(Integer color) {
public Sweetalert setCancelButtonBackgroundColor(String color) {
mCancelButtonBackgroundColor = color;
setButtonBackgroundColor(mCancelButton, color);
return this;
}

public Integer getCancelButtonBackgroundColor() {
public String getCancelButtonBackgroundColor() {
return mCancelButtonBackgroundColor;
}

private void setButtonBackgroundColor(Button btn, Integer color) {
private void setButtonBackgroundColor(Button btn, String color) {
if (btn != null && color != null) {
Drawable[] drawableItems = ViewUtils.getDrawable(btn);
if (drawableItems != null) {
GradientDrawable gradientDrawableUnChecked = (GradientDrawable) drawableItems[1];
//solid color
gradientDrawableUnChecked.setColor(color);
gradientDrawableUnChecked.setColor(Color.parseColor(color));
//stroke
gradientDrawableUnChecked.setStroke((int) strokeWidth, genStrokeColor(color));
gradientDrawableUnChecked.setStroke((int) strokeWidth, genStrokeColor(Color.parseColor(color)));
}
}
}
Expand All @@ -492,39 +494,39 @@ private int genStrokeColor(int color) {
return Color.HSVToColor(hsv);
}

public Sweetalert setConfirmButtonTextColor(Integer color) {
public Sweetalert setConfirmButtonTextColor(String color) {
mConfirmButtonTextColor = color;
if (mConfirmButton != null && color != null) {
mConfirmButton.setTextColor(mConfirmButtonTextColor);
mConfirmButton.setTextColor(Color.parseColor(mConfirmButtonTextColor));
}
return this;
}

public Integer getConfirmButtonTextColor() {
public String getConfirmButtonTextColor() {
return mConfirmButtonTextColor;
}

public Sweetalert setNeutralButtonTextColor(Integer color) {
public Sweetalert setNeutralButtonTextColor(String color) {
mNeutralButtonTextColor = color;
if (mNeutralButton != null && color != null) {
mNeutralButton.setTextColor(mNeutralButtonTextColor);
mNeutralButton.setTextColor(Color.parseColor(mNeutralButtonTextColor));
}
return this;
}

public Integer getNeutralButtonTextColor() {
public String getNeutralButtonTextColor() {
return mNeutralButtonTextColor;
}

public Sweetalert setCancelButtonTextColor(Integer color) {
public Sweetalert setCancelButtonTextColor(String color) {
mCancelButtonTextColor = color;
if (mCancelButton != null && color != null) {
mCancelButton.setTextColor(mCancelButtonTextColor);
mCancelButton.setTextColor(Color.parseColor(mCancelButtonTextColor));
}
return this;
}

public Integer getCancelButtonTextColor() {
public String getCancelButtonTextColor() {
return mCancelButtonTextColor;
}

Expand Down
7 changes: 3 additions & 4 deletions sweetalert2/src/main/res/layout/alert_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
android:paddingBottom="4dp"
android:visibility="visible">

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/dialog_blue_button"
android:layout_marginEnd="25dp"
Expand All @@ -191,7 +191,7 @@
tools:text="cancel"
tools:visibility="visible" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/neutral_button"
style="@style/dialog_blue_button"
android:layout_marginStart="-10dp"
Expand All @@ -201,13 +201,12 @@
tools:text="neutral"
tools:visibility="gone" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/confirm_button"
style="@style/dialog_blue_button"
android:text="@string/ok"
android:visibility="gone" />
</LinearLayout>


</LinearLayout>
</FrameLayout>

0 comments on commit 660e66e

Please sign in to comment.