forked from microsoft/fluentui-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathV2ProgressActivity.kt
361 lines (348 loc) · 12.6 KB
/
V2ProgressActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
package com.microsoft.fluentuidemo.demos
import android.content.Context
import android.os.Bundle
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Clear
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.microsoft.fluentui.theme.FluentTheme
import com.microsoft.fluentui.theme.token.FluentAliasTokens
import com.microsoft.fluentui.theme.token.FluentIcon
import com.microsoft.fluentui.theme.token.FluentStyle
import com.microsoft.fluentui.theme.token.controlTokens.CircularProgressIndicatorSize
import com.microsoft.fluentui.theme.token.controlTokens.ColorStyle
import com.microsoft.fluentui.theme.token.controlTokens.ProgressTextInfo
import com.microsoft.fluentui.theme.token.controlTokens.ProgressTextTokens
import com.microsoft.fluentui.tokenized.controls.Label
import com.microsoft.fluentui.tokenized.progress.CircularProgressIndicator
import com.microsoft.fluentui.tokenized.progress.LinearProgressIndicator
import com.microsoft.fluentui.tokenized.progress.ProgressText
import com.microsoft.fluentuidemo.V2DemoActivity
import kotlinx.coroutines.delay
import kotlin.random.Random
class V2ProgressActivity : V2DemoActivity() {
init {
setupActivity(this)
}
override val paramsUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#params-26"
override val controlTokensUrl = "https://github.com/microsoft/fluentui-android/wiki/Controls#control-tokens-25"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setActivityContent {
CreateProgressActivityUI(this)
}
}
}
@Composable
private fun CreateProgressActivityUI(context: Context) {
var linearProgress by remember { mutableStateOf(0f) }
var circularProgress by remember { mutableStateOf(0f) }
var progressString by remember {
mutableStateOf("Starting...")
}
var texts = ArrayList<String>()
texts.add("Starting...")
texts.add("Generating...")
texts.add("Publishing...")
texts.add("Completed...")
val textColor =
FluentTheme.aliasTokens.neutralForegroundColor[FluentAliasTokens.NeutralForegroundColorTokens.Foreground1].value(
themeMode = FluentTheme.themeMode
)
val brandTextColor =
FluentTheme.aliasTokens.brandForegroundColor[FluentAliasTokens.BrandForegroundColorTokens.BrandForeground1].value(
themeMode = FluentTheme.themeMode
)
Column(
Modifier
.padding(all = 16.dp)
.verticalScroll(rememberScrollState())
) {
LinearProgressIndicatorDemo(brandTextColor = brandTextColor, textColor = textColor)
CircularProgressIndicatorDemo(textColor = textColor)
DeterminateProgressIndicatorDemo(
linearProgress,
circularProgress
)
IndeterminateProgressIndicatorDemo()
ProgressTextDemo(linearProgress, context, progressString)
}
LaunchedEffect(key1 = linearProgress) {
if (linearProgress >= 1.0) {
linearProgress = 1f
delay(1000)
linearProgress = 0f
} else {
delay(500)
linearProgress += Random.nextFloat() / 5
if (linearProgress < 0.2f) {
progressString = texts[0]
} else if (linearProgress > 0.20f && linearProgress < 0.5f) {
progressString = texts[1]
} else if (linearProgress > 0.5f && linearProgress < 0.9f) {
progressString = texts[2]
} else if (linearProgress > 0.9f) {
progressString = texts[3]
}
}
}
LaunchedEffect(key1 = circularProgress) {
if (circularProgress >= 1.0) {
circularProgress = 1f
delay(1000)
circularProgress = 0f
} else {
delay(500)
circularProgress += Random.nextFloat() / 5
}
}
}
@Composable
private fun LinearProgressIndicatorDemo(brandTextColor: Color, textColor: Color) {
Column(verticalArrangement = Arrangement.spacedBy(16.dp)) {
Label(
text = "ProgressIndicators",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
Label(
text = "XXXSmall - 2dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
LinearProgressIndicator(modifier = Modifier.width(240.dp))
}
}
}
@Composable
private fun CircularProgressIndicatorDemo(textColor: Color) {
Column {
Row(
Modifier.height(42.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(36.dp)
) {
Label(
modifier = Modifier.width(100.dp),
text = "XSmall - 12dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
CircularProgressIndicator(style = FluentStyle.Brand)
CircularProgressIndicator()
}
Row(
Modifier.height(42.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
Label(
modifier = Modifier.width(100.dp),
text = "Small - 16dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
CircularProgressIndicator(
size = CircularProgressIndicatorSize.XSmall,
style = FluentStyle.Brand
)
CircularProgressIndicator(
CircularProgressIndicatorSize.XSmall
)
}
Row(
Modifier.height(42.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
Label(
modifier = Modifier.width(100.dp),
text = "Medium - 24dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
CircularProgressIndicator(
size = CircularProgressIndicatorSize.Medium,
style = FluentStyle.Brand
)
CircularProgressIndicator(
CircularProgressIndicatorSize.Medium
)
}
Row(
Modifier.height(48.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
Label(
modifier = Modifier.width(100.dp),
text = "Large - 32dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
CircularProgressIndicator(
size = CircularProgressIndicatorSize.Large,
style = FluentStyle.Brand
)
CircularProgressIndicator(
CircularProgressIndicatorSize.Large
)
}
Row(
Modifier.height(64.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
Label(
modifier = Modifier.width(100.dp),
text = "XLarge - 36dp",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
CircularProgressIndicator(
CircularProgressIndicatorSize.XLarge,
style = FluentStyle.Brand
)
CircularProgressIndicator(
CircularProgressIndicatorSize.XLarge
)
}
}
}
@Composable
private fun DeterminateProgressIndicatorDemo(
linearProgress: Float,
circularProgress: Float
) {
Label(
modifier = Modifier.padding(top = 16.dp),
text = "Determinate ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Label(
modifier = Modifier.padding(top = 16.dp, bottom = 8.dp),
text = "Linear ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
Row(
Modifier.height(24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
LinearProgressIndicator(linearProgress, modifier = Modifier.width(240.dp))
Label(
text = "" + "%.0f".format(linearProgress * 100) + "%",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
}
Label(
modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
text = "Circular ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
Row(
Modifier.height(24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
CircularProgressIndicator(
circularProgress,
size = CircularProgressIndicatorSize.XLarge,
style = FluentStyle.Brand
)
Label(
text = "" + "%.0f".format(circularProgress * 100) + "%",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
}
}
@Composable
private fun IndeterminateProgressIndicatorDemo() {
Label(
modifier = Modifier.padding(top = 16.dp),
text = "InDeterminate ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Label(
modifier = Modifier.padding(top = 16.dp, bottom = 8.dp),
text = "Linear ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
Row(
Modifier.height(24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
LinearProgressIndicator(modifier = Modifier.width(240.dp))
}
Label(
modifier = Modifier.padding(top = 16.dp, bottom = 16.dp),
text = "Circular ProgressIndicator",
textStyle = FluentAliasTokens.TypographyTokens.Caption1
)
Row(
Modifier.height(24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(32.dp)
) {
CircularProgressIndicator(
size = CircularProgressIndicatorSize.XLarge,
style = FluentStyle.Brand
)
}
}
@Composable
private fun ProgressTextDemo(linearProgress: Float, context: Context, progressString: String) {
Label(
modifier = Modifier.padding(top = 16.dp),
text = "Progress Text",
textStyle = FluentAliasTokens.TypographyTokens.Title2,
colorStyle = ColorStyle.Brand
)
Spacer(modifier = Modifier.height(12.dp))
ProgressText(
text = progressString,
progress = linearProgress,
modifier = Modifier.width(300.dp),
)
Spacer(modifier = Modifier.height(12.dp))
ProgressText(
text = "Ok... I'll summarize what you missed this morning",
progress = linearProgress,
leadingIconAccessory = FluentIcon(
Icons.Outlined.Clear,
onClick = { Toast.makeText(context, "Canceled", Toast.LENGTH_SHORT).show() }),
modifier = Modifier.width(325.dp),
progressTextTokens = GradientProgressTextToken()
)
}
class GradientProgressTextToken : ProgressTextTokens() {
@Composable
override fun progressbarBrush(progressTextInfo: ProgressTextInfo): Brush {
return gradient
}
}
private var gradient = Brush.horizontalGradient(
0.0f to Color(0xFF464FEB),
0.7f to Color(0xFF47CFFA),
0.92f to Color(0xFFB47CF8)
)