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.drawable.RotateDrawable 21 import android.view.Gravity 22 import android.view.ViewGroup 23 import android.widget.FrameLayout 24 import android.widget.ImageView 25 import android.widget.LinearLayout 26 import android.widget.Space 27 import com.android.launcher3.DeviceProfile 28 import com.android.launcher3.R 29 import com.android.launcher3.Utilities 30 import com.android.launcher3.taskbar.TaskbarActivityContext 31 import com.android.launcher3.taskbar.navbutton.NavButtonLayoutFactory.NavButtonLayoutter 32 33 /** 34 * Meant to be a simple container for data subclasses will need 35 * 36 * Assumes that the 3 navigation buttons (back/home/recents) have already been added to 37 * [navButtonContainer] 38 * 39 * @property navButtonContainer ViewGroup that holds the 3 navigation buttons. 40 * @property endContextualContainer ViewGroup that holds the end contextual button (ex, IME 41 * dismiss). 42 * @property startContextualContainer ViewGroup that holds the start contextual button (ex, A11y). 43 */ 44 abstract class AbstractNavButtonLayoutter( 45 val resources: Resources, 46 val navButtonContainer: LinearLayout, 47 protected val endContextualContainer: ViewGroup, 48 protected val startContextualContainer: ViewGroup, 49 protected val imeSwitcher: ImageView?, 50 protected val a11yButton: ImageView?, 51 protected val space: Space? 52 ) : NavButtonLayoutter { 53 protected val homeButton: ImageView? = navButtonContainer.findViewById(R.id.home) 54 protected val recentsButton: ImageView? = navButtonContainer.findViewById(R.id.recent_apps) 55 protected val backButton: ImageView? = navButtonContainer.findViewById(R.id.back) 56 57 init { 58 // setup back button drawable 59 if (backButton != null) { 60 val rotateDrawable = RotateDrawable() 61 rotateDrawable.drawable = backButton.context?.getDrawable(R.drawable.ic_sysbar_back) 62 rotateDrawable.fromDegrees = 0f 63 rotateDrawable.toDegrees = if (Utilities.isRtl(backButton.resources)) 90f else -90f 64 backButton.setImageDrawable(rotateDrawable) 65 } 66 } 67 getParamsToCenterViewnull68 fun getParamsToCenterView(): FrameLayout.LayoutParams { 69 val params = 70 FrameLayout.LayoutParams( 71 ViewGroup.LayoutParams.MATCH_PARENT, 72 ViewGroup.LayoutParams.MATCH_PARENT 73 ) 74 params.gravity = Gravity.CENTER 75 return params 76 } 77 adjustForSetupInPhoneModenull78 fun adjustForSetupInPhoneMode( 79 navButtonsLayoutParams: FrameLayout.LayoutParams, 80 navButtonsViewLayoutParams: FrameLayout.LayoutParams, 81 deviceProfile: DeviceProfile 82 ) { 83 val phoneOrPortraitSetupMargin = 84 resources.getDimensionPixelSize(R.dimen.taskbar_contextual_button_suw_margin) 85 navButtonsLayoutParams.marginStart = phoneOrPortraitSetupMargin 86 navButtonsLayoutParams.bottomMargin = 87 if (!deviceProfile.isLandscape) 0 88 else 89 phoneOrPortraitSetupMargin - 90 resources.getDimensionPixelSize(R.dimen.taskbar_nav_buttons_size) / 2 91 navButtonsViewLayoutParams.height = 92 resources.getDimensionPixelSize(R.dimen.taskbar_contextual_button_suw_height) 93 } 94 repositionContextualContainernull95 open fun repositionContextualContainer( 96 contextualContainer: ViewGroup, 97 buttonSize: Int, 98 barAxisMarginStart: Int, 99 barAxisMarginEnd: Int, 100 gravity: Int 101 ) { 102 val contextualContainerParams = 103 FrameLayout.LayoutParams(buttonSize, ViewGroup.LayoutParams.MATCH_PARENT) 104 contextualContainerParams.apply { 105 marginStart = barAxisMarginStart 106 marginEnd = barAxisMarginEnd 107 topMargin = 0 108 bottomMargin = 0 109 } 110 contextualContainerParams.gravity = gravity or Gravity.CENTER_VERTICAL 111 contextualContainer.layoutParams = contextualContainerParams 112 } 113 } 114