• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.launcher3.taskbar.navbutton
18 
19 import android.content.res.Resources
20 import android.view.ViewGroup
21 import android.widget.FrameLayout
22 import android.widget.LinearLayout
23 import com.android.launcher3.DeviceProfile
24 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.ID_END_CONTEXTUAL_BUTTONS
25 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.ID_END_NAV_BUTTONS
26 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.ID_START_CONTEXTUAL_BUTTONS
27 import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.Companion
28 import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter
29 
30 /**
31  * Select the correct layout for nav buttons
32  *
33  * Since layouts are done dynamically for the nav buttons on Taskbar, this class returns a
34  * corresponding [NavButtonLayoutter] via [Companion.getUiLayoutter] that can help position the
35  * buttons based on the current [DeviceProfile]
36  */
37 class NavButtonLayoutFactory {
38     companion object {
39         /**
40          * Get the correct instance of [NavButtonLayoutter]
41          *
42          * No layouts supported for configurations where:
43          * * taskbar isn't showing AND
44          * * the device is not in [phoneMode] OR
45          * * phone is showing
46          * * device is using gesture navigation
47          *
48          * @param navButtonsView ViewGroup that contains start, end, nav button ViewGroups
49          * @param isKidsMode no-op when taskbar is hidden/not showing
50          * @param isInSetup no-op when taskbar is hidden/not showing
51          * @param phoneMode refers to the device using the taskbar window on phones
52          * @param isThreeButtonNav are no-ops when taskbar is present/showing
53          */
getUiLayoutternull54         fun getUiLayoutter(
55             deviceProfile: DeviceProfile,
56             navButtonsView: FrameLayout,
57             resources: Resources,
58             isKidsMode: Boolean,
59             isInSetup: Boolean,
60             isThreeButtonNav: Boolean,
61             phoneMode: Boolean
62         ): NavButtonLayoutter {
63             val navButtonContainer = navButtonsView.findViewById<LinearLayout>(ID_END_NAV_BUTTONS)
64             val endContextualContainer =
65                 navButtonsView.findViewById<ViewGroup>(ID_END_CONTEXTUAL_BUTTONS)
66             val startContextualContainer =
67                 navButtonsView.findViewById<ViewGroup>(ID_START_CONTEXTUAL_BUTTONS)
68             val isPhoneNavMode = phoneMode && isThreeButtonNav
69             return when {
70                 isPhoneNavMode -> {
71                     if (!deviceProfile.isLandscape) {
72                         PhonePortraitNavLayoutter(
73                             resources,
74                             navButtonContainer,
75                             endContextualContainer,
76                             startContextualContainer
77                         )
78                     } else {
79                         PhoneLandscapeNavLayoutter(
80                             resources,
81                             navButtonContainer,
82                             endContextualContainer,
83                             startContextualContainer
84                         )
85                     }
86                 }
87                 deviceProfile.isTaskbarPresent -> {
88                     return when {
89                         isInSetup -> {
90                             SetupNavLayoutter(
91                                 resources,
92                                 navButtonContainer,
93                                 endContextualContainer,
94                                 startContextualContainer
95                             )
96                         }
97                         isKidsMode -> {
98                             KidsNavLayoutter(
99                                 resources,
100                                 navButtonContainer,
101                                 endContextualContainer,
102                                 startContextualContainer
103                             )
104                         }
105                         else ->
106                             TaskbarNavLayoutter(
107                                 resources,
108                                 navButtonContainer,
109                                 endContextualContainer,
110                                 startContextualContainer
111                             )
112                     }
113                 }
114                 else -> error("No layoutter found")
115             }
116         }
117     }
118 
119     /** Lays out and provides access to the home, recents, and back buttons for various mischief */
120     interface NavButtonLayoutter {
layoutButtonsnull121         fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean)
122     }
123 }
124