• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.media.controls.ui.composable
18 
19 import com.android.compose.animation.scene.ContentKey
20 import com.android.compose.animation.scene.ElementContentPicker
21 import com.android.compose.animation.scene.ElementKey
22 import com.android.compose.animation.scene.SceneTransitionLayoutState
23 import com.android.compose.animation.scene.StaticElementContentPicker
24 import com.android.compose.animation.scene.content.state.TransitionState
25 import com.android.systemui.scene.shared.model.Overlays
26 import com.android.systemui.scene.shared.model.Scenes
27 
28 /** [ElementContentPicker] implementation for the media carousel object. */
29 object MediaContentPicker : StaticElementContentPicker {
30 
31     override val contents =
32         setOf(
33             Overlays.NotificationsShade,
34             Overlays.QuickSettingsShade,
35             Scenes.Lockscreen,
36             Scenes.Shade,
37             Scenes.QuickSettings,
38             Scenes.Communal,
39         )
40 
41     override fun contentDuringTransition(
42         element: ElementKey,
43         transition: TransitionState.Transition,
44         fromContentZIndex: Long,
45         toContentZIndex: Long,
46     ): ContentKey {
47         return when {
48             transition.isTransitioningBetween(Scenes.Lockscreen, Scenes.Shade) -> {
49                 Scenes.Shade
50             }
51             transition.isTransitioningBetween(Scenes.Lockscreen, Overlays.NotificationsShade) -> {
52                 Overlays.NotificationsShade
53             }
54             transition.isTransitioningBetween(Scenes.Lockscreen, Scenes.Communal) -> {
55                 Scenes.Lockscreen
56             }
57             transition.isTransitioningBetween(Scenes.QuickSettings, Scenes.Shade) -> {
58                 Scenes.QuickSettings
59             }
60             transition.isTransitioningBetween(
61                 Overlays.QuickSettingsShade,
62                 Overlays.NotificationsShade,
63             ) -> {
64                 Overlays.QuickSettingsShade
65             }
66             transition.toContent in contents -> transition.toContent
67             else -> {
68                 check(transition.fromContent in contents) {
69                     "Media player should not be composed for the transition from " +
70                         "${transition.fromContent} to ${transition.toContent}"
71                 }
72                 transition.fromContent
73             }
74         }
75     }
76 }
77 
78 /** Whether media should be laid on top of the rest for the given [transition]. */
MediaContentPickernull79 fun MediaContentPicker.shouldElevateMedia(layoutState: SceneTransitionLayoutState): Boolean {
80     return layoutState.currentTransition?.let { transition ->
81         transition.isTransitioningBetween(Scenes.Lockscreen, Scenes.Shade) ||
82             transition.isTransitioningBetween(Scenes.Lockscreen, Overlays.NotificationsShade)
83     } ?: false
84 }
85