• 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         var navMarginEnd = resources.getDimension(dp.inv.inlineNavButtonsEndSpacing).toInt()
44         val contextualWidth = endContextualContainer.width
45         // If contextual buttons are showing, we check if the end margin is enough for the
46         // contextual button to be showing - if not, move the nav buttons over a smidge
47         if (isContextualButtonShowing && navMarginEnd < contextualWidth) {
48             // Additional spacing, eat up half of space between last icon and nav button
49             navMarginEnd += resources.getDimensionPixelSize(R.dimen.taskbar_hotseat_nav_spacing) / 2
50         }
51 
52         val navButtonParams = FrameLayout.LayoutParams(
53                 FrameLayout.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)
54         navButtonParams.apply {
55             gravity = Gravity.END or Gravity.CENTER_VERTICAL
56             marginEnd = navMarginEnd
57         }
58         navButtonContainer.orientation = LinearLayout.HORIZONTAL
59         navButtonContainer.layoutParams = navButtonParams
60 
61         // Add the spaces in between the nav buttons
62         val spaceInBetween = resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween)
63         for (i in 0 until navButtonContainer.childCount) {
64             val navButton = navButtonContainer.getChildAt(i)
65             val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams
66             buttonLayoutParams.weight = 0f
67             when (i) {
68                 0 -> {
69                     buttonLayoutParams.marginEnd = spaceInBetween / 2
70                 }
71                 navButtonContainer.childCount - 1 -> {
72                     buttonLayoutParams.marginStart = spaceInBetween / 2
73                 }
74                 else -> {
75                     buttonLayoutParams.marginStart = spaceInBetween / 2
76                     buttonLayoutParams.marginEnd = spaceInBetween / 2
77                 }
78             }
79         }
80     }
81 }
82