1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.wear.compose.material.samples
18 
19 import androidx.annotation.Sampled
20 import androidx.compose.animation.core.animateFloatAsState
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.foundation.layout.Spacer
23 import androidx.compose.foundation.layout.fillMaxSize
24 import androidx.compose.foundation.layout.padding
25 import androidx.compose.foundation.layout.requiredHeight
26 import androidx.compose.foundation.layout.width
27 import androidx.compose.runtime.Composable
28 import androidx.compose.runtime.getValue
29 import androidx.compose.runtime.mutableStateOf
30 import androidx.compose.runtime.remember
31 import androidx.compose.runtime.setValue
32 import androidx.compose.ui.Alignment
33 import androidx.compose.ui.Modifier
34 import androidx.compose.ui.semantics.clearAndSetSemantics
35 import androidx.compose.ui.unit.dp
36 import androidx.wear.compose.material.CircularProgressIndicator
37 import androidx.wear.compose.material.CompactChip
38 import androidx.wear.compose.material.ProgressIndicatorDefaults
39 import androidx.wear.compose.material.Text
40 
41 @Sampled
42 @Composable
IndeterminateCircularProgressIndicatornull43 public fun IndeterminateCircularProgressIndicator() {
44     CircularProgressIndicator()
45 }
46 
47 @Sampled
48 @Composable
CircularProgressIndicatorWithAnimationnull49 public fun CircularProgressIndicatorWithAnimation() {
50     var progress by remember { mutableStateOf(0.1f) }
51     val animatedProgress by
52         animateFloatAsState(
53             targetValue = progress,
54             animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec
55         )
56 
57     Column(horizontalAlignment = Alignment.CenterHorizontally) {
58         CircularProgressIndicator(
59             progress = animatedProgress,
60         )
61         Spacer(Modifier.requiredHeight(10.dp))
62         CompactChip(
63             modifier = Modifier.width(90.dp),
64             onClick = { if (progress < 1f) progress += 0.1f },
65             label = { Text("Increase") }
66         )
67     }
68 }
69 
70 @Sampled
71 @Composable
CircularProgressIndicatorFullscreenWithGapnull72 public fun CircularProgressIndicatorFullscreenWithGap() {
73     CircularProgressIndicator(
74         modifier = Modifier.fillMaxSize().padding(all = 1.dp).clearAndSetSemantics {},
75         startAngle = 295.5f,
76         endAngle = 245.5f,
77         progress = 0.3f,
78         strokeWidth = ProgressIndicatorDefaults.FullScreenStrokeWidth
79     )
80 }
81