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 | |
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 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 333 | static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz, |
| 334 | jlong nativePtr, |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 335 | jint deviceId, jint source, jint displayId, jint action, jint flags, jint edgeFlags, |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 336 | jint metaState, jint buttonState, jint classification, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 337 | jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision, |
| 338 | jlong downTimeNanos, jlong eventTimeNanos, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 339 | jint pointerCount, jobjectArray pointerPropertiesObjArray, |
| 340 | jobjectArray pointerCoordsObjArray) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 341 | if (!validatePointerCount(env, pointerCount) |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 342 | || !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 343 | || !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) { |
| 344 | return 0; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 345 | } |
| 346 | |
George Burgess IV | d657a38 | 2017-06-20 23:53:29 -0700 | [diff] [blame] | 347 | MotionEvent* event; |
| 348 | if (nativePtr) { |
| 349 | event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 350 | } else { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 351 | event = new MotionEvent(); |
| 352 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 353 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 354 | PointerProperties pointerProperties[pointerCount]; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 355 | PointerCoords rawPointerCoords[pointerCount]; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 356 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 357 | for (jint i = 0; i < pointerCount; i++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 358 | jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i); |
| 359 | if (!pointerPropertiesObj) { |
| 360 | goto Error; |
| 361 | } |
| 362 | pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]); |
| 363 | env->DeleteLocalRef(pointerPropertiesObj); |
| 364 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 365 | jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i); |
| 366 | if (!pointerCoordsObj) { |
| 367 | jniThrowNullPointerException(env, "pointerCoords"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 368 | goto Error; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 369 | } |
| 370 | pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]); |
| 371 | env->DeleteLocalRef(pointerCoordsObj); |
| 372 | } |
| 373 | |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 374 | event->initialize(deviceId, source, displayId, action, 0, flags, edgeFlags, metaState, |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 375 | buttonState, static_cast<MotionClassification>(classification), |
| 376 | xOffset, yOffset, xPrecision, yPrecision, |
Garfield Tan | 66fa5e2 | 2019-06-18 17:01:39 -0700 | [diff] [blame] | 377 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 378 | downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, 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 | |
| 574 | // ----------------- @CriticalNative ------------------------------ |
| 575 | |
| 576 | static jlong android_view_MotionEvent_nativeCopy(jlong destNativePtr, jlong sourceNativePtr, |
| 577 | jboolean keepHistory) { |
| 578 | MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr); |
| 579 | if (!destEvent) { |
| 580 | destEvent = new MotionEvent(); |
| 581 | } |
| 582 | MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr); |
| 583 | destEvent->copyFrom(sourceEvent, keepHistory); |
| 584 | return reinterpret_cast<jlong>(destEvent); |
| 585 | } |
| 586 | |
| 587 | static jint android_view_MotionEvent_nativeGetDeviceId(jlong nativePtr) { |
| 588 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 589 | return event->getDeviceId(); |
| 590 | } |
| 591 | |
| 592 | static jint android_view_MotionEvent_nativeGetSource(jlong nativePtr) { |
| 593 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 594 | return event->getSource(); |
| 595 | } |
| 596 | |
| 597 | static void android_view_MotionEvent_nativeSetSource(jlong nativePtr, jint source) { |
| 598 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 599 | event->setSource(source); |
| 600 | } |
| 601 | |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 602 | static jint android_view_MotionEvent_nativeGetDisplayId(jlong nativePtr) { |
| 603 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 604 | return event->getDisplayId(); |
| 605 | } |
| 606 | |
| 607 | static void android_view_MotionEvent_nativeSetDisplayId(jlong nativePtr, jint displayId) { |
| 608 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 609 | return event->setDisplayId(displayId); |
| 610 | } |
| 611 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 612 | static jint android_view_MotionEvent_nativeGetAction(jlong nativePtr) { |
| 613 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 614 | return event->getAction(); |
| 615 | } |
| 616 | |
| 617 | static void android_view_MotionEvent_nativeSetAction(jlong nativePtr, jint action) { |
| 618 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 619 | event->setAction(action); |
| 620 | } |
| 621 | |
| 622 | static int android_view_MotionEvent_nativeGetActionButton(jlong nativePtr) { |
| 623 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 624 | return event->getActionButton(); |
| 625 | } |
| 626 | |
| 627 | static void android_view_MotionEvent_nativeSetActionButton(jlong nativePtr, jint button) { |
| 628 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 629 | event->setActionButton(button); |
| 630 | } |
| 631 | |
| 632 | static jboolean android_view_MotionEvent_nativeIsTouchEvent(jlong nativePtr) { |
| 633 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 634 | return event->isTouchEvent(); |
| 635 | } |
| 636 | |
| 637 | static jint android_view_MotionEvent_nativeGetFlags(jlong nativePtr) { |
| 638 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 639 | return event->getFlags(); |
| 640 | } |
| 641 | |
| 642 | static void android_view_MotionEvent_nativeSetFlags(jlong nativePtr, jint flags) { |
| 643 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 644 | event->setFlags(flags); |
| 645 | } |
| 646 | |
| 647 | static jint android_view_MotionEvent_nativeGetEdgeFlags(jlong nativePtr) { |
| 648 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 649 | return event->getEdgeFlags(); |
| 650 | } |
| 651 | |
| 652 | static void android_view_MotionEvent_nativeSetEdgeFlags(jlong nativePtr, jint edgeFlags) { |
| 653 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 654 | event->setEdgeFlags(edgeFlags); |
| 655 | } |
| 656 | |
| 657 | static jint android_view_MotionEvent_nativeGetMetaState(jlong nativePtr) { |
| 658 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 659 | return event->getMetaState(); |
| 660 | } |
| 661 | |
| 662 | static jint android_view_MotionEvent_nativeGetButtonState(jlong nativePtr) { |
| 663 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 664 | return event->getButtonState(); |
| 665 | } |
| 666 | |
| 667 | static void android_view_MotionEvent_nativeSetButtonState(jlong nativePtr, jint buttonState) { |
| 668 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 669 | event->setButtonState(buttonState); |
| 670 | } |
| 671 | |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 672 | static jint android_view_MotionEvent_nativeGetClassification(jlong nativePtr) { |
| 673 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 674 | return static_cast<jint>(event->getClassification()); |
| 675 | } |
| 676 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 677 | static void android_view_MotionEvent_nativeOffsetLocation(jlong nativePtr, jfloat deltaX, |
| 678 | jfloat deltaY) { |
| 679 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 680 | return event->offsetLocation(deltaX, deltaY); |
| 681 | } |
| 682 | |
| 683 | static jfloat android_view_MotionEvent_nativeGetXOffset(jlong nativePtr) { |
| 684 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 685 | return event->getXOffset(); |
| 686 | } |
| 687 | |
| 688 | static jfloat android_view_MotionEvent_nativeGetYOffset(jlong nativePtr) { |
| 689 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 690 | return event->getYOffset(); |
| 691 | } |
| 692 | |
| 693 | static jfloat android_view_MotionEvent_nativeGetXPrecision(jlong nativePtr) { |
| 694 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 695 | return event->getXPrecision(); |
| 696 | } |
| 697 | |
| 698 | static jfloat android_view_MotionEvent_nativeGetYPrecision(jlong nativePtr) { |
| 699 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 700 | return event->getYPrecision(); |
| 701 | } |
| 702 | |
Garfield Tan | 1da8628 | 2019-07-15 14:00:35 -0700 | [diff] [blame] | 703 | static jfloat android_view_MotionEvent_nativeGetXCursorPosition(jlong nativePtr) { |
| 704 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 705 | return event->getXCursorPosition(); |
| 706 | } |
| 707 | |
| 708 | static jfloat android_view_MotionEvent_nativeGetYCursorPosition(jlong nativePtr) { |
| 709 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 710 | return event->getYCursorPosition(); |
| 711 | } |
| 712 | |
| 713 | static void android_view_MotionEvent_nativeSetCursorPosition(jlong nativePtr, jfloat x, jfloat y) { |
| 714 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 715 | event->setCursorPosition(x, y); |
| 716 | } |
| 717 | |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 718 | static jlong android_view_MotionEvent_nativeGetDownTimeNanos(jlong nativePtr) { |
| 719 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 720 | return event->getDownTime(); |
| 721 | } |
| 722 | |
| 723 | static void android_view_MotionEvent_nativeSetDownTimeNanos(jlong nativePtr, jlong downTimeNanos) { |
| 724 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 725 | event->setDownTime(downTimeNanos); |
| 726 | } |
| 727 | |
| 728 | static jint android_view_MotionEvent_nativeGetPointerCount(jlong nativePtr) { |
| 729 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 730 | return jint(event->getPointerCount()); |
| 731 | } |
| 732 | |
| 733 | static jint android_view_MotionEvent_nativeFindPointerIndex(jlong nativePtr, jint pointerId) { |
| 734 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 735 | return jint(event->findPointerIndex(pointerId)); |
| 736 | } |
| 737 | |
| 738 | static jint android_view_MotionEvent_nativeGetHistorySize(jlong nativePtr) { |
| 739 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 740 | return jint(event->getHistorySize()); |
| 741 | } |
| 742 | |
| 743 | static void android_view_MotionEvent_nativeScale(jlong nativePtr, jfloat scale) { |
| 744 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 745 | event->scale(scale); |
| 746 | } |
| 747 | |
| 748 | static void android_view_MotionEvent_nativeTransform(jlong nativePtr, jlong matrixPtr) { |
| 749 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 750 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixPtr); |
| 751 | |
| 752 | static_assert(SkMatrix::kMScaleX == 0, "SkMatrix unexpected index"); |
| 753 | static_assert(SkMatrix::kMSkewX == 1, "SkMatrix unexpected index"); |
| 754 | static_assert(SkMatrix::kMTransX == 2, "SkMatrix unexpected index"); |
| 755 | static_assert(SkMatrix::kMSkewY == 3, "SkMatrix unexpected index"); |
| 756 | static_assert(SkMatrix::kMScaleY == 4, "SkMatrix unexpected index"); |
| 757 | static_assert(SkMatrix::kMTransY == 5, "SkMatrix unexpected index"); |
| 758 | static_assert(SkMatrix::kMPersp0 == 6, "SkMatrix unexpected index"); |
| 759 | static_assert(SkMatrix::kMPersp1 == 7, "SkMatrix unexpected index"); |
| 760 | static_assert(SkMatrix::kMPersp2 == 8, "SkMatrix unexpected index"); |
| 761 | float m[9]; |
| 762 | matrix->get9(m); |
| 763 | event->transform(m); |
| 764 | } |
| 765 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 766 | // ---------------------------------------------------------------------------- |
| 767 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 768 | static const JNINativeMethod gMotionEventMethods[] = { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 769 | /* name, signature, funcPtr */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 770 | { "nativeInitialize", |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 771 | "(JIIIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;" |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 772 | "[Landroid/view/MotionEvent$PointerCoords;)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 773 | (void*)android_view_MotionEvent_nativeInitialize }, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 774 | { "nativeDispose", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 775 | "(J)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 776 | (void*)android_view_MotionEvent_nativeDispose }, |
| 777 | { "nativeAddBatch", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 778 | "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 779 | (void*)android_view_MotionEvent_nativeAddBatch }, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 780 | { "nativeReadFromParcel", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 781 | "(JLandroid/os/Parcel;)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 782 | (void*)android_view_MotionEvent_nativeReadFromParcel }, |
| 783 | { "nativeWriteToParcel", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 784 | "(JLandroid/os/Parcel;)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 785 | (void*)android_view_MotionEvent_nativeWriteToParcel }, |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 786 | { "nativeAxisToString", "(I)Ljava/lang/String;", |
| 787 | (void*)android_view_MotionEvent_nativeAxisToString }, |
| 788 | { "nativeAxisFromString", "(Ljava/lang/String;)I", |
| 789 | (void*)android_view_MotionEvent_nativeAxisFromString }, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 790 | { "nativeGetPointerProperties", |
| 791 | "(JILandroid/view/MotionEvent$PointerProperties;)V", |
| 792 | (void*)android_view_MotionEvent_nativeGetPointerProperties }, |
| 793 | { "nativeGetPointerCoords", |
| 794 | "(JIILandroid/view/MotionEvent$PointerCoords;)V", |
| 795 | (void*)android_view_MotionEvent_nativeGetPointerCoords }, |
| 796 | |
| 797 | // --------------- @FastNative ---------------------- |
| 798 | { "nativeGetPointerId", |
| 799 | "(JI)I", |
| 800 | (void*)android_view_MotionEvent_nativeGetPointerId }, |
| 801 | { "nativeGetToolType", |
| 802 | "(JI)I", |
| 803 | (void*)android_view_MotionEvent_nativeGetToolType }, |
| 804 | { "nativeGetEventTimeNanos", |
| 805 | "(JI)J", |
| 806 | (void*)android_view_MotionEvent_nativeGetEventTimeNanos }, |
| 807 | { "nativeGetRawAxisValue", |
| 808 | "(JIII)F", |
| 809 | (void*)android_view_MotionEvent_nativeGetRawAxisValue }, |
| 810 | { "nativeGetAxisValue", |
| 811 | "(JIII)F", |
| 812 | (void*)android_view_MotionEvent_nativeGetAxisValue }, |
| 813 | |
| 814 | // --------------- @CriticalNative ------------------ |
| 815 | |
| 816 | { "nativeCopy", |
| 817 | "(JJZ)J", |
| 818 | (void*)android_view_MotionEvent_nativeCopy }, |
| 819 | { "nativeGetDeviceId", |
| 820 | "(J)I", |
| 821 | (void*)android_view_MotionEvent_nativeGetDeviceId }, |
| 822 | { "nativeGetSource", |
| 823 | "(J)I", |
| 824 | (void*)android_view_MotionEvent_nativeGetSource }, |
| 825 | { "nativeSetSource", |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 826 | "(JI)V", |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 827 | (void*)android_view_MotionEvent_nativeSetSource }, |
Siarhei Vishniakou | 85ddfff | 2018-01-31 16:49:36 -0800 | [diff] [blame] | 828 | { "nativeGetDisplayId", |
| 829 | "(J)I", |
| 830 | (void*)android_view_MotionEvent_nativeGetDisplayId }, |
| 831 | { "nativeSetDisplayId", |
| 832 | "(JI)V", |
| 833 | (void*)android_view_MotionEvent_nativeSetDisplayId }, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 834 | { "nativeGetAction", |
| 835 | "(J)I", |
| 836 | (void*)android_view_MotionEvent_nativeGetAction }, |
| 837 | { "nativeSetAction", |
| 838 | "(JI)V", |
| 839 | (void*)android_view_MotionEvent_nativeSetAction }, |
| 840 | { "nativeGetActionButton", |
| 841 | "(J)I", |
| 842 | (void*)android_view_MotionEvent_nativeGetActionButton}, |
| 843 | { "nativeSetActionButton", |
| 844 | "(JI)V", |
| 845 | (void*)android_view_MotionEvent_nativeSetActionButton}, |
| 846 | { "nativeIsTouchEvent", |
| 847 | "(J)Z", |
| 848 | (void*)android_view_MotionEvent_nativeIsTouchEvent }, |
| 849 | { "nativeGetFlags", |
| 850 | "(J)I", |
| 851 | (void*)android_view_MotionEvent_nativeGetFlags }, |
| 852 | { "nativeSetFlags", |
| 853 | "(JI)V", |
| 854 | (void*)android_view_MotionEvent_nativeSetFlags }, |
| 855 | { "nativeGetEdgeFlags", |
| 856 | "(J)I", |
| 857 | (void*)android_view_MotionEvent_nativeGetEdgeFlags }, |
| 858 | { "nativeSetEdgeFlags", |
| 859 | "(JI)V", |
| 860 | (void*)android_view_MotionEvent_nativeSetEdgeFlags }, |
| 861 | { "nativeGetMetaState", |
| 862 | "(J)I", |
| 863 | (void*)android_view_MotionEvent_nativeGetMetaState }, |
| 864 | { "nativeGetButtonState", |
| 865 | "(J)I", |
| 866 | (void*)android_view_MotionEvent_nativeGetButtonState }, |
| 867 | { "nativeSetButtonState", |
| 868 | "(JI)V", |
| 869 | (void*)android_view_MotionEvent_nativeSetButtonState }, |
Siarhei Vishniakou | b05b0b5 | 2018-12-28 17:50:24 -0800 | [diff] [blame] | 870 | { "nativeGetClassification", |
| 871 | "(J)I", |
| 872 | (void*)android_view_MotionEvent_nativeGetClassification }, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 873 | { "nativeOffsetLocation", |
| 874 | "(JFF)V", |
| 875 | (void*)android_view_MotionEvent_nativeOffsetLocation }, |
| 876 | { "nativeGetXOffset", |
| 877 | "(J)F", |
| 878 | (void*)android_view_MotionEvent_nativeGetXOffset }, |
| 879 | { "nativeGetYOffset", |
| 880 | "(J)F", |
| 881 | (void*)android_view_MotionEvent_nativeGetYOffset }, |
| 882 | { "nativeGetXPrecision", |
| 883 | "(J)F", |
| 884 | (void*)android_view_MotionEvent_nativeGetXPrecision }, |
| 885 | { "nativeGetYPrecision", |
| 886 | "(J)F", |
| 887 | (void*)android_view_MotionEvent_nativeGetYPrecision }, |
Garfield Tan | 1da8628 | 2019-07-15 14:00:35 -0700 | [diff] [blame] | 888 | { "nativeGetXCursorPosition", |
| 889 | "(J)F", |
| 890 | (void*)android_view_MotionEvent_nativeGetXCursorPosition }, |
| 891 | { "nativeGetYCursorPosition", |
| 892 | "(J)F", |
| 893 | (void*)android_view_MotionEvent_nativeGetYCursorPosition }, |
| 894 | { "nativeSetCursorPosition", |
| 895 | "(JFF)V", |
| 896 | (void*)android_view_MotionEvent_nativeSetCursorPosition }, |
John Reck | 0970997 | 2016-10-03 15:47:18 -0700 | [diff] [blame] | 897 | { "nativeGetDownTimeNanos", |
| 898 | "(J)J", |
| 899 | (void*)android_view_MotionEvent_nativeGetDownTimeNanos }, |
| 900 | { "nativeSetDownTimeNanos", |
| 901 | "(JJ)V", |
| 902 | (void*)android_view_MotionEvent_nativeSetDownTimeNanos }, |
| 903 | { "nativeGetPointerCount", |
| 904 | "(J)I", |
| 905 | (void*)android_view_MotionEvent_nativeGetPointerCount }, |
| 906 | { "nativeFindPointerIndex", |
| 907 | "(JI)I", |
| 908 | (void*)android_view_MotionEvent_nativeFindPointerIndex }, |
| 909 | { "nativeGetHistorySize", |
| 910 | "(J)I", |
| 911 | (void*)android_view_MotionEvent_nativeGetHistorySize }, |
| 912 | { "nativeScale", |
| 913 | "(JF)V", |
| 914 | (void*)android_view_MotionEvent_nativeScale }, |
| 915 | { "nativeTransform", |
| 916 | "(JJ)V", |
| 917 | (void*)android_view_MotionEvent_nativeTransform }, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 918 | }; |
| 919 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 920 | int register_android_view_MotionEvent(JNIEnv* env) { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 921 | int res = RegisterMethodsOrDie(env, "android/view/MotionEvent", gMotionEventMethods, |
| 922 | NELEM(gMotionEventMethods)); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 923 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 924 | gMotionEventClassInfo.clazz = FindClassOrDie(env, "android/view/MotionEvent"); |
| 925 | gMotionEventClassInfo.clazz = MakeGlobalRefOrDie(env, gMotionEventClassInfo.clazz); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 926 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 927 | gMotionEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 928 | "obtain", "()Landroid/view/MotionEvent;"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 929 | gMotionEventClassInfo.recycle = GetMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 930 | "recycle", "()V"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 931 | gMotionEventClassInfo.mNativePtr = GetFieldIDOrDie(env, gMotionEventClassInfo.clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 932 | "mNativePtr", "J"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 933 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 934 | jclass clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerCoords"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 935 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 936 | gPointerCoordsClassInfo.mPackedAxisBits = GetFieldIDOrDie(env, clazz, "mPackedAxisBits", "J"); |
| 937 | gPointerCoordsClassInfo.mPackedAxisValues = GetFieldIDOrDie(env, clazz, "mPackedAxisValues", |
| 938 | "[F"); |
| 939 | gPointerCoordsClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "F"); |
| 940 | gPointerCoordsClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "F"); |
| 941 | gPointerCoordsClassInfo.pressure = GetFieldIDOrDie(env, clazz, "pressure", "F"); |
| 942 | gPointerCoordsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "F"); |
| 943 | gPointerCoordsClassInfo.touchMajor = GetFieldIDOrDie(env, clazz, "touchMajor", "F"); |
| 944 | gPointerCoordsClassInfo.touchMinor = GetFieldIDOrDie(env, clazz, "touchMinor", "F"); |
| 945 | gPointerCoordsClassInfo.toolMajor = GetFieldIDOrDie(env, clazz, "toolMajor", "F"); |
| 946 | gPointerCoordsClassInfo.toolMinor = GetFieldIDOrDie(env, clazz, "toolMinor", "F"); |
| 947 | gPointerCoordsClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "F"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 948 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 949 | clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerProperties"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 950 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 951 | gPointerPropertiesClassInfo.id = GetFieldIDOrDie(env, clazz, "id", "I"); |
| 952 | gPointerPropertiesClassInfo.toolType = GetFieldIDOrDie(env, clazz, "toolType", "I"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 953 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 954 | return res; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | } // namespace android |