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.keyguard.ui.composable.blueprint
18 
19 import androidx.compose.animation.core.LinearEasing
20 import androidx.compose.animation.core.tween
21 import com.android.compose.animation.scene.ElementKey
22 import com.android.compose.animation.scene.SceneKey
23 import com.android.compose.animation.scene.TransitionBuilder
24 import com.android.compose.animation.scene.transitions
25 import com.android.systemui.keyguard.ui.composable.blueprint.ClockElementKeys.largeClockElementKey
26 import com.android.systemui.keyguard.ui.composable.blueprint.ClockElementKeys.smallClockElementKey
27 import com.android.systemui.keyguard.ui.composable.blueprint.ClockElementKeys.smartspaceElementKey
28 import com.android.systemui.keyguard.ui.composable.blueprint.ClockTransition.transitioningToLargeClock
29 import com.android.systemui.keyguard.ui.composable.blueprint.ClockTransition.transitioningToSmallClock
30 import com.android.systemui.keyguard.ui.composable.blueprint.WeatherClockElementKeys.largeWeatherClockElementKeyList
31 import com.android.systemui.keyguard.ui.view.layout.sections.transitions.ClockSizeTransition.ClockFaceInTransition.Companion.CLOCK_IN_MILLIS
32 import com.android.systemui.keyguard.ui.view.layout.sections.transitions.ClockSizeTransition.ClockFaceInTransition.Companion.CLOCK_IN_START_DELAY_MILLIS
33 import com.android.systemui.keyguard.ui.view.layout.sections.transitions.ClockSizeTransition.ClockFaceOutTransition.Companion.CLOCK_OUT_MILLIS
34 import com.android.systemui.keyguard.ui.view.layout.sections.transitions.ClockSizeTransition.SmartspaceMoveTransition.Companion.STATUS_AREA_MOVE_DOWN_MILLIS
35 import com.android.systemui.keyguard.ui.view.layout.sections.transitions.ClockSizeTransition.SmartspaceMoveTransition.Companion.STATUS_AREA_MOVE_UP_MILLIS
36 
37 object ClockTransition {
<lambda>null38     val defaultClockTransitions = transitions {
39         from(ClockScenes.smallClockScene, to = ClockScenes.largeClockScene) {
40             transitioningToLargeClock(largeClockElements = listOf(largeClockElementKey))
41         }
42         from(ClockScenes.largeClockScene, to = ClockScenes.smallClockScene) {
43             transitioningToSmallClock(largeClockElements = listOf(largeClockElementKey))
44         }
45         from(ClockScenes.splitShadeLargeClockScene, to = ClockScenes.largeClockScene) {
46             spec = tween(300, easing = LinearEasing)
47         }
48 
49         from(WeatherClockScenes.largeClockScene, to = ClockScenes.smallClockScene) {
50             transitioningToSmallClock(largeClockElements = largeWeatherClockElementKeyList)
51         }
52 
53         from(ClockScenes.smallClockScene, to = WeatherClockScenes.largeClockScene) {
54             transitioningToLargeClock(largeClockElements = largeWeatherClockElementKeyList)
55         }
56 
57         from(
58             WeatherClockScenes.largeClockScene,
59             to = WeatherClockScenes.splitShadeLargeClockScene
60         ) {
61             spec = tween(300, easing = LinearEasing)
62         }
63     }
64 
TransitionBuildernull65     private fun TransitionBuilder.transitioningToLargeClock(largeClockElements: List<ElementKey>) {
66         spec = tween(durationMillis = STATUS_AREA_MOVE_UP_MILLIS.toInt())
67         timestampRange(
68             startMillis = CLOCK_IN_START_DELAY_MILLIS.toInt(),
69             endMillis = (CLOCK_IN_START_DELAY_MILLIS + CLOCK_IN_MILLIS).toInt()
70         ) {
71             largeClockElements.forEach { fade(it) }
72         }
73 
74         timestampRange(endMillis = CLOCK_OUT_MILLIS.toInt()) { fade(smallClockElementKey) }
75         anchoredTranslate(smallClockElementKey, smartspaceElementKey)
76     }
77 
TransitionBuildernull78     private fun TransitionBuilder.transitioningToSmallClock(largeClockElements: List<ElementKey>) {
79         spec = tween(durationMillis = STATUS_AREA_MOVE_DOWN_MILLIS.toInt())
80         timestampRange(
81             startMillis = CLOCK_IN_START_DELAY_MILLIS.toInt(),
82             endMillis = (CLOCK_IN_START_DELAY_MILLIS + CLOCK_IN_MILLIS).toInt()
83         ) {
84             fade(smallClockElementKey)
85         }
86 
87         timestampRange(endMillis = CLOCK_OUT_MILLIS.toInt()) {
88             largeClockElements.forEach { fade(it) }
89         }
90         anchoredTranslate(smallClockElementKey, smartspaceElementKey)
91     }
92 }
93 
94 object ClockScenes {
95     val smallClockScene = SceneKey("small-clock-scene")
96     val largeClockScene = SceneKey("large-clock-scene")
97     val splitShadeSmallClockScene = SceneKey("split-shade-small-clock-scene")
98     val splitShadeLargeClockScene = SceneKey("split-shade-large-clock-scene")
99 }
100 
101 object ClockElementKeys {
102     val largeClockElementKey = ElementKey("large-clock")
103     val smallClockElementKey = ElementKey("small-clock")
104     val smartspaceElementKey = ElementKey("smart-space")
105 }
106 
107 object WeatherClockScenes {
108     val largeClockScene = SceneKey("large-weather-clock-scene")
109     val splitShadeLargeClockScene = SceneKey("split-shade-large-weather-clock-scene")
110 }
111 
112 object WeatherClockElementKeys {
113     val timeElementKey = ElementKey("weather-large-clock-time")
114     val dateElementKey = ElementKey("weather-large-clock-date")
115     val weatherIconElementKey = ElementKey("weather-large-clock-weather-icon")
116     val temperatureElementKey = ElementKey("weather-large-clock-temperature")
117     val dndAlarmElementKey = ElementKey("weather-large-clock-dnd-alarm")
118     val largeWeatherClockElementKeyList =
119         listOf(
120             timeElementKey,
121             dateElementKey,
122             weatherIconElementKey,
123             temperatureElementKey,
124             dndAlarmElementKey
125         )
126 }
127