1 /*
2 * Copyright (C) 2024 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 * http://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.android.systemui.touchpad.tutorial.ui.composable
18
19 import androidx.compose.material3.MaterialTheme
20 import androidx.compose.runtime.Composable
21 import androidx.compose.runtime.remember
22 import com.airbnb.lottie.compose.rememberLottieDynamicProperties
23 import com.android.compose.theme.LocalAndroidColorScheme
24 import com.android.systemui.inputdevice.tutorial.ui.composable.TutorialScreenConfig
25 import com.android.systemui.inputdevice.tutorial.ui.composable.rememberColorFilterProperty
26 import com.android.systemui.res.R
27 import com.android.systemui.touchpad.tutorial.ui.viewmodel.BackGestureScreenViewModel
28 import com.android.systemui.touchpad.tutorial.ui.viewmodel.EasterEggGestureViewModel
29
30 @Composable
BackGestureTutorialScreennull31 fun BackGestureTutorialScreen(
32 viewModel: BackGestureScreenViewModel,
33 easterEggGestureViewModel: EasterEggGestureViewModel,
34 onDoneButtonClicked: () -> Unit,
35 onBack: () -> Unit,
36 onAutoProceed: (suspend () -> Unit)? = null,
37 ) {
38 val screenConfig =
39 TutorialScreenConfig(
40 colors = rememberScreenColors(),
41 strings =
42 TutorialScreenConfig.Strings(
43 titleResId = R.string.touchpad_back_gesture_action_title,
44 bodyResId = R.string.touchpad_back_gesture_guidance,
45 titleSuccessResId = R.string.touchpad_back_gesture_success_title,
46 bodySuccessResId = R.string.touchpad_back_gesture_success_body,
47 titleErrorResId = R.string.gesture_error_title,
48 bodyErrorResId = R.string.touchpad_back_gesture_error_body,
49 ),
50 animations = TutorialScreenConfig.Animations(educationResId = R.raw.trackpad_back_edu),
51 )
52 GestureTutorialScreen(
53 screenConfig = screenConfig,
54 tutorialStateFlow = viewModel.tutorialState,
55 motionEventConsumer = {
56 easterEggGestureViewModel.accept(it)
57 viewModel.handleEvent(it)
58 },
59 easterEggTriggeredFlow = easterEggGestureViewModel.easterEggTriggered,
60 onEasterEggFinished = easterEggGestureViewModel::onEasterEggFinished,
61 onDoneButtonClicked = onDoneButtonClicked,
62 onBack = onBack,
63 onAutoProceed = onAutoProceed,
64 )
65 }
66
67 @Composable
rememberScreenColorsnull68 private fun rememberScreenColors(): TutorialScreenConfig.Colors {
69 val onTertiary = MaterialTheme.colorScheme.onTertiary
70 val onTertiaryFixed = LocalAndroidColorScheme.current.onTertiaryFixed
71 val onTertiaryFixedVariant = LocalAndroidColorScheme.current.onTertiaryFixedVariant
72 val tertiaryFixedDim = LocalAndroidColorScheme.current.tertiaryFixedDim
73 val dynamicProperties =
74 rememberLottieDynamicProperties(
75 rememberColorFilterProperty(".tertiaryFixedDim", tertiaryFixedDim),
76 rememberColorFilterProperty(".onTertiaryFixed", onTertiaryFixed),
77 rememberColorFilterProperty(".onTertiary", onTertiary),
78 rememberColorFilterProperty(".onTertiaryFixedVariant", onTertiaryFixedVariant),
79 )
80 val screenColors =
81 remember(dynamicProperties) {
82 TutorialScreenConfig.Colors(
83 background = onTertiaryFixed,
84 title = tertiaryFixedDim,
85 animationColors = dynamicProperties,
86 )
87 }
88 return screenColors
89 }
90