Skip to content

Commit 430923c

Browse files
committed
Update compose library, migrate voice snippet
Change-Id: I1cb339e6d55c12717d20b27fea2d60fb3fafc0e1
1 parent 0fc880e commit 430923c

File tree

3 files changed

+44
-79
lines changed

3 files changed

+44
-79
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ media3 = "1.5.1"
4545
# @keep
4646
minSdk = "21"
4747
playServicesWearable = "19.0.0"
48-
protolayout = "1.3.0-beta01"
48+
protolayout = "1.3.0-beta02"
4949
recyclerview = "1.4.0"
5050
# @keep
5151
targetSdk = "34"
5252
tiles = "1.5.0-beta01"
5353
version-catalog-update = "0.8.5"
5454
wear = "1.3.0"
55-
wearComposeFoundation = "1.4.1"
56-
wearComposeMaterial = "1.4.1"
57-
wearComposeMaterial3 = "1.0.0-alpha37"
55+
wearComposeFoundation = "1.5.0-beta01"
56+
wearComposeMaterial = "1.5.0-beta01"
57+
wearComposeMaterial3 = "1.5.0-beta01"
5858
wearToolingPreview = "1.0.0"
5959

6060
[libraries]

wear/src/main/java/com.example.wear.snippets.m3/rotary/Rotary.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package com.example.wear.snippets.m3.rotary
1818

1919
import android.view.MotionEvent
2020
import androidx.compose.foundation.focusable
21-
import androidx.compose.foundation.gestures.animateScrollBy
2221
import androidx.compose.foundation.gestures.scrollBy
2322
import androidx.compose.foundation.layout.Arrangement
2423
import androidx.compose.foundation.layout.Box

wear/src/main/java/com.example.wear.snippets.m3/voiceinput/VoiceInputScreen.kt

Lines changed: 40 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,33 @@
1616

1717
package com.example.wear.snippets.m3.voiceinput
1818

19-
/*
20-
* Copyright 2021 The Android Open Source Project
21-
*
22-
* Licensed under the Apache License, Version 2.0 (the "License");
23-
* you may not use this file except in compliance with the License.
24-
* You may obtain a copy of the License at
25-
*
26-
* https://www.apache.org/licenses/LICENSE-2.0
27-
*
28-
* Unless required by applicable law or agreed to in writing, software
29-
* distributed under the License is distributed on an "AS IS" BASIS,
30-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31-
* See the License for the specific language governing permissions and
32-
* limitations under the License.
33-
*/
34-
3519
import android.content.Intent
3620
import android.speech.RecognizerIntent
3721
import androidx.activity.compose.rememberLauncherForActivityResult
3822
import androidx.activity.result.contract.ActivityResultContracts
39-
import androidx.compose.foundation.layout.Arrangement
40-
import androidx.compose.foundation.layout.Column
41-
import androidx.compose.foundation.layout.fillMaxSize
42-
import androidx.compose.foundation.layout.padding
43-
import androidx.compose.foundation.rememberScrollState
44-
import androidx.compose.foundation.verticalScroll
23+
import androidx.compose.foundation.layout.fillMaxWidth
4524
import androidx.compose.runtime.Composable
4625
import androidx.compose.runtime.getValue
4726
import androidx.compose.runtime.mutableStateOf
4827
import androidx.compose.runtime.remember
4928
import androidx.compose.runtime.setValue
5029
import androidx.compose.ui.Modifier
5130
import androidx.compose.ui.res.stringResource
52-
import androidx.wear.compose.foundation.rememberActiveFocusRequester
53-
import androidx.wear.compose.foundation.rotary.RotaryScrollableDefaults.behavior
54-
import androidx.wear.compose.foundation.rotary.rotaryScrollable
31+
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
32+
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
33+
import androidx.wear.compose.material3.AppScaffold
34+
import androidx.wear.compose.material3.Button
35+
import androidx.wear.compose.material3.ScreenScaffold
36+
import androidx.wear.compose.material3.Text
5537
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
5638
import androidx.wear.compose.ui.tooling.preview.WearPreviewFontScales
5739
import com.example.wear.R
58-
import com.google.android.horologist.annotations.ExperimentalHorologistApi
59-
import com.google.android.horologist.compose.layout.AppScaffold
60-
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
61-
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults.ItemType
62-
import com.google.android.horologist.compose.layout.ScreenScaffold
63-
import com.google.android.horologist.compose.material.Chip
40+
import com.google.android.horologist.compose.layout.ColumnItemType
41+
import com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding
6442

6543
/**
6644
* Shows voice input option
6745
*/
68-
@OptIn(ExperimentalHorologistApi::class)
6946
@Composable
7047
fun VoiceInputScreen() {
7148
AppScaffold {
@@ -83,52 +60,41 @@ fun VoiceInputScreen() {
8360
}
8461
}
8562

86-
val scrollState = rememberScrollState()
87-
88-
ScreenScaffold(scrollState = scrollState) {
89-
// rest of implementation here
90-
// [START_EXCLUDE]
91-
val padding = ScalingLazyColumnDefaults.padding(
92-
first = ItemType.Text,
93-
last = ItemType.Chip
94-
)()
95-
val focusRequester = rememberActiveFocusRequester()
96-
// [END_EXCLUDE]
97-
Column(
98-
// rest of implementation here
99-
// [START_EXCLUDE]
100-
modifier = Modifier
101-
.fillMaxSize()
102-
.verticalScroll(scrollState)
103-
.padding(padding)
104-
.rotaryScrollable(
105-
behavior = behavior(scrollableState = scrollState),
106-
focusRequester = focusRequester,
107-
),
108-
verticalArrangement = Arrangement.Center
63+
val scrollState = rememberTransformingLazyColumnState()
64+
ScreenScaffold(
65+
scrollState = scrollState,
66+
contentPadding = rememberResponsiveColumnPadding(
67+
first = ColumnItemType.Button
68+
)
69+
) { contentPadding ->
70+
TransformingLazyColumn(
71+
contentPadding = contentPadding,
72+
state = scrollState,
10973
) {
110-
// [END_EXCLUDE]
111-
112-
// Create an intent that can start the Speech Recognizer activity
113-
val voiceIntent: Intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
114-
putExtra(
115-
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
116-
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
117-
)
74+
item {
75+
// Create an intent that can start the Speech Recognizer activity
76+
val voiceIntent: Intent =
77+
Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
78+
putExtra(
79+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
80+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
81+
)
11882

119-
putExtra(
120-
RecognizerIntent.EXTRA_PROMPT,
121-
stringResource(R.string.voice_text_entry_label)
83+
putExtra(
84+
RecognizerIntent.EXTRA_PROMPT,
85+
stringResource(R.string.voice_text_entry_label)
86+
)
87+
}
88+
// Invoke the process from a Button
89+
Button(
90+
onClick = {
91+
voiceLauncher.launch(voiceIntent)
92+
},
93+
label = { Text(stringResource(R.string.voice_input_label)) },
94+
secondaryLabel = { Text(textForVoiceInput) },
95+
modifier = Modifier.fillMaxWidth()
12296
)
12397
}
124-
// Invoke the process from a chip
125-
Chip(
126-
onClick = {
127-
voiceLauncher.launch(voiceIntent)
128-
},
129-
label = stringResource(R.string.voice_input_label),
130-
secondaryLabel = textForVoiceInput
131-
)
13298
}
13399
}
134100
// [END android_wear_voice_input]

0 commit comments

Comments
 (0)