Skip to content

Commit ad93700

Browse files
authored
Various snippets for Material 3 migration guidance (#725)
* Various snippets for migration guidance * Apply Spotless --------- Co-authored-by: kul3r4 <820891+kul3r4@users.noreply.github.com>
1 parent 64af69f commit ad93700

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2025 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+
* https://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 com.example.wear.snippets.m3.components
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.ui.res.stringResource
21+
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
22+
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
23+
import androidx.wear.compose.material3.Button
24+
import androidx.wear.compose.material3.CompactButton
25+
import androidx.wear.compose.material3.ScreenScaffold
26+
import androidx.wear.compose.material3.EdgeButton
27+
import androidx.wear.compose.material3.IconButton
28+
import androidx.wear.compose.material3.Text
29+
import androidx.wear.compose.material3.TextButton
30+
import com.example.wear.R
31+
import com.google.android.horologist.compose.layout.ColumnItemType
32+
import com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding
33+
34+
@Composable
35+
fun EdgeButton() {
36+
// [START android_wear_edgebutton]
37+
val state = rememberTransformingLazyColumnState()
38+
ScreenScaffold(
39+
scrollState = state,
40+
contentPadding =
41+
rememberResponsiveColumnPadding(
42+
first = ColumnItemType.ListHeader
43+
),
44+
edgeButton = {
45+
EdgeButton(
46+
onClick = { }
47+
) {
48+
Text(stringResource(R.string.show))
49+
}
50+
}
51+
){ contentPadding ->
52+
TransformingLazyColumn(state = state, contentPadding = contentPadding,){
53+
// additional code here
54+
}
55+
}
56+
// [END android_wear_edgebutton]
57+
}
58+
59+
@Composable
60+
fun buttonsList() {
61+
// [START android_wear_buttons_list]
62+
//M3 Buttons
63+
Button(onClick = { }){}
64+
CompactButton(onClick = { }){}
65+
IconButton(onClick = { }){}
66+
TextButton(onClick = { }){}
67+
// [END android_wear_buttons_list]
68+
}

wear/src/main/java/com/example/wear/snippets/m3/pager/Pager.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ import androidx.compose.ui.Modifier
2222
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
2323
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
2424
import androidx.wear.compose.foundation.pager.HorizontalPager
25+
import androidx.wear.compose.foundation.pager.VerticalPager
2526
import androidx.wear.compose.foundation.pager.rememberPagerState
2627
import androidx.wear.compose.material3.AnimatedPage
2728
import androidx.wear.compose.material3.AppScaffold
2829
import androidx.wear.compose.material3.HorizontalPagerScaffold
2930
import androidx.wear.compose.material3.ListHeader
3031
import androidx.wear.compose.material3.ScreenScaffold
3132
import androidx.wear.compose.material3.Text
33+
import androidx.wear.compose.material3.VerticalPagerScaffold
3234
import com.google.android.horologist.compose.layout.ColumnItemType
3335
import com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding
3436

@@ -78,4 +80,25 @@ fun HorizontalPager() {
7880
}
7981
}
8082
// [END android_wear_horizontal_pager]
83+
}
84+
85+
@Composable
86+
fun verticalPager() {
87+
// [START android_wear_vertical_pager]
88+
AppScaffold {
89+
val pagerState = rememberPagerState(pageCount = { 10 })
90+
91+
VerticalPagerScaffold(pagerState = pagerState) {
92+
VerticalPager(
93+
state = pagerState
94+
) { page ->
95+
AnimatedPage(pageIndex = page, pagerState = pagerState) {
96+
ScreenScaffold {
97+
///…
98+
}
99+
}
100+
}
101+
}
102+
}
103+
// [END android_wear_vertical_pager]
81104
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2025 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+
* https://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 com.example.wear.snippets.m3.theme
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.ui.platform.LocalContext
21+
import androidx.wear.compose.material3.ColorScheme
22+
import androidx.wear.compose.material3.MaterialTheme
23+
import androidx.wear.compose.material3.dynamicColorScheme
24+
25+
// [START android_wear_dynamic_theme]
26+
@Composable
27+
fun myApp() {
28+
val dynamicColorScheme = dynamicColorScheme(LocalContext.current)
29+
MaterialTheme(colorScheme = dynamicColorScheme ?: myBrandColors) {}
30+
}
31+
32+
internal val myBrandColors: ColorScheme = ColorScheme( /* Specify colors here */)
33+
// [END android_wear_dynamic_theme]]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2025 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+
* https://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 com.example.wear.snippets.m3.theme
18+
19+
import androidx.wear.compose.material3.Shapes
20+
21+
// [START android_wear_shape]
22+
val Shapes = Shapes(
23+
// M3 Shapes parameters
24+
)
25+
// [END android_wear_shape]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2025 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+
* https://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 com.example.wear.snippets.m3.theme
18+
19+
import androidx.wear.compose.material3.Typography
20+
21+
// [START android_wear_typography]
22+
val Typography = Typography(
23+
// M3 TextStyle parameters
24+
)
25+
// [END android_wear_typography]

wear/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@
2525
<string name="my_complication_service_label">My Complication</string>
2626
<string name="my_complication_timeline_service_label">My Timeline Complication</string>
2727
<string name="configuration_activity_label">Configuration activity</string>
28+
<string name="show">Show</string>
2829
</resources>

0 commit comments

Comments
 (0)