• 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 open 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 endStartMargins = resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size)
46         val taskbarDimensions = DimensionUtils.getTaskbarPhoneDimensions(dp, resources,
47                 TaskbarManager.isPhoneMode(dp))
48         navButtonContainer.removeAllViews()
49         navButtonContainer.orientation = LinearLayout.VERTICAL
50 
51         val navContainerParams = FrameLayout.LayoutParams(
52                 taskbarDimensions.x, ViewGroup.LayoutParams.MATCH_PARENT)
53         navContainerParams.apply {
54             topMargin = endStartMargins
55             bottomMargin = endStartMargins
56             marginEnd = 0
57             marginStart = 0
58         }
59 
60         // Swap recents and back button
61         navButtonContainer.addView(recentsButton)
62         navButtonContainer.addView(homeButton)
63         navButtonContainer.addView(backButton)
64 
65         navButtonContainer.layoutParams = navContainerParams
66         navButtonContainer.gravity = Gravity.CENTER
67 
68         // Add the spaces in between the nav buttons
69         val spaceInBetween: Int =
70             resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone)
71         navButtonContainer.children.forEachIndexed { i, navButton ->
72             val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
73             buttonLayoutParams.weight = 1f
74             when (i) {
75                 0 -> {
76                     buttonLayoutParams.bottomMargin = spaceInBetween / 2
77                 }
78                 navButtonContainer.childCount - 1 -> {
79                     buttonLayoutParams.topMargin = spaceInBetween / 2
80                 }
81                 else -> {
82                     buttonLayoutParams.bottomMargin = spaceInBetween / 2
83                     buttonLayoutParams.topMargin = spaceInBetween / 2
84                 }
85             }
86         }
87     }
88 }
89