|
| 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.complication |
| 18 | + |
| 19 | +import android.os.Bundle |
| 20 | +import androidx.activity.ComponentActivity |
| 21 | +import androidx.activity.compose.setContent |
| 22 | +import androidx.compose.foundation.layout.Arrangement |
| 23 | +import androidx.compose.foundation.layout.Column |
| 24 | +import androidx.compose.foundation.layout.Spacer |
| 25 | +import androidx.compose.foundation.layout.fillMaxSize |
| 26 | +import androidx.compose.foundation.layout.height |
| 27 | +import androidx.compose.runtime.Composable |
| 28 | +import androidx.compose.ui.Alignment |
| 29 | +import androidx.compose.ui.Modifier |
| 30 | +import androidx.compose.ui.unit.dp |
| 31 | +import androidx.wear.compose.material3.Button |
| 32 | +import androidx.wear.compose.material3.Text |
| 33 | +import androidx.wear.watchface.complications.datasource.ComplicationDataSourceService.Companion.EXTRA_CONFIG_COMPLICATION_ID |
| 34 | +import androidx.wear.watchface.complications.datasource.ComplicationDataSourceService.Companion.EXTRA_CONFIG_COMPLICATION_TYPE |
| 35 | +import androidx.wear.watchface.complications.datasource.ComplicationDataSourceService.Companion.EXTRA_CONFIG_DATA_SOURCE_COMPONENT |
| 36 | + |
| 37 | +class ConfigurationActivity : ComponentActivity() { |
| 38 | + override fun onCreate(savedInstanceState: Bundle?) { |
| 39 | + super.onCreate(savedInstanceState) |
| 40 | + // [START android_wear_complication_configuration_intent] |
| 41 | + // Keys defined on ComplicationDataSourceService |
| 42 | + val id = intent.getIntExtra(EXTRA_CONFIG_COMPLICATION_ID, -1) |
| 43 | + val type = intent.getIntExtra(EXTRA_CONFIG_COMPLICATION_TYPE, -1) |
| 44 | + val source = intent.getStringExtra(EXTRA_CONFIG_DATA_SOURCE_COMPONENT) |
| 45 | + // [END android_wear_complication_configuration_intent] |
| 46 | + setContent { |
| 47 | + ComplicationConfig( |
| 48 | + id = id, |
| 49 | + type = type, |
| 50 | + source = source |
| 51 | + ) |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Composable |
| 56 | + fun ComplicationConfig( |
| 57 | + modifier: Modifier = Modifier, |
| 58 | + id: Int, |
| 59 | + type: Int, |
| 60 | + source: String? |
| 61 | + ) { |
| 62 | + Column( |
| 63 | + modifier = Modifier.fillMaxSize(), |
| 64 | + verticalArrangement = Arrangement.SpaceEvenly, |
| 65 | + horizontalAlignment = Alignment.CenterHorizontally |
| 66 | + ) { |
| 67 | + Text("ID: $id") |
| 68 | + Text("Type: $type") |
| 69 | + Text("Source: $source") |
| 70 | + Spacer(modifier = Modifier.height(4.dp)) |
| 71 | + Button(onClick = { |
| 72 | + // [START android_wear_complication_configuration_finish] |
| 73 | + setResult(RESULT_OK) // Or RESULT_CANCELLED to cancel configuration |
| 74 | + finish() |
| 75 | + // [END android_wear_complication_configuration_finish] |
| 76 | + }) { |
| 77 | + Text("Done!") |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments