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

CircularProgressLayout

open class CircularProgressLayout : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ androidx.wear.widget.CircularProgressLayout

CircularProgressLayout adds a circular countdown timer behind the view it contains, typically used to automatically confirm an operation after a short delay has elapsed.

The developer can specify a countdown interval via setTotalTime(long) and a listener via setOnTimerFinishedListener(OnTimerFinishedListener) to be called when the time has elapsed after startTimer() has been called. Tap action can be received via and can be used to cancel the timer via method.

Alternatively, this layout can be used to show indeterminate progress by calling method.

Summary

Nested classes
abstract

Interface to implement for listening to event.

Public constructors
<init>(context: Context!)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Sets the OnTimerFinishedListener to be notified when timer countdown is finished.

open IntArray!

Returns the color scheme colors of the progress drawable

open CircularProgressDrawable

Returns the CircularProgressDrawable used as background of this layout.

open Int

Returns the background color of the CircularProgressDrawable.

open Unit
setColorSchemeColors(vararg colors: Int)

Sets the color scheme colors of the progress drawable, which is equivalent to calling method on background drawable of this layout.

open Unit

Sets the starting rotation for the progress drawable to start from.

open Unit

Starts the timer countdown.

open Float

Returns the starting rotation of the progress drawable.

open Boolean

Returns if the timer is running.

open Float

Returns the stroke width of the progress drawable in pixels.

open Unit
setTotalTime(totalTime: Long)

Sets the total time in milliseconds for the timer to countdown to.

open Unit

Sets the background color of the CircularProgressDrawable, which is drawn as a circle inside the progress drawable.

open Long

Returns the total time in milliseconds for the timer to countdown to.

open Unit
setStrokeWidth(strokeWidth: Float)

Sets the stroke width of the progress drawable in pixels.

open Boolean

Returns if progress is showing as an indeterminate spinner.

open CircularProgressLayout.OnTimerFinishedListener?

Returns the OnTimerFinishedListener that is registered to this layout.

open Unit

Stops the timer countdown.

open Unit
setIndeterminate(indeterminate: Boolean)

Sets if progress should be shown as an indeterminate spinner.

Protected methods
open Unit

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

Public constructors

<init>

CircularProgressLayout(context: Context!)

<init>

CircularProgressLayout(context: Context!, attrs: AttributeSet!)

<init>

CircularProgressLayout(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>

CircularProgressLayout(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods

setOnTimerFinishedListener

open fun setOnTimerFinishedListener(@Nullable listener: CircularProgressLayout.OnTimerFinishedListener?): Unit

Sets the OnTimerFinishedListener to be notified when timer countdown is finished.

Parameters
listener CircularProgressLayout.OnTimerFinishedListener?: OnTimerFinishedListener to be notified, or null to clear

getColorSchemeColors

open fun getColorSchemeColors(): IntArray!

Returns the color scheme colors of the progress drawable

Return
IntArray!: list of ARGB colors

getProgressDrawable

@NonNull open fun getProgressDrawable(): CircularProgressDrawable

Returns the CircularProgressDrawable used as background of this layout.

Return
CircularProgressDrawable: CircularProgressDrawable

getBackgroundColor

open fun getBackgroundColor(): Int

Returns the background color of the CircularProgressDrawable.

Return
Int: an ARGB color

setColorSchemeColors

open fun setColorSchemeColors(vararg colors: Int): Unit

Sets the color scheme colors of the progress drawable, which is equivalent to calling method on background drawable of this layout.

Parameters
colors Int: list of ARGB colors

setStartingRotation

open fun setStartingRotation(rotation: Float): Unit

Sets the starting rotation for the progress drawable to start from. Default starting rotation is 0.75 and it corresponds clockwise geometric 270 degrees (12 o'clock on a watch)

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

startTimer

open fun startTimer(): Unit

Starts the timer countdown. Once the countdown is finished, if there is an registered by method, its OnTimerFinishedListener#onTimerFinished(CircularProgressLayout) method is called. If this method is called while there is already a running timer, it will restart the timer.

getStartingRotation

open fun getStartingRotation(): Float

Returns the starting rotation of the progress drawable.

Return
Float: starting rotation from [0..1]

isTimerRunning

open fun isTimerRunning(): Boolean

Returns if the timer is running.

Return
Boolean: true if the timer is running, false otherwise

getStrokeWidth

open fun getStrokeWidth(): Float

Returns the stroke width of the progress drawable in pixels.

Return
Float: stroke width in pixels

setTotalTime

open fun setTotalTime(totalTime: Long): Unit

Sets the total time in milliseconds for the timer to countdown to. Calling this method while the timer is already running will not change the duration of the current timer.

Parameters
totalTime Long: total time in milliseconds

setBackgroundColor

open fun setBackgroundColor(color: Int): Unit

Sets the background color of the CircularProgressDrawable, which is drawn as a circle inside the progress drawable. Colors are in ARGB format defined in Color.

Parameters
color Int: an ARGB color

getTotalTime

open fun getTotalTime(): Long

Returns the total time in milliseconds for the timer to countdown to.

Return
Long: total time in milliseconds

setStrokeWidth

open fun setStrokeWidth(strokeWidth: Float): Unit

Sets the stroke width of the progress drawable in pixels.

Parameters
strokeWidth Float: stroke width in pixels

isIndeterminate

open fun isIndeterminate(): Boolean

Returns if progress is showing as an indeterminate spinner.

Return
Boolean: true if indeterminate spinner is shown, false otherwise.

getOnTimerFinishedListener

@Nullable open fun getOnTimerFinishedListener(): CircularProgressLayout.OnTimerFinishedListener?

Returns the OnTimerFinishedListener that is registered to this layout.

Return
CircularProgressLayout.OnTimerFinishedListener?: registered OnTimerFinishedListener

stopTimer

open fun stopTimer(): Unit

Stops the timer countdown. If there is no timer running, calling this method will not do anything.

setIndeterminate

open fun setIndeterminate(indeterminate: Boolean): Unit

Sets if progress should be shown as an indeterminate spinner.

Parameters
indeterminate Boolean: true if indeterminate spinner should be shown, false otherwise.

Protected methods

onDetachedFromWindow

protected open fun onDetachedFromWindow(): Unit

onLayout

protected open fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int): Unit