CircularProgressIndicatorKt

Added in 1.3.0-alpha08

public final class CircularProgressIndicatorKt


Summary

Public methods

static final @NonNull LayoutElementBuilders.Box
circularProgressIndicator(
    @NonNull MaterialScope receiver,
    float staticProgress,
    DynamicBuilders.DynamicFloat dynamicProgress,
    @NonNull LayoutModifier modifier,
    float startAngleDegrees,
    float endAngleDegrees,
    @Dimension(unit = 0) float strokeWidth,
    @Dimension(unit = 0) float gapSize,
    @NonNull ProgressIndicatorColors colors,
    @NonNull DimensionBuilders.ContainerDimension size
)

Protolayout Material3 design circular progress indicator.

static final @NonNull LayoutElementBuilders.Box
segmentedCircularProgressIndicator(
    @NonNull MaterialScope receiver,
    @IntRange(from = 1) int segmentCount,
    float staticProgress,
    DynamicBuilders.DynamicFloat dynamicProgress,
    @NonNull LayoutModifier modifier,
    float startAngleDegrees,
    float endAngleDegrees,
    @Dimension(unit = 0) float strokeWidth,
    @Dimension(unit = 0) float gapSize,
    @NonNull ProgressIndicatorColors colors,
    @NonNull DimensionBuilders.ContainerDimension size
)

Protolayout Material3 design segmented circular progress indicator.

Public methods

circularProgressIndicator

public static final @NonNull LayoutElementBuilders.Box circularProgressIndicator(
    @NonNull MaterialScope receiver,
    float staticProgress,
    DynamicBuilders.DynamicFloat dynamicProgress,
    @NonNull LayoutModifier modifier,
    float startAngleDegrees,
    float endAngleDegrees,
    @Dimension(unit = 0) float strokeWidth,
    @Dimension(unit = 0) float gapSize,
    @NonNull ProgressIndicatorColors colors,
    @NonNull DimensionBuilders.ContainerDimension size
)

Protolayout Material3 design circular progress indicator.

Note that, the proper implementation of this component requires a ProtoLayout renderer with version equal to or above 1.403. When the renderer is lower than 1.403, this component will automatically fallback to an implementation with reduced features, without support for expandable size, and start/end transition.

This component consumes 3 animation quotas when dynamicProgress is specified with animation by the caller. It is highly recommend to use the recommendedAnimationSpec to animate the progress.

import androidx.wear.protolayout.DimensionBuilders.dp
import androidx.wear.protolayout.expression.DynamicBuilders.DynamicFloat
import androidx.wear.protolayout.material3.CircularProgressIndicatorDefaults
import androidx.wear.protolayout.material3.CircularProgressIndicatorDefaults.filledVariantProgressIndicatorColors
import androidx.wear.protolayout.material3.circularProgressIndicator
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.text

materialScope(context, deviceParameters) {
        circularProgressIndicator(
            dynamicProgress =
                DynamicFloat.animate(
                    0.0F,
                    1.1F,
                    CircularProgressIndicatorDefaults.recommendedAnimationSpec
                ),
            startAngleDegrees = 200F,
            endAngleDegrees = 520F,
            colors = filledVariantProgressIndicatorColors(),
            size = dp(85F)
        )
    }
Parameters
float staticProgress

The static progress of this progress indicator where 0 represent no progress and 1 represents completion. Progress above 1 is also allowed. If dynamicProgress is also set, this static value will only be used when the dynamic value cannot be evaluated. By default it equals to 0.

DynamicBuilders.DynamicFloat dynamicProgress

The dynamic progress of this progress indicator where 0 represent no progress and 1 represents completion. Progress above 1 is also allowed. If not provided, the staticProgress is used.

@NonNull LayoutModifier modifier

Modifiers to set to this element. It's highly recommended to set a content description using contentDescription.

float startAngleDegrees

The starting position of the progress arc, measured clockwise in degrees from the 12 o'clock position.

float endAngleDegrees

The ending position of the progress arc, measured clockwise in degrees from 12 o'clock position. Its value must be bigger than startAngleDegrees, otherwise an exception would be thrown. By default it equals to 'startAngleDegrees + 360'.

@Dimension(unit = 0) float strokeWidth

The stroke width for the progress indicator. The recommended values are CircularProgressIndicatorDefaults.LARGE_STROKE_WIDTH and CircularProgressIndicatorDefaults.SMALL_STROKE_WIDTH.

@Dimension(unit = 0) float gapSize

The size in dp of the gap between the ends of the progress indicator and the track. The stroke end caps are not included in this distance.

@NonNull ProgressIndicatorColors colors

ProgressIndicatorColors that will be used to resolve the indicator and track color for this progress indicator.

@NonNull DimensionBuilders.ContainerDimension size

