Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 19 | import android.graphics.Rect; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 20 | import android.graphics.Region; |
Vladislav Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 21 | import android.hardware.input.InputManager; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 22 | import android.view.MotionEvent; |
| 23 | import android.view.WindowManagerPolicy.PointerEventListener; |
| 24 | |
| 25 | import com.android.server.wm.WindowManagerService.H; |
| 26 | |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 27 | import static android.view.PointerIcon.TYPE_NOT_SPECIFIED; |
| 28 | import static android.view.PointerIcon.TYPE_HORIZONTAL_DOUBLE_ARROW; |
| 29 | import static android.view.PointerIcon.TYPE_VERTICAL_DOUBLE_ARROW; |
| 30 | import static android.view.PointerIcon.TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW; |
| 31 | import static android.view.PointerIcon.TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW; |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 32 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 33 | public class TaskTapPointerEventListener implements PointerEventListener { |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 34 | |
tingna_sung | 33d8e73 | 2014-10-25 21:32:40 +0800 | [diff] [blame] | 35 | final private Region mTouchExcludeRegion = new Region(); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 36 | private final WindowManagerService mService; |
| 37 | private final DisplayContent mDisplayContent; |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 38 | private final Rect mTmpRect = new Rect(); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 39 | private int mPointerIconType = TYPE_NOT_SPECIFIED; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 40 | |
Wale Ogunwale | e4a0c57 | 2015-06-30 08:40:31 -0700 | [diff] [blame] | 41 | public TaskTapPointerEventListener(WindowManagerService service, |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 42 | DisplayContent displayContent) { |
| 43 | mService = service; |
| 44 | mDisplayContent = displayContent; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void onPointerEvent(MotionEvent motionEvent) { |
| 49 | final int action = motionEvent.getAction(); |
| 50 | switch (action & MotionEvent.ACTION_MASK) { |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 51 | case MotionEvent.ACTION_DOWN: { |
Chong Zhang | 9817dd0 | 2016-01-08 13:39:29 -0800 | [diff] [blame] | 52 | final int x = (int) motionEvent.getX(); |
| 53 | final int y = (int) motionEvent.getY(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 54 | |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 55 | synchronized (this) { |
| 56 | if (!mTouchExcludeRegion.contains(x, y)) { |
Chong Zhang | 9817dd0 | 2016-01-08 13:39:29 -0800 | [diff] [blame] | 57 | mService.mH.obtainMessage(H.TAP_OUTSIDE_TASK, |
| 58 | x, y, mDisplayContent).sendToTarget(); |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 59 | } |
| 60 | } |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 61 | } |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 62 | break; |
Chong Zhang | 8e89b31 | 2015-09-09 15:09:30 -0700 | [diff] [blame] | 63 | |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 64 | case MotionEvent.ACTION_HOVER_MOVE: { |
| 65 | final int x = (int) motionEvent.getX(); |
| 66 | final int y = (int) motionEvent.getY(); |
Wale Ogunwale | 15ead90 | 2016-09-02 14:30:11 -0700 | [diff] [blame^] | 67 | final Task task = mDisplayContent.findTaskForResizePoint(x, y); |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 68 | int iconType = TYPE_NOT_SPECIFIED; |
Vladislav Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 69 | if (task != null) { |
| 70 | task.getDimBounds(mTmpRect); |
| 71 | if (!mTmpRect.isEmpty() && !mTmpRect.contains(x, y)) { |
| 72 | if (x < mTmpRect.left) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 73 | 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 Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 77 | } else if (x > mTmpRect.right) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 78 | 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 Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 82 | } else if (y < mTmpRect.top || y > mTmpRect.bottom) { |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 83 | iconType = TYPE_VERTICAL_DOUBLE_ARROW; |
Vladislav Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 84 | } |
| 85 | } |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 86 | } |
Michael Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 87 | if (mPointerIconType != iconType) { |
| 88 | mPointerIconType = iconType; |
| 89 | if (mPointerIconType == TYPE_NOT_SPECIFIED) { |
Vladislav Kaznacheev | 6f0b045 | 2016-04-29 17:34:49 -0700 | [diff] [blame] | 90 | // 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 Wright | e051f6f | 2016-05-13 17:44:16 +0100 | [diff] [blame] | 94 | InputManager.getInstance().setPointerIconType(mPointerIconType); |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 95 | } |
Jun Mukai | 41aab00 | 2015-10-01 23:18:47 -0700 | [diff] [blame] | 96 | } |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 97 | } |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 98 | break; |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 99 | } |
| 100 | } |
tingna_sung | 33d8e73 | 2014-10-25 21:32:40 +0800 | [diff] [blame] | 101 | |
Chong Zhang | 2e2c81a | 2016-07-15 11:28:17 -0700 | [diff] [blame] | 102 | void setTouchExcludeRegion(Region newRegion) { |
tingna_sung | 33d8e73 | 2014-10-25 21:32:40 +0800 | [diff] [blame] | 103 | synchronized (this) { |
| 104 | mTouchExcludeRegion.set(newRegion); |
| 105 | } |
| 106 | } |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 107 | } |