blob: 03afba11c1d8682cf1d5703bd976cfa9b490b6d2 [file] [log] [blame]
Winson Chung3d503fb2011-07-13 17:25:49 -07001/*
2 * Copyright (C) 2011 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
Daniel Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung3d503fb2011-07-13 17:25:49 -070018
19import android.content.Context;
Tony Wickhamd6b40372015-09-23 18:37:57 -070020import android.graphics.Rect;
Winson Chung3d503fb2011-07-13 17:25:49 -070021import android.util.AttributeSet;
Sunny Goyal07b69292018-01-08 14:19:34 -080022import android.view.Gravity;
Sunny Goyalc373e1c2021-03-09 17:27:53 -080023import android.view.LayoutInflater;
Sunny Goyald1580972019-04-09 11:52:49 -070024import android.view.MotionEvent;
Tony Wickham39938cb2021-02-26 09:15:31 -080025import android.view.View;
Sunny Goyal4ffec482016-02-09 11:28:52 -080026import android.view.ViewDebug;
Sunny Goyal07b69292018-01-08 14:19:34 -080027import android.view.ViewGroup;
Winson Chung3d503fb2011-07-13 17:25:49 -070028import android.widget.FrameLayout;
29
Hyunyoung Song95786e02020-09-15 00:34:10 -070030/**
31 * View class that represents the bottom row of the home screen.
32 */
33public class Hotseat extends CellLayout implements Insettable {
Winson Chung3d503fb2011-07-13 17:25:49 -070034
Sunny Goyalc373e1c2021-03-09 17:27:53 -080035 // Ratio of empty space, qsb should take up to appear visually centered.
36 public static final float QSB_CENTER_FACTOR = .325f;
37
Sunny Goyal4ffec482016-02-09 11:28:52 -080038 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal12069e62018-01-16 14:17:20 -080039 private boolean mHasVerticalHotseat;
Shikha Malhotraf78da1b2022-04-11 10:23:18 +000040 private Workspace<?> mWorkspace;
Adam Cohenb66675a2020-05-15 16:16:17 -070041 private boolean mSendTouchToWorkspace;
Winson Chung3d503fb2011-07-13 17:25:49 -070042
Sunny Goyalc373e1c2021-03-09 17:27:53 -080043 private final View mQsb;
Tony Wickhamae72b462021-03-10 16:18:40 -080044
Winson Chung3d503fb2011-07-13 17:25:49 -070045 public Hotseat(Context context) {
46 this(context, null);
47 }
48
49 public Hotseat(Context context, AttributeSet attrs) {
50 this(context, attrs, 0);
51 }
52
53 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
54 super(context, attrs, defStyle);
Sunny Goyalc373e1c2021-03-09 17:27:53 -080055
56 mQsb = LayoutInflater.from(context).inflate(R.layout.search_container_hotseat, this, false);
Sunny Goyalc373e1c2021-03-09 17:27:53 -080057 addView(mQsb);
Winson Chung3d503fb2011-07-13 17:25:49 -070058 }
59
Samuel Fufaaed008d2019-12-19 10:57:40 -080060 /**
61 * Returns orientation specific cell X given invariant order in the hotseat
62 */
63 public int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070064 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070065 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080066
Samuel Fufaaed008d2019-12-19 10:57:40 -080067 /**
68 * Returns orientation specific cell Y given invariant order in the hotseat
69 */
70 public int getCellYFromOrder(int rank) {
Sunny Goyal876e4622018-11-02 13:50:40 -070071 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070072 }
73
Sunny Goyalab770a12018-11-14 15:17:26 -080074 public void resetLayout(boolean hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070075 removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070076 mHasVerticalHotseat = hasVerticalHotseat;
Sunny Goyal19ff7282021-04-22 10:12:54 -070077 DeviceProfile dp = mActivity.getDeviceProfile();
Thales Lima8cd020b2022-03-15 20:15:14 +000078 resetCellSize(dp);
Sunny Goyal11e96492018-03-23 17:06:00 -070079 if (hasVerticalHotseat) {
Sunny Goyal19ff7282021-04-22 10:12:54 -070080 setGridSize(1, dp.numShownHotseatIcons);
Sunny Goyal11e96492018-03-23 17:06:00 -070081 } else {
Sunny Goyal19ff7282021-04-22 10:12:54 -070082 setGridSize(dp.numShownHotseatIcons, 1);
Sunny Goyal11e96492018-03-23 17:06:00 -070083 }
Winson Chung3d503fb2011-07-13 17:25:49 -070084 }
Adam Cohene25af792013-06-06 23:08:25 -070085
Adam Cohena5f4e482013-10-11 12:10:28 -070086 @Override
Sunny Goyal07b69292018-01-08 14:19:34 -080087 public void setInsets(Rect insets) {
88 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Sunny Goyalc4d32012020-04-03 17:10:11 -070089 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyal12069e62018-01-16 14:17:20 -080090
Sunny Goyal11e96492018-03-23 17:06:00 -070091 if (grid.isVerticalBarLayout()) {
Sunny Goyalc373e1c2021-03-09 17:27:53 -080092 mQsb.setVisibility(View.GONE);
Sunny Goyal07b69292018-01-08 14:19:34 -080093 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -080094 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080095 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070096 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -080097 } else {
98 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070099 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -0800100 }
101 } else {
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800102 mQsb.setVisibility(View.VISIBLE);
Sunny Goyal07b69292018-01-08 14:19:34 -0800103 lp.gravity = Gravity.BOTTOM;
104 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
Thales Limab8c05952022-05-23 16:58:38 +0100105 lp.height = grid.hotseatBarSizePx;
Sunny Goyal07b69292018-01-08 14:19:34 -0800106 }
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800107
Sunny Goyal57b22792021-05-25 14:35:01 -0700108 Rect padding = grid.getHotseatLayoutPadding(getContext());
109 setPadding(padding.left, padding.top, padding.right, padding.bottom);
Sunny Goyal07b69292018-01-08 14:19:34 -0800110 setLayoutParams(lp);
111 InsettableFrameLayout.dispatchInsets(this, insets);
112 }
Sunny Goyald1580972019-04-09 11:52:49 -0700113
Shikha Malhotraf78da1b2022-04-11 10:23:18 +0000114 public void setWorkspace(Workspace<?> w) {
Adam Cohenb66675a2020-05-15 16:16:17 -0700115 mWorkspace = w;
116 }
117
118 @Override
119 public boolean onInterceptTouchEvent(MotionEvent ev) {
120 // We allow horizontal workspace scrolling from within the Hotseat. We do this by delegating
121 // touch intercept the Workspace, and if it intercepts, delegating touch to the Workspace
122 // for the remainder of the this input stream.
123 int yThreshold = getMeasuredHeight() - getPaddingBottom();
124 if (mWorkspace != null && ev.getY() <= yThreshold) {
125 mSendTouchToWorkspace = mWorkspace.onInterceptTouchEvent(ev);
126 return mSendTouchToWorkspace;
127 }
128 return false;
129 }
130
Sunny Goyald1580972019-04-09 11:52:49 -0700131 @Override
132 public boolean onTouchEvent(MotionEvent event) {
Adam Cohenb66675a2020-05-15 16:16:17 -0700133 // See comment in #onInterceptTouchEvent
134 if (mSendTouchToWorkspace) {
135 final int action = event.getAction();
136 switch (action & MotionEvent.ACTION_MASK) {
137 case MotionEvent.ACTION_UP:
138 case MotionEvent.ACTION_CANCEL:
139 mSendTouchToWorkspace = false;
140 }
141 return mWorkspace.onTouchEvent(event);
142 }
Alex Chau21698c52021-09-24 14:36:15 +0100143 // Always let touch follow through to Workspace.
144 return false;
Sunny Goyald1580972019-04-09 11:52:49 -0700145 }
Schneider Victor-tulias3cf264f2020-09-22 12:58:38 -0700146
147 @Override
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800148 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
149 super.onMeasure(widthMeasureSpec, heightMeasureSpec);
150
Alex Chau206ede92022-08-01 17:46:12 +0100151 DeviceProfile dp = mActivity.getDeviceProfile();
152 mQsb.measure(MeasureSpec.makeMeasureSpec(dp.hotseatQsbWidth, MeasureSpec.EXACTLY),
153 MeasureSpec.makeMeasureSpec(dp.hotseatQsbHeight, MeasureSpec.EXACTLY));
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800154 }
155
156 @Override
157 protected void onLayout(boolean changed, int l, int t, int r, int b) {
158 super.onLayout(changed, l, t, r, b);
159
Alex Chau206ede92022-08-01 17:46:12 +0100160 int qsbMeasuredWidth = mQsb.getMeasuredWidth();
Thales Limaa1012902022-01-13 17:58:42 +0000161 int left;
Alex Chau206ede92022-08-01 17:46:12 +0100162 DeviceProfile dp = mActivity.getDeviceProfile();
163 if (dp.isQsbInline) {
164 int qsbSpace = dp.hotseatBorderSpace;
Thales Lima612230d2022-03-31 18:04:37 +0100165 left = Utilities.isRtl(getResources()) ? r - getPaddingRight() + qsbSpace
Alex Chau206ede92022-08-01 17:46:12 +0100166 : l + getPaddingLeft() - qsbMeasuredWidth - qsbSpace;
Thales Limaa1012902022-01-13 17:58:42 +0000167 } else {
Alex Chau206ede92022-08-01 17:46:12 +0100168 left = (r - l - qsbMeasuredWidth) / 2;
Thales Limaa1012902022-01-13 17:58:42 +0000169 }
Alex Chau206ede92022-08-01 17:46:12 +0100170 int right = left + qsbMeasuredWidth;
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800171
Alex Chau206ede92022-08-01 17:46:12 +0100172 int bottom = b - t - dp.getQsbOffsetY();
173 int top = bottom - dp.hotseatQsbHeight;
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800174 mQsb.layout(left, top, right, bottom);
175 }
176
Tony Wickham39938cb2021-02-26 09:15:31 -0800177 /**
Tony Wickham9ce3b252021-03-22 14:43:58 -0700178 * Sets the alpha value of just our ShortcutAndWidgetContainer.
179 */
180 public void setIconsAlpha(float alpha) {
181 getShortcutsAndWidgets().setAlpha(alpha);
Tony Wickhamae72b462021-03-10 16:18:40 -0800182 }
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800183
Alex Chauc1d26442022-06-09 15:09:26 +0100184 /**
185 * Sets the alpha value of just our QSB.
186 */
187 public void setQsbAlpha(float alpha) {
188 mQsb.setAlpha(alpha);
189 }
190
Tracy Zhouae881972021-09-30 10:14:34 -0700191 public float getIconsAlpha() {
192 return getShortcutsAndWidgets().getAlpha();
193 }
194
Sunny Goyalc373e1c2021-03-09 17:27:53 -0800195 /**
196 * Returns the QSB inside hotseat
197 */
198 public View getQsb() {
199 return mQsb;
200 }
Tony Wickham9ce3b252021-03-22 14:43:58 -0700201
Winson Chung3d503fb2011-07-13 17:25:49 -0700202}