blob: 6547b5394081ab33acd0f1b57253925b6ea89520 [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
Hyunyoung Song95786e02020-09-15 00:34:10 -070028/**
29 * View class that represents the bottom row of the home screen.
30 */
31public class Hotseat extends CellLayout implements Insettable {
Winson Chung3d503fb2011-07-13 17:25:49 -070032
Sunny Goyal4ffec482016-02-09 11:28:52 -080033 @ViewDebug.ExportedProperty(category = "launcher")
Sunny Goyal12069e62018-01-16 14:17:20 -080034 private boolean mHasVerticalHotseat;
Adam Cohenb66675a2020-05-15 16:16:17 -070035 private Workspace mWorkspace;
36 private boolean mSendTouchToWorkspace;
Winson Chung3d503fb2011-07-13 17:25:49 -070037
38 public Hotseat(Context context) {
39 this(context, null);
40 }
41
42 public Hotseat(Context context, AttributeSet attrs) {
43 this(context, attrs, 0);
44 }
45
46 public Hotseat(Context context, AttributeSet attrs, int defStyle) {
47 super(context, attrs, defStyle);
Winson Chung3d503fb2011-07-13 17:25:49 -070048 }
49
Samuel Fufaaed008d2019-12-19 10:57:40 -080050 /**
51 * Returns orientation specific cell X given invariant order in the hotseat
52 */
53 public int getCellXFromOrder(int rank) {
Sunny Goyal4f3e9382015-06-05 00:13:25 -070054 return mHasVerticalHotseat ? 0 : rank;
Winson Chung3d503fb2011-07-13 17:25:49 -070055 }
Hyunyoung Song31178b82015-02-24 14:12:51 -080056
Samuel Fufaaed008d2019-12-19 10:57:40 -080057 /**
58 * Returns orientation specific cell Y given invariant order in the hotseat
59 */
60 public int getCellYFromOrder(int rank) {
Sunny Goyal876e4622018-11-02 13:50:40 -070061 return mHasVerticalHotseat ? (getCountY() - (rank + 1)) : 0;
Winson Chung3d503fb2011-07-13 17:25:49 -070062 }
63
Sunny Goyalab770a12018-11-14 15:17:26 -080064 public void resetLayout(boolean hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070065 removeAllViewsInLayout();
Sunny Goyal11e96492018-03-23 17:06:00 -070066 mHasVerticalHotseat = hasVerticalHotseat;
Sunny Goyalab770a12018-11-14 15:17:26 -080067 InvariantDeviceProfile idp = mActivity.getDeviceProfile().inv;
Sunny Goyal11e96492018-03-23 17:06:00 -070068 if (hasVerticalHotseat) {
Sunny Goyal876e4622018-11-02 13:50:40 -070069 setGridSize(1, idp.numHotseatIcons);
Sunny Goyal11e96492018-03-23 17:06:00 -070070 } else {
Sunny Goyal876e4622018-11-02 13:50:40 -070071 setGridSize(idp.numHotseatIcons, 1);
Sunny Goyal11e96492018-03-23 17:06:00 -070072 }
Winson Chung3d503fb2011-07-13 17:25:49 -070073 }
Adam Cohene25af792013-06-06 23:08:25 -070074
Adam Cohena5f4e482013-10-11 12:10:28 -070075 @Override
Sunny Goyal07b69292018-01-08 14:19:34 -080076 public void setInsets(Rect insets) {
77 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) getLayoutParams();
Sunny Goyalc4d32012020-04-03 17:10:11 -070078 DeviceProfile grid = mActivity.getDeviceProfile();
Sunny Goyal12069e62018-01-16 14:17:20 -080079
Sunny Goyal11e96492018-03-23 17:06:00 -070080 if (grid.isVerticalBarLayout()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080081 lp.height = ViewGroup.LayoutParams.MATCH_PARENT;
Sunny Goyal7e2e67f2018-01-26 13:40:08 -080082 if (grid.isSeascape()) {
Sunny Goyal07b69292018-01-08 14:19:34 -080083 lp.gravity = Gravity.LEFT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070084 lp.width = grid.hotseatBarSizePx + insets.left;
Sunny Goyal07b69292018-01-08 14:19:34 -080085 } else {
86 lp.gravity = Gravity.RIGHT;
Tony Wickham1eeffbe2018-06-12 15:01:15 -070087 lp.width = grid.hotseatBarSizePx + insets.right;
Sunny Goyal07b69292018-01-08 14:19:34 -080088 }
89 } else {
90 lp.gravity = Gravity.BOTTOM;
91 lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
92 lp.height = grid.hotseatBarSizePx + insets.bottom;
Sunny Goyal07b69292018-01-08 14:19:34 -080093 }
Sunny Goyal81b4c7b2018-03-26 12:10:31 -070094 Rect padding = grid.getHotseatLayoutPadding();
Sunny Goyal876e4622018-11-02 13:50:40 -070095 setPadding(padding.left, padding.top, padding.right, padding.bottom);
Sunny Goyal81b4c7b2018-03-26 12:10:31 -070096
Sunny Goyal07b69292018-01-08 14:19:34 -080097 setLayoutParams(lp);
98 InsettableFrameLayout.dispatchInsets(this, insets);
99 }
Sunny Goyald1580972019-04-09 11:52:49 -0700100
Adam Cohenb66675a2020-05-15 16:16:17 -0700101 public void setWorkspace(Workspace w) {
102 mWorkspace = w;
103 }
104
105 @Override
106 public boolean onInterceptTouchEvent(MotionEvent ev) {
107 // We allow horizontal workspace scrolling from within the Hotseat. We do this by delegating
108 // touch intercept the Workspace, and if it intercepts, delegating touch to the Workspace
109 // for the remainder of the this input stream.
110 int yThreshold = getMeasuredHeight() - getPaddingBottom();
111 if (mWorkspace != null && ev.getY() <= yThreshold) {
112 mSendTouchToWorkspace = mWorkspace.onInterceptTouchEvent(ev);
113 return mSendTouchToWorkspace;
114 }
115 return false;
116 }
117
Sunny Goyald1580972019-04-09 11:52:49 -0700118 @Override
119 public boolean onTouchEvent(MotionEvent event) {
Adam Cohenb66675a2020-05-15 16:16:17 -0700120 // See comment in #onInterceptTouchEvent
121 if (mSendTouchToWorkspace) {
122 final int action = event.getAction();
123 switch (action & MotionEvent.ACTION_MASK) {
124 case MotionEvent.ACTION_UP:
125 case MotionEvent.ACTION_CANCEL:
126 mSendTouchToWorkspace = false;
127 }
128 return mWorkspace.onTouchEvent(event);
129 }
Samuel Fufaeacaf8a2019-09-17 11:31:11 -0700130 return event.getY() > getCellHeight();
Sunny Goyald1580972019-04-09 11:52:49 -0700131 }
Winson Chung3d503fb2011-07-13 17:25:49 -0700132}