• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.compose.animation.scene.demo
18 
19 import androidx.compose.foundation.layout.Box
20 import androidx.compose.foundation.layout.Column
21 import androidx.compose.foundation.layout.Spacer
22 import androidx.compose.foundation.layout.padding
23 import androidx.compose.runtime.Composable
24 import androidx.compose.ui.Modifier
25 import androidx.compose.ui.unit.dp
26 import androidx.compose.ui.zIndex
27 import com.android.compose.animation.scene.Back
28 import com.android.compose.animation.scene.ContentScope
29 import com.android.compose.animation.scene.ElementKey
30 import com.android.compose.animation.scene.Swipe
31 import com.android.compose.animation.scene.UserActionResult
32 import com.android.compose.animation.scene.UserActionResult.ShowOverlay
33 import com.android.compose.animation.scene.UserActionResult.ShowOverlay.HideCurrentOverlays
34 
35 object QuickSettingsShade {
36     object Elements {
37         val Root = ElementKey("QuickSettingsShadeRoot")
38         val Content = ElementKey("QuickSettingsShadeContent")
39     }
40 
41     val UserActions =
42         mapOf(
43             Back to UserActionResult.HideOverlay(Overlays.QuickSettings),
44             Swipe.Up to UserActionResult.HideOverlay(Overlays.QuickSettings),
45             Swipe.Down(fromSource = SceneContainerArea.StartHalf) to
46                 ShowOverlay(
47                     Overlays.Notifications,
48                     hideCurrentOverlays = HideCurrentOverlays.Some(Overlays.QuickSettings),
49                 ),
50         )
51 }
52 
53 @Composable
ContentScopenull54 fun ContentScope.QuickSettingsShade(
55     qsPager: @Composable ContentScope.() -> Unit,
56     mediaPlayer: @Composable (ContentScope.() -> Unit)?,
57     modifier: Modifier = Modifier,
58 ) {
59     PartialShade(QuickSettingsShade.Elements.Root, modifier) {
60         Column(Modifier.element(QuickSettingsShade.Elements.Content)) {
61             if (mediaPlayer != null) {
62                 // Ensure that the media player is above the QS tiles when they fade in.
63                 Box(Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp).zIndex(1f)) {
64                     mediaPlayer()
65                 }
66             }
67 
68             Spacer(Modifier.padding(top = 16.dp))
69             qsPager()
70         }
71     }
72 }
73