Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Tony Wickham | d6b4037 | 2015-09-23 18:37:57 -0700 | [diff] [blame] | 20 | import android.graphics.Rect; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 22 | import android.view.Gravity; |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 23 | import android.view.MotionEvent; |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 24 | import android.view.ViewDebug; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 25 | import android.view.ViewGroup; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 26 | import android.widget.FrameLayout; |
| 27 | |
Schneider Victor-tulias | 3cf264f | 2020-09-22 12:58:38 -0700 | [diff] [blame] | 28 | import androidx.annotation.Nullable; |
| 29 | |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 30 | import com.android.launcher3.config.FeatureFlags; |
| 31 | |
Schneider Victor-tulias | 3cf264f | 2020-09-22 12:58:38 -0700 | [diff] [blame] | 32 | import java.util.function.Consumer; |
| 33 | |
Hyunyoung Song | 95786e0 | 2020-09-15 00:34:10 -0700 | [diff] [blame] | 34 | /** |
| 35 | * View class that represents the bottom row of the home screen. |
| 36 | */ |
| 37 | public class Hotseat extends CellLayout implements Insettable { |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 38 | |
Sunny Goyal | 4ffec48 | 2016-02-09 11:28:52 -0800 | [diff] [blame] | 39 | @ViewDebug.ExportedProperty(category = "launcher") |
Sunny Goyal | 12069e6 | 2018-01-16 14:17:20 -0800 | [diff] [blame] | 40 | private boolean mHasVerticalHotseat; |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 41 | private Workspace mWorkspace; |
| 42 | private boolean mSendTouchToWorkspace; |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 43 | @Nullable |
| 44 | private Consumer<Boolean> mOnVisibilityAggregatedCallback; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 45 | |
| 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 Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 58 | /** |
| 59 | * Returns orientation specific cell X given invariant order in the hotseat |
| 60 | */ |
| 61 | public int getCellXFromOrder(int rank) { |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 62 | return mHasVerticalHotseat ? 0 : rank; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 63 | } |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 64 | |
Samuel Fufa | aed008d | 2019-12-19 10:57:40 -0800 | [diff] [blame] | 65 | /** |
| 66 | * Returns orientation specific cell Y given invariant order in the hotseat |
| 67 | */ |
| 68 | public int getCellYFromOrder(int rank) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 69 | return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0; |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 72 | public void resetLayout(boolean hasVerticalHotseat) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 73 | removeAllViewsInLayout(); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 74 | mHasVerticalHotseat = hasVerticalHotseat; |
Sunny Goyal | ab770a1 | 2018-11-14 15:17:26 -0800 | [diff] [blame] | 75 | InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv; |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 76 | if (hasVerticalHotseat) { |
Sunny Goyal | 876e462 | 2018-11-02 13:50:40 -0700 | [diff] [blame] | 77 | setGridSize(1, idp.numHotseatIcons); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 78 | } else { |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 79 | setGridSize(idp.numHotseatIcons, FeatureFlags.ENABLE_DEVICE_SEARCH.get() ? 2 : 1); |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 80 | } |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 81 | showInlineQsb(); |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 82 | } |
Adam Cohen | e25af79 | 2013-06-06 23:08:25 -0700 | [diff] [blame] | 83 | |
Adam Cohen | a5f4e48 | 2013-10-11 12:10:28 -0700 | [diff] [blame] | 84 | @Override |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 85 | public void setInsets(Rect insets) { |
| 86 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams(); |
Sunny Goyal | c4d3201 | 2020-04-03 17:10:11 -0700 | [diff] [blame] | 87 | DeviceProfile grid = mActivity.getDeviceProfile(); |
Sunny Goyal | 12069e6 | 2018-01-16 14:17:20 -0800 | [diff] [blame] | 88 | |
Sunny Goyal | 11e9649 | 2018-03-23 17:06:00 -0700 | [diff] [blame] | 89 | if (grid.isVerticalBarLayout()) { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 90 | lp.height = ViewGroup.LayoutParams.MATCH_PARENT; |
Sunny Goyal | 7e2e67f | 2018-01-26 13:40:08 -0800 | [diff] [blame] | 91 | if (grid.isSeascape()) { |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 92 | lp.gravity = Gravity.LEFT; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 93 | lp.width = grid.hotseatBarSizePx + insets.left; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 94 | } else { |
| 95 | lp.gravity = Gravity.RIGHT; |
Tony Wickham | 1eeffbe | 2018-06-12 15:01:15 -0700 | [diff] [blame] | 96 | lp.width = grid.hotseatBarSizePx + insets.right; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 97 | } |
| 98 | } else { |
| 99 | lp.gravity = Gravity.BOTTOM; |
| 100 | lp.width = ViewGroup.LayoutParams.MATCH_PARENT; |
| 101 | lp.height = grid.hotseatBarSizePx + insets.bottom; |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 102 | } |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 103 | Rect padding = grid.getHotseatLayoutPadding(); |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 104 | int paddingBottom = padding.bottom; |
| 105 | if (FeatureFlags.ENABLE_DEVICE_SEARCH.get() && !grid.isVerticalBarLayout()) { |
| 106 | paddingBottom -= grid.hotseatBarBottomPaddingPx; |
| 107 | } |
| 108 | setPadding(padding.left, padding.top, padding.right, paddingBottom); |
Sunny Goyal | 81b4c7b | 2018-03-26 12:10:31 -0700 | [diff] [blame] | 109 | |
Sunny Goyal | 07b6929 | 2018-01-08 14:19:34 -0800 | [diff] [blame] | 110 | setLayoutParams(lp); |
| 111 | InsettableFrameLayout.dispatchInsets(this, insets); |
| 112 | } |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 113 | |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 114 | public void setWorkspace(Workspace w) { |
| 115 | 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 Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 131 | @Override |
| 132 | public boolean onTouchEvent(MotionEvent event) { |
Adam Cohen | b66675a | 2020-05-15 16:16:17 -0700 | [diff] [blame] | 133 | // 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 | } |
Samuel Fufa | eacaf8a | 2019-09-17 11:31:11 -0700 | [diff] [blame] | 143 | return event.getY() > getCellHeight(); |
Sunny Goyal | d158097 | 2019-04-09 11:52:49 -0700 | [diff] [blame] | 144 | } |
Schneider Victor-tulias | 3cf264f | 2020-09-22 12:58:38 -0700 | [diff] [blame] | 145 | |
| 146 | @Override |
| 147 | public void onVisibilityAggregated(boolean isVisible) { |
| 148 | super.onVisibilityAggregated(isVisible); |
| 149 | |
| 150 | if (mOnVisibilityAggregatedCallback != null) { |
| 151 | mOnVisibilityAggregatedCallback.accept(isVisible); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** Sets a callback to be called onVisibilityAggregated */ |
| 156 | public void setOnVisibilityAggregatedCallback(@Nullable Consumer<Boolean> callback) { |
| 157 | mOnVisibilityAggregatedCallback = callback; |
| 158 | } |
Samuel Fufa | 2ea01e4 | 2020-12-02 13:48:18 -0600 | [diff] [blame^] | 159 | |
| 160 | protected void showInlineQsb() { |
| 161 | //Does nothing |
| 162 | } |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 163 | } |