BaseProgressIndicator

public abstract class BaseProgressIndicator<S extends BaseProgressIndicatorSpec>

Known direct subclasses
CircularProgressIndicator

This class implements the circular type progress indicators.

LinearProgressIndicator

This class implements the linear type progress indicators.


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

static final int
static final int
static final int
static final int
static final int
static final int
static final int

Protected constructors

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

Public methods

Drawable

Returns the corresponding drawable based on current indeterminate state.

int

Returns the hide animation behavior used in this progress indicator.

IndeterminateDrawable<S>
int[]

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

int

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

DeterminateDrawable<S>
int

Returns the show animation behavior used in this progress indicator.

int

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

int

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

float

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

int

Returns the track thickness of this progress indicator in pixels.

int

Returns the amplitude of the indicator's amplitude in pixels.

int

Returns the speed of the indicator's waveform in pixels.

int

Returns the wavelength, in pixels, of the indicator's waveform in determinate mode.

int

Returns the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

Hides the progress indicator.

void
void
setHideAnimationBehavior(int hideAnimationBehavior)

Sets the hide animation behavior used in this progress indicator.

synchronized void
setIndeterminate(boolean indeterminate)

Sets the progress mode of the progress indicator.

void
setIndeterminateAnimatorDurationScale(
    float indeterminateAnimatorDurationScale
)

Sets the scale of the animation duration in indeterminate mode.

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.

synchronized 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

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

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
setWaveAmplitude(int waveAmplitude)

Sets the amplitude of the indicator's amplitude in pixels.

void
setWaveSpeed(int waveSpeed)

Sets the speed of the indicator's waveform in pixels.

void
setWavelength(int wavelength)

Sets the wavelength of the indicator's determinate and indeterminate waveform in pixels.

void
setWavelengthDeterminate(int wavelength)

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

void

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
void
synchronized void
onDraw(Canvas canvas)
void
onLayout(boolean changed, int left, int top, int right, int bottom)
synchronized void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onVisibilityChanged(View changedView, int visibility)
void
onWindowVisibilityChanged(int visibility)

Constants

HIDE_ESCAPE

public static final int HIDE_ESCAPE = 3

HIDE_INWARD

public static final int HIDE_INWARD = 2

HIDE_NONE

public static final int HIDE_NONE = 0

HIDE_OUTWARD

public static final int HIDE_OUTWARD = 1

SHOW_INWARD

public static final int SHOW_INWARD = 2

SHOW_NONE

public static final int SHOW_NONE = 0

SHOW_OUTWARD

public static final int SHOW_OUTWARD = 1

Protected constructors

BaseProgressIndicator

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

Public methods

getCurrentDrawable

public Drawable getCurrentDrawable()

Returns the corresponding drawable based on current indeterminate state.

getHideAnimationBehavior

public int getHideAnimationBehavior()

Returns the hide animation behavior used in this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_hideAnimationBehavior

getIndeterminateDrawable

public IndeterminateDrawable<S> getIndeterminateDrawable()

getIndicatorColor

public int[] getIndicatorColor()

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_indicatorColor

getIndicatorTrackGapSize

public int getIndicatorTrackGapSize()

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_indicatorTrackGapSize

getProgressDrawable

public DeterminateDrawable<S> getProgressDrawable()

getShowAnimationBehavior

public int getShowAnimationBehavior()

Returns the show animation behavior used in this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_showAnimationBehavior

getTrackColor

public int getTrackColor()

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackColor

See also
setTrackColor

getTrackCornerRadius

public int getTrackCornerRadius()

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackCornerRadius

getTrackCornerRadiusFraction

public float getTrackCornerRadiusFraction()

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackCornerRadius

getTrackThickness

public int getTrackThickness()

Returns the track thickness of this progress indicator in pixels.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackThickness

getWaveAmplitude

public int getWaveAmplitude()

Returns the amplitude of the indicator's amplitude in pixels.

See also
setWaveAmplitude

getWaveSpeed

public int getWaveSpeed()

Returns the speed of the indicator's waveform in pixels.

See also
setWaveSpeed

