RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 android.accessibilityservice; |
| 18 | |
| 19 | |
Ameer Armaly | 51106a3 | 2019-09-17 14:40:36 -0700 | [diff] [blame] | 20 | import static android.accessibilityservice.AccessibilityService.GESTURE_DOUBLE_TAP; |
| 21 | import static android.accessibilityservice.AccessibilityService.GESTURE_DOUBLE_TAP_AND_HOLD; |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 22 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_DOWN; |
| 23 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_DOWN_AND_LEFT; |
| 24 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_DOWN_AND_RIGHT; |
| 25 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_DOWN_AND_UP; |
| 26 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_LEFT; |
| 27 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_LEFT_AND_DOWN; |
| 28 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_LEFT_AND_RIGHT; |
| 29 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_LEFT_AND_UP; |
| 30 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_RIGHT; |
| 31 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_RIGHT_AND_DOWN; |
| 32 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_RIGHT_AND_LEFT; |
| 33 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_RIGHT_AND_UP; |
| 34 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_UP; |
| 35 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_UP_AND_DOWN; |
| 36 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_UP_AND_LEFT; |
| 37 | import static android.accessibilityservice.AccessibilityService.GESTURE_SWIPE_UP_AND_RIGHT; |
| 38 | |
| 39 | import android.annotation.IntDef; |
| 40 | import android.annotation.NonNull; |
| 41 | import android.annotation.TestApi; |
| 42 | import android.os.Parcel; |
| 43 | import android.os.Parcelable; |
| 44 | |
| 45 | import java.lang.annotation.Retention; |
| 46 | import java.lang.annotation.RetentionPolicy; |
| 47 | |
| 48 | /** |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 49 | * This class describes the gesture event including gesture id and which display it happens |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 50 | * on. |
| 51 | * <p> |
| 52 | * <strong>Note:</strong> Accessibility services setting the |
| 53 | * {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE} |
| 54 | * flag can receive gestures. |
| 55 | * |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 56 | * @see AccessibilityService#onGesture(AccessibilityGestureEvent) |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 57 | */ |
| 58 | |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 59 | public final class AccessibilityGestureEvent implements Parcelable { |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 60 | |
| 61 | /** @hide */ |
| 62 | @IntDef(prefix = { "GESTURE_" }, value = { |
Ameer Armaly | 51106a3 | 2019-09-17 14:40:36 -0700 | [diff] [blame] | 63 | GESTURE_DOUBLE_TAP, |
| 64 | GESTURE_DOUBLE_TAP_AND_HOLD, |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 65 | GESTURE_SWIPE_UP, |
| 66 | GESTURE_SWIPE_UP_AND_LEFT, |
| 67 | GESTURE_SWIPE_UP_AND_DOWN, |
| 68 | GESTURE_SWIPE_UP_AND_RIGHT, |
| 69 | GESTURE_SWIPE_DOWN, |
| 70 | GESTURE_SWIPE_DOWN_AND_LEFT, |
| 71 | GESTURE_SWIPE_DOWN_AND_UP, |
| 72 | GESTURE_SWIPE_DOWN_AND_RIGHT, |
| 73 | GESTURE_SWIPE_LEFT, |
| 74 | GESTURE_SWIPE_LEFT_AND_UP, |
| 75 | GESTURE_SWIPE_LEFT_AND_RIGHT, |
| 76 | GESTURE_SWIPE_LEFT_AND_DOWN, |
| 77 | GESTURE_SWIPE_RIGHT, |
| 78 | GESTURE_SWIPE_RIGHT_AND_UP, |
| 79 | GESTURE_SWIPE_RIGHT_AND_LEFT, |
| 80 | GESTURE_SWIPE_RIGHT_AND_DOWN |
| 81 | }) |
| 82 | @Retention(RetentionPolicy.SOURCE) |
ryanlwlin | dafef88 | 2019-11-11 20:21:31 +0800 | [diff] [blame] | 83 | public @interface GestureId {} |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 84 | |
ryanlwlin | dafef88 | 2019-11-11 20:21:31 +0800 | [diff] [blame] | 85 | @GestureId |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 86 | private final int mGestureId; |
| 87 | private final int mDisplayId; |
| 88 | |
| 89 | /** @hide */ |
| 90 | @TestApi |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 91 | public AccessibilityGestureEvent(int gestureId, int displayId) { |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 92 | mGestureId = gestureId; |
| 93 | mDisplayId = displayId; |
| 94 | } |
| 95 | |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 96 | private AccessibilityGestureEvent(@NonNull Parcel parcel) { |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 97 | mGestureId = parcel.readInt(); |
| 98 | mDisplayId = parcel.readInt(); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Returns the display id of the received-gesture display, for use with |
| 103 | * {@link android.hardware.display.DisplayManager#getDisplay(int)}. |
| 104 | * |
| 105 | * @return the display id. |
| 106 | */ |
| 107 | public int getDisplayId() { |
| 108 | return mDisplayId; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Returns performed gesture id. |
| 113 | * |
| 114 | * @return the performed gesture id. |
| 115 | * |
| 116 | */ |
ryanlwlin | dafef88 | 2019-11-11 20:21:31 +0800 | [diff] [blame] | 117 | @GestureId public int getGestureId() { |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 118 | return mGestureId; |
| 119 | } |
| 120 | |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 121 | @NonNull |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 122 | @Override |
| 123 | public String toString() { |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 124 | StringBuilder stringBuilder = new StringBuilder("AccessibilityGestureEvent["); |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 125 | stringBuilder.append("gestureId: ").append(mGestureId); |
| 126 | stringBuilder.append(", "); |
| 127 | stringBuilder.append("displayId: ").append(mDisplayId); |
| 128 | stringBuilder.append(']'); |
| 129 | return stringBuilder.toString(); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * {@inheritDoc} |
| 134 | */ |
| 135 | @Override |
| 136 | public int describeContents() { |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 141 | public void writeToParcel(@NonNull Parcel parcel, int flags) { |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 142 | parcel.writeInt(mGestureId); |
| 143 | parcel.writeInt(mDisplayId); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * @see Parcelable.Creator |
| 148 | */ |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 149 | public static final @NonNull Parcelable.Creator<AccessibilityGestureEvent> CREATOR = |
| 150 | new Parcelable.Creator<AccessibilityGestureEvent>() { |
| 151 | public AccessibilityGestureEvent createFromParcel(Parcel parcel) { |
| 152 | return new AccessibilityGestureEvent(parcel); |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 153 | } |
| 154 | |
RyanlwLin | 0d17f04 | 2019-09-02 21:22:09 +0800 | [diff] [blame] | 155 | public AccessibilityGestureEvent[] newArray(int size) { |
| 156 | return new AccessibilityGestureEvent[size]; |
RyanlwLin | a0daddd | 2019-06-19 11:39:01 +0800 | [diff] [blame] | 157 | } |
| 158 | }; |
| 159 | |
| 160 | } |