Skip to content

Commit

Permalink
Update to the latest changes in Compose for Wear OS version 1.2 (#9)
Browse files Browse the repository at this point in the history
* Update dependencies Jetpack dependencies and bump Compose for Wear OS to version 1.2.

* Migrate ScalingLazyColumn to use from the foundation.lazy package (used script from android/wear-os-samples#663)

* - Update Preview annotations to use wear configuration mode (with round views) for component preview
- Use multi-device preview for main app screen
- Remove obsolete PreviewConstants

* Bump Compose for Wear OS to v1.2 stable
  • Loading branch information
shumelchyk committed Aug 9, 2023
1 parent 8c72fb8 commit 4991d55
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 204 deletions.
18 changes: 9 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
buildscript {
ext {
// Dependency versions.
activity_compose_version = '1.6.1'
compose_version = '1.3.1'
compose_compiler_version = '1.3.2'
lifecycle_version = '2.5.1'
wear_compose_version = '1.1.0'
kotlin_version = '1.7.20'
activity_compose_version = '1.7.2'
compose_version = '1.4.3'
compose_compiler_version = '1.4.7'
lifecycle_version = '2.6.1'
wear_compose_version = '1.2.0'
kotlin_version = '1.8.21'

junit_version = '4.13.2'
androidx_test_ext_junit_version = '1.1.3'
espresso_version = '3.4.0'
androidx_test_ext_junit_version = '1.1.5'
espresso_version = '3.5.1'
}

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:8.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
5 changes: 4 additions & 1 deletion finished/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.example.android.wearable.composeforwearos"
Expand Down Expand Up @@ -78,6 +78,9 @@ dependencies {
// Foundation is additive, so you can use the mobile version in your Wear OS app.
implementation "androidx.wear.compose:compose-foundation:$wear_compose_version"

// Compose preview annotations for Wear OS.
implementation "androidx.wear.compose:compose-ui-tooling:$wear_compose_version"

// If you are using Compose Navigation, use the Wear OS version (NOT the
// androidx.navigation:navigation-compose version), that is, uncomment the line below.
// implementation "androidx.wear.compose:compose-navigation:$wear_compose_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.AutoCenteringParams
import androidx.wear.compose.foundation.lazy.AutoCenteringParams
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.material.TimeText
import androidx.wear.compose.material.Vignette
import androidx.wear.compose.material.VignettePosition
import androidx.wear.compose.material.rememberScalingLazyListState
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.material.scrollAway
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
import com.example.android.wearable.composeforwearos.theme.WearAppTheme

/**
Expand Down Expand Up @@ -118,15 +118,7 @@ fun WearApp() {
}
}

// Note: Preview in Android Studio doesn't support the round view yet (coming soon).
@Preview(
widthDp = WEAR_PREVIEW_DEVICE_WIDTH_DP,
heightDp = WEAR_PREVIEW_DEVICE_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
)
@WearPreviewDevices
@Composable
fun WearAppPreview() {
WearApp()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.example.android.wearable.composeforwearos

import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -34,11 +35,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role.Companion.Switch
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.AppCard
Expand All @@ -50,7 +51,6 @@ import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Switch
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.ToggleChip
import androidx.wear.compose.material.ToggleChipDefaults
import com.example.android.wearable.composeforwearos.theme.WearAppTheme

/* Contains individual Wear OS demo composables for the code lab. */
Expand Down Expand Up @@ -180,17 +180,12 @@ fun StartOnlyTextComposables() {
}

/* Previews of Composables. */
// Note: Preview in Android Studio doesn't support the round view yet (coming soon).

// Hello, world starter text preview
@Preview(
group = "Starter",
widthDp = WEAR_PREVIEW_ELEMENT_WIDTH_DP,
heightDp = WEAR_PREVIEW_ELEMENT_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND
)
@Composable
fun StartOnlyTextComposablesPreview() {
Expand All @@ -201,13 +196,9 @@ fun StartOnlyTextComposablesPreview() {

// Button Preview
@Preview(
group = "Button",
widthDp = WEAR_PREVIEW_ELEMENT_WIDTH_DP,
heightDp = WEAR_PREVIEW_ELEMENT_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND
)
@Composable
fun ButtonExamplePreview() {
Expand All @@ -225,13 +216,9 @@ fun ButtonExamplePreview() {

// Text Preview
@Preview(
group = "Text",
widthDp = WEAR_PREVIEW_ROW_WIDTH_DP,
heightDp = WEAR_PREVIEW_ROW_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND
)
@Composable
fun TextExamplePreview() {
Expand All @@ -246,13 +233,9 @@ fun TextExamplePreview() {

// Card Preview
@Preview(
group = "Card",
widthDp = WEAR_PREVIEW_ROW_WIDTH_DP,
heightDp = WEAR_PREVIEW_ROW_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND
)
@Composable
fun CardExamplePreview() {
Expand All @@ -271,13 +254,9 @@ fun CardExamplePreview() {

// Chip Preview
@Preview(
group = "Chip",
widthDp = WEAR_PREVIEW_ROW_WIDTH_DP,
heightDp = WEAR_PREVIEW_ROW_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND,
)
@Composable
fun ChipExamplePreview() {
Expand All @@ -295,13 +274,9 @@ fun ChipExamplePreview() {

// Toggle Chip Preview
@Preview(
group = "Toggle Chip",
widthDp = WEAR_PREVIEW_ROW_WIDTH_DP,
heightDp = WEAR_PREVIEW_ROW_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
apiLevel = 26,
uiMode = Configuration.UI_MODE_TYPE_WATCH,
device = Devices.WEAR_OS_SMALL_ROUND
)
@Composable
fun ToggleChipExamplePreview() {
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official
android.defaults.buildfeatures.buildconfig=true
android.nonTransitiveRClass=false
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#
#Thu Oct 07 14:30:13 PDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
5 changes: 4 additions & 1 deletion start/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ plugins {
}

android {
compileSdk 33
compileSdk 34

defaultConfig {
applicationId "com.example.android.wearable.composeforwearos"
Expand Down Expand Up @@ -78,6 +78,9 @@ dependencies {
// Foundation is additive, so you can use the mobile version in your Wear OS app.
implementation "androidx.wear.compose:compose-foundation:$wear_compose_version"

// Compose preview annotations for Wear OS.
implementation "androidx.wear.compose:compose-ui-tooling:$wear_compose_version"

// If you are using Compose Navigation, use the Wear OS version (NOT the
// androidx.navigation:navigation-compose version), that is, uncomment the line below.
// implementation "androidx.wear.compose:compose-navigation:$wear_compose_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.AutoCenteringParams
import androidx.wear.compose.foundation.lazy.AutoCenteringParams
import androidx.wear.compose.material.PositionIndicator
import androidx.wear.compose.material.Scaffold
import androidx.wear.compose.material.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.material.TimeText
import androidx.wear.compose.material.Vignette
import androidx.wear.compose.material.VignettePosition
import androidx.wear.compose.material.rememberScalingLazyListState
import androidx.wear.compose.foundation.lazy.rememberScalingLazyListState
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
import com.example.android.wearable.composeforwearos.theme.WearAppTheme

/**
Expand Down Expand Up @@ -110,16 +110,8 @@ fun WearApp() {
}
}

// Note: Preview in Android Studio doesn't support the round view yet (coming soon).
@Preview(
widthDp = WEAR_PREVIEW_DEVICE_WIDTH_DP,
heightDp = WEAR_PREVIEW_DEVICE_HEIGHT_DP,
apiLevel = WEAR_PREVIEW_API_LEVEL,
uiMode = WEAR_PREVIEW_UI_MODE,
backgroundColor = WEAR_PREVIEW_BACKGROUND_COLOR_BLACK,
showBackground = WEAR_PREVIEW_SHOW_BACKGROUND
)
@WearPreviewDevices
@Composable
fun WearAppPreview() {
WearApp()
}
}

This file was deleted.

Loading

0 comments on commit 4991d55

Please sign in to comment.