• 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.widget.FrameLayout
23 import android.widget.LinearLayout
24 import com.android.launcher3.DeviceProfile
25 import com.android.launcher3.R
26 
27 /** Layoutter for showing 3 button navigation on large screen */
28 class TaskbarNavLayoutter(
29     resources: Resources,
30     navBarContainer: LinearLayout,
31     endContextualContainer: ViewGroup,
32     startContextualContainer: ViewGroup
33 ) :
34     AbstractNavButtonLayoutter(
35         resources,
36         navBarContainer,
37         endContextualContainer,
38         startContextualContainer
39     ) {
40 
layoutButtonsnull41     override fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean) {
42         // Add spacing after the end of the last nav button
43         val navButtonParams = navButtonContainer.layoutParams as FrameLayout.LayoutParams
44         var navMarginEnd = resources.getDimension(dp.inv.inlineNavButtonsEndSpacing).toInt()
45         val contextualWidth = endContextualContainer.width
46         // If contextual buttons are showing, we check if the end margin is enough for the
47         // contextual button to be showing - if not, move the nav buttons over a smidge
48         if (isContextualButtonShowing && navMarginEnd < contextualWidth) {
49             // Additional spacing, eat up half of space between last icon and nav button
50             navMarginEnd += resources.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing) / 2
51         }
52 
53         navButtonParams.apply {
54             gravity = Gravity.END
55             width = FrameLayout.LayoutParams.WRAP_CONTENT
56             height = ViewGroup.LayoutParams.MATCH_PARENT
57             marginEnd = navMarginEnd
58         }
59         navButtonContainer.orientation = LinearLayout.HORIZONTAL
60         navButtonContainer.layoutParams = navButtonParams
61 
62         // Add the spaces in between the nav buttons
63         val spaceInBetween = resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
64         for (i in 0 until navButtonContainer.childCount) {
65             val navButton = navButtonContainer.getChildAt(i)
66             val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
67             buttonLayoutParams.weight = 0f
68             when (i) {
69                 0 -> {
70                     buttonLayoutParams.marginEnd = spaceInBetween / 2
71                 }
72                 navButtonContainer.childCount - 1 -> {
73                     buttonLayoutParams.marginStart = spaceInBetween / 2
74                 }
75                 else -> {
76                     buttonLayoutParams.marginStart = spaceInBetween / 2
77                     buttonLayoutParams.marginEnd = spaceInBetween / 2
78                 }
79             }
80         }
81     }
82 }
83