ProgressDialog

class ProgressDialog @JvmOverloads constructor(modeConstant: Int, context: Context, themeConstant: Int)

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

context

The Activity context which must be provided for sure no matter which overloaded constructor is called.

modeConstant

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.

themeConstant

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

Link copied to clipboard
fun ProgressDialog(context: Context, themeConstant: Int = THEME_LIGHT)
Link copied to clipboard
fun ProgressDialog(modeConstant: Int = MODE_INDETERMINATE, context: Context, themeConstant: Int = THEME_LIGHT)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
annotation class ModeConstant
Link copied to clipboard
annotation class ThemeConstant

Functions

Link copied to clipboard
fun dismiss()

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.

Link copied to clipboard
fun getDeterminateDrawable(): Drawable?

Gets the Drawable object used to draw the Determinate ProgressBar. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun getIndeterminateDrawable(): Drawable?

Gets the Drawable object used to draw the Indeterminate ProgressBar. Can be used only in MODE_INDETERMINATE.

Link copied to clipboard
fun getMessage(): CharSequence

Gets the Message showed in the ProgressDialog.

Link copied to clipboard
fun getTitle(): CharSequence

Gets the Current Title of The ProgressDialog.

Link copied to clipboard
fun hasProgressReachedMaxValue(): Boolean

Checks if ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun hasSecondaryProgressReachedMaxValue(): Boolean

Checks if Secondary ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun hideNegativeButton()

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.

Link copied to clipboard
fun hideProgressText(): Boolean

Hides the Progress TextView. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun hideTitle(): Boolean

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.

Link copied to clipboard
fun incrementProgress()

Increments the Progress Value of Determinate ProgressBar using the Offset Value set using setIncrementValue. Can be used only in MODE_DETERMINATE Mode.

Link copied to clipboard
fun remainingProgress(): Int

Gets the Integral Value required to reach MaxValue from the current ProgressValue. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun secondaryRemainingProgress(): Int

Gets the Integral Value required to reach MaxValue from the current Secondary ProgressValue. Can be used only in MODE_DETERMINATE.

Link copied to clipboard
fun setDeterminateDrawable(progressDrawable: Drawable?): Boolean

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.

fun setDeterminateDrawable(@DrawableRes progressDrawableResID: Int): Boolean

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.

Link copied to clipboard
fun setIndeterminateDrawable(progressDrawable: Drawable?): Boolean

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.

fun setIndeterminateDrawable(@DrawableRes progressDrawableResID: Int): Boolean

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.

Link copied to clipboard
fun setMessage(message: CharSequence)

Sets the Text to be displayed alongside ProgressBar. Message is "Loading" by Default.

fun setMessage(@StringRes messageResID: Int)

Sets the Text from the resID provided, to be displayed alongside ProgressBar. Message is "Loading" by Default.

Link copied to clipboard
fun setNegativeButton(text: CharSequence, title: CharSequence, listener: View.OnClickListener?)

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.

fun setNegativeButton(@StringRes textResID: Int, @StringRes titleResID: Int, listener: View.OnClickListener?)

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.

Link copied to clipboard
fun setOnCancelListener(onCancelListener: DialogInterface.OnCancelListener): Boolean

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.

Link copied to clipboard
fun setOnDismissListener(onDismissListener: DialogInterface.OnDismissListener)

Sets the DialogInterface.OnDismissListener for ProgressDialog.

Link copied to clipboard
fun setOnShowListener(onShowListener: DialogInterface.OnShowListener)

Sets the DialogInterface.OnShowListener for ProgressDialog.

Link copied to clipboard
fun setTitle(title: CharSequence)

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.

fun setTitle(@StringRes titleResID: Int)

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.

Link copied to clipboard
fun show()

Starts the ProgressDialog and shows it on the Screen.

Link copied to clipboard
fun showProgressTextAsFraction(progressTextAsFraction: Boolean): Boolean

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

Link copied to clipboard
var incrementValue: Int = 0

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.

Link copied to clipboard
var isCancelable: Boolean = false

Toggles the Cancelable property of ProgressDialog which is false by Default. If it is set to true, the User can cancel the ProgressDialog by pressing Back Button or by touching any other part of the screen. It is NOT RECOMMENDED to set Cancelable to true.

Link copied to clipboard
var maxValue: Int

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.

Link copied to clipboard
var mode: Int

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.

Link copied to clipboard
var progress: Int

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.

Link copied to clipboard
var progressTintList: ColorStateList?

Gets/Sets the Tint List Associated with the Current MODE_DETERMINATE or MODE_INDETERMINATE Mode ProgressDialog respectively.

Link copied to clipboard
var secondaryProgress: Int

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.

Link copied to clipboard
var secondaryProgressTintList: ColorStateList?

Gets/Sets the Secondary Progress Tint List Associated with the Current MODE_DETERMINATE or MODE_INDETERMINATE Mode ProgressDialog respectively.

Link copied to clipboard
var theme: Int

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.