• 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.Gravity
21 import android.view.ViewGroup
22 import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
23 import android.widget.FrameLayout
24 import android.widget.ImageView
25 import android.widget.LinearLayout
26 import android.widget.Space
27 import com.android.launcher3.DeviceProfile
28 import com.android.launcher3.R
29 import com.android.launcher3.taskbar.TaskbarActivityContext
30 
31 const val SQUARE_ASPECT_RATIO_BOTTOM_BOUND = 0.95
32 const val SQUARE_ASPECT_RATIO_UPPER_BOUND = 1.05
33 
34 class SetupNavLayoutter(
35     resources: Resources,
36     navButtonsView: NearestTouchFrame,
37     navButtonContainer: LinearLayout,
38     endContextualContainer: ViewGroup,
39     startContextualContainer: ViewGroup,
40     imeSwitcher: ImageView?,
41     a11yButton: ImageView?,
42     space: Space?
43 ) :
44     AbstractNavButtonLayoutter(
45         resources,
46         navButtonContainer,
47         endContextualContainer,
48         startContextualContainer,
49         imeSwitcher,
50         a11yButton,
51         space
52     ) {
53     private val mNavButtonsView = navButtonsView
54 
layoutButtonsnull55     override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) {
56         // Since setup wizard only has back button enabled, it looks strange to be
57         // end-aligned, so start-align instead.
58         val navButtonsLayoutParams = navButtonContainer.layoutParams as FrameLayout.LayoutParams
59         val navButtonsViewLayoutParams = mNavButtonsView.layoutParams as FrameLayout.LayoutParams
60         val deviceProfile: DeviceProfile = context.deviceProfile
61 
62         navButtonsLayoutParams.marginEnd = 0
63         navButtonsLayoutParams.gravity = Gravity.START
64         context.setTaskbarWindowSize(context.setupWindowSize)
65 
66         // If SUW is on a large screen device that is landscape (or has a square aspect
67         // ratio) the back button has to be placed accordingly
68         if (
69             deviceProfile.isTablet && deviceProfile.isLandscape ||
70                 (deviceProfile.aspectRatio > SQUARE_ASPECT_RATIO_BOTTOM_BOUND &&
71                     deviceProfile.aspectRatio < SQUARE_ASPECT_RATIO_UPPER_BOUND)
72         ) {
73             navButtonsLayoutParams.marginStart =
74                 resources.getDimensionPixelSize(R.dimen.taskbar_back_button_suw_start_margin)
75             navButtonsViewLayoutParams.bottomMargin =
76                 resources.getDimensionPixelSize(R.dimen.taskbar_back_button_suw_bottom_margin)
77             navButtonsLayoutParams.height =
78                 resources.getDimensionPixelSize(R.dimen.taskbar_back_button_suw_height)
79         } else {
80             adjustForSetupInPhoneMode(
81                 navButtonsLayoutParams,
82                 navButtonsViewLayoutParams,
83                 deviceProfile
84             )
85         }
86         mNavButtonsView.layoutParams = navButtonsViewLayoutParams
87         navButtonContainer.layoutParams = navButtonsLayoutParams
88 
89         endContextualContainer.removeAllViews()
90         startContextualContainer.removeAllViews()
91 
92         val contextualMargin =
93             resources.getDimensionPixelSize(R.dimen.taskbar_contextual_button_padding)
94         repositionContextualContainer(endContextualContainer, WRAP_CONTENT, 0, 0, Gravity.END)
95         repositionContextualContainer(
96             startContextualContainer,
97             WRAP_CONTENT,
98             contextualMargin,
99             contextualMargin,
100             Gravity.START
101         )
102 
103         if (imeSwitcher != null) {
104             startContextualContainer.addView(imeSwitcher)
105             imeSwitcher.layoutParams = getParamsToCenterView()
106         }
107         if (a11yButton != null) {
108             endContextualContainer.addView(a11yButton)
109             a11yButton.layoutParams = getParamsToCenterView()
110         }
111     }
112 }
113