项目作者: achmadqomarudin

项目描述 :
A beautiful Sweet Alert Dialog Examples in Java using Library.
高级语言: Java
项目地址: git://github.com/achmadqomarudin/SweetAlertDialog.git
创建时间: 2020-07-02T13:22:05Z
项目社区:https://github.com/achmadqomarudin/SweetAlertDialog

开源协议:Apache License 2.0

下载


Sweet Alert Dialog

Platform
License
Gradle Version
Awesome Badge

A beautiful Sweet Alert Dialog Examples in Java using Library.

Source

Repo to demonstrate Sweet Alert Dialog in Android. This is a follow up on the github at :

SweetAlertDialog

Demo App






















Example 1 Example 2
Example 3 Example 4

Setup

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

Gradle(Module)

  1. dependencies {
  2. implementation 'com.github.cazaea:sweet-alert-dialog:1.0.0'
  3. }

Gradle(Project)

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url 'https://jitpack.io' }
  5. ...
  6. }
  7. }

Usage

show material progress

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

image

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)

thanks to the project materialish-progress and @pedant participation.

more usages about progress, please see the sample.

A basic message:

  1. new SweetAlertDialog(this)
  2. .setTitleText("Here's a message!")
  3. .setConfirmText("OK") // Do not set the property, do not show the button
  4. .show();

A title with a text under:

  1. new SweetAlertDialog(this)
  2. .setTitleText("Here's a message!")
  3. .setContentText("It's pretty, isn't it?")
  4. .setConfirmText("OK")
  5. .show();

A error message:

  1. new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
  2. .setTitleText("Oops...")
  3. .setContentText("Something went wrong!")
  4. .setConfirmText("OK")
  5. .show();

A warning message:

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

A success message:

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

A message with a custom icon:

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

Bind the listener to confirm button:

  1. new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
  2. .setTitleText("Are you sure?")
  3. .setContentText("Won't be able to recover this file!")
  4. .setConfirmText("Yes,delete it!")
  5. .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
  6. @Override
  7. public void onClick(SweetAlertDialog sDialog) {
  8. sDialog.dismissWithAnimation();
  9. }
  10. })
  11. .show();

Show the cancel button and bind listener to it:

  1. new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
  2. .setTitleText("Are you sure?")
  3. .setContentText("Won't be able to recover this file!")
  4. .setCancelText("No,cancel plx!")
  5. .setConfirmText("Yes,delete it!")
  6. .showCancelButton(true)
  7. .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() {
  8. @Override
  9. public void onClick(SweetAlertDialog sDialog) {
  10. sDialog.cancel();
  11. }
  12. })
  13. .show();

Change the dialog style upon confirming:

  1. new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
  2. .setTitleText("Are you sure?")
  3. .setContentText("Won't be able to recover this file!")
  4. .setConfirmText("Yes,delete it!")
  5. .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
  6. @Override
  7. public void onClick(SweetAlertDialog sDialog) {
  8. sDialog
  9. .setTitleText("Deleted!")
  10. .setContentText("Your imaginary file has been deleted!")
  11. .setConfirmText("OK")
  12. .setConfirmClickListener(null)
  13. .changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
  14. }
  15. })
  16. .show();

License

  1. Copyright (C) Achmad Qomarudin
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.