• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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.widget.FrameLayout
23 import android.widget.LinearLayout
24 import androidx.core.view.children
25 import com.android.launcher3.DeviceProfile
26 import com.android.launcher3.R
27 import com.android.launcher3.taskbar.TaskbarManager
28 import com.android.launcher3.util.DimensionUtils
29 
30 class PhoneLandscapeNavLayoutter(
31     resources: Resources,
32     navBarContainer: LinearLayout,
33     endContextualContainer: ViewGroup,
34     startContextualContainer: ViewGroup
35 ) :
36     AbstractNavButtonLayoutter(
37         resources,
38         navBarContainer,
39         endContextualContainer,
40         startContextualContainer
41     ) {
42 
43     override fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean) {
44         // TODO(b/230395757): Polish pending, this is just to make it usable
45         val navContainerParams = navButtonContainer.layoutParams as FrameLayout.LayoutParams
46         val endStartMargins = resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
47         val taskbarDimensions =
48             DimensionUtils.getTaskbarPhoneDimensions(dp, resources, TaskbarManager.isPhoneMode(dp))
49         navButtonContainer.removeAllViews()
50         navButtonContainer.orientation = LinearLayout.VERTICAL
51 
52         navContainerParams.apply {
53             width = taskbarDimensions.x
54             height = ViewGroup.LayoutParams.MATCH_PARENT
55             gravity = Gravity.CENTER
56             topMargin = endStartMargins
57             bottomMargin = endStartMargins
58             marginEnd = 0
59             marginStart = 0
60         }
61 
62         // Swap recents and back button
63         navButtonContainer.addView(recentsButton)
64         navButtonContainer.addView(homeButton)
65         navButtonContainer.addView(backButton)
66 
67         navButtonContainer.layoutParams = navContainerParams
68 
69         // Add the spaces in between the nav buttons
70         val spaceInBetween: Int =
71             resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone)
72         navButtonContainer.children.forEachIndexed { i, navButton ->
73             val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
74             buttonLayoutParams.weight = 1f
75             when (i) {
76                 0 -> {
77                     buttonLayoutParams.bottomMargin = spaceInBetween / 2
78                 }
79                 navButtonContainer.childCount - 1 -> {
80                     buttonLayoutParams.topMargin = spaceInBetween / 2
81                 }
82                 else -> {
83                     buttonLayoutParams.bottomMargin = spaceInBetween / 2
84                     buttonLayoutParams.topMargin = spaceInBetween / 2
85                 }
86             }
87         }
88     }
89 }
90