1 /* 2 * Copyright (C) 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.systemui.communal.shared.model 18 19 import com.android.compose.animation.scene.SceneKey 20 import com.android.systemui.scene.shared.flag.SceneContainerFlag 21 import com.android.systemui.scene.shared.model.SceneFamilies 22 import com.android.systemui.scene.shared.model.Scenes 23 24 /** Definition of the possible scenes for the communal UI. */ 25 @Deprecated( 26 "CommunalScenes are deprecated when SceneContainerFlag is enabled. " + 27 "Use com.android.systemui.scene.shared.model.Scenes instead. " + 28 "Use SceneKey.toSceneContainerSceneKey() to map legacy scenes to scene container scenes. " + 29 "Use SceneKey.isCommunal() to check whether a scene is a communal scene." 30 ) 31 object CommunalScenes { 32 /** The default scene, shows nothing and is only there to allow swiping to communal. */ 33 @JvmField val Blank = SceneKey("blank") 34 35 /** The communal scene containing the hub UI. */ 36 @JvmField val Communal = SceneKey("communal") 37 38 @JvmField val Default = Blank 39 SceneKeynull40 private fun SceneKey.isCommunalScene(): Boolean { 41 return this == Blank || this == Communal 42 } 43 44 /** 45 * Maps a legacy communal scene to a scene in the scene container. 46 * 47 * The rules are simple: 48 * - A legacy communal scene maps to a communal scene in the Scene Transition Framework (STF). 49 * - A legacy blank scene means that the communal scene layout does not render anything so 50 * whatever is beneath the layout is shown. That usually means lockscreen or dream, both in 51 * STL are represented by the home scene family. 52 */ SceneKeynull53 fun SceneKey.toSceneContainerSceneKey(): SceneKey { 54 if (!isCommunalScene() || !SceneContainerFlag.isEnabled) { 55 return this 56 } 57 58 return when (this) { 59 Communal -> Scenes.Communal 60 Blank -> SceneFamilies.Home 61 else -> throw Throwable("Unrecognized communal scene: $this") 62 } 63 } 64 65 /** Checks whether this is a communal scene based on whether [SceneContainerFlag] is enabled. */ SceneKeynull66 fun SceneKey.isCommunal(): Boolean { 67 return if (SceneContainerFlag.isEnabled) this == Scenes.Communal else this == Communal 68 } 69 } 70