Progress Dialog
An easy to use ProgressDialog library for Android API level 24 and above. The below given parameters apply for all the overloaded constructors in Java or a Single Constructor with default arguments in Kotlin.
Parameters
The Activity context which must be provided for sure no matter which overloaded constructor is called.
The Int constant, which is an optional parameter that accepts either MODE_DETERMINATE or MODE_INDETERMINATE. If it is not passed, MODE_INDETERMINATE will be set by default, which can be changed later by setting mode.
The Int constant, which is an optional parameter that accepts either THEME_DARK, THEME_LIGHT, or THEME_FOLLOW_SYSTEM If it is not passed, THEME_LIGHT will be set by default, which can be changed later by setting theme.
NOTE : THEME_FOLLOW_SYSTEM can be used starting from Android API Level 31 (Android 11) only. Attempting to use it in lower versions will throw IllegalArgumentException.
Constructors
Types
Functions
Dismisses the ProgressDialog, removing it from the Screen. Calls DialogInterface.OnDismissListener, if it is set using setOnDismissListener. To be used after the Task calling ProgressDialog is Over or if any Exception Occurs during Task execution. In case of passing to Another Activity/Fragment, this method SHOULD be called before starting the next Activity/Fragment. Else, it would cause WindowLeakedException.
Gets the Drawable object used to draw the Determinate ProgressBar. Can be used only in MODE_DETERMINATE.
Gets the Drawable object used to draw the Indeterminate ProgressBar. Can be used only in MODE_INDETERMINATE.
Gets the Message showed in the ProgressDialog.
Gets the Current Title of The ProgressDialog.
Checks if ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.
Checks if Secondary ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.
Hides the NegativeButton. NegativeButton is Hidden by Default. Use this method only if you have used setNegativeButton or setNegativeButton before. Note : This method will not hide the Title. You have to explicitly call hideTitle to do the same.
Hides the Progress TextView. Can be used only in MODE_DETERMINATE.
Hides the Title of ProgressDialog. Title is Hidden by Default. Use this method only if you have used setTitle before. This method won't work if setNegativeButton was used before.
Increments the Progress Value of Determinate ProgressBar using the Offset Value set using setIncrementValue. Can be used only in MODE_DETERMINATE Mode.
Gets the Integral Value required to reach MaxValue from the current ProgressValue. Can be used only in MODE_DETERMINATE.
Gets the Integral Value required to reach MaxValue from the current Secondary ProgressValue. Can be used only in MODE_DETERMINATE.
Sets a Custom Drawable to the Determinate ProgressBar. Can be used only in MODE_DETERMINATE. Use this when you need to define a custom Drawable Design for Determinate ProgressBar.
Sets a Custom Drawable from the passed Drawable resource to the Determinate ProgressBar. Can be used only in MODE_DETERMINATE. Use this when you need to define a custom Drawable Design for Determinate ProgressBar.
Sets a Custom Drawable to the Indeterminate ProgressBar. Can be used only in MODE_DETERMINATE. Use this when you need to define a custom Drawable Design for Indeterminate ProgressBar.
Sets a Custom Drawable from the passed Drawable resource to the Indeterminate ProgressBar. Can be used only in MODE_INDETERMINATE. Use this when you need to define a custom Drawable Design for Indeterminate ProgressBar.
Sets the Text to be displayed alongside ProgressBar. Message is "Loading" by Default.
Sets the Text from the resID provided, to be displayed alongside ProgressBar. Message is "Loading" by Default.
Sets the NegativeButton with the passed text for the ProgressDialog and also sets the OnClickListener for the Button. NegativeButton is hidden by default. This method makes it visible. This method also enables the Title to be shown (even if it was hidden till then). If setTitle or setTitle was used before, and new Title is passed, the new Title will Override the previously set Title. If null is passed for listener, default listener which dismisses the ProgressDialog when clicked, will be used.
Sets the NegativeButton with the text from passed resource id for the ProgressDialog and also sets the OnClickListener for the Button. NegativeButton is hidden by default. This method makes it visible. This method also enables the Title to be shown (even if it was hidden till then). If setTitle or setTitle was used before, and new titleResID is passed, the new Title will Override the previously set Title. If null is passed for listener, default listener which dismisses the ProgressDialog when clicked, will be used.
Sets the DialogInterface.OnCancelListener for ProgressDialog. Should be used only if setCancelable was passed with true earlier since cancel() cannot be called explicitly and ProgressDialog is NOT cancelable by Default.
Sets the DialogInterface.OnDismissListener for ProgressDialog.
Sets the DialogInterface.OnShowListener for ProgressDialog.
Sets the Title of ProgressDialog. This is "ProgressDialog" by Default. Title is Hidden by Default. This Method makes the Title Visible. Title will be made visible automatically if setNegativeButton or setNegativeButton was used before.
Sets the Title of ProgressDialog using the String resource given. Title is "ProgressDialog" by Default. Title is Hidden by Default. This Method makes the Title Visible. Title will be made visible automatically if setNegativeButton or setNegativeButton was used before.
Toggles the Progress TextView's format as Fraction if "true" is passed. Progress TextView's Default format is Percentage format. Can be used only in MODE_DETERMINATE. If hideProgressText was used before, this method will again make Progress TextView visible.
Properties
Gets/Sets the Increment Value of the MODE_DETERMINATE ProgressDialog. Gets the Increment Value only if the ProgressDialog is in MODE_DETERMINATE Mode, else -1 is returned. Sets the Increment Value only if the ProgressDialog is in MODE_DETERMINATE Mode. If the passed parameter is greater than maxValue, it will not be set.
Gets/Sets the Maximum value of MODE_DETERMINATE ProgressBar. Gets the Maximum Value only if the ProgressBar is in MODE_DETERMINATE. Else, -1 is returned. Sets the parameter value as Maximum Value only if the ProgressBar is in MODE_DETERMINATE Mode. It is advised to Set this value before setting progress or calling incrementProgress Method.
Gets/Sets the mode of the ProgressDialog which is MODE_INDETERMINATE by Default. If you're going to use only one Mode constantly, no need to set this. Instead, use an appropriate Constructor to set the required Mode during Instantiation. Only MODE_DETERMINATE or MODE_INDETERMINATE should be passed as parameter for the Setter.
Gets/Sets the Progress Value of Determinate ProgressBar. Can be used only in MODE_DETERMINATE Mode. Does not do anything if the ProgressDialog is in MODE_INDETERMINATE Mode. If the parameter progress is greater than MaxValue for Setter, MaxValue will be set as Progress. The Getter will return the current Progress Value if it is in MODE_DETERMINATE Mode, else -1 will be returned.
Gets/Sets the Tint List Associated with the Current MODE_DETERMINATE or MODE_INDETERMINATE Mode ProgressDialog respectively.
Gets/Sets the Secondary ProgressValue. Can be used only in MODE_DETERMINATE. Getter returns the Secondary ProgressValue only if the ProgressDialog is in MODE_DETERMINATE else -1 is returned. Setter works only when called on MODE_DETERMINATE Mode.
Gets/Sets the Secondary Progress Tint List Associated with the Current MODE_DETERMINATE or MODE_INDETERMINATE Mode ProgressDialog respectively.
Gets/Sets the theme of the ProgressDialog. The theme is THEME_LIGHT by Default. If you're going to use only one Theme constantly, no need to set this. Instead, use an appropriate Constructor to set the required Theme during Instantiation. Only THEME_LIGHT, THEME_DARK or THEME_FOLLOW_SYSTEM should be passed as parameter for the Setter.