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.bouncer.ui.composable
18 
19 import androidx.compose.material3.windowsizeclass.WindowHeightSizeClass
20 import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
21 import androidx.compose.runtime.Composable
22 import com.android.compose.windowsizeclass.LocalWindowSizeClass
23 import com.android.systemui.bouncer.ui.helper.BouncerSceneLayout
24 import com.android.systemui.bouncer.ui.helper.SizeClass
25 import com.android.systemui.bouncer.ui.helper.calculateLayoutInternal
26 
27 /**
28  * Returns the [BouncerSceneLayout] that should be used by the bouncer scene. If
29  * [isSideBySideSupported] is `false`, then [BouncerSceneLayout.BESIDE_USER_SWITCHER] is replaced by
30  * [BouncerSceneLayout.STANDARD_BOUNCER].
31  */
32 @Composable
calculateLayoutnull33 fun calculateLayout(
34     isSideBySideSupported: Boolean,
35 ): BouncerSceneLayout {
36     val windowSizeClass = LocalWindowSizeClass.current
37 
38     return calculateLayoutInternal(
39         width = windowSizeClass.widthSizeClass.toEnum(),
40         height = windowSizeClass.heightSizeClass.toEnum(),
41         isSideBySideSupported = isSideBySideSupported,
42     )
43 }
44 
WindowWidthSizeClassnull45 private fun WindowWidthSizeClass.toEnum(): SizeClass {
46     return when (this) {
47         WindowWidthSizeClass.Compact -> SizeClass.COMPACT
48         WindowWidthSizeClass.Medium -> SizeClass.MEDIUM
49         WindowWidthSizeClass.Expanded -> SizeClass.EXPANDED
50         else -> error("Unsupported WindowWidthSizeClass \"$this\"")
51     }
52 }
53 
WindowHeightSizeClassnull54 private fun WindowHeightSizeClass.toEnum(): SizeClass {
55     return when (this) {
56         WindowHeightSizeClass.Compact -> SizeClass.COMPACT
57         WindowHeightSizeClass.Medium -> SizeClass.MEDIUM
58         WindowHeightSizeClass.Expanded -> SizeClass.EXPANDED
59         else -> error("Unsupported WindowHeightSizeClass \"$this\"")
60     }
61 }
62