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.helper
18
19 import androidx.annotation.VisibleForTesting
20
21 /** Enumerates all known adaptive layout configurations. */
22 enum class BouncerSceneLayout {
23 /** The default UI with the bouncer laid out normally. */
24 STANDARD_BOUNCER,
25 /** The bouncer is displayed vertically stacked with the user switcher. */
26 BELOW_USER_SWITCHER,
27 /** The bouncer is displayed side-by-side with the user switcher or an empty space. */
28 BESIDE_USER_SWITCHER,
29 /** The bouncer is split in two with both sides shown side-by-side. */
30 SPLIT_BOUNCER,
31 }
32
33 /** Enumerates the supported window size classes. */
34 enum class SizeClass {
35 COMPACT,
36 MEDIUM,
37 EXPANDED,
38 }
39
40 /**
41 * Internal version of `calculateLayout` in the System UI Compose library, extracted here to allow
42 * for testing that's not dependent on Compose.
43 */
44 @VisibleForTesting
calculateLayoutInternalnull45 fun calculateLayoutInternal(
46 width: SizeClass,
47 height: SizeClass,
48 isSideBySideSupported: Boolean,
49 ): BouncerSceneLayout {
50 return when (height) {
51 SizeClass.COMPACT -> BouncerSceneLayout.SPLIT_BOUNCER
52 SizeClass.MEDIUM ->
53 when (width) {
54 SizeClass.COMPACT -> BouncerSceneLayout.STANDARD_BOUNCER
55 SizeClass.MEDIUM -> BouncerSceneLayout.STANDARD_BOUNCER
56 SizeClass.EXPANDED -> BouncerSceneLayout.BESIDE_USER_SWITCHER
57 }
58 SizeClass.EXPANDED ->
59 when (width) {
60 SizeClass.COMPACT -> BouncerSceneLayout.STANDARD_BOUNCER
61 SizeClass.MEDIUM -> BouncerSceneLayout.BELOW_USER_SWITCHER
62 SizeClass.EXPANDED -> BouncerSceneLayout.BESIDE_USER_SWITCHER
63 }
64 }.takeIf { it != BouncerSceneLayout.BESIDE_USER_SWITCHER || isSideBySideSupported }
65 ?: BouncerSceneLayout.STANDARD_BOUNCER
66 }
67