• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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.Canvas
20 import androidx.compose.foundation.layout.Box
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.foundation.layout.fillMaxSize
23 import androidx.compose.foundation.layout.padding
24 import androidx.compose.foundation.layout.size
25 import androidx.compose.material3.MaterialTheme
26 import androidx.compose.runtime.Composable
27 import androidx.compose.ui.Alignment
28 import androidx.compose.ui.Modifier
29 import androidx.compose.ui.graphics.Color
30 import androidx.compose.ui.unit.dp
31 import com.android.compose.animation.scene.ContentScope
32 import com.android.compose.animation.scene.ElementKey
33 import com.android.compose.animation.scene.SceneKey
34 import com.android.compose.animation.scene.Swipe
35 import com.android.compose.animation.scene.UserAction
36 import com.android.compose.animation.scene.UserActionResult
37 import com.android.compose.grid.VerticalGrid
38 
39 object Launcher {
userActionsnull40     fun userActions(
41         shadeScene: SceneKey,
42         configuration: DemoConfiguration,
43     ): Map<UserAction, UserActionResult> {
44         return buildList {
45                 if (configuration.enableOverlays) {
46                     add(
47                         Swipe.Down(fromSource = SceneContainerArea.StartHalf) to
48                             UserActionResult.ShowOverlay(Overlays.Notifications)
49                     )
50                     add(
51                         Swipe.Down(fromSource = SceneContainerArea.EndHalf) to
52                             UserActionResult.ShowOverlay(Overlays.QuickSettings)
53                     )
54                 } else {
55                     add(Swipe.Down to shadeScene)
56                     add(Swipe.Down(pointerCount = 2) to Scenes.QuickSettings)
57                 }
58             }
59             .toMap()
60     }
61 
62     object Elements {
63         val Scene = ElementKey("LauncherScene")
64         val SmartSpace = ElementKey("SmartSpace")
65         val IconsGrid = ElementKey("LauncherIconsGrid")
66     }
67 }
68 
69 @Composable
ContentScopenull70 fun ContentScope.Launcher(columnsCount: Int, modifier: Modifier = Modifier) {
71     Column(modifier.element(Launcher.Elements.Scene)) {
72         SmartSpace(
73             MaterialTheme.colorScheme.onBackground,
74             Modifier.element(Launcher.Elements.SmartSpace).padding(top = 40.dp, start = 40.dp),
75         )
76 
77         VerticalGrid(columnsCount, Modifier.element(Launcher.Elements.IconsGrid).padding(16.dp)) {
78             val iconColor = MaterialTheme.colorScheme.tertiary
79             repeat(columnsCount * 5) {
80                 Box(Modifier.fillMaxSize()) { AppIcon(iconColor, Modifier.align(Alignment.Center)) }
81             }
82         }
83     }
84 }
85 
86 @Composable
AppIconnull87 private fun AppIcon(color: Color, modifier: Modifier = Modifier) {
88     Canvas(modifier.size(60.dp)) { drawCircle(color) }
89 }
90