added in version 26.1.0
belongs to Maven artifact com.android.support:swiperefreshlayout:28.0.0-alpha1

CircularProgressDrawable

public class CircularProgressDrawable
extends Drawable implements Animatable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.support.v4.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 stop() methods, this may also be used to draw a progress arc using setStartEndTrim(float, float) 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

int DEFAULT

Maps to ProgressBar default style.

int LARGE

Maps to ProgressBar.Large style.

Public constructors

CircularProgressDrawable(Context context)

Public methods

void draw(Canvas canvas)
int getAlpha()
boolean getArrowEnabled()

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

float getArrowHeight()

Returns the arrow height in pixels.

float getArrowScale()

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

float getArrowWidth()

Returns the arrow width in pixels.

int getBackgroundColor()

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

float getCenterRadius()

Returns the center radius for the progress spinner in pixels.

int[] getColorSchemeColors()

Returns the colors used in the progress animation

float getEndTrim()

Returns the end trim for the progress spinner arc

int getOpacity()
float getProgressRotation()

Returns the amount of rotation applied to the progress spinner.

float getStartTrim()

Returns the start trim for the progress spinner arc

Paint.Cap getStrokeCap()

Returns the stroke cap of the progress spinner.

float getStrokeWidth()

Returns the stroke width for the progress spinner in pixels.

boolean isRunning()
void setAlpha(int alpha)
void setArrowDimensions(float width, float height)

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

void setArrowEnabled(boolean show)

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

void setArrowScale(float scale)

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

void setBackgroundColor(int color)

Sets the background color of the circle inside the drawable.

void setCenterRadius(float centerRadius)

Sets the center radius for the progress spinner in pixels.

void setColorFilter(ColorFilter colorFilter)
void setColorSchemeColors(int... colors)

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

void setProgressRotation(float rotation)

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

void setStartEndTrim(float start, float end)

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

void setStrokeCap(Paint.Cap strokeCap)

Sets the stroke cap of the progress spinner.

void setStrokeWidth(float strokeWidth)

Sets the stroke width for the progress spinner in pixels.

void setStyle(int size)

Sets the overall size for the progress spinner.

void start()

Starts the animation for the spinner.

void stop()

Stops the animation for the spinner.

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface android.graphics.drawable.Animatable

Constants

DEFAULT

added in version 26.1.0
int DEFAULT

Maps to ProgressBar default style.

Constant Value: 1 (0x00000001)

LARGE

added in version 26.1.0
int LARGE

Maps to ProgressBar.Large style.

Constant Value: 0 (0x00000000)

Public constructors

CircularProgressDrawable

added in version 26.1.0
CircularProgressDrawable (Context context)

Parameters
context Context: application context

Public methods

draw

added in version 26.1.0
void draw (Canvas canvas)

Parameters
canvas Canvas

getAlpha

int getAlpha ()

Returns
int

getArrowEnabled

added in version 26.1.0
boolean getArrowEnabled ()

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 version 26.1.0
float getArrowHeight ()

Returns the arrow height in pixels.

Returns
float arrow height in pixels

getArrowScale

added in version 26.1.0
float getArrowScale ()

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

Returns
float scale of the arrow

getArrowWidth

added in version 26.1.0
float getArrowWidth ()

Returns the arrow width in pixels.

Returns
float arrow width in pixels

getBackgroundColor

added in version 26.1.0
int getBackgroundColor ()

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

Returns
int an ARGB color

getCenterRadius

added in version 26.1.0
float getCenterRadius ()

Returns the center radius for the progress spinner in pixels.

Returns
float center radius in pixels

getColorSchemeColors

added in version 26.1.0
int[] getColorSchemeColors ()

Returns the colors used in the progress animation

Returns
int[] list of ARGB colors

getEndTrim

added in version 26.1.0
float getEndTrim ()

Returns the end trim for the progress spinner arc

Returns
float end trim from [0..1]

getOpacity

added in version 26.1.0
int getOpacity ()

Returns
int

getProgressRotation

added in version 26.1.0
float getProgressRotation ()

Returns the amount of rotation applied to the progress spinner.

Returns
float amount of rotation from [0..1]

getStartTrim

added in version 26.1.0
float getStartTrim ()

Returns the start trim for the progress spinner arc

Returns
float start trim from [0..1]

getStrokeCap

added in version 26.1.0
Paint.Cap getStrokeCap ()

Returns the stroke cap of the progress spinner.

Returns
Paint.Cap stroke cap

getStrokeWidth

added in version 26.1.0
float getStrokeWidth ()

Returns the stroke width for the progress spinner in pixels.

Returns
float stroke width in pixels

isRunning

added in version 26.1.0
boolean isRunning ()

Returns
boolean

setAlpha

added in version 26.1.0
void setAlpha (int alpha)

Parameters
alpha int

setArrowDimensions

added in version 26.1.0
void setArrowDimensions (float width, 
                float height)

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 version 26.1.0
void setArrowEnabled (boolean show)

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 version 26.1.0
void setArrowScale (float scale)

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 version 26.1.0
void setBackgroundColor (int color)

Sets the background color of the circle inside the drawable. Calling setAlpha(int) 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 version 26.1.0
void setCenterRadius (float centerRadius)

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 version 26.1.0
void setColorFilter (ColorFilter colorFilter)

Parameters
colorFilter ColorFilter

setColorSchemeColors

added in version 26.1.0
void setColorSchemeColors (int... colors)

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

added in version 26.1.0
void setProgressRotation (float rotation)

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

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

setStartEndTrim

added in version 26.1.0
void setStartEndTrim (float start, 
                float end)

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 version 26.1.0
void setStrokeCap (Paint.Cap strokeCap)

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

Parameters
strokeCap Paint.Cap: stroke cap

setStrokeWidth

added in version 26.1.0
void setStrokeWidth (float strokeWidth)

Sets the stroke width for the progress spinner in pixels.

Parameters
strokeWidth float: stroke width in pixels

setStyle

added in version 26.1.0
void setStyle (int size)

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 version 26.1.0
void start ()

Starts the animation for the spinner.

stop

added in version 26.1.0
void stop ()

Stops the animation for the spinner.