Skip to content

Commit 95c7295

Browse files
committed
Added stroke cap picker to Compose sample
1 parent 2906d84 commit 95c7295

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed

sample/src/main/kotlin/app/futured/donutsample/ui/playground/compose/PlaygroundComposeActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import androidx.compose.animation.core.tween
1919
import androidx.compose.runtime.collectAsState
2020
import androidx.compose.runtime.getValue
2121
import androidx.compose.ui.graphics.Color
22+
import androidx.compose.ui.graphics.StrokeCap
2223
import androidx.compose.ui.platform.ComposeView
2324
import app.futured.donut.compose.data.DonutConfig
2425
import app.futured.donut.compose.data.DonutModel
@@ -211,6 +212,14 @@ class PlaygroundComposeActivity : AppCompatActivity() {
211212
updateAnimationSpecs()
212213
}
213214
//endregion
215+
216+
findViewById<RadioGroup>(R.id.stroke_caps_radio_group).setOnCheckedChangeListener { _, checkedId ->
217+
mutateData { data -> data.copy(strokeCap = when (checkedId) {
218+
R.id.stroke_cap_round -> StrokeCap.Round
219+
R.id.stroke_cap_butt -> StrokeCap.Butt
220+
else -> error("Unexpected id: $checkedId")
221+
}) }
222+
}
214223
}
215224

216225
private fun updateAnimationSpecs() {

sample/src/main/res/layout/activity_playground.xml

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -329,39 +329,7 @@
329329

330330
</HorizontalScrollView>
331331

332-
<TextView
333-
android:layout_width="wrap_content"
334-
android:layout_height="wrap_content"
335-
android:layout_marginTop="8dp"
336-
android:text="@string/animation_stroke_caps"/>
337-
338-
<HorizontalScrollView
339-
android:layout_width="match_parent"
340-
android:layout_height="wrap_content">
341-
342-
<RadioGroup
343-
android:id="@+id/stroke_caps_radio_group"
344-
android:layout_width="wrap_content"
345-
android:layout_height="wrap_content"
346-
android:orientation="horizontal">
347-
348-
<androidx.appcompat.widget.AppCompatRadioButton
349-
android:id="@+id/stroke_cap_round"
350-
android:layout_width="wrap_content"
351-
android:layout_height="wrap_content"
352-
android:layout_marginStart="8dp"
353-
android:checked="true"
354-
android:text="@string/stroke_cap_round"/>
355-
356-
<androidx.appcompat.widget.AppCompatRadioButton
357-
android:id="@+id/stroke_cap_butt"
358-
android:layout_width="wrap_content"
359-
android:layout_height="wrap_content"
360-
android:text="@string/stroke_cap_butt"/>
361-
362-
</RadioGroup>
363-
364-
</HorizontalScrollView>
332+
<include layout="@layout/pick_stroke_cap" />
365333

366334
</LinearLayout>
367335

sample/src/main/res/layout/activity_playground_compose.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@
306306

307307
</HorizontalScrollView>
308308

309+
<include layout="@layout/pick_stroke_cap" />
310+
309311
</LinearLayout>
310312

311313
</ScrollView>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<merge xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
tools:showIn="@layout/activity_playground">
5+
6+
7+
<TextView
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_marginTop="8dp"
11+
android:text="@string/animation_stroke_caps" />
12+
13+
<HorizontalScrollView
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content">
16+
17+
<RadioGroup
18+
android:id="@+id/stroke_caps_radio_group"
19+
android:layout_width="wrap_content"
20+
android:layout_height="wrap_content"
21+
android:orientation="horizontal">
22+
23+
<androidx.appcompat.widget.AppCompatRadioButton
24+
android:id="@+id/stroke_cap_round"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_marginStart="8dp"
28+
android:checked="true"
29+
android:text="@string/stroke_cap_round" />
30+
31+
<androidx.appcompat.widget.AppCompatRadioButton
32+
android:id="@+id/stroke_cap_butt"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:text="@string/stroke_cap_butt" />
36+
37+
</RadioGroup>
38+
39+
</HorizontalScrollView>
40+
</merge>

0 commit comments

Comments
 (0)