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>(context: Context)

Public methods
open Float

Returns the center radius for the progress spinner in pixels.

open Unit
draw(canvas: Canvas!)

open Unit
setStrokeCap(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 Unit
setCenterRadius(centerRadius: Float)

Sets the center radius for the progress spinner in pixels.

open Int

open Unit
setAlpha(alpha: Int)

open Cap

Returns the stroke cap of the progress spinner.

open Float

Returns the amount of rotation applied to the progress spinner.

open Int

open Float

Returns the start trim for the progress spinner arc

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 Boolean

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 IntArray

Returns the colors used in the progress animation

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 Float

Returns the arrow height in pixels.

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 Float

Returns the stroke width for the progress spinner in pixels.

open Float

Returns the arrow width in pixels.

open Unit
setColorSchemeColors(vararg colors: Int)

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

open Unit

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

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

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

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(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

draw

open fun draw(canvas: Canvas!): Unit

setStrokeCap

open fun setStrokeCap(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.

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

getStrokeCap

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]

getOpacity

open fun getOpacity(): Int

getStartTrim

open fun getStartTrim(): Float

Returns the start trim for the progress spinner arc

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

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

isRunning

open fun isRunning(): Boolean

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]

getColorSchemeColors

open fun getColorSchemeColors(): IntArray

Returns the colors used in the progress animation

Return
IntArray: list of ARGB colors

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

getArrowHeight

open fun getArrowHeight(): Float

Returns the arrow height in pixels.

Return
Float: arrow height in pixels

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

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

setColorSchemeColors

open fun setColorSchemeColors(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

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

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