diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..7533339
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2021 Muhammad Taimoor Sultani
+
+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/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java b/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java
index 62226f7..b8cb207 100644
--- a/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java
+++ b/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java
@@ -5,125 +5,236 @@
import android.annotation.SuppressLint;
import android.graphics.Color;
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;
-import taimoor.sultani.customlog.CustomLogs;
+import taimoor.sultani.sweetalert2.Constants;
import taimoor.sultani.sweetalert2.Sweetalert;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- Button loading_sweetalert, basic_sweetalert, error_sweetalert, delete_confirmation_sweetalert, custom_sweetalert;
+ private int i = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- loading_sweetalert = findViewById(R.id.loading_sweetalert);
- basic_sweetalert = findViewById(R.id.basic_sweetalert);
- error_sweetalert = findViewById(R.id.error_sweetalert);
- delete_confirmation_sweetalert = findViewById(R.id.delete_confirmation_sweetalert);
- custom_sweetalert = findViewById(R.id.custom_sweetalert);
-
- loading_sweetalert.setOnClickListener(this);
- basic_sweetalert.setOnClickListener(this);
- error_sweetalert.setOnClickListener(this);
- delete_confirmation_sweetalert.setOnClickListener(this);
- custom_sweetalert.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.custom_view_test, R.id.custom_btn_colors_test
+ };
+ for (Integer id : btnIds) {
+ findViewById(id).setOnClickListener(this);
+ findViewById(id).setOnTouchListener(Constants.FOCUS_TOUCH_LISTENER);
+ }
+
+ CheckBox dark_style = findViewById(R.id.dark_style);
+ dark_style.setOnCheckedChangeListener((buttonView, isChecked) -> Sweetalert.DARK_STYLE = isChecked);
}
- @SuppressLint("NonConstantResourceId")
+ @SuppressLint({"NonConstantResourceId", "SetTextI18n"})
@Override
public void onClick(View v) {
- int id = v.getId();
- CustomLogs.e("Id is: " + id);
- CustomLogs.d("Id is: " + id);
- switch (id) {
- case R.id.loading_sweetalert: {
- showLoadingSweetalert();
+ switch (v.getId()) {
+ case R.id.basic_test:
+ Sweetalert sd = new Sweetalert(this);
+ sd.setCancelable(true);
+ sd.setCanceledOnTouchOutside(true);
+ sd.setContentText("Here's a message");
+ sd.show();
break;
- }
- case R.id.basic_sweetalert: {
- showBasicSweetalert();
+ case R.id.basic_test_without_buttons:
+ Sweetalert sd2 = new Sweetalert(this);
+ sd2.setCancelable(true);
+ sd2.setCanceledOnTouchOutside(true);
+ sd2.setContentText("Here's a message");
+ sd2.hideConfirmButton();
+ sd2.show();
break;
- }
- case R.id.error_sweetalert: {
- showErrorSweetalert();
+ case R.id.under_text_test:
+ new Sweetalert(this)
+ .setTitleText("Title")
+ .setContentText("It's pretty, isn't it?")
+ .show();
break;
- }
- case R.id.delete_confirmation_sweetalert: {
- showDeleteSweetalert();
+ case R.id.styled_text_and_stroke:
+ new Sweetalert(this)
+ .setTitleText("Red title")
+ .setContentText("Big green bold")
+ .setContentTextSize(21)
+ .setStrokeWidth(2)
+ .show();
break;
- }
- case R.id.custom_sweetalert: {
- showCustomSweetalert();
+ case R.id.error_text_test:
+ new Sweetalert(this, Sweetalert.ERROR_TYPE)
+ .setTitleText("Oops...")
+ .setContentText("Something went wrong!")
+ .show();
break;
- }
- }
- }
+ case R.id.success_text_test:
+ new Sweetalert(this, Sweetalert.SUCCESS_TYPE)
+ .setTitleText("Good job!")
+ .setContentText("You clicked the button!")
+ .show();
+ break;
+ case R.id.warning_confirm_test:
+ new Sweetalert(this, Sweetalert.WARNING_TYPE)
+ .setTitleText("Are you sure?")
+ .setContentText("Won't be able to recover this file!")
+ .setCancelButton("Yes, delete it!", sweetAlertDialog -> {
+ // reuse previous dialog instance
+ sweetAlertDialog
+ .setTitleText("Loading")
+ .setContentText("Please wait...")
+ .hideConfirmButton()
+ .changeAlertType(Sweetalert.PROGRESS_TYPE);
+ new Handler(Looper.myLooper()).postDelayed(() -> sweetAlertDialog
+ .setTitleText("Deleted!")
+ .setContentText("Your imaginary file has been deleted!")
+ .setConfirmClickListener(null)
+ .changeAlertType(Sweetalert.SUCCESS_TYPE), 3000);
+ })
+ .show();
+ break;
+ case R.id.warning_cancel_test:
+ new Sweetalert(this, Sweetalert.WARNING_TYPE)
+ .setTitleText("Are you sure?")
+ .setContentText("Won't be able to recover this file!")
+ .setCancelText("No, cancel pls!")
+ .setConfirmText("Yes, delete it!")
+ .showCancelButton(true)
+ .setCancelClickListener(sDialog -> {
+ // reuse previous dialog instance, keep widget user state, reset them if you need
+ sDialog.setTitleText("Cancelled!")
+ .setContentText("Your imaginary file is safe :)")
+ .setConfirmText("OK")
+ .showCancelButton(false)
+ .setCancelClickListener(null)
+ .setConfirmClickListener(null)
+ .changeAlertType(Sweetalert.ERROR_TYPE);
+ })
+ .setConfirmClickListener(sDialog -> sDialog.setTitleText("Deleted!")
+ .setContentText("Your imaginary file has been deleted!")
+ .setConfirmText("OK")
+ .showCancelButton(false)
+ .setCancelClickListener(null)
+ .setConfirmClickListener(null)
+ .changeAlertType(Sweetalert.SUCCESS_TYPE))
+ .show();
+ break;
+ case R.id.custom_img_test:
+ new Sweetalert(this, Sweetalert.CUSTOM_IMAGE_TYPE)
+ .setTitleText("Sweet!")
+ .setContentText("Here's a custom image.")
+ .setCustomImage(R.drawable.custom_img)
+ .show();
+ break;
+ case R.id.progress_dialog:
+ final Sweetalert pDialog = new Sweetalert(this, Sweetalert.PROGRESS_TYPE)
+ .setTitleText("Loading");
+ pDialog.show();
+ pDialog.setCancelable(false);
+ new CountDownTimer(800 * 7, 800) {
+ public void onTick(long millisUntilFinished) {
+ // you can change the progress bar color by ProgressHelper every 800 millis
+ i++;
+ switch (i) {
+ case 0:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.blue_btn_bg_color));
+ break;
+ case 1:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_deep_teal_50));
+ break;
+ case 2:
+ case 6:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.success_stroke_color));
+ break;
+ case 3:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_deep_teal_20));
+ break;
+ case 4:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.material_blue_grey_80));
+ break;
+ case 5:
+ pDialog.getProgressHelper().setBarColor(getResources().getColor(R.color.warning_stroke_color));
+ break;
+ }
+ }
- private void showLoadingSweetalert() {
- Sweetalert pDialog = new Sweetalert(this, Sweetalert.PROGRESS_TYPE);
- pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
- pDialog.setTitleText("Loading");
- pDialog.setCancelable(false);
- pDialog.show();
- new Handler(Looper.myLooper()).postDelayed(new Runnable() {
- @Override
- public void run() {
- pDialog.dismissWithAnimation();
- }
- }, 2000);
- }
+ public void onFinish() {
+ i = -1;
+ pDialog.setTitleText("Success!")
+ .setConfirmText("OK")
+ .changeAlertType(Sweetalert.SUCCESS_TYPE);
+ }
+ }.start();
+ break;
- private void showBasicSweetalert() {
- new Sweetalert(this)
- .setTitleText("Here's a message!")
- .show();
- }
+ case R.id.neutral_btn_test:
+ new Sweetalert(this, Sweetalert.NORMAL_TYPE)
+ .setTitleText("Title")
+ .setContentText("Three buttons dialog")
+ .setConfirmText("Confirm")
+ .setCancelText("Cancel")
+ .setNeutralText("Neutral")
+ .show();
+ break;
- private void showErrorSweetalert() {
- new Sweetalert(this, Sweetalert.ERROR_TYPE)
- .setTitleText("Oops...")
- .setContentText("Something went wrong!")
- .show();
- }
+ case R.id.disabled_btn_test:
+ final Sweetalert disabledBtnDialog = new Sweetalert(this, Sweetalert.NORMAL_TYPE)
+ .setTitleText("Title")
+ .setContentText("Disabled button dialog")
+ .setConfirmText("OK")
+ .setCancelText("Cancel")
+ .setNeutralText("Neutral");
- private void showDeleteSweetalert() {
- new Sweetalert(this, Sweetalert.WARNING_TYPE)
- .setTitleText("Are you sure?")
- .setContentText("Won't be able to recover this file!")
- .setConfirmText("Yes, delete it!")
- .setConfirmClickListener(new Sweetalert.OnSweetClickListener() {
- @Override
- public void onClick(Sweetalert sDialog) {
- sDialog.setTitleText("Loading").setContentText("Please wait...").changeAlertType(Sweetalert.PROGRESS_TYPE);
- Handler handler = new Handler();
- handler.postDelayed(new Runnable() {
- public void run() {
- sDialog
- .setTitleText("Deleted!")
- .setContentText("Your imaginary file has been deleted!")
- .setConfirmText("OK")
- .setConfirmClickListener(null)
- .changeAlertType(Sweetalert.SUCCESS_TYPE);
- }
- }, 2000);
- }
- })
- .show();
- }
+ disabledBtnDialog.setOnShowListener(dialog -> disabledBtnDialog.getButton(Sweetalert.BUTTON_CONFIRM).setEnabled(false));
+ disabledBtnDialog.show();
+ 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 (Sweetalert.DARK_STYLE) {
+ editText.setTextColor(Color.WHITE);
+ checkBox.setTextColor(Color.WHITE);
+ }
- private void showCustomSweetalert() {
- Sweetalert.DARK_STYLE = true;
- new Sweetalert(this, Sweetalert.ERROR_TYPE)
- .setTitleText("Red title")
- .setContentText("Big green bold")
- .setContentTextSize(21)
- .setStrokeWidth(2)
- .show();
- Sweetalert.DARK_STYLE = false;
+ LinearLayout linearLayout = new LinearLayout(getApplicationContext());
+ linearLayout.setOrientation(LinearLayout.VERTICAL);
+ linearLayout.addView(editText);
+ linearLayout.addView(checkBox);
+
+ Sweetalert dialog = new Sweetalert(this, Sweetalert.NORMAL_TYPE)
+ .setTitleText("Custom view")
+ .hideConfirmButton();
+
+ dialog.setCustomView(linearLayout);
+ dialog.show();
+ break;
+ case R.id.custom_btn_colors_test:
+ new Sweetalert(this, Sweetalert.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;
+
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/custom_img.jpg b/app/src/main/res/drawable/custom_img.jpg
new file mode 100644
index 0000000..8b459c9
Binary files /dev/null and b/app/src/main/res/drawable/custom_img.jpg differ
diff --git a/app/src/main/res/drawable/logo_big.png b/app/src/main/res/drawable/logo_big.png
new file mode 100644
index 0000000..115df19
Binary files /dev/null and b/app/src/main/res/drawable/logo_big.png differ
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 8d84360..0f47b4f 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -1,57 +1,197 @@
-
+ android:background="#FFF">
-
+ android:layout_gravity="center|top">
-
+
-
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index a01b740..3e4b50c 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -1,4 +1,4 @@
- 0dp
+ 10dp
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 990b780..ba893b7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,4 +6,20 @@
Error Sweetalert
Delete Confirmation Sweetalert
Custom Sweetalert
+ Dark style
+ Show material progress
+ Try me!
+ A basic message
+ A basic message \nwithout buttons
+ A title with a text under
+ Styled text and stroke
+ Show error message
+ A success message
+ A warning message, with a listener bind to the Confirm-button...
+ A warning message, with listeners bind to Cancel and Confirm button...
+ A message with a custom icon
+ A message with neutral button
+ Disabled OK button
+ Custom view
+ Custom btn colors
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 8604dde..314e6f8 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -13,4 +13,12 @@
- ?attr/colorPrimaryVariant
+
+
\ No newline at end of file
diff --git a/sweetalert2/build.gradle b/sweetalert2/build.gradle
index 29412db..df35f7f 100644
--- a/sweetalert2/build.gradle
+++ b/sweetalert2/build.gradle
@@ -10,16 +10,12 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
- versionName "1.0"
-
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- consumerProguardFiles "consumer-rules.pro"
+ versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
diff --git a/sweetalert2/consumer-rules.pro b/sweetalert2/consumer-rules.pro
deleted file mode 100644
index e69de29..0000000
diff --git a/sweetalert2/proguard-rules.pro b/sweetalert2/proguard-rules.pro
deleted file mode 100644
index 481bb43..0000000
--- a/sweetalert2/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
\ No newline at end of file