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.graphics.Color 21 import android.graphics.drawable.PaintDrawable 22 import android.view.Gravity 23 import android.view.ViewGroup 24 import android.view.ViewGroup.LayoutParams.WRAP_CONTENT 25 import android.widget.FrameLayout 26 import android.widget.ImageView 27 import android.widget.LinearLayout 28 import android.widget.Space 29 import com.android.launcher3.R 30 import com.android.launcher3.taskbar.TaskbarActivityContext 31 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.* 32 33 class KidsNavLayoutter( 34 resources: Resources, 35 navBarContainer: LinearLayout, 36 endContextualContainer: ViewGroup, 37 startContextualContainer: ViewGroup, 38 imeSwitcher: ImageView?, 39 a11yButton: ImageView?, 40 space: Space? 41 ) : 42 AbstractNavButtonLayoutter( 43 resources, 44 navBarContainer, 45 endContextualContainer, 46 startContextualContainer, 47 imeSwitcher, 48 a11yButton, 49 space 50 ) { 51 layoutButtonsnull52 override fun layoutButtons(context: TaskbarActivityContext, isA11yButtonPersistent: Boolean) { 53 val iconSize: Int = resources.getDimensionPixelSize(DIMEN_TASKBAR_ICON_SIZE_KIDS) 54 val buttonWidth: Int = resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_WIDTH_KIDS) 55 val buttonHeight: Int = 56 resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_HEIGHT_KIDS) 57 val buttonRadius: Int = 58 resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_CORNER_RADIUS_KIDS) 59 val paddingLeft = (buttonWidth - iconSize) / 2 60 val paddingTop = (buttonHeight - iconSize) / 2 61 62 // Update icons 63 backButton!!.setImageDrawable(backButton.context.getDrawable(DRAWABLE_SYSBAR_BACK_KIDS)) 64 backButton.scaleType = ImageView.ScaleType.FIT_CENTER 65 backButton.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop) 66 homeButton!!.setImageDrawable(homeButton.context.getDrawable(DRAWABLE_SYSBAR_HOME_KIDS)) 67 homeButton.scaleType = ImageView.ScaleType.FIT_CENTER 68 homeButton.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop) 69 70 // Home button layout 71 val homeLayoutparams = LinearLayout.LayoutParams(buttonWidth, buttonHeight) 72 val homeButtonLeftMargin: Int = 73 resources.getDimensionPixelSize(DIMEN_TASKBAR_HOME_BUTTON_LEFT_MARGIN_KIDS) 74 homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0) 75 homeButton.layoutParams = homeLayoutparams 76 77 // Back button layout 78 val backLayoutParams = LinearLayout.LayoutParams(buttonWidth, buttonHeight) 79 val backButtonLeftMargin: Int = 80 resources.getDimensionPixelSize(DIMEN_TASKBAR_BACK_BUTTON_LEFT_MARGIN_KIDS) 81 backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0) 82 backButton.layoutParams = backLayoutParams 83 84 // Button backgrounds 85 val whiteWith10PctAlpha = Color.argb(0.1f, 1f, 1f, 1f) 86 val buttonBackground = PaintDrawable(whiteWith10PctAlpha) 87 buttonBackground.setCornerRadius(buttonRadius.toFloat()) 88 homeButton.background = buttonBackground 89 backButton.background = buttonBackground 90 91 // Update alignment within taskbar 92 val navButtonsLayoutParams = navButtonContainer.layoutParams as FrameLayout.LayoutParams 93 navButtonsLayoutParams.apply { 94 marginStart = navButtonsLayoutParams.marginEnd / 2 95 marginEnd = navButtonsLayoutParams.marginStart 96 gravity = Gravity.CENTER 97 } 98 navButtonContainer.requestLayout() 99 100 homeButton.onLongClickListener = null 101 102 endContextualContainer.removeAllViews() 103 startContextualContainer.removeAllViews() 104 105 val contextualMargin = 106 resources.getDimensionPixelSize(R.dimen.taskbar_contextual_button_padding) 107 repositionContextualContainer(endContextualContainer, WRAP_CONTENT, 0, 0, Gravity.END) 108 repositionContextualContainer( 109 startContextualContainer, 110 WRAP_CONTENT, 111 contextualMargin, 112 contextualMargin, 113 Gravity.START 114 ) 115 116 if (imeSwitcher != null) { 117 startContextualContainer.addView(imeSwitcher) 118 imeSwitcher.layoutParams = getParamsToCenterView() 119 } 120 if (a11yButton != null) { 121 endContextualContainer.addView(a11yButton) 122 a11yButton.layoutParams = getParamsToCenterView() 123 } 124 } 125 } 126