BaseProgressIndicator

public abstract class BaseProgressIndicator
extends ProgressBar

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ProgressBar
       ↳ com.google.android.material.progressindicator.BaseProgressIndicator<S extends com.google.android.material.progressindicator.BaseProgressIndicatorSpec>


This class contains the common functions shared in different types of progress indicators. This is an abstract class which is not meant for directly use.

With the default style Widget.MaterialComponents.ProgressIndicator, 4dp indicator/track thickness and no animation is used for visibility change. Without customization, primaryColor will be used as the indicator color; the indicator color applying disabledAlpha will be used as the track color. The following attributes can be used to customize the progress indicator's appearance:

  • trackThickness: the thickness of the indicator and track.
  • indicatorColor: the color(s) of the indicator.
  • trackColor: the color of the track.
  • trackCornerRadius: the radius of the rounded corner of the indicator and track.
  • showAnimationBehavior: the animation direction to show the indicator and track.
  • hideAnimationBehavior: the animation direction to hide the indicator and track.

Summary

Constants

int HIDE_ESCAPE

int HIDE_INWARD

int HIDE_NONE

int HIDE_OUTWARD

int SHOW_INWARD

int SHOW_NONE

int SHOW_OUTWARD

Inherited constants

Inherited fields

Protected constructors

BaseProgressIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

Drawable getCurrentDrawable()

Returns the corresponding drawable based on current indeterminate state.

int getHideAnimationBehavior()

Returns the hide animation behavior used in this progress indicator.

IndeterminateDrawable<S> getIndeterminateDrawable()
int[] getIndicatorColor()

Returns the array of colors used in the indicator of this progress indicator.

int getIndicatorTrackGapSize()

Returns the size of the gap between the indicator and track in pixels.

DeterminateDrawable<S> getProgressDrawable()
int getShowAnimationBehavior()

Returns the show animation behavior used in this progress indicator.

int getTrackColor()

Returns the color used in the track of this progress indicator.

int getTrackCornerRadius()

Returns the radius of the rounded corner for the indicator and track in pixels.

int getTrackThickness()

Returns the track thickness of this progress indicator in pixels.

void hide()

Hides the progress indicator.

void invalidate()
void setHideAnimationBehavior(int hideAnimationBehavior)

Sets the hide animation behavior used in this progress indicator.

void setIndeterminate(boolean indeterminate)

Sets the progress mode of the progress indicator.

void setIndeterminateDrawable(Drawable drawable)

Sets a new indeterminate drawable.

void setIndicatorColor(int... indicatorColors)

Sets the colors used in the indicator of this progress indicator.

void setIndicatorTrackGapSize(int indicatorTrackGapSize)

Sets the size of the gap between the indicator and track in pixels.

void setProgress(int progress)

Sets the current progress to the specified value.

void setProgressCompat(int progress, boolean animated)

Sets the current progress to the specified value with/without animation based on the input.

void setProgressDrawable(Drawable drawable)

Sets a new progress drawable.

void setShowAnimationBehavior(int showAnimationBehavior)

Sets the show animation behavior used in this progress indicator.

void setTrackColor(int trackColor)

Sets the color of the track of this progress indicator.

void setTrackCornerRadius(int trackCornerRadius)

Sets the radius of the rounded corner for the indicator and track in pixels.

void setTrackThickness(int trackThickness)

Sets the track thickness of this progress indicator.

void setVisibilityAfterHide(int visibility)

Sets the visibility which the component will be after hide animation finishes.

void show()

Shows the progress indicator.

Protected methods

void applyNewVisibility(boolean animate)

If it changes to visible, the start animation will be started if showAnimationBehavior indicates any.

void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void onVisibilityChanged(View changedView, int visibility)
void onWindowVisibilityChanged(int visibility)

Inherited methods

Constants

HIDE_ESCAPE

public static final int HIDE_ESCAPE

Constant Value: 3 (0x00000003)

HIDE_INWARD

public static final int HIDE_INWARD

Constant Value: 2 (0x00000002)

HIDE_NONE

public static final int HIDE_NONE

Constant Value: 0 (0x00000000)

HIDE_OUTWARD

public static final int HIDE_OUTWARD

Constant Value: 1 (0x00000001)

SHOW_INWARD

public static final int SHOW_INWARD

Constant Value: 2 (0x00000002)

SHOW_NONE

public static final int SHOW_NONE

Constant Value: 0 (0x00000000)

SHOW_OUTWARD

public static final int SHOW_OUTWARD

Constant Value: 1 (0x00000001)

Protected constructors

BaseProgressIndicator

