Skip to content

sigma1326/SweetAlertDialogPersian

Repository files navigation

Sweet Alert Dialog Persian

updated version of original sweetAlertDialog repo

Setup

The simplest way to use SweetAlertDialog is to add the library as aar dependency to your build.

Gradle

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

dependencies {
        implementation 'com.github.sigma1326:SweetAlertDialogPersian:v1.0'
}

Usage

show material progress

SweetAlertDialog pDialog = new SweetAlertDialog(this, SweetAlertDialog.PROGRESS_TYPE);
pDialog.getProgressHelper().setBarColor(Color.parseColor("#A5DC86"));
pDialog.setTitleText("Loading");
pDialog.setCancelable(false);
pDialog.show();

You can customize progress bar dynamically with materialish-progress methods via SweetAlertDialog.getProgressHelper():

  • resetCount()
  • isSpinning()
  • spin()
  • stopSpinning()
  • getProgress()
  • setProgress(float progress)
  • setInstantProgress(float progress)
  • getCircleRadius()
  • setCircleRadius(int circleRadius)
  • getBarWidth()
  • setBarWidth(int barWidth)
  • getBarColor()
  • setBarColor(int barColor)
  • getRimWidth()
  • setRimWidth(int rimWidth)
  • getRimColor()
  • setRimColor(int rimColor)
  • getSpinSpeed()
  • setSpinSpeed(float spinSpeed)

more usages about progress, please see the sample.

A basic message:

new SweetAlertDialog(this)
    .setTitleText("Here's a message!")
    .show();

A title with a text under:

new SweetAlertDialog(this)
    .setTitleText("Here's a message!")
    .setContentText("It's pretty, isn't it?")
    .show();

A error message:

new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
    .setTitleText("Oops...")
    .setContentText("Something went wrong!")
    .show();

A warning message:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes,delete it!")
    .show();

A success message:

new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
    .setTitleText("Good job!")
    .setContentText("You clicked the button!")
    .show();

A message with a custom icon:

new SweetAlertDialog(this, SweetAlertDialog.CUSTOM_IMAGE_TYPE)
    .setTitleText("Sweet!")
    .setContentText("Here's a custom image.")
    .setCustomImage(R.drawable.custom_img)
    .show();

Bind the listener to confirm button:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes,delete it!")
    .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
        @Override
        public void onClick(SweetAlertDialog sDialog) {
            sDialog.dismissWithAnimation();
        }
    })
    .show();

Show the cancel button and bind listener to it:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setCancelText("No,cancel plx!")
    .setConfirmText("Yes,delete it!")
    .showCancelButton(true)
    .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
        @Override
        public void onClick(SweetAlertDialog sDialog) {
            sDialog.cancel();
        }
    })
    .show();

Change the dialog style upon confirming:

new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
    .setTitleText("Are you sure?")
    .setContentText("Won't be able to recover this file!")
    .setConfirmText("Yes,delete it!")
    .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
        @Override
        public void onClick(SweetAlertDialog sDialog) {
            sDialog
                .setTitleText("Deleted!")
                .setContentText("Your imaginary file has been deleted!")
                .setConfirmText("OK")
                .setConfirmClickListener(null)
                .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
        }
    })
    .show();