blob: 42a2d9df5fb5dbc4919be789fe3cca11ee424468 [file] [log] [blame]
Craig Mautner037aa8d2013-06-07 10:35:44 -07001/*
2 * Copyright (C) 2013 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
17package com.android.server.wm;
18
Jun Mukai41aab002015-10-01 23:18:47 -070019import android.graphics.Rect;
Craig Mautner037aa8d2013-06-07 10:35:44 -070020import android.graphics.Region;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070021import android.hardware.input.InputManager;
Craig Mautner037aa8d2013-06-07 10:35:44 -070022import android.view.MotionEvent;
23import android.view.WindowManagerPolicy.PointerEventListener;
24
25import com.android.server.wm.WindowManagerService.H;
26
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070027import static android.view.Display.DEFAULT_DISPLAY;
Michael Wrighte051f6f2016-05-13 17:44:16 +010028import static android.view.PointerIcon.TYPE_NOT_SPECIFIED;
29import static android.view.PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
30import static android.view.PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
31import static android.view.PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
32import static android.view.PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
Jun Mukai41aab002015-10-01 23:18:47 -070033
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070034public class TaskTapPointerEventListener implements PointerEventListener {
Craig Mautner037aa8d2013-06-07 10:35:44 -070035
tingna_sung33d8e732014-10-25 21:32:40 +080036 final private Region mTouchExcludeRegion = new Region();
Craig Mautner037aa8d2013-06-07 10:35:44 -070037 private final WindowManagerService mService;
38 private final DisplayContent mDisplayContent;
Jun Mukai41aab002015-10-01 23:18:47 -070039 private final Rect mTmpRect = new Rect();
Michael Wrighte051f6f2016-05-13 17:44:16 +010040 private int mPointerIconType = TYPE_NOT_SPECIFIED;
Craig Mautner037aa8d2013-06-07 10:35:44 -070041
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070042 public TaskTapPointerEventListener(WindowManagerService service,
Craig Mautner037aa8d2013-06-07 10:35:44 -070043 DisplayContent displayContent) {
44 mService = service;
45 mDisplayContent = displayContent;
Craig Mautner037aa8d2013-06-07 10:35:44 -070046 }
47
48 @Override
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -070049 public void onPointerEvent(MotionEvent motionEvent, int displayId) {
50 if (displayId == getDisplayId()) {
51 onPointerEvent(motionEvent);
52 }
53 }
54
55 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -070056 public void onPointerEvent(MotionEvent motionEvent) {
57 final int action = motionEvent.getAction();
58 switch (action & MotionEvent.ACTION_MASK) {
Chong Zhang8e89b312015-09-09 15:09:30 -070059 case MotionEvent.ACTION_DOWN: {
Chong Zhang9817dd02016-01-08 13:39:29 -080060 final int x = (int) motionEvent.getX();
61 final int y = (int) motionEvent.getY();
Chong Zhang8e89b312015-09-09 15:09:30 -070062
Chong Zhang8e89b312015-09-09 15:09:30 -070063 synchronized (this) {
64 if (!mTouchExcludeRegion.contains(x, y)) {
Chong Zhang9817dd02016-01-08 13:39:29 -080065 mService.mH.obtainMessage(H.TAP_OUTSIDE_TASK,
66 x, y, mDisplayContent).sendToTarget();
Chong Zhang8e89b312015-09-09 15:09:30 -070067 }
68 }
Chong Zhang8e89b312015-09-09 15:09:30 -070069 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -070070 break;
Chong Zhang8e89b312015-09-09 15:09:30 -070071
Jun Mukai41aab002015-10-01 23:18:47 -070072 case MotionEvent.ACTION_HOVER_MOVE: {
73 final int x = (int) motionEvent.getX();
74 final int y = (int) motionEvent.getY();
Wale Ogunwale15ead902016-09-02 14:30:11 -070075 final Task task = mDisplayContent.findTaskForResizePoint(x, y);
Michael Wrighte051f6f2016-05-13 17:44:16 +010076 int iconType = TYPE_NOT_SPECIFIED;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070077 if (task != null) {
78 task.getDimBounds(mTmpRect);
79 if (!mTmpRect.isEmpty() && !mTmpRect.contains(x, y)) {
80 if (x < mTmpRect.left) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010081 iconType =
82 (y < mTmpRect.top) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW :
83 (y > mTmpRect.bottom) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW :
84 TYPE_HORIZONTAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070085 } else if (x > mTmpRect.right) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010086 iconType =
87 (y < mTmpRect.top) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW :
88 (y > mTmpRect.bottom) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW :
89 TYPE_HORIZONTAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070090 } else if (y < mTmpRect.top || y > mTmpRect.bottom) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010091 iconType = TYPE_VERTICAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070092 }
93 }
Jun Mukai41aab002015-10-01 23:18:47 -070094 }
Michael Wrighte051f6f2016-05-13 17:44:16 +010095 if (mPointerIconType != iconType) {
96 mPointerIconType = iconType;
97 if (mPointerIconType == TYPE_NOT_SPECIFIED) {
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070098 // Find the underlying window and ask it restore the pointer icon.
99 mService.mH.obtainMessage(H.RESTORE_POINTER_ICON,
100 x, y, mDisplayContent).sendToTarget();
101 } else {
Michael Wrighte051f6f2016-05-13 17:44:16 +0100102 InputManager.getInstance().setPointerIconType(mPointerIconType);
Jun Mukai41aab002015-10-01 23:18:47 -0700103 }
Jun Mukai41aab002015-10-01 23:18:47 -0700104 }
Craig Mautner037aa8d2013-06-07 10:35:44 -0700105 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700106 break;
Craig Mautner037aa8d2013-06-07 10:35:44 -0700107 }
108 }
tingna_sung33d8e732014-10-25 21:32:40 +0800109
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700110 void setTouchExcludeRegion(Region newRegion) {
tingna_sung33d8e732014-10-25 21:32:40 +0800111 synchronized (this) {
112 mTouchExcludeRegion.set(newRegion);
113 }
114 }
Tarandeep Singhe1cfcf42017-07-10 18:50:00 -0700115
116 private int getDisplayId() {
117 return mDisplayContent.getDisplayId();
118 }
Craig Mautner037aa8d2013-06-07 10:35:44 -0700119}