-
- All Implemented Interfaces:
public final class ProgressDialog
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public @interface
ProgressDialog.ThemeConstant
public @interface
ProgressDialog.ModeConstant
public class
ProgressDialog.Companion
-
Field Summary
Fields Modifier and Type Field Description private Integer
mode
private Integer
theme
private Boolean
isCancelable
private Integer
progress
private Integer
incrementValue
private Integer
maxValue
private Integer
secondaryProgress
private ColorStateList
progressTintList
private ColorStateList
secondaryProgressTintList
-
Constructor Summary
Constructors Constructor Description ProgressDialog(Context context, Integer themeConstant)
ProgressDialog(Integer modeConstant, Context context, Integer themeConstant)
ProgressDialog(Integer modeConstant, Context context)
ProgressDialog(Context context)
-
Method Summary
Modifier and Type Method Description final Integer
getMode()
final Unit
setMode(Integer mode)
final Integer
getTheme()
final Unit
setTheme(Integer theme)
final Boolean
isCancelable()
Toggles the Cancelable property of ProgressDialog which is false by Default. final Unit
setCancelable(Boolean isCancelable)
final Integer
getProgress()
final Unit
setProgress(Integer progress)
final Integer
getIncrementValue()
final Unit
setIncrementValue(Integer incrementValue)
final Integer
getMaxValue()
final Unit
setMaxValue(Integer maxValue)
final Integer
getSecondaryProgress()
final Unit
setSecondaryProgress(Integer secondaryProgress)
final ColorStateList
getProgressTintList()
final Unit
setProgressTintList(ColorStateList progressTintList)
final ColorStateList
getSecondaryProgressTintList()
final Unit
setSecondaryProgressTintList(ColorStateList secondaryProgressTintList)
final CharSequence
getMessage()
Gets the Message showed in the ProgressDialog. final Unit
setMessage(CharSequence message)
Sets the Text to be displayed alongside ProgressBar. final Unit
setMessage(@StringRes() Integer messageResID)
Sets the Text from the resID provided, to be displayed alongside ProgressBar. final CharSequence
getTitle()
Gets the Current Title of The ProgressDialog. final Unit
setTitle(CharSequence title)
Sets the Title of ProgressDialog. final Unit
setTitle(@StringRes() Integer titleResID)
Sets the Title of ProgressDialog using the String resource given. final Boolean
hideTitle()
Hides the Title of ProgressDialog. final Unit
incrementProgress()
Increments the Progress Value of Determinate ProgressBar using the Offset Value set using incrementValue. final Boolean
showProgressTextAsFraction(Boolean progressTextAsFraction)
Toggles the Progress TextView's format as Fraction if "true" is passed. final Boolean
hideProgressText()
Hides the Progress TextView. final Unit
show()
Starts the ProgressDialog and shows it on the Screen. final Unit
dismiss()
Dismisses the ProgressDialog, removing it from the Screen. final Boolean
setOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
Sets the DialogInterface.OnCancelListener for ProgressDialog. final Unit
setOnDismissListener(DialogInterface.OnDismissListener onDismissListener)
Sets the DialogInterface.OnDismissListener for ProgressDialog. final Unit
setOnShowListener(DialogInterface.OnShowListener onShowListener)
Sets the DialogInterface.OnShowListener for ProgressDialog. final Boolean
hasProgressReachedMaxValue()
Checks if ProgressValue is equal to MaxValue. final Integer
remainingProgress()
Gets the Integral Value required to reach MaxValue from the current ProgressValue. final Integer
secondaryRemainingProgress()
Gets the Integral Value required to reach MaxValue from the current Secondary ProgressValue. final Boolean
hasSecondaryProgressReachedMaxValue()
Checks if Secondary ProgressValue is equal to MaxValue. final Boolean
setIndeterminateDrawable(Drawable progressDrawable)
Sets a Custom Drawable to the Indeterminate ProgressBar. final Boolean
setIndeterminateDrawable(@DrawableRes() Integer progressDrawableResID)
Sets a Custom Drawable from the passed Drawable resource to the Indeterminate ProgressBar. final Drawable
getIndeterminateDrawable()
Gets the Drawable object used to draw the Indeterminate ProgressBar. final Boolean
setDeterminateDrawable(Drawable progressDrawable)
Sets a Custom Drawable to the Determinate ProgressBar. final Boolean
setDeterminateDrawable(@DrawableRes() Integer progressDrawableResID)
Sets a Custom Drawable from the passed Drawable resource to the Determinate ProgressBar. final Drawable
getDeterminateDrawable()
Gets the Drawable object used to draw the Determinate ProgressBar. final Unit
setNegativeButton(CharSequence text, CharSequence title, View.OnClickListener listener)
Sets the NegativeButton with the passed text for the ProgressDialog and also sets the OnClickListener for the Button. final Unit
setNegativeButton(@StringRes() Integer textResID, @StringRes() Integer titleResID, View.OnClickListener listener)
Sets the NegativeButton with the text from passed resource id for the ProgressDialog and also sets the OnClickListener for the Button. final Unit
hideNegativeButton()
Hides the NegativeButton. -
-
Constructor Detail
-
ProgressDialog
ProgressDialog(Integer modeConstant, Context context, Integer themeConstant)
- Parameters:
modeConstant
- The Int constant, which is an optional parameter that accepts either MODE_DETERMINATE or MODE_INDETERMINATE.context
- The Activity context which must be provided for sure no matter which overloaded constructor is called.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.
-
ProgressDialog
ProgressDialog(Integer modeConstant, Context context)
- Parameters:
modeConstant
- The Int constant, which is an optional parameter that accepts either MODE_DETERMINATE or MODE_INDETERMINATE.context
- The Activity context which must be provided for sure no matter which overloaded constructor is called.
-
ProgressDialog
ProgressDialog(Context context)
- Parameters:
context
- The Activity context which must be provided for sure no matter which overloaded constructor is called.
-
-
Method Detail
-
isCancelable
final Boolean isCancelable()
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.
-
setCancelable
final Unit setCancelable(Boolean isCancelable)
-
getProgress
final Integer getProgress()
-
setProgress
final Unit setProgress(Integer progress)
-
getIncrementValue
final Integer getIncrementValue()
-
setIncrementValue
final Unit setIncrementValue(Integer incrementValue)
-
getMaxValue
final Integer getMaxValue()
-
setMaxValue
final Unit setMaxValue(Integer maxValue)
-
getSecondaryProgress
final Integer getSecondaryProgress()
-
setSecondaryProgress
final Unit setSecondaryProgress(Integer secondaryProgress)
-
getProgressTintList
final ColorStateList getProgressTintList()
-
setProgressTintList
final Unit setProgressTintList(ColorStateList progressTintList)
-
getSecondaryProgressTintList
final ColorStateList getSecondaryProgressTintList()
-
setSecondaryProgressTintList
final Unit setSecondaryProgressTintList(ColorStateList secondaryProgressTintList)
-
getMessage
final CharSequence getMessage()
Gets the Message showed in the ProgressDialog.
-
setMessage
final Unit setMessage(CharSequence message)
Sets the Text to be displayed alongside ProgressBar. Message is "Loading" by Default.
- Parameters:
message
- The Text to be displayed inside ProgressDialog.
-
setMessage
final Unit setMessage(@StringRes() Integer messageResID)
Sets the Text from the resID provided, to be displayed alongside ProgressBar. Message is "Loading" by Default.
- Parameters:
messageResID
- The resource id for the string resource.
-
getTitle
final CharSequence getTitle()
Gets the Current Title of The ProgressDialog.
-
setTitle
final Unit setTitle(CharSequence title)
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.
- Parameters:
title
- The text to be set as the Title of ProgressDialog.
-
setTitle
final Unit setTitle(@StringRes() Integer titleResID)
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.
- Parameters:
titleResID
- The resource id of the string resource.
-
hideTitle
final Boolean hideTitle()
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.
-
incrementProgress
final Unit incrementProgress()
Increments the Progress Value of Determinate ProgressBar using the Offset Value set using incrementValue. Can be used only in MODE_DETERMINATE Mode.
-
showProgressTextAsFraction
final Boolean showProgressTextAsFraction(Boolean progressTextAsFraction)
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.
- Parameters:
progressTextAsFraction
- The boolean value to change Progress TextView's format.
-
hideProgressText
final Boolean hideProgressText()
Hides the Progress TextView. Can be used only in MODE_DETERMINATE.
-
dismiss
final Unit 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.
-
setOnCancelListener
final Boolean setOnCancelListener(DialogInterface.OnCancelListener onCancelListener)
Sets the DialogInterface.OnCancelListener for ProgressDialog. Should be used only if isCancelable was set true earlier since cancel() cannot be called explicitly and ProgressDialog is NOT cancelable by Default.
- Parameters:
onCancelListener
- DialogInterface.OnCancelListener listener object.
-
setOnDismissListener
final Unit setOnDismissListener(DialogInterface.OnDismissListener onDismissListener)
Sets the DialogInterface.OnDismissListener for ProgressDialog.
- Parameters:
onDismissListener
- DialogInterface.OnDismissListener listener object.
-
setOnShowListener
final Unit setOnShowListener(DialogInterface.OnShowListener onShowListener)
Sets the DialogInterface.OnShowListener for ProgressDialog.
- Parameters:
onShowListener
- DialogInterface.OnShowListener listener object.
-
hasProgressReachedMaxValue
final Boolean hasProgressReachedMaxValue()
Checks if ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.
-
remainingProgress
final Integer remainingProgress()
Gets the Integral Value required to reach MaxValue from the current ProgressValue. Can be used only in MODE_DETERMINATE.
-
secondaryRemainingProgress
final Integer secondaryRemainingProgress()
Gets the Integral Value required to reach MaxValue from the current Secondary ProgressValue. Can be used only in MODE_DETERMINATE.
-
hasSecondaryProgressReachedMaxValue
final Boolean hasSecondaryProgressReachedMaxValue()
Checks if Secondary ProgressValue is equal to MaxValue. Can be used only in MODE_DETERMINATE.
-
setIndeterminateDrawable
final Boolean setIndeterminateDrawable(Drawable progressDrawable)
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.
- Parameters:
progressDrawable
- The Drawable object used to draw the Indeterminate ProgressBar.
-
setIndeterminateDrawable
final Boolean setIndeterminateDrawable(@DrawableRes() Integer progressDrawableResID)
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.
- Parameters:
progressDrawableResID
- The resource id of the Drawable resource used to draw the Indeterminate ProgressBar.
-
getIndeterminateDrawable
final Drawable getIndeterminateDrawable()
Gets the Drawable object used to draw the Indeterminate ProgressBar. Can be used only in MODE_INDETERMINATE.
-
setDeterminateDrawable
final Boolean setDeterminateDrawable(Drawable progressDrawable)
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.
- Parameters:
progressDrawable
- The Drawable object used to draw the Determinate ProgressBar.
-
setDeterminateDrawable
final Boolean setDeterminateDrawable(@DrawableRes() Integer progressDrawableResID)
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.
- Parameters:
progressDrawableResID
- The resource id of the Drawable resource used to draw the Determinate ProgressBar.
-
getDeterminateDrawable
final Drawable getDeterminateDrawable()
Gets the Drawable object used to draw the Determinate ProgressBar. Can be used only in MODE_DETERMINATE.
-
setNegativeButton
final Unit setNegativeButton(CharSequence text, CharSequence title, View.OnClickListener listener)
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.
- Parameters:
text
- The text to be set in the NegativeButton.listener
- The View.OnClickListener listener to be set to NegativeButton.
-
setNegativeButton
final Unit setNegativeButton(@StringRes() Integer textResID, @StringRes() Integer titleResID, View.OnClickListener listener)
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.
- Parameters:
textResID
- The resource id of the text to be set in the NegativeButton.listener
- The View.OnClickListener listener to be set to NegativeButton.
-
hideNegativeButton
final Unit 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.
-
-
-
-