From f815772b44815f914d8ffb91dfc5073b01b64080 Mon Sep 17 00:00:00 2001 From: Muhammad Taimoor Sultani Date: Sat, 19 Jun 2021 00:23:37 +0500 Subject: [PATCH] Feat: Sweetalert2 library completed --- app/build.gradle | 5 +- .../android_sweetaler2/MainActivity.java | 117 ++- app/src/main/res/layout/activity_main.xml | 57 +- app/src/main/res/values/dimens.xml | 4 + app/src/main/res/values/strings.xml | 8 +- build.gradle | 3 +- settings.gradle | 1 + sweetalert2/.gitignore | 1 + sweetalert2/build.gradle | 33 + sweetalert2/consumer-rules.pro | 0 sweetalert2/proguard-rules.pro | 21 + sweetalert2/src/main/AndroidManifest.xml | 5 + .../sultani/sweetalert2/Constants.java | 31 + .../sweetalert2/OptAnimationLoader.java | 78 ++ .../sultani/sweetalert2/ProgressHelper.java | 167 +++++ .../sweetalert2/Rotate3dAnimation.java | 147 ++++ .../sultani/sweetalert2/SuccessTickView.java | 117 +++ .../sultani/sweetalert2/Sweetalert.java | 700 ++++++++++++++++++ .../sultani/sweetalert2/ViewUtils.java | 19 + .../src/main/res/anim/error_frame_in.xml | 20 + sweetalert2/src/main/res/anim/error_x_in.xml | 32 + sweetalert2/src/main/res/anim/modal_in.xml | 39 + sweetalert2/src/main/res/anim/modal_out.xml | 14 + .../src/main/res/anim/success_bow_roate.xml | 10 + .../src/main/res/anim/success_mask_layout.xml | 18 + .../res/drawable/blue_button_background.xml | 17 + .../main/res/drawable/dialog_background.xml | 5 + .../res/drawable/dialog_background_dark.xml | 5 + .../src/main/res/drawable/error_center_x.xml | 34 + .../src/main/res/drawable/error_circle.xml | 9 + .../res/drawable/gray_button_background.xml | 17 + .../res/drawable/green_button_background.xml | 17 + .../res/drawable/red_button_background.xml | 17 + .../src/main/res/drawable/success_bow.xml | 9 + .../src/main/res/drawable/success_circle.xml | 9 + .../src/main/res/drawable/warning_circle.xml | 9 + .../src/main/res/drawable/warning_sigh.xml | 24 + .../src/main/res/layout/alert_dialog.xml | 213 ++++++ sweetalert2/src/main/res/values/attrs.xml | 18 + sweetalert2/src/main/res/values/colors.xml | 48 ++ sweetalert2/src/main/res/values/dimens.xml | 9 + sweetalert2/src/main/res/values/strings.xml | 9 + sweetalert2/src/main/res/values/styles.xml | 39 + 43 files changed, 2141 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 sweetalert2/.gitignore create mode 100644 sweetalert2/build.gradle create mode 100644 sweetalert2/consumer-rules.pro create mode 100644 sweetalert2/proguard-rules.pro create mode 100644 sweetalert2/src/main/AndroidManifest.xml create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/Constants.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/OptAnimationLoader.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/ProgressHelper.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/Rotate3dAnimation.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/SuccessTickView.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/Sweetalert.java create mode 100644 sweetalert2/src/main/java/taimoor/sultani/sweetalert2/ViewUtils.java create mode 100644 sweetalert2/src/main/res/anim/error_frame_in.xml create mode 100644 sweetalert2/src/main/res/anim/error_x_in.xml create mode 100644 sweetalert2/src/main/res/anim/modal_in.xml create mode 100644 sweetalert2/src/main/res/anim/modal_out.xml create mode 100644 sweetalert2/src/main/res/anim/success_bow_roate.xml create mode 100644 sweetalert2/src/main/res/anim/success_mask_layout.xml create mode 100644 sweetalert2/src/main/res/drawable/blue_button_background.xml create mode 100644 sweetalert2/src/main/res/drawable/dialog_background.xml create mode 100644 sweetalert2/src/main/res/drawable/dialog_background_dark.xml create mode 100644 sweetalert2/src/main/res/drawable/error_center_x.xml create mode 100644 sweetalert2/src/main/res/drawable/error_circle.xml create mode 100644 sweetalert2/src/main/res/drawable/gray_button_background.xml create mode 100644 sweetalert2/src/main/res/drawable/green_button_background.xml create mode 100644 sweetalert2/src/main/res/drawable/red_button_background.xml create mode 100644 sweetalert2/src/main/res/drawable/success_bow.xml create mode 100644 sweetalert2/src/main/res/drawable/success_circle.xml create mode 100644 sweetalert2/src/main/res/drawable/warning_circle.xml create mode 100644 sweetalert2/src/main/res/drawable/warning_sigh.xml create mode 100644 sweetalert2/src/main/res/layout/alert_dialog.xml create mode 100644 sweetalert2/src/main/res/values/attrs.xml create mode 100644 sweetalert2/src/main/res/values/colors.xml create mode 100644 sweetalert2/src/main/res/values/dimens.xml create mode 100644 sweetalert2/src/main/res/values/strings.xml create mode 100644 sweetalert2/src/main/res/values/styles.xml diff --git a/app/build.gradle b/app/build.gradle index c5cfb78..94b915a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,11 +29,12 @@ android { } dependencies { - implementation 'androidx.appcompat:appcompat:1.3.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' - testImplementation 'junit:junit:4.+' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + implementation project(':sweetalert2') + implementation 'com.github.taimoorsultani:android-library-test:1.0.1' } \ No newline at end of file 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 fa09fcd..62226f7 100644 --- a/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java +++ b/app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java @@ -2,13 +2,128 @@ import androidx.appcompat.app.AppCompatActivity; +import android.annotation.SuppressLint; +import android.graphics.Color; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.View; +import android.widget.Button; -public class MainActivity extends AppCompatActivity { +import taimoor.sultani.customlog.CustomLogs; +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; @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); + } + + @SuppressLint("NonConstantResourceId") + @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(); + break; + } + case R.id.basic_sweetalert: { + showBasicSweetalert(); + break; + } + case R.id.error_sweetalert: { + showErrorSweetalert(); + break; + } + case R.id.delete_confirmation_sweetalert: { + showDeleteSweetalert(); + break; + } + case R.id.custom_sweetalert: { + showCustomSweetalert(); + 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); + } + + private void showBasicSweetalert() { + new Sweetalert(this) + .setTitleText("Here's a message!") + .show(); + } + + private void showErrorSweetalert() { + new Sweetalert(this, Sweetalert.ERROR_TYPE) + .setTitleText("Oops...") + .setContentText("Something went wrong!") + .show(); + } + + 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(); + } + + 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; } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4fc2444..8d84360 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,18 +1,57 @@ - + tools:context=".MainActivity" + android:orientation="vertical"> + android:text="Hello World!" /> - \ No newline at end of file +