The bounding box size of this progress indicator, applies to both width and height. The indicator arc and track arc are located on the largest circle that can be inscribed inside. It is highly recommended for the progress indicator in a graphics card to have its size as ExpandedDimensionProp, which is the default, to fill the available space for the best result across different screen sizes. Setting size with a WrappedDimensionProp instance will cause failure and throws an IllegalArgumentException.

Throws
kotlin.IllegalArgumentException

When size is set to be WrappedDimensionProp instance or the provided endAngleDegrees is smaller than the startAngleDegrees.

segmentedCircularProgressIndicator

public static final @NonNull LayoutElementBuilders.Box segmentedCircularProgressIndicator(
    @NonNull MaterialScope receiver,
    @IntRange(from = 1) int segmentCount,
    float staticProgress,
    DynamicBuilders.DynamicFloat dynamicProgress,
    @NonNull LayoutModifier modifier,
    float startAngleDegrees,
    float endAngleDegrees,
    @Dimension(unit = 0) float strokeWidth,
    @Dimension(unit = 0) float gapSize,
    @NonNull ProgressIndicatorColors colors,
    @NonNull DimensionBuilders.ContainerDimension size
)

Protolayout Material3 design segmented circular progress indicator.

A segmented variant of circularProgressIndicator that is divided into equally sized segments.

Note that, the proper implementation of this component requires a ProtoLayout renderer with version equal to or above 1.403. When the renderer is lower than 1.403, this component will automatically fallback to an implementation with reduced features, without support for multiple segments, expandable size, and start/end transition.

This component consumes 2 animation quotas when dynamicProgress is specified with animation by the caller. It is highly recommend to use the recommendedAnimationSpec to animate the progress.

import androidx.wear.protolayout.DimensionBuilders.dp
import androidx.wear.protolayout.expression.DynamicBuilders.DynamicFloat
import androidx.wear.protolayout.material3.CircularProgressIndicatorDefaults
import androidx.wear.protolayout.material3.CircularProgressIndicatorDefaults.filledVariantProgressIndicatorColors
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.segmentedCircularProgressIndicator
import androidx.wear.protolayout.material3.text

materialScope(context, deviceParameters) {
        segmentedCircularProgressIndicator(
            segmentCount = 5,
            dynamicProgress =
                DynamicFloat.animate(
                    0.0F,
                    1.1F,
                    CircularProgressIndicatorDefaults.recommendedAnimationSpec
                ),
            startAngleDegrees = 200F,
            endAngleDegrees = 520F,
            colors = filledVariantProgressIndicatorColors(),
            size = dp(85F)
        )
    }
Parameters
@IntRange(from = 1) int segmentCount

Number of equal segments that the progress indicator should be divided into. Has to be a number greater than or equal to 1.

float staticProgress

The static progress of this progress indicator where 0 represent no progress and 1 represents completion. Progress above 1 is also allowed. If dynamicProgress is also set, this static value will only be used when the dynamic value cannot be evaluated. By default it equals to 0.

DynamicBuilders.DynamicFloat dynamicProgress

The dynamic progress of this progress indicator where 0 represent no progress and 1 represents completion. Progress above 1 is also allowed. If not provided, the staticProgress is used.

@NonNull LayoutModifier modifier

Modifiers to set to this element. It's highly recommended to set a content description using contentDescription.

float startAngleDegrees

The starting position of the progress arc, measured clockwise in degrees from the 12 o'clock position.

float endAngleDegrees

The ending position of the progress arc, measured clockwise in degrees from 12 o'clock position. This value must be bigger than startAngleDegrees, otherwise an exception would be thrown. By default it equals to 'startAngleDegrees + 360'.

@Dimension(unit = 0) float strokeWidth

The stroke width for the progress indicator. The recommended values are CircularProgressIndicatorDefaults.LARGE_STROKE_WIDTH and CircularProgressIndicatorDefaults.SMALL_STROKE_WIDTH.

@Dimension(unit = 0) float gapSize

The size in dp of the gap between the ends of the progress indicator and the track. The stroke end caps are not included in this distance.

@NonNull ProgressIndicatorColors colors

ProgressIndicatorColors that will be used to resolve the indicator and track color for this progress indicator.

@NonNull DimensionBuilders.ContainerDimension size

The bounding box size of this progress indicator, applies to both width and height. The indicator arc and track arc are located on the largest circle that can be inscribed inside. It is highly recommended for the progress indicator in graphicDataCard to have its size as expand, which is the default, to fill the available space for the best result across different screen sizes. Setting size with a WrappedDimensionProp instance will cause failure and throws an IllegalArgumentException.

Throws
kotlin.IllegalArgumentException

When size is set to be WrappedDimensionProp instance or the provided endAngleDegrees is smaller than the startAngleDegrees.