Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #define LOG_TAG "input" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <android/input.h> |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 21 | #include <input/Input.h> |
| 22 | #include <input/InputTransport.h> |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 23 | #include <utils/Looper.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Vector.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 26 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 27 | #include <android_runtime/android_app_NativeActivity.h> |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 28 | #include <android_runtime/android_view_InputQueue.h> |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 29 | #include <android_view_MotionEvent.h> |
| 30 | #include <android_view_KeyEvent.h> |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 31 | |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 32 | #include <poll.h> |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 33 | #include <errno.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 34 | |
| 35 | using android::InputEvent; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 36 | using android::InputQueue; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 37 | using android::KeyEvent; |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 38 | using android::Looper; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 39 | using android::MotionEvent; |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 40 | using android::sp; |
| 41 | using android::Vector; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 42 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 43 | int32_t AInputEvent_getType(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 44 | return static_cast<const InputEvent*>(event)->getType(); |
| 45 | } |
| 46 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 47 | int32_t AInputEvent_getDeviceId(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 48 | return static_cast<const InputEvent*>(event)->getDeviceId(); |
| 49 | } |
| 50 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 51 | int32_t AInputEvent_getSource(const AInputEvent* event) { |
| 52 | return static_cast<const InputEvent*>(event)->getSource(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 55 | void AInputEvent_release(const AInputEvent* event) { |
| 56 | delete event; |
| 57 | } |
| 58 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 59 | int32_t AKeyEvent_getAction(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 60 | return static_cast<const KeyEvent*>(key_event)->getAction(); |
| 61 | } |
| 62 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 63 | int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 64 | return static_cast<const KeyEvent*>(key_event)->getFlags(); |
| 65 | } |
| 66 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 67 | int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 68 | return static_cast<const KeyEvent*>(key_event)->getKeyCode(); |
| 69 | } |
| 70 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 71 | int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 72 | return static_cast<const KeyEvent*>(key_event)->getScanCode(); |
| 73 | } |
| 74 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 75 | int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 76 | return static_cast<const KeyEvent*>(key_event)->getMetaState(); |
| 77 | } |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 78 | int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 79 | return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); |
| 80 | } |
| 81 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 82 | int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 83 | return static_cast<const KeyEvent*>(key_event)->getDownTime(); |
| 84 | } |
| 85 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 86 | const AInputEvent* AKeyEvent_fromJava(JNIEnv* env, jobject keyEvent) { |
| 87 | std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); |
| 88 | android::status_t ret = android::android_view_KeyEvent_toNative(env, keyEvent, event.get()); |
| 89 | if (ret == android::OK) { |
| 90 | return event.release(); |
| 91 | } |
| 92 | return nullptr; |
| 93 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 94 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 95 | int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 96 | return static_cast<const KeyEvent*>(key_event)->getEventTime(); |
| 97 | } |
| 98 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 99 | int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 100 | return static_cast<const MotionEvent*>(motion_event)->getAction(); |
| 101 | } |
| 102 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 103 | int32_t AMotionEvent_getFlags(const AInputEvent* motion_event) { |
| 104 | return static_cast<const MotionEvent*>(motion_event)->getFlags(); |
| 105 | } |
| 106 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 107 | int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 108 | return static_cast<const MotionEvent*>(motion_event)->getMetaState(); |
| 109 | } |
| 110 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 111 | int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event) { |
| 112 | return static_cast<const MotionEvent*>(motion_event)->getButtonState(); |
| 113 | } |
| 114 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 115 | int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 116 | return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); |
| 117 | } |
| 118 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 119 | int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 120 | return static_cast<const MotionEvent*>(motion_event)->getDownTime(); |
| 121 | } |
| 122 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 123 | int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 124 | return static_cast<const MotionEvent*>(motion_event)->getEventTime(); |
| 125 | } |
| 126 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 127 | float AMotionEvent_getXOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 128 | return static_cast<const MotionEvent*>(motion_event)->getXOffset(); |
| 129 | } |
| 130 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 131 | float AMotionEvent_getYOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 132 | return static_cast<const MotionEvent*>(motion_event)->getYOffset(); |
| 133 | } |
| 134 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 135 | float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 136 | return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); |
| 137 | } |
| 138 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 139 | float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 140 | return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); |
| 141 | } |
| 142 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 143 | size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 144 | return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); |
| 145 | } |
| 146 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 147 | int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 148 | return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); |
| 149 | } |
| 150 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 151 | int32_t AMotionEvent_getToolType(const AInputEvent* motion_event, size_t pointer_index) { |
| 152 | return static_cast<const MotionEvent*>(motion_event)->getToolType(pointer_index); |
| 153 | } |
| 154 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 155 | float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 156 | return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); |
| 157 | } |
| 158 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 159 | float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 160 | return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); |
| 161 | } |
| 162 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 163 | float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 164 | return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); |
| 165 | } |
| 166 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 167 | float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 168 | return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); |
| 169 | } |
| 170 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 171 | float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 172 | return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); |
| 173 | } |
| 174 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 175 | float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 176 | return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); |
| 177 | } |
| 178 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 179 | float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 180 | return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); |
| 181 | } |
| 182 | |
| 183 | float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 184 | return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); |
| 185 | } |
| 186 | |
| 187 | float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 188 | return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); |
| 189 | } |
| 190 | |
| 191 | float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 192 | return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); |
| 193 | } |
| 194 | |
| 195 | float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { |
| 196 | return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); |
| 197 | } |
| 198 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 199 | float AMotionEvent_getAxisValue(const AInputEvent* motion_event, |
| 200 | int32_t axis, size_t pointer_index) { |
| 201 | return static_cast<const MotionEvent*>(motion_event)->getAxisValue(axis, pointer_index); |
| 202 | } |
| 203 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 204 | size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 205 | return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); |
| 206 | } |
| 207 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 208 | int64_t AMotionEvent_getHistoricalEventTime(const AInputEvent* motion_event, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 209 | size_t history_index) { |
| 210 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( |
| 211 | history_index); |
| 212 | } |
| 213 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 214 | float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 215 | size_t history_index) { |
| 216 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( |
| 217 | pointer_index, history_index); |
| 218 | } |
| 219 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 220 | float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 221 | size_t history_index) { |
| 222 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( |
| 223 | pointer_index, history_index); |
| 224 | } |
| 225 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 226 | float AMotionEvent_getHistoricalX(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 227 | size_t history_index) { |
| 228 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( |
| 229 | pointer_index, history_index); |
| 230 | } |
| 231 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 232 | float AMotionEvent_getHistoricalY(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 233 | size_t history_index) { |
| 234 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( |
| 235 | pointer_index, history_index); |
| 236 | } |
| 237 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 238 | float AMotionEvent_getHistoricalPressure(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 239 | size_t history_index) { |
| 240 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( |
| 241 | pointer_index, history_index); |
| 242 | } |
| 243 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 244 | float AMotionEvent_getHistoricalSize(const AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 245 | size_t history_index) { |
| 246 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( |
| 247 | pointer_index, history_index); |
| 248 | } |
| 249 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 250 | float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 251 | size_t history_index) { |
| 252 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( |
| 253 | pointer_index, history_index); |
| 254 | } |
| 255 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 256 | float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 257 | size_t history_index) { |
| 258 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( |
| 259 | pointer_index, history_index); |
| 260 | } |
| 261 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 262 | float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 263 | size_t history_index) { |
| 264 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( |
| 265 | pointer_index, history_index); |
| 266 | } |
| 267 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 268 | float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 269 | size_t history_index) { |
| 270 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( |
| 271 | pointer_index, history_index); |
| 272 | } |
| 273 | |
Andrew Hsieh | c01e1ed | 2013-05-27 12:27:10 +0800 | [diff] [blame] | 274 | float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 275 | size_t history_index) { |
| 276 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( |
| 277 | pointer_index, history_index); |
| 278 | } |
| 279 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 280 | float AMotionEvent_getHistoricalAxisValue(const AInputEvent* motion_event, |
| 281 | int32_t axis, size_t pointer_index, size_t history_index) { |
| 282 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalAxisValue( |
| 283 | axis, pointer_index, history_index); |
| 284 | } |
| 285 | |
Chris Ye | 3da1d20 | 2020-04-07 19:39:38 -0700 | [diff] [blame] | 286 | const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) { |
| 287 | MotionEvent* eventSrc = android::android_view_MotionEvent_getNativePtr(env, motionEvent); |
| 288 | if (eventSrc == nullptr) { |
| 289 | return nullptr; |
| 290 | } |
| 291 | MotionEvent* event = new MotionEvent(); |
| 292 | event->copyFrom(eventSrc, true); |
| 293 | return event; |
| 294 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 295 | |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 296 | void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, |
Jeff Brown | 4fe6c3e | 2010-09-13 23:17:30 -0700 | [diff] [blame] | 297 | int ident, ALooper_callbackFunc callback, void* data) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 298 | InputQueue* iq = static_cast<InputQueue*>(queue); |
Brian Carlstrom | 82b007d | 2013-12-12 23:12:55 -0800 | [diff] [blame] | 299 | Looper* l = reinterpret_cast<Looper*>(looper); |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 300 | iq->attachLooper(l, ident, callback, data); |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void AInputQueue_detachLooper(AInputQueue* queue) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 304 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 305 | iq->detachLooper(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 308 | int32_t AInputQueue_hasEvents(AInputQueue* queue) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 309 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 310 | return iq->hasEvents(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 313 | int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 314 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 315 | InputEvent* event; |
| 316 | int32_t res = iq->getEvent(&event); |
| 317 | *outEvent = event; |
| 318 | return res; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 321 | int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 322 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 323 | InputEvent* e = static_cast<InputEvent*>(event); |
| 324 | return iq->preDispatchEvent(e) ? 1 : 0; |
Dianne Hackborn | 2c6081c | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 327 | void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 328 | InputQueue* iq = static_cast<InputQueue*>(queue); |
| 329 | InputEvent* e = static_cast<InputEvent*>(event); |
| 330 | iq->finishEvent(e, handled != 0); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 331 | } |