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