protected BaseProgressIndicator (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

getCurrentDrawable

public Drawable getCurrentDrawable ()

Returns the corresponding drawable based on current indeterminate state.

Returns
Drawable

getHideAnimationBehavior

public int getHideAnimationBehavior ()

Returns the hide animation behavior used in this progress indicator.

Returns
int

getIndeterminateDrawable

public IndeterminateDrawable<S> getIndeterminateDrawable ()

Returns
IndeterminateDrawable<S>

getIndicatorColor

public int[] getIndicatorColor ()

Returns the array of colors used in the indicator of this progress indicator.

Returns
int[]

getIndicatorTrackGapSize

public int getIndicatorTrackGapSize ()

Returns the size of the gap between the indicator and track in pixels.

Returns
int

getProgressDrawable

public DeterminateDrawable<S> getProgressDrawable ()

Returns
DeterminateDrawable<S>

getShowAnimationBehavior

public int getShowAnimationBehavior ()

Returns the show animation behavior used in this progress indicator.

Returns
int

getTrackColor

public int getTrackColor ()

Returns the color used in the track of this progress indicator.

Returns
int

See also:

getTrackCornerRadius

public int getTrackCornerRadius ()

Returns the radius of the rounded corner for the indicator and track in pixels.

Returns
int

getTrackThickness

public int getTrackThickness ()

Returns the track thickness of this progress indicator in pixels.

Returns
int

hide

public void hide ()

Hides the progress indicator. If minHideDelay has been set to a positive value, wait until the delay elapsed before starting the hide action. Otherwise start hiding immediately.

invalidate

public void invalidate ()

setHideAnimationBehavior

public void setHideAnimationBehavior (int hideAnimationBehavior)

Sets the hide animation behavior used in this progress indicator.

Parameters
hideAnimationBehavior int: The new behavior of hide animation.

setIndeterminate

public void setIndeterminate (boolean indeterminate)

Sets the progress mode of the progress indicator. Will throw an IllegalStateException if the progress indicator is visible.

Parameters
indeterminate boolean: Whether the progress indicator should be in indeterminate mode.

setIndeterminateDrawable

public void setIndeterminateDrawable (Drawable drawable)

Sets a new indeterminate drawable. It has to inherit from IndeterminateDrawable.

Parameters
drawable Drawable: The new indeterminate drawable.

Throws
IllegalArgumentException if a framework drawable is passed in.

setIndicatorColor

public void setIndicatorColor (int... indicatorColors)

Sets the colors used in the indicator of this progress indicator.

Parameters
indicatorColors int: The new colors used in indicator.

setIndicatorTrackGapSize

public void setIndicatorTrackGapSize (int indicatorTrackGapSize)

Sets the size of the gap between the indicator and track in pixels.

Parameters
indicatorTrackGapSize int: The new gap size in pixels.

setProgress

public void setProgress (int progress)

Sets the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode. Animation is not used by default. This default setting is aligned with ProgressBar.setProgress(int).

Parameters
progress int: The new progress value.

setProgressCompat

public void setProgressCompat (int progress, 
                boolean animated)

Sets the current progress to the specified value with/without animation based on the input.

If it's in the indeterminate mode, it will smoothly transition to determinate mode by finishing the current indeterminate animation cycle.

Parameters
progress int: The new progress value.

animated boolean: Whether to update the progress with the animation.

See also:

setProgressDrawable

public void setProgressDrawable (Drawable drawable)

Sets a new progress drawable. It has to inherit from DeterminateDrawable.

Parameters
drawable Drawable: The new progress drawable.

Throws
IllegalArgumentException if a framework drawable is passed in.

setShowAnimationBehavior

public void setShowAnimationBehavior (int showAnimationBehavior)

Sets the show animation behavior used in this progress indicator.

Parameters
showAnimationBehavior int: The new behavior of show animation.

setTrackColor

public void setTrackColor (int trackColor)

Sets the color of the track of this progress indicator.

Parameters
trackColor int: The new color used in the track of this progress indicator.

See also:

setTrackCornerRadius

public void setTrackCornerRadius (int trackCornerRadius)

Sets the radius of the rounded corner for the indicator and track in pixels.

Parameters
trackCornerRadius int: The new corner radius in pixels.

setTrackThickness

public void setTrackThickness (int trackThickness)

Sets the track thickness of this progress indicator.

Parameters
trackThickness int: The new track/indicator thickness in pixels.

setVisibilityAfterHide

public void setVisibilityAfterHide (int visibility)

Sets the visibility which the component will be after hide animation finishes.

Parameters
visibility int: New component's visibility after the hide animation finishes.

show

public void show ()

Shows the progress indicator. If showDelay has been set to a positive value, wait until the delay elapsed before starting the show action. Otherwise start showing immediately.

Protected methods

applyNewVisibility

protected void applyNewVisibility (boolean animate)

If it changes to visible, the start animation will be started if showAnimationBehavior indicates any. If it changes to invisible, hides the drawable immediately.

Parameters
animate boolean: Whether to change the visibility with animation.

onAttachedToWindow

protected void onAttachedToWindow ()

onDetachedFromWindow

protected void onDetachedFromWindow ()

onDraw

protected void onDraw (Canvas canvas)

Parameters
canvas Canvas

onMeasure

protected void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onVisibilityChanged

protected void onVisibilityChanged (View changedView, 
                int visibility)

Parameters
changedView View

visibility int

onWindowVisibilityChanged

protected void onWindowVisibilityChanged (int visibility)

Parameters
visibility int