Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 "MotionEvent-JNI" |
| 18 | |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 19 | #include <nativehelper/JNIHelp.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 20 | |
Derek Sollenberger | 4dc0aae | 2019-12-27 15:15:18 -0500 | [diff] [blame] | 21 | #include <android/graphics/matrix.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 22 | #include <android_runtime/AndroidRuntime.h> |
Ruben Brunk | 87eac99 | 2013-09-09 17:44:59 -0700 | [diff] [blame] | 23 | #include <android_runtime/Log.h> |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> |
Jeff Brown | 9d3b1a4 | 2013-07-01 19:07:15 -0700 | [diff] [blame] | 25 | #include <input/Input.h> |
Steven Moreland | 2279b25 | 2017-07-19 09:50:45 -0700 | [diff] [blame] | 26 | #include <nativehelper/ScopedUtfChars.h> |
Jeff Sharkey | d84e1ce | 2012-03-06 18:26:19 -0800 | [diff] [blame] | 27 | #include "android_os_Parcel.h" |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 28 | #include "android_view_MotionEvent.h" |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 29 | #include "android_util_Binder.h" |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 30 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 31 | #include "core_jni_helpers.h" |
| 32 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 33 | namespace android { |
| 34 | |
| 35 | // ---------------------------------------------------------------------------- |
| 36 | |
| 37 | static struct { |
| 38 | jclass clazz; |
| 39 | |
| 40 | jmethodID obtain; |
| 41 | jmethodID recycle; |
| 42 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 43 | jfieldID mNativePtr; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 44 | } gMotionEventClassInfo; |
| 45 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 46 | static struct { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 47 | jfieldID mPackedAxisBits; |
| 48 | jfieldID mPackedAxisValues; |
| 49 | jfieldID x; |
| 50 | jfieldID y; |
| 51 | jfieldID pressure; |
| 52 | jfieldID size; |
| 53 | jfieldID touchMajor; |
| 54 | jfieldID touchMinor; |
| 55 | jfieldID toolMajor; |
| 56 | jfieldID toolMinor; |
| 57 | jfieldID orientation; |
| 58 | } gPointerCoordsClassInfo; |
| 59 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 60 | static struct { |
| 61 | jfieldID id; |
| 62 | jfieldID toolType; |
| 63 | } gPointerPropertiesClassInfo; |
| 64 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 65 | // ---------------------------------------------------------------------------- |
| 66 | |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 67 | MotionEvent* android_view_MotionEvent_getNativePtr(JNIEnv* env, jobject eventObj) { |
| 68 | if (!eventObj) { |
| 69 | return NULL; |
| 70 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 71 | return reinterpret_cast<MotionEvent*>( |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 72 | env->GetLongField(eventObj, gMotionEventClassInfo.mNativePtr)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 73 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 74 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 75 | static void android_view_MotionEvent_setNativePtr(JNIEnv* env, jobject eventObj, |
| 76 | MotionEvent* event) { |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 77 | env->SetLongField(eventObj, gMotionEventClassInfo.mNativePtr, |
| 78 | reinterpret_cast<jlong>(event)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 81 | jobject android_view_MotionEvent_obtainAsCopy(JNIEnv* env, const MotionEvent* event) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 82 | jobject eventObj = env->CallStaticObjectMethod(gMotionEventClassInfo.clazz, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 83 | gMotionEventClassInfo.obtain); |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 84 | if (env->ExceptionCheck() || !eventObj) { |
Steve Block | 3762c31 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 85 | ALOGE("An exception occurred while obtaining a motion event."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 86 | LOGE_EX(env); |
| 87 | env->ExceptionClear(); |
| 88 | return NULL; |
| 89 | } |
| 90 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 91 | MotionEvent* destEvent = android_view_MotionEvent_getNativePtr(env, eventObj); |
| 92 | if (!destEvent) { |
| 93 | destEvent = new MotionEvent(); |
| 94 | android_view_MotionEvent_setNativePtr(env, eventObj, destEvent); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 97 | destEvent->copyFrom(event, true); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 98 | return eventObj; |
| 99 | } |
| 100 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 101 | status_t android_view_MotionEvent_recycle(JNIEnv* env, jobject eventObj) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 102 | env->CallVoidMethod(eventObj, gMotionEventClassInfo.recycle); |
| 103 | if (env->ExceptionCheck()) { |
Steve Block | 8564c8d | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 104 | ALOGW("An exception occurred while recycling a motion event."); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 105 | LOGW_EX(env); |
| 106 | env->ExceptionClear(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 107 | return UNKNOWN_ERROR; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 108 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 109 | return OK; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 112 | // ---------------------------------------------------------------------------- |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 113 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 114 | static const jint HISTORY_CURRENT = -0x80000000; |
| 115 | |
| 116 | static bool validatePointerCount(JNIEnv* env, jint pointerCount) { |
| 117 | if (pointerCount < 1) { |
| 118 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 119 | "pointerCount must be at least 1"); |
| 120 | return false; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 121 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 122 | return true; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 125 | static bool validatePointerPropertiesArray(JNIEnv* env, jobjectArray pointerPropertiesObjArray, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 126 | size_t pointerCount) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 127 | if (!pointerPropertiesObjArray) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 128 | jniThrowException(env, "java/lang/IllegalArgumentException", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 129 | "pointerProperties array must not be null"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 130 | return false; |
| 131 | } |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 132 | size_t length = size_t(env->GetArrayLength(pointerPropertiesObjArray)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 133 | if (length < pointerCount) { |
| 134 | jniThrowException(env, "java/lang/IllegalArgumentException", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 135 | "pointerProperties array must be large enough to hold all pointers"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 136 | return false; |
| 137 | } |
| 138 | return true; |
| 139 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 140 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 141 | static bool validatePointerCoordsObjArray(JNIEnv* env, jobjectArray pointerCoordsObjArray, |
| 142 | size_t pointerCount) { |
| 143 | if (!pointerCoordsObjArray) { |
| 144 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 145 | "pointerCoords array must not be null"); |
| 146 | return false; |
| 147 | } |
| 148 | size_t length = size_t(env->GetArrayLength(pointerCoordsObjArray)); |
| 149 | if (length < pointerCount) { |
| 150 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 151 | "pointerCoords array must be large enough to hold all pointers"); |
| 152 | return false; |
| 153 | } |
| 154 | return true; |
| 155 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 156 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 157 | static bool validatePointerIndex(JNIEnv* env, jint pointerIndex, size_t pointerCount) { |
| 158 | if (pointerIndex < 0 || size_t(pointerIndex) >= pointerCount) { |
| 159 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 160 | "pointerIndex out of range"); |
| 161 | return false; |
| 162 | } |
| 163 | return true; |
| 164 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 165 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 166 | static bool validateHistoryPos(JNIEnv* env, jint historyPos, size_t historySize) { |
| 167 | if (historyPos < 0 || size_t(historyPos) >= historySize) { |
| 168 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 169 | "historyPos out of range"); |
| 170 | return false; |
| 171 | } |
| 172 | return true; |
| 173 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 174 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 175 | static bool validatePointerCoords(JNIEnv* env, jobject pointerCoordsObj) { |
| 176 | if (!pointerCoordsObj) { |
| 177 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 178 | "pointerCoords must not be null"); |
| 179 | return false; |
| 180 | } |
| 181 | return true; |
| 182 | } |
| 183 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 184 | static bool validatePointerProperties(JNIEnv* env, jobject pointerPropertiesObj) { |
| 185 | if (!pointerPropertiesObj) { |
| 186 | jniThrowException(env, "java/lang/IllegalArgumentException", |
| 187 | "pointerProperties must not be null"); |
| 188 | return false; |
| 189 | } |
| 190 | return true; |
| 191 | } |
| 192 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 193 | static void pointerCoordsToNative(JNIEnv* env, jobject pointerCoordsObj, |
| 194 | float xOffset, float yOffset, PointerCoords* outRawPointerCoords) { |
| 195 | outRawPointerCoords->clear(); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 196 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_X, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 197 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.x) - xOffset); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 198 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_Y, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 199 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.y) - yOffset); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 200 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 201 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.pressure)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 202 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_SIZE, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 203 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.size)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 204 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 205 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.touchMajor)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 206 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 207 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.touchMinor)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 208 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 209 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.toolMajor)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 210 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 211 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.toolMinor)); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 212 | outRawPointerCoords->setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 213 | env->GetFloatField(pointerCoordsObj, gPointerCoordsClassInfo.orientation)); |
| 214 | |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 215 | BitSet64 bits = |
| 216 | BitSet64(env->GetLongField(pointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits)); |
| 217 | if (!bits.isEmpty()) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 218 | jfloatArray valuesArray = jfloatArray(env->GetObjectField(pointerCoordsObj, |
| 219 | gPointerCoordsClassInfo.mPackedAxisValues)); |
| 220 | if (valuesArray) { |
| 221 | jfloat* values = static_cast<jfloat*>( |
| 222 | env->GetPrimitiveArrayCritical(valuesArray, NULL)); |
| 223 | |
| 224 | uint32_t index = 0; |
| 225 | do { |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 226 | uint32_t axis = bits.clearFirstMarkedBit(); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 227 | outRawPointerCoords->setAxisValue(axis, values[index++]); |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 228 | } while (!bits.isEmpty()); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 229 | |
| 230 | env->ReleasePrimitiveArrayCritical(valuesArray, values, JNI_ABORT); |
| 231 | env->DeleteLocalRef(valuesArray); |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static jfloatArray obtainPackedAxisValuesArray(JNIEnv* env, uint32_t minSize, |
| 237 | jobject outPointerCoordsObj) { |
| 238 | jfloatArray outValuesArray = jfloatArray(env->GetObjectField(outPointerCoordsObj, |
| 239 | gPointerCoordsClassInfo.mPackedAxisValues)); |
| 240 | if (outValuesArray) { |
| 241 | uint32_t size = env->GetArrayLength(outValuesArray); |
| 242 | if (minSize <= size) { |
| 243 | return outValuesArray; |
| 244 | } |
| 245 | env->DeleteLocalRef(outValuesArray); |
| 246 | } |
| 247 | uint32_t size = 8; |
| 248 | while (size < minSize) { |
| 249 | size *= 2; |
| 250 | } |
| 251 | outValuesArray = env->NewFloatArray(size); |
| 252 | env->SetObjectField(outPointerCoordsObj, |
| 253 | gPointerCoordsClassInfo.mPackedAxisValues, outValuesArray); |
| 254 | return outValuesArray; |
| 255 | } |
| 256 | |
| 257 | static void pointerCoordsFromNative(JNIEnv* env, const PointerCoords* rawPointerCoords, |
| 258 | float xOffset, float yOffset, jobject outPointerCoordsObj) { |
| 259 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.x, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 260 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_X) + xOffset); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 261 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.y, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 262 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_Y) + yOffset); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 263 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.pressure, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 264 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_PRESSURE)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 265 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.size, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 266 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_SIZE)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 267 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMajor, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 268 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 269 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.touchMinor, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 270 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 271 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMajor, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 272 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 273 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.toolMinor, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 274 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 275 | env->SetFloatField(outPointerCoordsObj, gPointerCoordsClassInfo.orientation, |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 276 | rawPointerCoords->getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 277 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 278 | uint64_t outBits = 0; |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 279 | BitSet64 bits = BitSet64(rawPointerCoords->bits); |
| 280 | bits.clearBit(AMOTION_EVENT_AXIS_X); |
| 281 | bits.clearBit(AMOTION_EVENT_AXIS_Y); |
| 282 | bits.clearBit(AMOTION_EVENT_AXIS_PRESSURE); |
| 283 | bits.clearBit(AMOTION_EVENT_AXIS_SIZE); |
| 284 | bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MAJOR); |
| 285 | bits.clearBit(AMOTION_EVENT_AXIS_TOUCH_MINOR); |
| 286 | bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MAJOR); |
| 287 | bits.clearBit(AMOTION_EVENT_AXIS_TOOL_MINOR); |
| 288 | bits.clearBit(AMOTION_EVENT_AXIS_ORIENTATION); |
| 289 | if (!bits.isEmpty()) { |
| 290 | uint32_t packedAxesCount = bits.count(); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 291 | jfloatArray outValuesArray = obtainPackedAxisValuesArray(env, packedAxesCount, |
| 292 | outPointerCoordsObj); |
| 293 | if (!outValuesArray) { |
| 294 | return; // OOM |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 297 | jfloat* outValues = static_cast<jfloat*>(env->GetPrimitiveArrayCritical( |
| 298 | outValuesArray, NULL)); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 299 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 300 | uint32_t index = 0; |
| 301 | do { |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 302 | uint32_t axis = bits.clearFirstMarkedBit(); |
| 303 | outBits |= BitSet64::valueForBit(axis); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 304 | outValues[index++] = rawPointerCoords->getAxisValue(axis); |
Michael Wright | cbf1486 | 2014-05-19 15:42:01 -0700 | [diff] [blame] | 305 | } while (!bits.isEmpty()); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 306 | |
| 307 | env->ReleasePrimitiveArrayCritical(outValuesArray, outValues, 0); |
| 308 | env->DeleteLocalRef(outValuesArray); |
| 309 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 310 | env->SetLongField(outPointerCoordsObj, gPointerCoordsClassInfo.mPackedAxisBits, outBits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 313 | static void pointerPropertiesToNative(JNIEnv* env, jobject pointerPropertiesObj, |
| 314 | PointerProperties* outPointerProperties) { |
| 315 | outPointerProperties->clear(); |
| 316 | outPointerProperties->id = env->GetIntField(pointerPropertiesObj, |
| 317 | gPointerPropertiesClassInfo.id); |
| 318 | outPointerProperties->toolType = env->GetIntField(pointerPropertiesObj, |
| 319 | gPointerPropertiesClassInfo.toolType); |
| 320 | } |
| 321 | |
| 322 | static void pointerPropertiesFromNative(JNIEnv* env, const PointerProperties* pointerProperties, |
| 323 | jobject outPointerPropertiesObj) { |
| 324 | env->SetIntField(outPointerPropertiesObj, gPointerPropertiesClassInfo.id, |
| 325 | pointerProperties->id); |
| 326 | env->SetIntField(outPointerPropertiesObj, gPointerPropertiesClassInfo.toolType, |
| 327 | pointerProperties->toolType); |
| 328 | } |
| 329 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 330 | |
| 331 | // ---------------------------------------------------------------------------- |
| 332 | |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 333 | static jlong android_view_MotionEvent_nativeInitialize( |
| 334 | JNIEnv* env, jclass clazz, jlong nativePtr, jint deviceId, jint source, jint displayId, |
| 335 | jint action, jint flags, jint edgeFlags, jint metaState, jint buttonState, |
| 336 | jint classification, jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision, |
| 337 | jlong downTimeNanos, jlong eventTimeNanos, jint pointerCount, |
| 338 | jobjectArray pointerPropertiesObjArray, jobjectArray pointerCoordsObjArray) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 339 | if (!validatePointerCount(env, pointerCount) |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 340 | || !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 341 | || !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) { |
| 342 | return 0; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 343 | } |
| 344 | |
George Burgess IV | d657a38 | 2017-06-20 23:53:29 -0700 | [diff] [blame] | 345 | MotionEvent* event; |
| 346 | if (nativePtr) { |
| 347 | event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 348 | } else { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 349 | event = new MotionEvent(); |
| 350 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 351 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 352 | PointerProperties pointerProperties[pointerCount]; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 353 | PointerCoords rawPointerCoords[pointerCount]; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 354 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 355 | for (jint i = 0; i < pointerCount; i++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 356 | jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i); |
| 357 | if (!pointerPropertiesObj) { |
| 358 | goto Error; |
| 359 | } |
| 360 | pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]); |
| 361 | env->DeleteLocalRef(pointerPropertiesObj); |
| 362 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 363 | jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i); |
| 364 | if (!pointerCoordsObj) { |
| 365 | jniThrowNullPointerException(env, "pointerCoords"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 366 | goto Error; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 367 | } |
| 368 | pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]); |
| 369 | env->DeleteLocalRef(pointerCoordsObj); |
| 370 | } |
| 371 | |
Garfield Tan | c8362b2 | 2020-01-24 11:32:14 -0800 | [diff] [blame] | 372 | event->initialize(InputEvent::nextId(), deviceId, source, displayId, INVALID_HMAC, action, 0, |
| 373 | flags, edgeFlags, metaState, buttonState, |
| 374 | static_cast<MotionClassification>(classification), 1 /*xScale*/, 1 /*yScale*/, |
| 375 | xOffset, yOffset, xPrecision, yPrecision, |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 376 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 377 | downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, |
| 378 | rawPointerCoords); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 379 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 380 | return reinterpret_cast<jlong>(event); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 381 | |
| 382 | Error: |
| 383 | if (!nativePtr) { |
| 384 | delete event; |
| 385 | } |
| 386 | return 0; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 387 | } |
| 388 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 389 | static void android_view_MotionEvent_nativeDispose(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 390 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 391 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 392 | delete event; |
| 393 | } |
| 394 | |
| 395 | static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 396 | jlong nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 397 | jint metaState) { |
| 398 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 399 | size_t pointerCount = event->getPointerCount(); |
| 400 | if (!validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) { |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | PointerCoords rawPointerCoords[pointerCount]; |
| 405 | |
| 406 | for (size_t i = 0; i < pointerCount; i++) { |
| 407 | jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i); |
| 408 | if (!pointerCoordsObj) { |
| 409 | jniThrowNullPointerException(env, "pointerCoords"); |
| 410 | return; |
| 411 | } |
| 412 | pointerCoordsToNative(env, pointerCoordsObj, |
| 413 | event->getXOffset(), event->getYOffset(), &rawPointerCoords[i]); |
| 414 | env->DeleteLocalRef(pointerCoordsObj); |
| 415 | } |
| 416 | |
| 417 | event->addSample(eventTimeNanos, rawPointerCoords); |
| 418 | event->setMetaState(event->getMetaState() | metaState); |
| 419 | } |
| 420 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 421 | static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 422 | jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 423 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 424 | size_t pointerCount = event->getPointerCount(); |
| 425 | if (!validatePointerIndex(env, pointerIndex, pointerCount) |
| 426 | || !validatePointerCoords(env, outPointerCoordsObj)) { |
| 427 | return; |
| 428 | } |
| 429 | |
| 430 | const PointerCoords* rawPointerCoords; |
| 431 | if (historyPos == HISTORY_CURRENT) { |
| 432 | rawPointerCoords = event->getRawPointerCoords(pointerIndex); |
| 433 | } else { |
| 434 | size_t historySize = event->getHistorySize(); |
| 435 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 436 | return; |
| 437 | } |
| 438 | rawPointerCoords = event->getHistoricalRawPointerCoords(pointerIndex, historyPos); |
| 439 | } |
| 440 | pointerCoordsFromNative(env, rawPointerCoords, event->getXOffset(), event->getYOffset(), |
| 441 | outPointerCoordsObj); |
| 442 | } |
| 443 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 444 | static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 445 | jlong nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 446 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 447 | size_t pointerCount = event->getPointerCount(); |
| 448 | if (!validatePointerIndex(env, pointerIndex, pointerCount) |
| 449 | || !validatePointerProperties(env, outPointerPropertiesObj)) { |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | const PointerProperties* pointerProperties = event->getPointerProperties(pointerIndex); |
| 454 | pointerPropertiesFromNative(env, pointerProperties, outPointerPropertiesObj); |
| 455 | } |
| 456 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 457 | static jlong android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz, |
| 458 | jlong nativePtr, jobject parcelObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 459 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 460 | if (!event) { |
| 461 | event = new MotionEvent(); |
| 462 | } |
| 463 | |
| 464 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 465 | |
| 466 | status_t status = event->readFromParcel(parcel); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 467 | if (status) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 468 | if (!nativePtr) { |
| 469 | delete event; |
| 470 | } |
| 471 | jniThrowRuntimeException(env, "Failed to read MotionEvent parcel."); |
| 472 | return 0; |
| 473 | } |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 474 | return reinterpret_cast<jlong>(event); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 478 | jlong nativePtr, jobject parcelObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 479 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 480 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 481 | |
| 482 | status_t status = event->writeToParcel(parcel); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 483 | if (status) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 484 | jniThrowRuntimeException(env, "Failed to write MotionEvent parcel."); |
| 485 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 488 | static jstring android_view_MotionEvent_nativeAxisToString(JNIEnv* env, jclass clazz, |
| 489 | jint axis) { |
| 490 | return env->NewStringUTF(MotionEvent::getLabel(static_cast<int32_t>(axis))); |
| 491 | } |
| 492 | |
| 493 | static jint android_view_MotionEvent_nativeAxisFromString(JNIEnv* env, jclass clazz, |
| 494 | jstring label) { |
| 495 | ScopedUtfChars axisLabel(env, label); |
| 496 | return static_cast<jint>(MotionEvent::getAxisFromLabel(axisLabel.c_str())); |
| 497 | } |
| 498 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 499 | // ---------------- @FastNative ---------------------------------- |
| 500 | |
| 501 | static jint android_view_MotionEvent_nativeGetPointerId(JNIEnv* env, jclass clazz, |
| 502 | jlong nativePtr, jint pointerIndex) { |
| 503 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 504 | size_t pointerCount = event->getPointerCount(); |
| 505 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 506 | return -1; |
| 507 | } |
| 508 | return event->getPointerId(pointerIndex); |
| 509 | } |
| 510 | |
| 511 | static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz, |
| 512 | jlong nativePtr, jint pointerIndex) { |
| 513 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 514 | size_t pointerCount = event->getPointerCount(); |
| 515 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 516 | return -1; |
| 517 | } |
| 518 | return event->getToolType(pointerIndex); |
| 519 | } |
| 520 | |
| 521 | static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz, |
| 522 | jlong nativePtr, jint historyPos) { |
| 523 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 524 | if (historyPos == HISTORY_CURRENT) { |
| 525 | return event->getEventTime(); |
| 526 | } else { |
| 527 | size_t historySize = event->getHistorySize(); |
| 528 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 529 | return 0; |
| 530 | } |
| 531 | return event->getHistoricalEventTime(historyPos); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static jfloat android_view_MotionEvent_nativeGetRawAxisValue(JNIEnv* env, jclass clazz, |
| 536 | jlong nativePtr, jint axis, |
| 537 | jint pointerIndex, jint historyPos) { |
| 538 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 539 | size_t pointerCount = event->getPointerCount(); |
| 540 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | if (historyPos == HISTORY_CURRENT) { |
| 545 | return event->getRawAxisValue(axis, pointerIndex); |
| 546 | } else { |
| 547 | size_t historySize = event->getHistorySize(); |
| 548 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 549 | return 0; |
| 550 | } |
| 551 | return event->getHistoricalRawAxisValue(axis, pointerIndex, historyPos); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz, |
| 556 | jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) { |
| 557 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 558 | size_t pointerCount = event->getPointerCount(); |
| 559 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 560 | return 0; |
| 561 | } |
| 562 | |
| 563 | if (historyPos == HISTORY_CURRENT) { |
| 564 | return event->getAxisValue(axis, pointerIndex); |
| 565 | } else { |
| 566 | size_t historySize = event->getHistorySize(); |
| 567 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 568 | return 0; |
| 569 | } |
| 570 | return event->getHistoricalAxisValue(axis, pointerIndex, historyPos); |
| 571 | } |
| 572 | } |
| 573 | |
Derek Sollenberger | 4dc0aae | 2019-12-27 15:15:18 -0500 | [diff] [blame] | 574 | static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz, |
| 575 | jlong nativePtr, jobject matrixObj) { |
| 576 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 577 | |
| 578 | float m[9]; |
| 579 | AMatrix_getContents(env, matrixObj, m); |
| 580 | event->transform(m); |
| 581 | } |
| 582 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 583 | // ----------------- @CriticalNative ------------------------------ |
| 584 | |
| 585 | static jlong android_view_MotionEvent_nativeCopy(jlong destNativePtr, jlong sourceNativePtr, |
| 586 | jboolean keepHistory) { |
| 587 | MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr); |
| 588 | if (!destEvent) { |
| 589 | destEvent = new MotionEvent(); |
| 590 | } |
| 591 | MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr); |
| 592 | destEvent->copyFrom(sourceEvent, keepHistory); |
| 593 | return reinterpret_cast<jlong>(destEvent); |
| 594 | } |
| 595 | |
Garfield Tan | c8362b2 | 2020-01-24 11:32:14 -0800 | [diff] [blame] | 596 | static jint android_view_MotionEvent_nativeGetId(jlong nativePtr) { |
| 597 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 598 | return event->getId(); |
| 599 | } |
| 600 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 601 | static jint android_view_MotionEvent_nativeGetDeviceId(jlong nativePtr) { |
| 602 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 603 | return event->getDeviceId(); |
| 604 | } |
| 605 | |
| 606 | static jint android_view_MotionEvent_nativeGetSource(jlong nativePtr) { |
| 607 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 608 | return event->getSource(); |
| 609 | } |
| 610 | |
| 611 | static void android_view_MotionEvent_nativeSetSource(jlong nativePtr, jint source) { |
| 612 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 613 | event->setSource(source); |
| 614 | } |
| 615 | |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 616 | static jint android_view_MotionEvent_nativeGetDisplayId(jlong nativePtr) { |
| 617 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 618 | return event->getDisplayId(); |
| 619 | } |
| 620 | |
| 621 | static void android_view_MotionEvent_nativeSetDisplayId(jlong nativePtr, jint displayId) { |
| 622 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 623 | return event->setDisplayId(displayId); |
| 624 | } |
| 625 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 626 | static jint android_view_MotionEvent_nativeGetAction(jlong nativePtr) { |
| 627 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 628 | return event->getAction(); |
| 629 | } |
| 630 | |
| 631 | static void android_view_MotionEvent_nativeSetAction(jlong nativePtr, jint action) { |
| 632 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 633 | event->setAction(action); |
| 634 | } |
| 635 | |
| 636 | static int android_view_MotionEvent_nativeGetActionButton(jlong nativePtr) { |
| 637 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 638 | return event->getActionButton(); |
| 639 | } |
| 640 | |
| 641 | static void android_view_MotionEvent_nativeSetActionButton(jlong nativePtr, jint button) { |
| 642 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 643 | event->setActionButton(button); |
| 644 | } |
| 645 | |
| 646 | static jboolean android_view_MotionEvent_nativeIsTouchEvent(jlong nativePtr) { |
| 647 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 648 | return event->isTouchEvent(); |
| 649 | } |
| 650 | |
| 651 | static jint android_view_MotionEvent_nativeGetFlags(jlong nativePtr) { |
| 652 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 653 | return event->getFlags(); |
| 654 | } |
| 655 | |
| 656 | static void android_view_MotionEvent_nativeSetFlags(jlong nativePtr, jint flags) { |
| 657 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 658 | event->setFlags(flags); |
| 659 | } |
| 660 | |
| 661 | static jint android_view_MotionEvent_nativeGetEdgeFlags(jlong nativePtr) { |
| 662 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 663 | return event->getEdgeFlags(); |
| 664 | } |
| 665 | |
| 666 | static void android_view_MotionEvent_nativeSetEdgeFlags(jlong nativePtr, jint edgeFlags) { |
| 667 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 668 | event->setEdgeFlags(edgeFlags); |
| 669 | } |
| 670 | |
| 671 | static jint android_view_MotionEvent_nativeGetMetaState(jlong nativePtr) { |
| 672 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 673 | return event->getMetaState(); |
| 674 | } |
| 675 | |
| 676 | static jint android_view_MotionEvent_nativeGetButtonState(jlong nativePtr) { |
| 677 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 678 | return event->getButtonState(); |
| 679 | } |
| 680 | |
| 681 | static void android_view_MotionEvent_nativeSetButtonState(jlong nativePtr, jint buttonState) { |
| 682 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 683 | event->setButtonState(buttonState); |
| 684 | } |
| 685 | |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 686 | static jint android_view_MotionEvent_nativeGetClassification(jlong nativePtr) { |
| 687 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 688 | return static_cast<jint>(event->getClassification()); |
| 689 | } |
| 690 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 691 | static void android_view_MotionEvent_nativeOffsetLocation(jlong nativePtr, jfloat deltaX, |
| 692 | jfloat deltaY) { |
| 693 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 694 | return event->offsetLocation(deltaX, deltaY); |
| 695 | } |
| 696 | |
| 697 | static jfloat android_view_MotionEvent_nativeGetXOffset(jlong nativePtr) { |
| 698 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 699 | return event->getXOffset(); |
| 700 | } |
| 701 | |
| 702 | static jfloat android_view_MotionEvent_nativeGetYOffset(jlong nativePtr) { |
| 703 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 704 | return event->getYOffset(); |
| 705 | } |
| 706 | |
| 707 | static jfloat android_view_MotionEvent_nativeGetXPrecision(jlong nativePtr) { |
| 708 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 709 | return event->getXPrecision(); |
| 710 | } |
| 711 | |
| 712 | static jfloat android_view_MotionEvent_nativeGetYPrecision(jlong nativePtr) { |
| 713 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 714 | return event->getYPrecision(); |
| 715 | } |
| 716 | |
Garfield Tan | 1da8628 | 2019-07-15 14:00:35 -0700 | [diff] [blame] | 717 | static jfloat android_view_MotionEvent_nativeGetXCursorPosition(jlong nativePtr) { |
| 718 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 719 | return event->getXCursorPosition(); |
| 720 | } |
| 721 | |
| 722 | static jfloat android_view_MotionEvent_nativeGetYCursorPosition(jlong nativePtr) { |
| 723 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 724 | return event->getYCursorPosition(); |
| 725 | } |
| 726 | |
| 727 | static void android_view_MotionEvent_nativeSetCursorPosition(jlong nativePtr, jfloat x, jfloat y) { |
| 728 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 729 | event->setCursorPosition(x, y); |
| 730 | } |
| 731 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 732 | static jlong android_view_MotionEvent_nativeGetDownTimeNanos(jlong nativePtr) { |
| 733 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 734 | return event->getDownTime(); |
| 735 | } |
| 736 | |
| 737 | static void android_view_MotionEvent_nativeSetDownTimeNanos(jlong nativePtr, jlong downTimeNanos) { |
| 738 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 739 | event->setDownTime(downTimeNanos); |
| 740 | } |
| 741 | |
| 742 | static jint android_view_MotionEvent_nativeGetPointerCount(jlong nativePtr) { |
| 743 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 744 | return jint(event->getPointerCount()); |
| 745 | } |
| 746 | |
| 747 | static jint android_view_MotionEvent_nativeFindPointerIndex(jlong nativePtr, jint pointerId) { |
| 748 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 749 | return jint(event->findPointerIndex(pointerId)); |
| 750 | } |
| 751 | |
| 752 | static jint android_view_MotionEvent_nativeGetHistorySize(jlong nativePtr) { |
| 753 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 754 | return jint(event->getHistorySize()); |
| 755 | } |
| 756 | |
| 757 | static void android_view_MotionEvent_nativeScale(jlong nativePtr, jfloat scale) { |
| 758 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 759 | event->scale(scale); |
| 760 | } |
| 761 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 762 | // ---------------------------------------------------------------------------- |
| 763 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 764 | static const JNINativeMethod gMotionEventMethods[] = { |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 765 | /* name, signature, funcPtr */ |
| 766 | {"nativeInitialize", |
| 767 | "(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;" |
| 768 | "[Landroid/view/MotionEvent$PointerCoords;)J", |
| 769 | (void*)android_view_MotionEvent_nativeInitialize}, |
| 770 | {"nativeDispose", "(J)V", (void*)android_view_MotionEvent_nativeDispose}, |
| 771 | {"nativeAddBatch", "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V", |
| 772 | (void*)android_view_MotionEvent_nativeAddBatch}, |
| 773 | {"nativeReadFromParcel", "(JLandroid/os/Parcel;)J", |
| 774 | (void*)android_view_MotionEvent_nativeReadFromParcel}, |
| 775 | {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V", |
| 776 | (void*)android_view_MotionEvent_nativeWriteToParcel}, |
| 777 | {"nativeAxisToString", "(I)Ljava/lang/String;", |
| 778 | (void*)android_view_MotionEvent_nativeAxisToString}, |
| 779 | {"nativeAxisFromString", "(Ljava/lang/String;)I", |
| 780 | (void*)android_view_MotionEvent_nativeAxisFromString}, |
| 781 | {"nativeGetPointerProperties", "(JILandroid/view/MotionEvent$PointerProperties;)V", |
| 782 | (void*)android_view_MotionEvent_nativeGetPointerProperties}, |
| 783 | {"nativeGetPointerCoords", "(JIILandroid/view/MotionEvent$PointerCoords;)V", |
| 784 | (void*)android_view_MotionEvent_nativeGetPointerCoords}, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 785 | |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 786 | // --------------- @FastNative ---------------------- |
| 787 | {"nativeGetPointerId", "(JI)I", (void*)android_view_MotionEvent_nativeGetPointerId}, |
| 788 | {"nativeGetToolType", "(JI)I", (void*)android_view_MotionEvent_nativeGetToolType}, |
| 789 | {"nativeGetEventTimeNanos", "(JI)J", |
| 790 | (void*)android_view_MotionEvent_nativeGetEventTimeNanos}, |
| 791 | {"nativeGetRawAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetRawAxisValue}, |
| 792 | {"nativeGetAxisValue", "(JIII)F", (void*)android_view_MotionEvent_nativeGetAxisValue}, |
| 793 | {"nativeTransform", "(JLandroid/graphics/Matrix;)V", |
| 794 | (void*)android_view_MotionEvent_nativeTransform}, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 795 | |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 796 | // --------------- @CriticalNative ------------------ |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 797 | |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 798 | {"nativeCopy", "(JJZ)J", (void*)android_view_MotionEvent_nativeCopy}, |
Garfield Tan | c8362b2 | 2020-01-24 11:32:14 -0800 | [diff] [blame] | 799 | {"nativeGetId", "(J)I", (void*)android_view_MotionEvent_nativeGetId}, |
Siarhei Vishniakou | 6a3346d | 2020-01-23 19:49:39 -0600 | [diff] [blame] | 800 | {"nativeGetDeviceId", "(J)I", (void*)android_view_MotionEvent_nativeGetDeviceId}, |
| 801 | {"nativeGetSource", "(J)I", (void*)android_view_MotionEvent_nativeGetSource}, |
| 802 | {"nativeSetSource", "(JI)V", (void*)android_view_MotionEvent_nativeSetSource}, |
| 803 | {"nativeGetDisplayId", "(J)I", (void*)android_view_MotionEvent_nativeGetDisplayId}, |
| 804 | {"nativeSetDisplayId", "(JI)V", (void*)android_view_MotionEvent_nativeSetDisplayId}, |
| 805 | {"nativeGetAction", "(J)I", (void*)android_view_MotionEvent_nativeGetAction}, |
| 806 | {"nativeSetAction", "(JI)V", (void*)android_view_MotionEvent_nativeSetAction}, |
| 807 | {"nativeGetActionButton", "(J)I", (void*)android_view_MotionEvent_nativeGetActionButton}, |
| 808 | {"nativeSetActionButton", "(JI)V", (void*)android_view_MotionEvent_nativeSetActionButton}, |
| 809 | {"nativeIsTouchEvent", "(J)Z", (void*)android_view_MotionEvent_nativeIsTouchEvent}, |
| 810 | {"nativeGetFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetFlags}, |
| 811 | {"nativeSetFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetFlags}, |
| 812 | {"nativeGetEdgeFlags", "(J)I", (void*)android_view_MotionEvent_nativeGetEdgeFlags}, |
| 813 | {"nativeSetEdgeFlags", "(JI)V", (void*)android_view_MotionEvent_nativeSetEdgeFlags}, |
| 814 | {"nativeGetMetaState", "(J)I", (void*)android_view_MotionEvent_nativeGetMetaState}, |
| 815 | {"nativeGetButtonState", "(J)I", (void*)android_view_MotionEvent_nativeGetButtonState}, |
| 816 | {"nativeSetButtonState", "(JI)V", (void*)android_view_MotionEvent_nativeSetButtonState}, |
| 817 | {"nativeGetClassification", "(J)I", |
| 818 | (void*)android_view_MotionEvent_nativeGetClassification}, |
| 819 | {"nativeOffsetLocation", "(JFF)V", (void*)android_view_MotionEvent_nativeOffsetLocation}, |
| 820 | {"nativeGetXOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetXOffset}, |
| 821 | {"nativeGetYOffset", "(J)F", (void*)android_view_MotionEvent_nativeGetYOffset}, |
| 822 | {"nativeGetXPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetXPrecision}, |
| 823 | {"nativeGetYPrecision", "(J)F", (void*)android_view_MotionEvent_nativeGetYPrecision}, |
| 824 | {"nativeGetXCursorPosition", "(J)F", |
| 825 | (void*)android_view_MotionEvent_nativeGetXCursorPosition}, |
| 826 | {"nativeGetYCursorPosition", "(J)F", |
| 827 | (void*)android_view_MotionEvent_nativeGetYCursorPosition}, |
| 828 | {"nativeSetCursorPosition", "(JFF)V", |
| 829 | (void*)android_view_MotionEvent_nativeSetCursorPosition}, |
| 830 | {"nativeGetDownTimeNanos", "(J)J", (void*)android_view_MotionEvent_nativeGetDownTimeNanos}, |
| 831 | {"nativeSetDownTimeNanos", "(JJ)V", (void*)android_view_MotionEvent_nativeSetDownTimeNanos}, |
| 832 | {"nativeGetPointerCount", "(J)I", (void*)android_view_MotionEvent_nativeGetPointerCount}, |
| 833 | {"nativeFindPointerIndex", "(JI)I", (void*)android_view_MotionEvent_nativeFindPointerIndex}, |
| 834 | {"nativeGetHistorySize", "(J)I", (void*)android_view_MotionEvent_nativeGetHistorySize}, |
| 835 | {"nativeScale", "(JF)V", (void*)android_view_MotionEvent_nativeScale}, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 836 | }; |
| 837 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 838 | int register_android_view_MotionEvent(JNIEnv* env) { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 839 | int res = RegisterMethodsOrDie(env, "android/view/MotionEvent", gMotionEventMethods, |
| 840 | NELEM(gMotionEventMethods)); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 841 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 842 | gMotionEventClassInfo.clazz = FindClassOrDie(env, "android/view/MotionEvent"); |
| 843 | gMotionEventClassInfo.clazz = MakeGlobalRefOrDie(env, gMotionEventClassInfo.clazz); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 844 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 845 | gMotionEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 846 | "obtain", "()Landroid/view/MotionEvent;"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 847 | gMotionEventClassInfo.recycle = GetMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 848 | "recycle", "()V"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 849 | gMotionEventClassInfo.mNativePtr = GetFieldIDOrDie(env, gMotionEventClassInfo.clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 850 | "mNativePtr", "J"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 851 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 852 | jclass clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerCoords"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 853 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 854 | gPointerCoordsClassInfo.mPackedAxisBits = GetFieldIDOrDie(env, clazz, "mPackedAxisBits", "J"); |
| 855 | gPointerCoordsClassInfo.mPackedAxisValues = GetFieldIDOrDie(env, clazz, "mPackedAxisValues", |
| 856 | "[F"); |
| 857 | gPointerCoordsClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "F"); |
| 858 | gPointerCoordsClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "F"); |
| 859 | gPointerCoordsClassInfo.pressure = GetFieldIDOrDie(env, clazz, "pressure", "F"); |
| 860 | gPointerCoordsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "F"); |
| 861 | gPointerCoordsClassInfo.touchMajor = GetFieldIDOrDie(env, clazz, "touchMajor", "F"); |
| 862 | gPointerCoordsClassInfo.touchMinor = GetFieldIDOrDie(env, clazz, "touchMinor", "F"); |
| 863 | gPointerCoordsClassInfo.toolMajor = GetFieldIDOrDie(env, clazz, "toolMajor", "F"); |
| 864 | gPointerCoordsClassInfo.toolMinor = GetFieldIDOrDie(env, clazz, "toolMinor", "F"); |
| 865 | gPointerCoordsClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "F"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 866 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 867 | clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerProperties"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 868 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 869 | gPointerPropertiesClassInfo.id = GetFieldIDOrDie(env, clazz, "id", "I"); |
| 870 | gPointerPropertiesClassInfo.toolType = GetFieldIDOrDie(env, clazz, "toolType", "I"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 871 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 872 | return res; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | } // namespace android |