blob: dd9ba7355d7ca6757cdea35085b7a50eedde84d2 [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
Michael Wrighte051f6f2016-05-13 17:44:16 +010027import static android.view.PointerIcon.TYPE_NOT_SPECIFIED;
28import static android.view.PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW;
29import static android.view.PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW;
30import static android.view.PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
31import static android.view.PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
Jun Mukai41aab002015-10-01 23:18:47 -070032
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070033public class TaskTapPointerEventListener implements PointerEventListener {
Craig Mautner037aa8d2013-06-07 10:35:44 -070034
tingna_sung33d8e732014-10-25 21:32:40 +080035 final private Region mTouchExcludeRegion = new Region();
Craig Mautner037aa8d2013-06-07 10:35:44 -070036 private final WindowManagerService mService;
37 private final DisplayContent mDisplayContent;
Jun Mukai41aab002015-10-01 23:18:47 -070038 private final Rect mTmpRect = new Rect();
Michael Wrighte051f6f2016-05-13 17:44:16 +010039 private int mPointerIconType = TYPE_NOT_SPECIFIED;
Craig Mautner037aa8d2013-06-07 10:35:44 -070040
Wale Ogunwalee4a0c572015-06-30 08:40:31 -070041 public TaskTapPointerEventListener(WindowManagerService service,
Craig Mautner037aa8d2013-06-07 10:35:44 -070042 DisplayContent displayContent) {
43 mService = service;
44 mDisplayContent = displayContent;
Craig Mautner037aa8d2013-06-07 10:35:44 -070045 }
46
47 @Override
48 public void onPointerEvent(MotionEvent motionEvent) {
49 final int action = motionEvent.getAction();
50 switch (action & MotionEvent.ACTION_MASK) {
Chong Zhang8e89b312015-09-09 15:09:30 -070051 case MotionEvent.ACTION_DOWN: {
Chong Zhang9817dd02016-01-08 13:39:29 -080052 final int x = (int) motionEvent.getX();
53 final int y = (int) motionEvent.getY();
Chong Zhang8e89b312015-09-09 15:09:30 -070054
Chong Zhang8e89b312015-09-09 15:09:30 -070055 synchronized (this) {
56 if (!mTouchExcludeRegion.contains(x, y)) {
Chong Zhang9817dd02016-01-08 13:39:29 -080057 mService.mH.obtainMessage(H.TAP_OUTSIDE_TASK,
58 x, y, mDisplayContent).sendToTarget();
Chong Zhang8e89b312015-09-09 15:09:30 -070059 }
60 }
Chong Zhang8e89b312015-09-09 15:09:30 -070061 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -070062 break;
Chong Zhang8e89b312015-09-09 15:09:30 -070063
Jun Mukai41aab002015-10-01 23:18:47 -070064 case MotionEvent.ACTION_HOVER_MOVE: {
65 final int x = (int) motionEvent.getX();
66 final int y = (int) motionEvent.getY();
Wale Ogunwale15ead902016-09-02 14:30:11 -070067 final Task task = mDisplayContent.findTaskForResizePoint(x, y);
Michael Wrighte051f6f2016-05-13 17:44:16 +010068 int iconType = TYPE_NOT_SPECIFIED;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070069 if (task != null) {
70 task.getDimBounds(mTmpRect);
71 if (!mTmpRect.isEmpty() && !mTmpRect.contains(x, y)) {
72 if (x < mTmpRect.left) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010073 iconType =
74 (y < mTmpRect.top) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW :
75 (y > mTmpRect.bottom) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW :
76 TYPE_HORIZONTAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070077 } else if (x > mTmpRect.right) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010078 iconType =
79 (y < mTmpRect.top) ? TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW :
80 (y > mTmpRect.bottom) ? TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW :
81 TYPE_HORIZONTAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070082 } else if (y < mTmpRect.top || y > mTmpRect.bottom) {
Michael Wrighte051f6f2016-05-13 17:44:16 +010083 iconType = TYPE_VERTICAL_DOUBLE_ARROW;
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070084 }
85 }
Jun Mukai41aab002015-10-01 23:18:47 -070086 }
Michael Wrighte051f6f2016-05-13 17:44:16 +010087 if (mPointerIconType != iconType) {
88 mPointerIconType = iconType;
89 if (mPointerIconType == TYPE_NOT_SPECIFIED) {
Vladislav Kaznacheev6f0b0452016-04-29 17:34:49 -070090 // Find the underlying window and ask it restore the pointer icon.
91 mService.mH.obtainMessage(H.RESTORE_POINTER_ICON,
92 x, y, mDisplayContent).sendToTarget();
93 } else {
Michael Wrighte051f6f2016-05-13 17:44:16 +010094 InputManager.getInstance().setPointerIconType(mPointerIconType);
Jun Mukai41aab002015-10-01 23:18:47 -070095 }
Jun Mukai41aab002015-10-01 23:18:47 -070096 }
Craig Mautner037aa8d2013-06-07 10:35:44 -070097 }
Chong Zhang2e2c81a2016-07-15 11:28:17 -070098 break;
Craig Mautner037aa8d2013-06-07 10:35:44 -070099 }
100 }
tingna_sung33d8e732014-10-25 21:32:40 +0800101
Chong Zhang2e2c81a2016-07-15 11:28:17 -0700102 void setTouchExcludeRegion(Region newRegion) {
tingna_sung33d8e732014-10-25 21:32:40 +0800103 synchronized (this) {
104 mTouchExcludeRegion.set(newRegion);
105 }
106 }
Craig Mautner037aa8d2013-06-07 10:35:44 -0700107}