Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A simple and lightweight Material 3 progress dialog library for Android to replace now-deprecated android.app.ProgressDialog

License

NotificationsYou must be signed in to change notification settings

tashilapathum/PleaseWait

Repository files navigation

Maven Central

PleaseWait is a lightweight library that can be used as a drop-in replacement for now-deprecatedandroid.app.ProgressDialog.According to Google, the reason to deprecate the good oldProgressDialog is:

ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI.

I understand the reasoning but it means we have to do some more work to prevent the user from doing something unexpected before the operation is finished. But come on, using a progress dialog is so much easier. So I made this library to use in my apps to avoid those deprecation warnings everywhere and to improve the look of the progress dialog. Also I wanted to learn the process of publishing a library.

Preview

Indeterminate modeDeterminate modeDark and light modes
PreviewPreviewPreview

Features

  • Supports Material 2 and the latest Material 3 design
  • Both determinate and indeterminate progress modes
  • Both circular and linear progress bars
  • Ability to set a delay before showing
  • Ability to set a minimum duration to show the dialog
  • Follows Dark and Light modes automatically
  • Adapts to your app's theme colors
  • Retains state between orientation changes
  • Smooth Material animations and transitions
  • Lightweight and Easy to implement
  • Fully interoperable with Java

How to use

  1. Add the dependency to the app-levelbuild.gradle.
implementation'io.github.tashilapathum:please-wait:0.5.0'
  1. Intitialize withActivity orFragment context and show.
val progressDialog=PleaseWaitDialog(context=this)progressDialog.show()
  1. Optionally set title and message
progressDialog.setTitle("Please wait")progressDialog.setMessage("Loading...")
  1. Dismiss when the operation is complete
progressDialog.dismiss()

Additional options

  • Choose progress style:CIRCULAR,LINEAR,BOTH orNONE. Default isCIRCULAR
progressDialog.setProgressStyle(PleaseWaitDialog.ProgressStyle.LINEAR)
  • Set determinate or indeterminate mode. Default istrue.
progressDialog.setIndeterminate(false)//apply to both progress barsprogressDialog.setIndeterminate(ProgressStyle.LINEAR,false)//apply to a specific progress bar
  • Set progress. You can just set the progress and the progress bars will smoothly animate from indeterminate to determinate mode.
progressDialog.setProgress(20)
  • Set a delay before showing to avoid flashing the progress dialog for short operations. The dialog won't be shown if you calleddismiss() before the time has elapsed.
progressDialog.setShowDelay(2000)
  • Set a delay before dismissing the dialog to show the dialog for a minimum amount of time.
progressDialog.setDismissDelay(3000)
  • Set title and message by overriding resources onstrings.xml. There's no title or message by default.
<stringname="please_wait_dialog_default_title">Please wait</string><stringname="please_wait_dialog_default_message">Loading…</string>

Java implementation

PleaseWaitDialogprogressDialog =newPleaseWaitDialog(this);progressDialog.setTitle("Please wait");progressDialog.setMessage("Loading...");progressDialog.setCancelable(false);progressDialog.show();

[8]ページ先頭

©2009-2025 Movatter.jp