Skip to content

Commit

Permalink
Feat: Sweetalert2 library completed
Browse files Browse the repository at this point in the history
  • Loading branch information
taimoorsultani committed Jun 18, 2021
1 parent b6e32e4 commit f815772
Show file tree
Hide file tree
Showing 43 changed files with 2,141 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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("<font color='red'>Red</font> title")
.setContentText("Big <font color='green'>green </font><b><i> bold</i></b>")
.setContentTextSize(21)
.setStrokeWidth(2)
.show();
Sweetalert.DARK_STYLE = false;
}
}
57 changes: 48 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
tools:context=".MainActivity"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="Hello World!" />

</androidx.constraintlayout.widget.ConstraintLayout>
<Button
android:id="@+id/loading_sweetalert"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/loading_sweetalert"/>

<Button
android:id="@+id/basic_sweetalert"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/basic_sweetalert"/>

<Button
android:id="@+id/error_sweetalert"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/error_sweetalert"/>

<Button
android:id="@+id/delete_confirmation_sweetalert"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/delete_confirmation_sweetalert"/>

<Button
android:id="@+id/custom_sweetalert"
android:padding="4dp"
android:layout_margin="11dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/custom_sweetalert"/>

</LinearLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="mp1">0dp</dimen>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<resources>
<string name="app_name">Android-Sweetaler2</string>
<string name="app_name">Android-Sweetalert2</string>
<string name="test_sweet_alert">Test Sweet Alert</string>
<string name="loading_sweetalert">Loading Sweetalert</string>
<string name="basic_sweetalert">Basic Sweetalert</string>
<string name="error_sweetalert">Error Sweetalert</string>
<string name="delete_confirmation_sweetalert">Delete Confirmation Sweetalert</string>
<string name="custom_sweetalert">Custom Sweetalert</string>
</resources>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ allprojects {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rootProject.name = "Android-Sweetaler2"
include ':app'
include ':sweetalert2'
1 change: 1 addition & 0 deletions sweetalert2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions sweetalert2/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'com.android.library'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation 'com.pnikosis:materialish-progress:1.7'
}
Empty file added sweetalert2/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions sweetalert2/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
5 changes: 5 additions & 0 deletions sweetalert2/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="taimoor.sultani.sweetalert2">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package taimoor.sultani.sweetalert2;

import android.annotation.SuppressLint;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;

public class Constants {
// Make bg a little bit darker
public static final View.OnTouchListener FOCUS_TOUCH_LISTENER = new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
Drawable drawable = v.getBackground();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_BUTTON_PRESS:
drawable.setColorFilter(0x20000000, PorterDuff.Mode.SRC_ATOP);
v.invalidate();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
drawable.clearColorFilter();
v.invalidate();
break;
}
return false;
}
};
}
Loading

0 comments on commit f815772

Please sign in to comment.