progress-dialog
progress-dialog copied to clipboard
A ProgressDialog Library for Android API 24+ apps provided by Techiness Overloaded (Developer name : Arunprasadh C). Quite Useful for showing progress during any operation. Has support for both Determ...
ProgressDialog Library
An easily customisable ProgressDialog Library for Android API 24 and above provided by Techiness Overloaded (Developer name: Arunprasadh C). Quite Useful for showing progress during any operation. Has support for both Determinate and Indeterminate ProgressBar. Also supports Dark Theme. Has javadoc Documentation for all public Constructors, Attributes and Methods, making it easy to learn about the Library from Android Studio IDE.
[!NOTE] It is highly recommended to use the Latest Release Version of the Library and it is strongly recommended NOT to use any Pre-release versions of the library as they are used for testing out changes and are not production-ready. It is readily observable that Pre-release versions have "a" or "rc" in their version code (Example: Version 1.4.0a4 or 1.4.4-rc1). It is strictly recommended not to use version 1.4.2 or 1.5.0 as the build artifacts are not properly published. You can instead prefer the latest version (1.5.1).
Usage examples available at Usage Examples Java Documentation of Class and Methods available at Java Documentation of Library Kotlin Documentation of Class and Methods available at Kotlin Documentation of Library You can find the Entire Change Log at ProgressDialog Library Change Log See the Contributing Guide to learn more about Contributing to this Project.
Key Features
- Highly Customisable.
- Has support for Dark Theme.
- Has support for AutoTheming from Android 11 (API Level 30).
- Can be set in both Determinate and Indeterminate Mode.
- Has support for Time Tracking in Determinate Mode.
- Has support for Negative Button, Title, and ProgressView.
- Desgined for usage in both Java and Kotlin Android Projects.
- Clear Documentation is available.
What's New in Version 1.5.1 (Feature Update) ?
Features
- Added Time Tracking feature for Determinate Mode ProgressDialog as suggested by @vzool in Issue #13. Time tracking can be enabled by passing
true
to the first parameter ofsetOnShowListener
method. The time elapsed will be updated until theprogress
reachesmaxValue
.
Bug Fixes
- Fixed an Issue where unwanted views got displayed on the ProgressDialog, as pointed out by @soenkegissel and @mg2000 in Issue #16.
Maintenance
- Merged Pull Requests #11, #12, #14, #15, #17 given by @dependabot to update Material Version, Gradle Version, Gradle Build Action Version, ConstraintLayout Version and AppCompat Version.
You can find the Entire Change Log at ProgressDialog Library Change Log
Steps to add ProgressDialog Library to your Android Studio Project
Make Sure that you are using JDK Version 11 Include the following code in your Project-level Gradle Build file at the end of repositories:
Gradle Groovy DSL (If you have build.gradle file):
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Gradle Kotlin DSL (If you have build.gradle.kts file):
allprojects {
repositories {
maven { url = uri("https://jitpack.io") }
}
}
Now, include the following dependency in your App-level Gradle Build file:
[!NOTE] Current latest version is 1.5.1
Gradle Groovy DSL (If you have build.gradle file):
dependencies {
implementation 'com.github.techinessoverloaded:progress-dialog:1.5.1'
}
Gradle Kotlin DSL (If you have build.gradle.kts file):
dependencies {
implementation("com.github.techinessoverloaded:progress-dialog:1.5.1")
}
Or you can also define the version as a String like this(You can copy either this code or the above one):
Gradle Groovy DSL (If you have build.gradle file):
dependencies {
def latest-version = "1.5.1"
implementation "com.github.techinessoverloaded:progress-dialog:$latest-version"
}
Gradle Kotlin DSL (If you have build.gradle.kts file):
dependencies {
val latest-version = "1.5.1"
implementation("com.github.techinessoverloaded:progress-dialog:$latest-version")
}
Now import ProgressDialog class in your Activity/Fragment:
import com.techiness.progressdialoglibrary.ProgressDialog;
Various Constructors available
Simple Constructor
Uses Light Theme by Default.
[!NOTE] Theme can be changed after Instantiation using
setTheme(int themeConstant)
method.
[!IMPORTANT] If you want to Instantiate
ProgressDialog
Class in a Fragment, userequireContext()
method instead ofthis
keyword for passingContext
object. Similarly, for InstantiatingProgressDialog
Class in Inner Classes, useYourActivity.this
in Java orthis@YourActivity
in Kotlin instead of simplethis
keyword for passingContext
object.
Java Code:
ProgressDialog progressDialog = new ProgressDialog(this); //same as new ProgressDialog(this, ProgressDialog.THEME_LIGHT);
Kotlin Code:
val progressDialog = ProgressDialog(this) //same as ProgressDialog(this, ProgressDialog.THEME_LIGHT)
Constructor for Alternate Theme
This Constructor can be used for setting Dark Theme.
Java Code:
ProgressDialog progressDialog = new ProgressDialog(this, ProgressDialog.THEME_DARK);
Kotlin Code:
val progressDialog = ProgressDialog(this, ProgressDialog.THEME_DARK)
Constructor for Alternate Mode
Default mode is Indeterminate mode.
[!NOTE] Mode can be changed as and when necessary using in-built methods.
Java Code:
ProgressDialog progressDialog = new ProgressDialog(ProgressDialog.MODE_DETERMINATE,this); // for instantiating with Determinate mode
Kotlin Code:
val progressDialog = ProgressDialog(ProgressDialog.MODE_DETERMINATE,this) // for instantiating with Determinate mode
Constructor for Alternate Mode and Theme
This constructor can be used to customise both Mode and Theme of ProgressDialog.
Java Code:
ProgressDialog progressDialog = new ProgressDialog(ProgressDialog.MODE_DETERMINATE,this,ProgressDialog.THEME_DARK);
Kotlin Code:
val progressDialog = ProgressDialog(ProgressDialog.MODE_DETERMINATE,this,ProgressDialog.THEME_DARK)
Simple Examples
Note: These examples are for simple illustration of ProgressDialog Library. For completely knowing about the Library, refer to the JavaDoc/KDoc Documentation of the Library through Android Studio.
How to use ProgressDialog.THEME_FOLLOW_SYSTEM
with Constructor ?
Java Code:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) //Check if Android API Level is greater than or equal to 30
{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_FOLLOW_SYSTEM); //This is optional. This will enable Android's Autotheming for the entire App
ProgressDialog progressDialog = new ProgressDialog(this,ProgressDialog.THEME_FOLLOW_SYSTEM); // Enables AutoTheming for the ProgressDialog instance.
}
else //Autotheming not compatible
{
ProgressDialog progressDialog = new ProgressDialog(this,ProgressDialog.THEME_DARK); // or any other constructors mentioned above
}
Kotlin Code:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) //Check if Android API Level is greater than or equal to 30
{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_FOLLOW_SYSTEM) //This is optional. This will enable Android's Autotheming for the entire App
val progressDialog = ProgressDialog(this,ProgressDialog.THEME_FOLLOW_SYSTEM) // Enables AutoTheming for the ProgressDialog instance.
}
else //Autotheming not compatible
{
val progressDialog = ProgressDialog(this,ProgressDialog.THEME_DARK) // or any other constructors mentioned above
}
How to use ProgressDialog.THEME_FOLLOW_SYSTEM
with setTheme(int themeConstant)
method ?
Java Code:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) //Check if Android API Level is greater than or equal to 30
{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_FOLLOW_SYSTEM); //This is optional. This will enable Android's Autotheming for the entire App
progressDialog.setTheme(ProgressDialog.THEME_FOLLOW_SYSTEM); // Enables AutoTheming for the ProgressDialog instance.
}
else //Autotheming not compatible
{
progressDialog.setTheme(ProgressDialog.THEME_DARK); // or ProgressDialog.THEME_LIGHT
}
Kotlin Code:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) //Check if Android API Level is greater than or equal to 30
{
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_FOLLOW_SYSTEM) //This is optional. This will enable Android's Autotheming for the entire App
progressDialog.theme = ProgressDialog.THEME_FOLLOW_SYSTEM) // Enables AutoTheming for the ProgressDialog instance.
}
else //Autotheming not compatible
{
progressDialog.theme = ProgressDialog.THEME_DARK // or ProgressDialog.THEME_LIGHT
}
Indeterminate ProgressDialog without Title (Light Theme)
Java Code:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.show();
Kotlin Code:
val progressDialog = ProgressDialog(this)
progressDialog.show()
Output:
Indeterminate ProgressDialog without Title (Dark Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
show()
}
Output:
Determinate ProgressDialog without Title, without ProgressView, with Secondary Progress (Light Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(65);
progressDialog.setSecondaryProgress(80);
progressDialog.hideProgressText();
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_DETERMINATE
progress = 65
secondaryProgress = 80
hideProgressText()
show()
}
Output:
Determinate ProgressDialog without Title, without ProgressView, with Secondary Progress (Dark Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(65);
progressDialog.setSecondaryProgress(80);
progressDialog.hideProgressText();
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_DETERMINATE
progress = 65
secondaryProgress = 80
hideProgressText()
show()
}
Output:
Determinate ProgressDialog without Title, with ProgressView as Percentage (Light Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(65);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_DETERMINATE
setprogress = 65
show()
}
Output:
Determinate ProgressDialog without Title, with ProgressView as Percentage (Dark Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(65);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_DETERMINATE
progress = 65
show()
}
Output:
Indeterminate ProgressDialog with Title (Light Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_INDETERMINATE);
progressDialog.setTitle("Indeterminate");
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_INDETERMINATE
setTitle("Indeterminate")
show()
}
Output:
Indeterminate ProgressDialog with Title (Dark Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_INDETERMINATE);
progressDialog.setTitle("Indeterminate");
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_INDETERMINATE
setTitle("Indeterminate")
show()
}
Output:
Determinate ProgressDialog with Title, Secondary Progress and ProgressView as Fraction (Light Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setTitle("Determinate");
progressDialog.setProgress(65);
progressDialog.setSecondaryProgress(80);
progressDialog.showProgressTextAsFraction(true);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_DETERMINATE
setTitle("Determinate")
progress = 65
secondaryProgress = 80
showProgressTextAsFraction(true)
show()
}
Output:
Determinate ProgressDialog with Title, Secondary Progress and ProgressView as Fraction (Dark Theme)
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setTitle("Determinate");
progressDialog.setProgress(65);
progressDialog.setSecondaryProgress(80);
progressDialog.showProgressTextAsFraction(true);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_DETERMINATE
setTitle("Determinate")
progress = 65
secondaryProgress = 80
showProgressTextAsFraction(true)
show()
}
Output:
Indeterminate ProgressDialog with NegativeButton and Custom OnClickListener for NegativeButton (Light Theme)
[!NOTE] Enabling NegativeButton will automatically enable TitleView.
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_INDETERMINATE);
progressDialog.setNegativeButton("Dismiss","Indeterminate",v -> {
Toast.makeText(this,"Custom OnClickListener for Indeterminate",Toast.LENGTH_LONG).show();
progressDialog.dismiss();
});
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_INDETERMINATE
setNegativeButton("Dismiss", "Determinate") {
Toast.makeText(this@KotlinActivity, "Custom OnClickListener for Indeterminate", Toast.LENGTH_LONG).show()
dismiss()
}
show()
}
Output:
Indeterminate ProgressDialog with NegativeButton and Custom OnClickListener for NegativeButton (Dark Theme)
[!NOTE] Enabling NegativeButton will automatically enable TitleView.
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_INDETERMINATE);
progressDialog.setNegativeButton("Dismiss","Indeterminate",v -> {
Toast.makeText(this,"Custom OnClickListener for Indeterminate",Toast.LENGTH_LONG).show();
progressDialog.dismiss();
});
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_INDETERMINATE
setNegativeButton("Dismiss", "Determinate") {
Toast.makeText(this@KotlinActivity, "Custom OnClickListener for Indeterminate", Toast.LENGTH_LONG).show()
dismiss()
}
show()
}
Output:
Determinate ProgressDialog with NegativeButton and Default OnClickListener for NegativeButton (Light Theme)
[!NOTE] Enabling NegativeButton will automatically enable TitleView.
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_LIGHT);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(54);
progressDialog.showProgressTextAsFraction(true);
progressDialog.setNegativeButton("Cancel","Determinate",null);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_LIGHT
mode = ProgressDialog.MODE_DETERMINATE
progress = 54
showProgressTextAsFraction(true)
setNegativeButton("Cancel","Determinate",null)
show()
}
Output:
Determinate ProgressDialog with NegativeButton and Default OnClickListener for NegativeButton (Dark Theme)
Note: Enabling NegativeButton will automatically enable TitleView.
Java Code:
progressDialog.setTheme(ProgressDialog.THEME_DARK);
progressDialog.setMode(ProgressDialog.MODE_DETERMINATE);
progressDialog.setProgress(54);
progressDialog.showProgressTextAsFraction(true);
progressDialog.setNegativeButton("Cancel","Determinate",null);
progressDialog.show();
Kotlin Code:
with(progressDialog)
{
theme = ProgressDialog.THEME_DARK
mode = ProgressDialog.MODE_DETERMINATE
progress = 54
showProgressTextAsFraction(true)
setNegativeButton("Cancel","Determinate",null)
show()
}