CircularProgressDrawable


class CircularProgressDrawable : Drawable, Animatable


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 stop methods, this may also be used to draw a progress arc using setStartEndTrim method. CircularProgressDrawable also supports adding an arrow at the end of the arc by setArrowEnabled and setArrowDimensions methods.

To use one of the pre-defined sizes instead of using your own, setStyle 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 or setStyle methods, CircularProgressDrawable will fill the bounds set via setBounds.

Summary

Constants

const Int

Maps to ProgressBar default style.

const Int
LARGE = 0

Maps to ProgressBar.Large style.

Public constructors

Public functions

Unit
draw(canvas: Canvas!)
Int
Boolean

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

Float

Returns the arrow height in pixels.

Float

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

Float

Returns the arrow width in pixels.

Int

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

Float

Returns the center radius for the progress spinner in pixels.

IntArray<Int>

Returns the colors used in the progress animation

Float

Returns the end trim for the progress spinner arc

Int

This function is deprecated.

Float

Returns the amount of rotation applied to the progress spinner.

Float

Returns the start trim for the progress spinner arc

Paint.Cap

Returns the stroke cap of the progress spinner.

Float

Returns the stroke width for the progress spinner in pixels.

Boolean
Unit
setAlpha(alpha: Int)
Unit
setArrowDimensions(width: Float, height: Float)

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

Unit

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

Unit

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

Unit

Sets the background color of the circle inside the drawable.

Unit
setCenterRadius(centerRadius: Float)

Sets the center radius for the progress spinner in pixels.

Unit
setColorFilter(colorFilter: ColorFilter!)
Unit

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

Unit

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

Unit
setStartEndTrim(start: Float, end: Float)

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

Unit
setStrokeCap(strokeCap: Paint.Cap)

Sets the stroke cap of the progress spinner.

Unit
setStrokeWidth(strokeWidth: Float)

Sets the stroke width for the progress spinner in pixels.

Unit
setStyle(size: Int)

Sets the overall size for the progress spinner.

Unit

Starts the animation for the spinner.

Unit

Stops the animation for the spinner.

Inherited functions

From android.graphics.drawable.Drawable
Unit
Boolean
Unit
Rect!
Unit
copyBounds(bounds: Rect!)
java-static Drawable!
createFromPath(pathName: String!)
java-static Drawable!
createFromResourceStream(
    res: Resources!,
    value: TypedValue!,
    is: InputStream!,
    srcName: String!
)
java-static Drawable!
createFromStream(is: InputStream!, srcName: String!)
java-static Drawable!
java-static Drawable!
createFromXmlInner(
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!
)
Rect!
Drawable.Callback!
Int
ColorFilter!
Drawable.ConstantState!
Drawable!
Rect!
Unit
Int
Int
Int
Int
Int
Int
Insets!
Unit
getOutline(outline: Outline!)
Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Boolean
Unit
inflate(r: Resources!, parser: XmlPullParser!, attrs: AttributeSet!)
Unit
Boolean
Boolean
Boolean
Boolean
Boolean
Unit
Drawable!
Unit
onBoundsChange(bounds: Rect!)
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
Boolean
Boolean
java-static Int
resolveOpacity(op1: Int, op2: Int)
Unit
scheduleSelf(what: Runnable!, when: Long)
Unit
Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
Unit
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setLayoutDirection(layoutDirection: Int)
Boolean
setLevel(level: Int)
Boolean
setState(stateSet: IntArray!)
Unit
setTint(tintColor: Int)
Unit
Unit
Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)
Unit

Constants

DEFAULT

Added in 1.0.0
const val DEFAULT = 1: Int

Maps to ProgressBar default style.

LARGE

Added in 1.0.0
const val LARGE = 0: Int

Maps to ProgressBar.Large style.

Public constructors

CircularProgressDrawable

Added in 1.0.0
CircularProgressDrawable(context: Context)
Parameters
context: Context

application context

Public functions

draw

Added in 1.0.0
fun draw(canvas: Canvas!): Unit

getAlpha

fun getAlpha(): Int

getArrowEnabled

Added in 1.0.0
fun getArrowEnabled(): Boolean

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

Returns
Boolean

true if the arrow is shown, false otherwise.

getArrowHeight

Added in 1.0.0
fun getArrowHeight(): Float

Returns the arrow height in pixels.

Returns
Float

arrow height in pixels

getArrowScale

Added in 1.0.0
fun getArrowScale(): Float

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

Returns
Float

scale of the arrow

getArrowWidth

Added in 1.0.0
fun getArrowWidth(): Float

Returns the arrow width in pixels.

Returns
Float

arrow width in pixels

getBackgroundColor

Added in 1.0.0
fun getBackgroundColor(): Int

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

Returns
Int

an ARGB color

getCenterRadius

Added in 1.0.0
fun getCenterRadius(): Float

Returns the center radius for the progress spinner in pixels.

Returns
Float

center radius in pixels

getColorSchemeColors

Added in 1.0.0
fun getColorSchemeColors(): IntArray<Int>

Returns the colors used in the progress animation

Returns
IntArray<Int>

list of ARGB colors

getEndTrim

Added in 1.0.0
fun getEndTrim(): Float

Returns the end trim for the progress spinner arc

Returns
Float

end trim from [0..1]

getOpacity

Added in 1.0.0
fun getOpacity(): Int

getProgressRotation

Added in 1.0.0
fun getProgressRotation(): Float

Returns the amount of rotation applied to the progress spinner.

Returns
Float

amount of rotation from [0..1]

getStartTrim

Added in 1.0.0
fun getStartTrim(): Float

Returns the start trim for the progress spinner arc

Returns
Float

start trim from [0..1]

getStrokeCap

Added in 1.0.0
fun getStrokeCap(): Paint.Cap

Returns the stroke cap of the progress spinner.

Returns
Paint.Cap

stroke cap

getStrokeWidth

Added in 1.0.0
fun getStrokeWidth(): Float

Returns the stroke width for the progress spinner in pixels.

Returns
Float

stroke width in pixels

isRunning

Added in 1.0.0
fun isRunning(): Boolean

setAlpha

Added in 1.0.0
fun setAlpha(alpha: Int): Unit

setArrowDimensions

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
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

Added in 1.0.0
fun setBackgroundColor(color: Int): Unit

Sets the background color of the circle inside the drawable. Calling setAlpha 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

Added in 1.0.0
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

Added in 1.0.0
fun setColorFilter(colorFilter: ColorFilter!): Unit

setColorSchemeColors

fun setColorSchemeColors(colors: IntArray): 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: IntArray

list of ARGB colors to be used in the spinner

setProgressRotation

Added in 1.0.0
fun setProgressRotation(rotation: Float): Unit

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

Parameters
rotation: Float

rotation from [0..1]

setStartEndTrim

Added in 1.0.0
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

Added in 1.0.0
fun setStrokeCap(strokeCap: Paint.Cap): Unit

Sets the stroke cap of the progress spinner. Default stroke cap is SQUARE.

Parameters
strokeCap: Paint.Cap

stroke cap

setStrokeWidth

Added in 1.0.0
fun setStrokeWidth(strokeWidth: Float): Unit

Sets the stroke width for the progress spinner in pixels.

Parameters
strokeWidth: Float

stroke width in pixels

setStyle

Added in 1.0.0
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

Added in 1.0.0
fun start(): Unit

Starts the animation for the spinner.

stop

Added in 1.0.0
fun stop(): Unit

Stops the animation for the spinner.