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 import com.android.launcher3.taskbar.TaskbarManager 27 import com.android.launcher3.util.DimensionUtils 28 29 class PhonePortraitNavLayoutter( 30 resources: Resources, 31 navBarContainer: LinearLayout, 32 endContextualContainer: ViewGroup, 33 startContextualContainer: ViewGroup 34 ) : 35 AbstractNavButtonLayoutter( 36 resources, 37 navBarContainer, 38 endContextualContainer, 39 startContextualContainer 40 ) { 41 layoutButtonsnull42 override fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean) { 43 // TODO(b/230395757): Polish pending, this is just to make it usable 44 val taskbarDimensions = 45 DimensionUtils.getTaskbarPhoneDimensions(dp, resources, 46 TaskbarManager.isPhoneMode(dp)) 47 val endStartMargins = resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size) 48 49 // Ensure order of buttons is correct 50 navButtonContainer.removeAllViews() 51 navButtonContainer.orientation = LinearLayout.HORIZONTAL 52 53 val navContainerParams = FrameLayout.LayoutParams( 54 taskbarDimensions.x, ViewGroup.LayoutParams.MATCH_PARENT) 55 navContainerParams.apply { 56 topMargin = 0 57 bottomMargin = 0 58 marginEnd = endStartMargins 59 marginStart = endStartMargins 60 } 61 62 // Swap recents and back button in case we were landscape prior to this 63 navButtonContainer.addView(backButton) 64 navButtonContainer.addView(homeButton) 65 navButtonContainer.addView(recentsButton) 66 67 navButtonContainer.layoutParams = navContainerParams 68 navButtonContainer.gravity = Gravity.CENTER 69 70 // Add the spaces in between the nav buttons 71 val spaceInBetween = 72 resources.getDimensionPixelSize(R.dimen.taskbar_button_space_inbetween_phone) 73 for (i in 0 until navButtonContainer.childCount) { 74 val navButton = navButtonContainer.getChildAt(i) 75 val buttonLayoutParams = navButton.layoutParams as LinearLayout.LayoutParams 76 buttonLayoutParams.weight = 1f 77 when (i) { 78 0 -> { 79 // First button 80 buttonLayoutParams.marginEnd = spaceInBetween / 2 81 } 82 navButtonContainer.childCount - 1 -> { 83 // Last button 84 buttonLayoutParams.marginStart = spaceInBetween / 2 85 } 86 else -> { 87 // other buttons 88 buttonLayoutParams.marginStart = spaceInBetween / 2 89 buttonLayoutParams.marginEnd = spaceInBetween / 2 90 } 91 } 92 } 93 } 94 } 95