getWavelengthDeterminate

public int getWavelengthDeterminate()

Returns the wavelength, in pixels, of the indicator's waveform in determinate mode.

getWavelengthIndeterminate

public int getWavelengthIndeterminate()

Returns the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

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.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_hideAnimationBehavior

Parameters
int hideAnimationBehavior

The new behavior of hide animation.

setIndeterminate

synchronized public void setIndeterminate(boolean indeterminate)

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

Parameters
boolean indeterminate

Whether the progress indicator should be in indeterminate mode.

setIndeterminateAnimatorDurationScale

public void setIndeterminateAnimatorDurationScale(
    float indeterminateAnimatorDurationScale
)

Sets the scale of the animation duration in indeterminate mode.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_indeterminateAnimatorDurationScale

Parameters
float indeterminateAnimatorDurationScale

The new scale of the animation duration 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
java.lang.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.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_indicatorColor

Parameters
int[] indicatorColors

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.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_indicatorTrackGapSize

Parameters
int indicatorTrackGapSize

The new gap size in pixels.

setProgress

synchronized 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 setProgress.

Parameters
int progress

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
int progress

The new progress value.

boolean animated

Whether to update the progress with the animation.

See also
setProgress

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
java.lang.IllegalArgumentException

if a framework drawable is passed in.

setShowAnimationBehavior

public void setShowAnimationBehavior(int showAnimationBehavior)

Sets the show animation behavior used in this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_showAnimationBehavior

Parameters
int showAnimationBehavior

The new behavior of show animation.

setTrackColor

public void setTrackColor(int trackColor)

Sets the color of the track of this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackColor

Parameters
int trackColor

The new color used in the track of this progress indicator.

See also
getTrackColor

setTrackCornerRadius

public void setTrackCornerRadius(int trackCornerRadius)

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackCornerRadius

Parameters
int trackCornerRadius

The new corner radius in pixels.

setTrackCornerRadiusFraction

public void setTrackCornerRadiusFraction(float fraction)

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

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackCornerRadius

Parameters
float fraction

The fraction of corner radius to track thickness.

setTrackThickness

public void setTrackThickness(int trackThickness)

Sets the track thickness of this progress indicator.

ref com.google.android.material.progressindicator.R.styleable#BaseProgressIndicator_trackThickness

Parameters
int trackThickness

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
int visibility

New component's visibility after the hide animation finishes.

setWaveAmplitude

public void setWaveAmplitude(int waveAmplitude)

Sets the amplitude of the indicator's amplitude in pixels.

Parameters
int waveAmplitude

The new amplitude in pixels.

See also
getWaveAmplitude

setWaveSpeed

public void setWaveSpeed(int waveSpeed)

Sets the speed of the indicator's waveform in pixels.

Parameters
int waveSpeed

The new speed in pixels.

See also
getWaveSpeed

setWavelength

public void setWavelength(int wavelength)

Sets the wavelength of the indicator's determinate and indeterminate waveform in pixels.

Parameters
int wavelength

The new wavelength in pixels. No waves are drawn, if it equals to 0.

setWavelengthDeterminate

public void setWavelengthDeterminate(int wavelength)

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

Parameters
int wavelength

The new wavelength in pixels. No waves are drawn when wavelength is zero.

setWavelengthIndeterminate

public void setWavelengthIndeterminate(int wavelength)

Sets the wavelength, in pixels, of the indicator's waveform in indeterminate mode.

Parameters
int wavelength

The new wavelength in pixels. No waves are drawn when wavelength is zero.

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
boolean animate

Whether to change the visibility with animation.

onAttachedToWindow

protected void onAttachedToWindow()

onDetachedFromWindow

protected void onDetachedFromWindow()

onDraw

synchronized protected void onDraw(Canvas canvas)

onLayout

protected void onLayout(boolean changed, int left, int top, int right, int bottom)

onMeasure

synchronized protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)

onVisibilityChanged

protected void onVisibilityChanged(View changedView, int visibility)

onWindowVisibilityChanged

protected void onWindowVisibilityChanged(int visibility)