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