• 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.graphics.Color
21 import android.graphics.drawable.PaintDrawable
22 import android.view.Gravity
23 import android.view.ViewGroup
24 import android.widget.FrameLayout
25 import android.widget.ImageView
26 import android.widget.LinearLayout
27 import com.android.launcher3.DeviceProfile
28 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_BACK_BUTTON_LEFT_MARGIN_KIDS
29 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_HOME_BUTTON_LEFT_MARGIN_KIDS
30 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_ICON_SIZE_KIDS
31 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_NAV_BUTTONS_CORNER_RADIUS_KIDS
32 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_NAV_BUTTONS_HEIGHT_KIDS
33 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DIMEN_TASKBAR_NAV_BUTTONS_WIDTH_KIDS
34 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DRAWABLE_SYSBAR_BACK_KIDS
35 import com.android.launcher3.taskbar.navbutton.LayoutResourceHelper.DRAWABLE_SYSBAR_HOME_KIDS
36 
37 class KidsNavLayoutter(
38     resources: Resources,
39     navBarContainer: LinearLayout,
40     endContextualContainer: ViewGroup,
41     startContextualContainer: ViewGroup
42 ) :
43     AbstractNavButtonLayoutter(
44         resources,
45         navBarContainer,
46         endContextualContainer,
47         startContextualContainer
48     ) {
49 
layoutButtonsnull50     override fun layoutButtons(dp: DeviceProfile, isContextualButtonShowing: Boolean) {
51         val iconSize: Int = resources.getDimensionPixelSize(DIMEN_TASKBAR_ICON_SIZE_KIDS)
52         val buttonWidth: Int = resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_WIDTH_KIDS)
53         val buttonHeight: Int =
54             resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_HEIGHT_KIDS)
55         val buttonRadius: Int =
56             resources.getDimensionPixelSize(DIMEN_TASKBAR_NAV_BUTTONS_CORNER_RADIUS_KIDS)
57         val paddingLeft = (buttonWidth - iconSize) / 2
58         val paddingTop = (buttonHeight - iconSize) / 2
59 
60         // Update icons
61         backButton.setImageDrawable(backButton.context.getDrawable(DRAWABLE_SYSBAR_BACK_KIDS))
62         backButton.scaleType = ImageView.ScaleType.FIT_CENTER
63         backButton.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop)
64         homeButton.setImageDrawable(homeButton.getContext().getDrawable(DRAWABLE_SYSBAR_HOME_KIDS))
65         homeButton.scaleType = ImageView.ScaleType.FIT_CENTER
66         homeButton.setPadding(paddingLeft, paddingTop, paddingLeft, paddingTop)
67 
68         // Home button layout
69         val homeLayoutparams = LinearLayout.LayoutParams(buttonWidth, buttonHeight)
70         val homeButtonLeftMargin: Int =
71             resources.getDimensionPixelSize(DIMEN_TASKBAR_HOME_BUTTON_LEFT_MARGIN_KIDS)
72         homeLayoutparams.setMargins(homeButtonLeftMargin, 0, 0, 0)
73         homeButton.layoutParams = homeLayoutparams
74 
75         // Back button layout
76         val backLayoutParams = LinearLayout.LayoutParams(buttonWidth, buttonHeight)
77         val backButtonLeftMargin: Int =
78             resources.getDimensionPixelSize(DIMEN_TASKBAR_BACK_BUTTON_LEFT_MARGIN_KIDS)
79         backLayoutParams.setMargins(backButtonLeftMargin, 0, 0, 0)
80         backButton.layoutParams = backLayoutParams
81 
82         // Button backgrounds
83         val whiteWith10PctAlpha = Color.argb(0.1f, 1f, 1f, 1f)
84         val buttonBackground = PaintDrawable(whiteWith10PctAlpha)
85         buttonBackground.setCornerRadius(buttonRadius.toFloat())
86         homeButton.background = buttonBackground
87         backButton.background = buttonBackground
88 
89         // Update alignment within taskbar
90         val navButtonsLayoutParams = navButtonContainer.layoutParams as FrameLayout.LayoutParams
91         navButtonsLayoutParams.apply {
92             marginStart = navButtonsLayoutParams.marginEnd / 2
93             marginEnd = navButtonsLayoutParams.marginStart
94             gravity = Gravity.CENTER
95         }
96         navButtonContainer.requestLayout()
97 
98         homeButton.onLongClickListener = null
99     }
100 }
101