Skip to content

Commit

Permalink
Feat: Hide confirm button & set title text size option added
Browse files Browse the repository at this point in the history
  • Loading branch information
taimoorsultani committed Jun 24, 2021
1 parent 09ddee1 commit c0cfcc7
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 71 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.1.0</version>
<version>1.2.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.1.0'
implementation 'com.github.taimoorsultani:android-sweetalert2:1.2.0'
}

## Usage
Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ dependencies {
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'
}
}
135 changes: 89 additions & 46 deletions app/src/main/java/taimoor/sultani/android_sweetaler2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,73 +43,150 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
switch (v.getId()) {
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;
}
}

public void onFinish() {
i = -1;
pDialog.setTitleText("Success!")
.showConfirmButton(true)
.setConfirmText("OK")
.changeAlertType(Sweetalert.SUCCESS_TYPE);
}
}.start();
break;

case R.id.basic_test:
Sweetalert sd = new Sweetalert(this);
sd.setCancelable(true);
sd.setCanceledOnTouchOutside(true);
sd.setContentText("Here's a message");
sd.setContentText("Here's a message with buttons");
sd.showConfirmButton(true);
sd.setConfirmText("Okay");
sd.showCancelButton(true);
sd.setCancelText("Close");
sd.show();
break;

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.showConfirmButton(false);
sd2.showCancelButton(false);
sd2.show();
break;

case R.id.under_text_test:
new Sweetalert(this)
.setTitleText("Title")
.setContentText("It's pretty, isn't it?")
.showConfirmButton(true)
.setConfirmText("Okay")
.showCancelButton(true)
.setCancelText("Close")
.show();
break;

case R.id.styled_text_and_stroke:
new Sweetalert(this)
.setTitleText("<font color='red'>Red</font> title")
.setTitleTextSize(32)
.setContentText("Big <font color='green'>green </font><b><i> bold</i></b>")
.setContentTextSize(21)
.setStrokeWidth(2)
.show();
break;

case R.id.error_text_test:
new Sweetalert(this, Sweetalert.ERROR_TYPE)
.setTitleText("Oops...")
.setContentText("Something went wrong!")
.showConfirmButton(true)
.setConfirmText("Okay")
.showCancelButton(true)
.setCancelText("Close")
.show();
break;

case R.id.success_text_test:
new Sweetalert(this, Sweetalert.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.showConfirmButton(true)
.setConfirmText("Okay")
.showCancelButton(true)
.setCancelText("Close")
.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!")
.showConfirmButton(true)
.setConfirmText("NO")
.showCancelButton(true)
.setCancelButton("Yes, delete it!", sweetAlertDialog -> {
// reuse previous dialog instance
sweetAlertDialog
.setTitleText("Loading")
.setContentText("Please wait...")
.hideConfirmButton()
.showCancelButton(false)
.showConfirmButton(false)
.changeAlertType(Sweetalert.PROGRESS_TYPE);
new Handler(Looper.myLooper()).postDelayed(() -> sweetAlertDialog
.setTitleText("Deleted!")
.setContentText("Your imaginary file has been deleted!")
.setConfirmClickListener(null)
.setCancelClickListener(null)
.setConfirmText("OKAY")
.setCancelText("CLOSE")
.showCancelButton(true)
.showConfirmButton(true)
.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)
.showConfirmButton(true)
.setCancelClickListener(sDialog -> {
// reuse previous dialog instance, keep widget user state, reset them if you need
sDialog.setTitleText("Cancelled!")
Expand All @@ -129,58 +206,21 @@ public void onClick(View v) {
.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;
}
}

public void onFinish() {
i = -1;
pDialog.setTitleText("Success!")
.setConfirmText("OK")
.changeAlertType(Sweetalert.SUCCESS_TYPE);
}
}.start();
break;

case R.id.neutral_btn_test:
new Sweetalert(this, Sweetalert.NORMAL_TYPE)
.setTitleText("Title")
.setContentText("Three buttons dialog")
.showConfirmButton(true)
.showCancelButton(true)
.setConfirmText("Confirm")
.setCancelText("Cancel")
.setNeutralText("Neutral")
Expand All @@ -193,8 +233,9 @@ public void onFinish() {
.setContentText("Disabled button dialog")
.setConfirmText("OK")
.setCancelText("Cancel")
.showCancelButton(true)
.showConfirmButton(true)
.setNeutralText("Neutral");

disabledBtnDialog.setOnShowListener(dialog -> disabledBtnDialog.getButton(Sweetalert.BUTTON_CONFIRM).setEnabled(false));
disabledBtnDialog.show();
break;
Expand All @@ -217,15 +258,17 @@ public void onFinish() {
linearLayout.addView(checkBox);

Sweetalert dialog = new Sweetalert(this, Sweetalert.NORMAL_TYPE)
.setTitleText("Custom view")
.hideConfirmButton();
.setTitleText("Custom view");

dialog.setCustomView(linearLayout);
dialog.show();
break;

case R.id.custom_btn_colors_test:
new Sweetalert(this, Sweetalert.NORMAL_TYPE)
.setTitleText("Custom view")
.showCancelButton(true)
.showConfirmButton(true)
.setCancelButton("red", null)
.setCancelButtonBackgroundColor(Color.RED)
.setNeutralButton("cyan", null)
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<string name="dark_style">Dark style</string>
<string name="show_material_progress">Show material progress</string>
<string name="try_me">Try me!</string>
<string name="a_basic_message">A basic message</string>
<string name="a_basic_message">A basic message with buttons</string>
<string name="a_basic_message_nwithout_buttons">A basic message \nwithout buttons</string>
<string name="a_title_with_a_text_under">A title with a text under</string>
<string name="styled_text_and_stroke">Styled text and stroke</string>
<string name="show_error_message">Show error message</string>
<string name="a_success_message">A success message</string>
<string name="a_warning_message_with_a_listener_bind_to_the_confirm_button">A warning message, with a listener bind to the Confirm-button...</string>
<string name="a_warning_message_with_listeners_bind_to_cancel_and_confirm_button">A warning message, with listeners bind to Cancel and Confirm button...</string>
<string name="a_warning_message_with_a_listener_bind_to_the_confirm_button">A warning message, with a listener bind to the Confirm-button</string>
<string name="a_warning_message_with_listeners_bind_to_cancel_and_confirm_button">A warning message, with listeners bind to Cancel and Confirm button</string>
<string name="a_message_with_a_custom_icon">A message with a custom icon</string>
<string name="a_message_with_neutral_button">A message with neutral button</string>
<string name="disabled_ok_button">Disabled OK button</string>
Expand Down
4 changes: 2 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 2
versionName "1.1.0"
versionCode 3
versionName "1.2.0"
}

buildTypes {
Expand Down
Loading

0 comments on commit c0cfcc7

Please sign in to comment.