Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

CircularProgressDrawable

open class CircularProgressDrawable : Drawable, Animatable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ androidx.swiperefreshlayout.widget.CircularProgressDrawable

Drawable that renders the animated indeterminate progress indicator in the Material design style without depending on API level 11.

While this may be used to draw an indeterminate spinner using start() and methods, this may also be used to draw a progress arc using method. CircularProgressDrawable also supports adding an arrow at the end of the arc by setArrowEnabled(boolean) and setArrowDimensions(float, * float) methods.

To use one of the pre-defined sizes instead of using your own, setStyle(int) should be called with one of the DEFAULT or LARGE styles as its parameter. Doing it so will update the arrow dimensions, ring size and stroke width to fit the one specified.

If no center radius is set via setCenterRadius(float) or setStyle(int) methods, CircularProgressDrawable will fill the bounds set via setBounds(Rect).

Summary

Constants

static Int

Maps to ProgressBar default style.

static Int

Maps to ProgressBar.

Public constructors

<init>(@NonNull context: Context)

Public methods

open Unit
draw(canvas: Canvas!)

open Int

open Boolean

Returns true if the arrow at the end of the spinner is shown.

open Float

Returns the arrow height in pixels.

open Float

Returns the scale of the arrow at the end of the spinner.

open Float

Returns the arrow width in pixels.

open Int

Returns the background color of the circle drawn inside the drawable.

open Float

Returns the center radius for the progress spinner in pixels.

open IntArray

Returns the colors used in the progress animation

open Float

Returns the end trim for the progress spinner arc

open Int

open Float

Returns the amount of rotation applied to the progress spinner.

open Float

Returns the start trim for the progress spinner arc

open Cap

Returns the stroke cap of the progress spinner.

open Float

Returns the stroke width for the progress spinner in pixels.

open Boolean

open Unit
setAlpha(alpha: Int)

open Unit
setArrowDimensions(width: Float, height: Float)

Sets the dimensions of the arrow at the end of the spinner in pixels.

open Unit

Sets if the arrow at the end of the spinner should be shown.

open Unit

Sets the scale of the arrow at the end of the spinner.

open Unit

Sets the background color of the circle inside the drawable.

open Unit
setCenterRadius(centerRadius: Float)

Sets the center radius for the progress spinner in pixels.

open Unit
setColorFilter(colorFilter: ColorFilter!)

open Unit
setColorSchemeColors(@NonNull vararg colors: Int)

Sets the colors used in the progress animation from a color list.

open Unit

Sets the amount of rotation to apply to the progress spinner.

open Unit
setStartEndTrim(start: Float, end: Float)

Sets the start and end trim for the progress spinner arc.

open Unit
setStrokeCap(@NonNull strokeCap: Cap)

Sets the stroke cap of the progress spinner.

open Unit
setStrokeWidth(strokeWidth: Float)

Sets the stroke width for the progress spinner in pixels.

open Unit
setStyle(size: Int)

Sets the overall size for the progress spinner.

open Unit

Starts the animation for the spinner.

open Unit

Stops the animation for the spinner.

Constants

DEFAULT

static val DEFAULT: Int

Maps to ProgressBar default style.

Value: 1

LARGE

static val LARGE: Int

Maps to ProgressBar.Large style.

Value: 0

Public constructors

<init>

CircularProgressDrawable(@NonNull context: Context)
Parameters
context Context: application context

Public methods

draw

open fun draw(canvas: Canvas!): Unit

getAlpha

open fun getAlpha(): Int

getArrowEnabled

open fun getArrowEnabled(): Boolean

Returns true if the arrow at the end of the spinner is shown.

Return
Boolean: true if the arrow is shown, false otherwise.

getArrowHeight

open fun getArrowHeight(): Float

Returns the arrow height in pixels.

Return
Float: arrow height in pixels

getArrowScale

open fun getArrowScale(): Float

Returns the scale of the arrow at the end of the spinner.

Return
Float: scale of the arrow

getArrowWidth

open fun getArrowWidth(): Float

Returns the arrow width in pixels.

Return
Float: arrow width in pixels

getBackgroundColor

open fun getBackgroundColor(): Int

