Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

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.

static Int

Maps to ProgressBar default style.

Public constructors
<init>(@NonNull context: Context)

Public methods
open Float

Returns the center radius for the progress spinner in pixels.

open Unit
setStrokeCap(@NonNull strokeCap: Cap)

Sets the stroke cap of the progress spinner.

open Boolean

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

open Unit

Starts the animation for the spinner.

open Cap

Returns the stroke cap of the progress spinner.

open Float

Returns the amount of rotation applied to the progress spinner.

open Float

Returns the start trim for the progress spinner arc

open Boolean

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

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

open Unit
setStyle(size: Int)

Sets the overall size for the progress spinner.

open Unit

Sets the background color of the circle inside the drawable.

open Int

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

open Unit

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

open Float

Returns the end trim for the progress spinner arc

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
setArrowDimensions(width: Float, height: Float)

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

open Unit
draw(canvas: Canvas!)

open Unit
setCenterRadius(centerRadius: Float)

Sets the center radius for the progress spinner in pixels.

open Int

open Unit
setAlpha(alpha: Int)

open Int

open Unit

Stops the animation for the spinner.

open Unit
setStrokeWidth(strokeWidth: Float)

Sets the stroke width for the progress spinner in pixels.

open Float

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

open Unit

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

open IntArray

Returns the colors used in the progress animation

open Float

Returns the arrow height in pixels.

open Float

Returns the stroke width for the progress spinner in pixels.

open Float

Returns the arrow width in pixels.

open Unit

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

Constants

LARGE

static val LARGE: Int

Maps to ProgressBar.Large style.

Value: 0

DEFAULT

static val DEFAULT: Int

Maps to ProgressBar default style.

Value: 1

Public constructors

<init>

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

Public methods

getCenterRadius

open fun getCenterRadius(): Float

Returns the center radius for the progress spinner in pixels.

Return
Float: center radius in pixels

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

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.

start

open fun start(): Unit

Starts the animation for the spinner.

getStrokeCap

@NonNull open fun getStrokeCap(): Cap

Returns the stroke cap of the progress spinner.

Return
Cap: stroke cap

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]

isRunning

open fun isRunning(): Boolean

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]

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

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

getBackgroundColor

open fun getBackgroundColor(): Int

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

Return
Int: an ARGB color

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.

getEndTrim

open fun getEndTrim(): Float

Returns the end trim for the progress spinner arc

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

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

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

draw

open fun draw(canvas: Canvas!): Unit

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

getAlpha

open fun getAlpha(): Int

setAlpha

open fun setAlpha(alpha: Int): Unit

getOpacity

open fun getOpacity(): Int

stop

open fun stop(): Unit

Stops the animation for the spinner.

setStrokeWidth

open fun setStrokeWidth(strokeWidth: Float): Unit

Sets the stroke width for the progress spinner in pixels.

Parameters
strokeWidth Float: stroke width 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

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]

getColorSchemeColors

@NonNull open fun getColorSchemeColors(): IntArray

Returns the colors used in the progress animation

Return
IntArray: list of ARGB colors

getArrowHeight

open fun getArrowHeight(): Float

Returns the arrow height in pixels.

Return
Float: arrow height in pixels

getStrokeWidth

open fun getStrokeWidth(): Float

Returns the stroke width for the progress spinner in pixels.

Return
Float: stroke width in pixels

getArrowWidth

open fun getArrowWidth(): Float

Returns the arrow width in pixels.

Return
Float: arrow width 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