blob: ebaacb67d0688ec7152fbdf96c1fd5b4bab15709 [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 Goyald1580972019-04-09 11:52:49 -070023import android.view.MotionEvent;
Sunny Goyal4ffec482016-02-09 11:28:52 -080024import android.view.ViewDebug;
Sunny Goyal07b69292018-01-08 14:19:34 -080025import android.view.ViewGroup;
Winson Chung3d503fb2011-07-13 17:25:49 -070026import android.widget.FrameLayout;
27
Schneider Victor-tulias3cf264f2020-09-22 12:58:38 -070028import androidx.annotation.Nullable;
29
Samuel Fufa2ea01e42020-12-02 13:48:18 -060030import com.android.launcher3.config.FeatureFlags;
31
Schneider Victor-tulias3cf264f2020-09-22 12:58:38 -070032import java.util.function.Consumer;
33
Hyunyoung Song95786e02020-09-15 00:34:10 -070034/**
35 * View class that represents the bottom row of the home screen.
36 */
37public class Hotseat extends CellLayout implements Insettable {
Winson Chung3d503fb2011-07-13 17:25:49 -070038
Sunny Goyal4ffec482016-02-09 11:28:52 -080039 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal12069e62018-01-16 14:17:20 -080040 private boolean mHasVerticalHotseat;
Adam Cohenb66675a2020-05-15 16:16:17 -070041 private Workspace mWorkspace;
42 private boolean mSendTouchToWorkspace;
Samuel Fufa2ea01e42020-12-02 13:48:18 -060043 @Nullable
44 private Consumer<Boolean> mOnVisibilityAggregatedCallback;
Winson Chung3d503fb2011-07-13 17:25:49 -070045
46 public Hotseat(Context context) {
47 this(context, null);
48 }
49
50 public Hotseat(Context context, AttributeSet attrs) {
51 this(context, attrs, 0);
52 }
53
54 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
55 super(context, attrs, defStyle);
Winson Chung3d503fb2011-07-13 17:25:49 -070056 }
57
Samuel Fufaaed008d2019-12-19 10:57:40 -080058 /**
59 * Returns orientation specific cell X given invariant order in the hotseat
60 */
61 public int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070062 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070063 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080064
Samuel Fufaaed008d2019-12-19 10:57:40 -080065 /**
66 * Returns orientation specific cell Y given invariant order in the hotseat
67 */
68 public int getCellYFromOrder(int rank) {
Sunny Goyal876e4622018-11-02 13:50:40 -070069 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070070 }
71
Sunny Goyalab770a12018-11-14 15:17:26 -080072 public void resetLayout(boolean hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070073 removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070074 mHasVerticalHotseat = hasVerticalHotseat;
Sunny Goyalab770a12018-11-14 15:17:26 -080075 InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv;
Sunny Goyal11e96492018-03-23 17:06:00 -070076 if (hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070077 setGridSize(1, idp.numHotseatIcons);
Sunny Goyal11e96492018-03-23 17:06:00 -070078 } else {
Samuel Fufa2ea01e42020-12-02 13:48:18 -060079 setGridSize(idp.numHotseatIcons, FeatureFlags.ENABLE_DEVICE_SEARCH.get() ? 2 : 1);
Sunny Goyal11e96492018-03-23 17:06:00 -070080 }
Samuel Fufa2ea01e42020-12-02 13:48:18 -060081 showInlineQsb();
Winson Chung3d503fb2011-07-13 17:25:49 -070082 }
Adam Cohene25af792013-06-06 23:08:25 -070083
Adam Cohena5f4e482013-10-11 12:10:28 -070084 @Override
Sunny Goyal07b69292018-01-08 14:19:34 -080085 public void setInsets(Rect insets) {
86 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Sunny Goyalc4d32012020-04-03 17:10:11 -070087 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyal12069e62018-01-16 14:17:20 -080088
Sunny Goyal11e96492018-03-23 17:06:00 -070089 if (grid.isVerticalBarLayout()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080090 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -080091 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080092 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070093 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -080094 } else {
95 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070096 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -080097 }
98 } else {
99 lp.gravity = Gravity.BOTTOM;
100 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
Tony Wickhama29a0462021-03-02 12:28:25 -0800101 lp.height = grid.isTaskbarPresent
102 ? grid.taskbarSize
103 : grid.hotseatBarSizePx + insets.bottom;
Sunny Goyal07b69292018-01-08 14:19:34 -0800104 }
Tony Wickhama29a0462021-03-02 12:28:25 -0800105 if (!grid.isTaskbarPresent) {
106 // When taskbar is present, we set the padding separately to ensure a seamless visual
107 // handoff between taskbar and hotseat during drag and drop.
108 Rect padding = grid.getHotseatLayoutPadding();
109 int paddingBottom = padding.bottom;
110 if (FeatureFlags.ENABLE_DEVICE_SEARCH.get() && !grid.isVerticalBarLayout()) {
111 paddingBottom -= grid.hotseatBarBottomPaddingPx;
112 }
113 setPadding(padding.left, padding.top, padding.right, paddingBottom);
Samuel Fufa2ea01e42020-12-02 13:48:18 -0600114 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -0700115
Sunny Goyal07b69292018-01-08 14:19:34 -0800116 setLayoutParams(lp);
117 InsettableFrameLayout.dispatchInsets(this, insets);
118 }
Sunny Goyald1580972019-04-09 11:52:49 -0700119
Adam Cohenb66675a2020-05-15 16:16:17 -0700120 public void setWorkspace(Workspace w) {
121 mWorkspace = w;
122 }
123
124 @Override
125 public boolean onInterceptTouchEvent(MotionEvent ev) {
126 // We allow horizontal workspace scrolling from within the Hotseat. We do this by delegating
127 // touch intercept the Workspace, and if it intercepts, delegating touch to the Workspace
128 // for the remainder of the this input stream.
129 int yThreshold = getMeasuredHeight() - getPaddingBottom();
130 if (mWorkspace != null && ev.getY() <= yThreshold) {
131 mSendTouchToWorkspace = mWorkspace.onInterceptTouchEvent(ev);
132 return mSendTouchToWorkspace;
133 }
134 return false;
135 }
136
Sunny Goyald1580972019-04-09 11:52:49 -0700137 @Override
138 public boolean onTouchEvent(MotionEvent event) {
Adam Cohenb66675a2020-05-15 16:16:17 -0700139 // See comment in #onInterceptTouchEvent
140 if (mSendTouchToWorkspace) {
141 final int action = event.getAction();
142 switch (action & MotionEvent.ACTION_MASK) {
143 case MotionEvent.ACTION_UP:
144 case MotionEvent.ACTION_CANCEL:
145 mSendTouchToWorkspace = false;
146 }
147 return mWorkspace.onTouchEvent(event);
148 }
Samuel Fufaeacaf8a2019-09-17 11:31:11 -0700149 return event.getY() > getCellHeight();
Sunny Goyald1580972019-04-09 11:52:49 -0700150 }
Schneider Victor-tulias3cf264f2020-09-22 12:58:38 -0700151
152 @Override
153 public void onVisibilityAggregated(boolean isVisible) {
154 super.onVisibilityAggregated(isVisible);
155
156 if (mOnVisibilityAggregatedCallback != null) {
157 mOnVisibilityAggregatedCallback.accept(isVisible);
158 }
159 }
160
161 /** Sets a callback to be called onVisibilityAggregated */
162 public void setOnVisibilityAggregatedCallback(@Nullable Consumer<Boolean> callback) {
163 mOnVisibilityAggregatedCallback = callback;
164 }
Samuel Fufa2ea01e42020-12-02 13:48:18 -0600165
166 protected void showInlineQsb() {
167 //Does nothing
168 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700169}