Returns the background color of the circle drawn inside the drawable.

Return
Int: an ARGB color

getCenterRadius

open fun getCenterRadius(): Float

Returns the center radius for the progress spinner in pixels.

Return
Float: center radius in pixels

getColorSchemeColors

@NonNull open fun getColorSchemeColors(): IntArray

Returns the colors used in the progress animation

Return
IntArray: list of ARGB colors

getEndTrim

open fun getEndTrim(): Float

Returns the end trim for the progress spinner arc

Return
Float: end trim from [0..1]

getOpacity

open fun getOpacity(): Int

getProgressRotation

open fun getProgressRotation(): Float

Returns the amount of rotation applied to the progress spinner.

Return
Float: amount of rotation from [0..1]

getStartTrim

open fun getStartTrim(): Float

Returns the start trim for the progress spinner arc

Return
Float: start trim from [0..1]

getStrokeCap

@NonNull open fun getStrokeCap(): Cap

Returns the stroke cap of the progress spinner.

Return
Cap: stroke cap

getStrokeWidth

open fun getStrokeWidth(): Float

Returns the stroke width for the progress spinner in pixels.

Return
Float: stroke width in pixels

isRunning

open fun isRunning(): Boolean

setAlpha

open fun setAlpha(alpha: Int): Unit

setArrowDimensions

open fun setArrowDimensions(width: Float, height: Float): Unit

Sets the dimensions of the arrow at the end of the spinner in pixels.

Parameters
width Float: width of the baseline of the arrow in pixels
height Float: distance from tip of the arrow to its baseline in pixels

setArrowEnabled

open fun setArrowEnabled(show: Boolean): Unit

Sets if the arrow at the end of the spinner should be shown.

Parameters
show Boolean: true if the arrow should be drawn, false otherwise

setArrowScale

open fun setArrowScale(scale: Float): Unit

Sets the scale of the arrow at the end of the spinner.

Parameters
scale Float: scaling that will be applied to the arrow's both width and height when drawing.

setBackgroundColor

open fun setBackgroundColor(color: Int): Unit

Sets the background color of the circle inside the drawable. Calling does not affect the visibility background color, so it should be set separately if it needs to be hidden or visible.

Parameters
color Int: an ARGB color

setCenterRadius

open fun setCenterRadius(centerRadius: Float): Unit

Sets the center radius for the progress spinner in pixels. If set to 0, this drawable will fill the bounds when drawn.

Parameters
centerRadius Float: center radius in pixels

setColorFilter

open fun setColorFilter(colorFilter: ColorFilter!): Unit

setColorSchemeColors

open fun setColorSchemeColors(@NonNull vararg colors: Int): Unit

Sets the colors used in the progress animation from a color list. The first color will also be the color to be used if animation is not started yet.

Parameters
colors Int: list of ARGB colors to be used in the spinner

setProgressRotation

open fun setProgressRotation(rotation: Float): Unit

Sets the amount of rotation to apply to the progress spinner.

Parameters
rotation Float: rotation from [0..1]

setStartEndTrim

open fun setStartEndTrim(start: Float, end: Float): Unit

Sets the start and end trim for the progress spinner arc. 0 corresponds to the geometric angle of 0 degrees (3 o'clock on a watch) and it increases clockwise, coming to a full circle at 1.

Parameters
start Float: starting position of the arc from [0..1]
end Float: ending position of the arc from [0..1]

setStrokeCap

open fun setStrokeCap(@NonNull strokeCap: Cap): Unit

Sets the stroke cap of the progress spinner. Default stroke cap is Paint.Cap#SQUARE.

Parameters
strokeCap Cap: stroke cap

setStrokeWidth

open fun setStrokeWidth(strokeWidth: Float): Unit

Sets the stroke width for the progress spinner in pixels.

Parameters
strokeWidth Float: stroke width in pixels

setStyle

open fun setStyle(size: Int): Unit

Sets the overall size for the progress spinner. This updates the radius and stroke width of the ring, and arrow dimensions.

Parameters
size Int: one of LARGE or DEFAULT

start

open fun start(): Unit

Starts the animation for the spinner.

stop

open fun stop(): Unit

Stops the animation for the spinner.