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 | |
| 19 | #include "JNIHelp.h" |
| 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> |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 26 | #include <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, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 336 | jint deviceId, jint source, jint action, jint flags, jint edgeFlags, |
| 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 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 348 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 349 | if (!event) { |
| 350 | event = new MotionEvent(); |
| 351 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 352 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 353 | PointerProperties pointerProperties[pointerCount]; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 354 | PointerCoords rawPointerCoords[pointerCount]; |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 355 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 356 | for (jint i = 0; i < pointerCount; i++) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 357 | jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i); |
| 358 | if (!pointerPropertiesObj) { |
| 359 | goto Error; |
| 360 | } |
| 361 | pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]); |
| 362 | env->DeleteLocalRef(pointerPropertiesObj); |
| 363 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 364 | jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i); |
| 365 | if (!pointerCoordsObj) { |
| 366 | jniThrowNullPointerException(env, "pointerCoords"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 367 | goto Error; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 368 | } |
| 369 | pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]); |
| 370 | env->DeleteLocalRef(pointerCoordsObj); |
| 371 | } |
| 372 | |
Michael Wright | 7a629cc | 2015-06-10 14:57:33 +0100 | [diff] [blame] | 373 | event->initialize(deviceId, source, action, 0, flags, edgeFlags, metaState, buttonState, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 374 | xOffset, yOffset, xPrecision, yPrecision, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 375 | downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, rawPointerCoords); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 376 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 377 | return reinterpret_cast<jlong>(event); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 378 | |
| 379 | Error: |
| 380 | if (!nativePtr) { |
| 381 | delete event; |
| 382 | } |
| 383 | return 0; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 384 | } |
| 385 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 386 | static jlong android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz, |
| 387 | jlong destNativePtr, jlong sourceNativePtr, jboolean keepHistory) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 388 | MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr); |
| 389 | if (!destEvent) { |
| 390 | destEvent = new MotionEvent(); |
| 391 | } |
| 392 | MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr); |
| 393 | destEvent->copyFrom(sourceEvent, keepHistory); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 394 | return reinterpret_cast<jlong>(destEvent); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static void android_view_MotionEvent_nativeDispose(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 398 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 399 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 400 | delete event; |
| 401 | } |
| 402 | |
| 403 | static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 404 | jlong nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 405 | jint metaState) { |
| 406 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 407 | size_t pointerCount = event->getPointerCount(); |
| 408 | if (!validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) { |
| 409 | return; |
| 410 | } |
| 411 | |
| 412 | PointerCoords rawPointerCoords[pointerCount]; |
| 413 | |
| 414 | for (size_t i = 0; i < pointerCount; i++) { |
| 415 | jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i); |
| 416 | if (!pointerCoordsObj) { |
| 417 | jniThrowNullPointerException(env, "pointerCoords"); |
| 418 | return; |
| 419 | } |
| 420 | pointerCoordsToNative(env, pointerCoordsObj, |
| 421 | event->getXOffset(), event->getYOffset(), &rawPointerCoords[i]); |
| 422 | env->DeleteLocalRef(pointerCoordsObj); |
| 423 | } |
| 424 | |
| 425 | event->addSample(eventTimeNanos, rawPointerCoords); |
| 426 | event->setMetaState(event->getMetaState() | metaState); |
| 427 | } |
| 428 | |
| 429 | static jint android_view_MotionEvent_nativeGetDeviceId(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 430 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 431 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 432 | return event->getDeviceId(); |
| 433 | } |
| 434 | |
| 435 | static jint android_view_MotionEvent_nativeGetSource(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 436 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 437 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 438 | return event->getSource(); |
| 439 | } |
| 440 | |
| 441 | static void android_view_MotionEvent_nativeSetSource(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 442 | jlong nativePtr, jint source) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 443 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 444 | event->setSource(source); |
| 445 | } |
| 446 | |
| 447 | static jint android_view_MotionEvent_nativeGetAction(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 448 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 449 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 450 | return event->getAction(); |
| 451 | } |
| 452 | |
| 453 | static void android_view_MotionEvent_nativeSetAction(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 454 | jlong nativePtr, jint action) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 455 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 456 | event->setAction(action); |
| 457 | } |
| 458 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 459 | static int android_view_MotionEvent_nativeGetActionButton(JNIEnv* env, jclass clazz, |
| 460 | jlong nativePtr) { |
| 461 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 462 | return event->getActionButton(); |
| 463 | } |
| 464 | |
Michael Wright | 6b819b4 | 2015-06-17 21:06:03 +0100 | [diff] [blame] | 465 | static void android_view_MotionEvent_nativeSetActionButton(JNIEnv* env, jclass clazz, |
| 466 | jlong nativePtr, jint button) { |
| 467 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 468 | event->setActionButton(button); |
| 469 | } |
| 470 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 471 | static jboolean android_view_MotionEvent_nativeIsTouchEvent(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 472 | jlong nativePtr) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 473 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 474 | return event->isTouchEvent(); |
| 475 | } |
| 476 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 477 | static jint android_view_MotionEvent_nativeGetFlags(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 478 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 479 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 480 | return event->getFlags(); |
| 481 | } |
| 482 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 483 | static void android_view_MotionEvent_nativeSetFlags(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 484 | jlong nativePtr, jint flags) { |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 485 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 486 | event->setFlags(flags); |
| 487 | } |
| 488 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 489 | static jint android_view_MotionEvent_nativeGetEdgeFlags(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 490 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 491 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 492 | return event->getEdgeFlags(); |
| 493 | } |
| 494 | |
| 495 | static void android_view_MotionEvent_nativeSetEdgeFlags(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 496 | jlong nativePtr, jint edgeFlags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 497 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 498 | event->setEdgeFlags(edgeFlags); |
| 499 | } |
| 500 | |
| 501 | static jint android_view_MotionEvent_nativeGetMetaState(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 502 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 503 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 504 | return event->getMetaState(); |
| 505 | } |
| 506 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 507 | static jint android_view_MotionEvent_nativeGetButtonState(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 508 | jlong nativePtr) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 509 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 510 | return event->getButtonState(); |
| 511 | } |
| 512 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 513 | static void android_view_MotionEvent_nativeSetButtonState(JNIEnv* env, jclass clazz, |
| 514 | jlong nativePtr, jint buttonState) { |
| 515 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 516 | event->setButtonState(buttonState); |
| 517 | } |
| 518 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 519 | static void android_view_MotionEvent_nativeOffsetLocation(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 520 | jlong nativePtr, jfloat deltaX, jfloat deltaY) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 521 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 522 | return event->offsetLocation(deltaX, deltaY); |
| 523 | } |
| 524 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 525 | static jfloat android_view_MotionEvent_nativeGetXOffset(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 526 | jlong nativePtr) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 527 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 528 | return event->getXOffset(); |
| 529 | } |
| 530 | |
| 531 | static jfloat android_view_MotionEvent_nativeGetYOffset(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 532 | jlong nativePtr) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 533 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 534 | return event->getYOffset(); |
| 535 | } |
| 536 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 537 | static jfloat android_view_MotionEvent_nativeGetXPrecision(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 538 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 539 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 540 | return event->getXPrecision(); |
| 541 | } |
| 542 | |
| 543 | static jfloat android_view_MotionEvent_nativeGetYPrecision(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 544 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 545 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 546 | return event->getYPrecision(); |
| 547 | } |
| 548 | |
| 549 | static jlong android_view_MotionEvent_nativeGetDownTimeNanos(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 550 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 551 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 552 | return event->getDownTime(); |
| 553 | } |
| 554 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 555 | static void android_view_MotionEvent_nativeSetDownTimeNanos(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 556 | jlong nativePtr, jlong downTimeNanos) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 557 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 558 | event->setDownTime(downTimeNanos); |
| 559 | } |
| 560 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 561 | static jint android_view_MotionEvent_nativeGetPointerCount(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 562 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 563 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 564 | return jint(event->getPointerCount()); |
| 565 | } |
| 566 | |
| 567 | static jint android_view_MotionEvent_nativeGetPointerId(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 568 | jlong nativePtr, jint pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 569 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 570 | size_t pointerCount = event->getPointerCount(); |
| 571 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 572 | return -1; |
| 573 | } |
| 574 | return event->getPointerId(pointerIndex); |
| 575 | } |
| 576 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 577 | static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 578 | jlong nativePtr, jint pointerIndex) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 579 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 580 | size_t pointerCount = event->getPointerCount(); |
| 581 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 582 | return -1; |
| 583 | } |
| 584 | return event->getToolType(pointerIndex); |
| 585 | } |
| 586 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 587 | static jint android_view_MotionEvent_nativeFindPointerIndex(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 588 | jlong nativePtr, jint pointerId) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 589 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
Jeff Brown | 2ed2462 | 2011-03-14 19:39:54 -0700 | [diff] [blame] | 590 | return jint(event->findPointerIndex(pointerId)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static jint android_view_MotionEvent_nativeGetHistorySize(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 594 | jlong nativePtr) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 595 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 596 | return jint(event->getHistorySize()); |
| 597 | } |
| 598 | |
| 599 | static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 600 | jlong nativePtr, jint historyPos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 601 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 602 | if (historyPos == HISTORY_CURRENT) { |
| 603 | return event->getEventTime(); |
| 604 | } else { |
| 605 | size_t historySize = event->getHistorySize(); |
| 606 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 607 | return 0; |
| 608 | } |
| 609 | return event->getHistoricalEventTime(historyPos); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | static jfloat android_view_MotionEvent_nativeGetRawAxisValue(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 614 | jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 615 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 616 | size_t pointerCount = event->getPointerCount(); |
| 617 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | if (historyPos == HISTORY_CURRENT) { |
| 622 | return event->getRawAxisValue(axis, pointerIndex); |
| 623 | } else { |
| 624 | size_t historySize = event->getHistorySize(); |
| 625 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 626 | return 0; |
| 627 | } |
| 628 | return event->getHistoricalRawAxisValue(axis, pointerIndex, historyPos); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 633 | jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 634 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 635 | size_t pointerCount = event->getPointerCount(); |
| 636 | if (!validatePointerIndex(env, pointerIndex, pointerCount)) { |
| 637 | return 0; |
| 638 | } |
| 639 | |
| 640 | if (historyPos == HISTORY_CURRENT) { |
| 641 | return event->getAxisValue(axis, pointerIndex); |
| 642 | } else { |
| 643 | size_t historySize = event->getHistorySize(); |
| 644 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 645 | return 0; |
| 646 | } |
| 647 | return event->getHistoricalAxisValue(axis, pointerIndex, historyPos); |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 652 | jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 653 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 654 | size_t pointerCount = event->getPointerCount(); |
| 655 | if (!validatePointerIndex(env, pointerIndex, pointerCount) |
| 656 | || !validatePointerCoords(env, outPointerCoordsObj)) { |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | const PointerCoords* rawPointerCoords; |
| 661 | if (historyPos == HISTORY_CURRENT) { |
| 662 | rawPointerCoords = event->getRawPointerCoords(pointerIndex); |
| 663 | } else { |
| 664 | size_t historySize = event->getHistorySize(); |
| 665 | if (!validateHistoryPos(env, historyPos, historySize)) { |
| 666 | return; |
| 667 | } |
| 668 | rawPointerCoords = event->getHistoricalRawPointerCoords(pointerIndex, historyPos); |
| 669 | } |
| 670 | pointerCoordsFromNative(env, rawPointerCoords, event->getXOffset(), event->getYOffset(), |
| 671 | outPointerCoordsObj); |
| 672 | } |
| 673 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 674 | static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 675 | jlong nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 676 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 677 | size_t pointerCount = event->getPointerCount(); |
| 678 | if (!validatePointerIndex(env, pointerIndex, pointerCount) |
| 679 | || !validatePointerProperties(env, outPointerPropertiesObj)) { |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | const PointerProperties* pointerProperties = event->getPointerProperties(pointerIndex); |
| 684 | pointerPropertiesFromNative(env, pointerProperties, outPointerPropertiesObj); |
| 685 | } |
| 686 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 687 | static void android_view_MotionEvent_nativeScale(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 688 | jlong nativePtr, jfloat scale) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 689 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 690 | event->scale(scale); |
| 691 | } |
| 692 | |
| 693 | static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 694 | jlong nativePtr, jobject matrixObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 695 | SkMatrix* matrix = android_graphics_Matrix_getSkMatrix(env, matrixObj); |
| 696 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
Jeff Brown | 1109328 | 2013-07-15 18:05:59 -0700 | [diff] [blame] | 697 | |
| 698 | float m[9]; |
| 699 | m[0] = SkScalarToFloat(matrix->get(SkMatrix::kMScaleX)); |
| 700 | m[1] = SkScalarToFloat(matrix->get(SkMatrix::kMSkewX)); |
| 701 | m[2] = SkScalarToFloat(matrix->get(SkMatrix::kMTransX)); |
| 702 | m[3] = SkScalarToFloat(matrix->get(SkMatrix::kMSkewY)); |
| 703 | m[4] = SkScalarToFloat(matrix->get(SkMatrix::kMScaleY)); |
| 704 | m[5] = SkScalarToFloat(matrix->get(SkMatrix::kMTransY)); |
| 705 | m[6] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp0)); |
| 706 | m[7] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp1)); |
| 707 | m[8] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp2)); |
| 708 | event->transform(m); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 709 | } |
| 710 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 711 | static jlong android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz, |
| 712 | jlong nativePtr, jobject parcelObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 713 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 714 | if (!event) { |
| 715 | event = new MotionEvent(); |
| 716 | } |
| 717 | |
| 718 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 719 | |
| 720 | status_t status = event->readFromParcel(parcel); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 721 | if (status) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 722 | if (!nativePtr) { |
| 723 | delete event; |
| 724 | } |
| 725 | jniThrowRuntimeException(env, "Failed to read MotionEvent parcel."); |
| 726 | return 0; |
| 727 | } |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 728 | return reinterpret_cast<jlong>(event); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 732 | jlong nativePtr, jobject parcelObj) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 733 | MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr); |
| 734 | Parcel* parcel = parcelForJavaObject(env, parcelObj); |
| 735 | |
| 736 | status_t status = event->writeToParcel(parcel); |
Jeff Brown | ebbd5d1 | 2011-02-17 13:01:34 -0800 | [diff] [blame] | 737 | if (status) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 738 | jniThrowRuntimeException(env, "Failed to write MotionEvent parcel."); |
| 739 | } |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 742 | static jstring android_view_MotionEvent_nativeAxisToString(JNIEnv* env, jclass clazz, |
| 743 | jint axis) { |
| 744 | return env->NewStringUTF(MotionEvent::getLabel(static_cast<int32_t>(axis))); |
| 745 | } |
| 746 | |
| 747 | static jint android_view_MotionEvent_nativeAxisFromString(JNIEnv* env, jclass clazz, |
| 748 | jstring label) { |
| 749 | ScopedUtfChars axisLabel(env, label); |
| 750 | return static_cast<jint>(MotionEvent::getAxisFromLabel(axisLabel.c_str())); |
| 751 | } |
| 752 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 753 | // ---------------------------------------------------------------------------- |
| 754 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 755 | static const JNINativeMethod gMotionEventMethods[] = { |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 756 | /* name, signature, funcPtr */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 757 | { "nativeInitialize", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 758 | "(JIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;" |
| 759 | "[Landroid/view/MotionEvent$PointerCoords;)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 760 | (void*)android_view_MotionEvent_nativeInitialize }, |
| 761 | { "nativeCopy", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 762 | "(JJZ)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 763 | (void*)android_view_MotionEvent_nativeCopy }, |
| 764 | { "nativeDispose", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 765 | "(J)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 766 | (void*)android_view_MotionEvent_nativeDispose }, |
| 767 | { "nativeAddBatch", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 768 | "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 769 | (void*)android_view_MotionEvent_nativeAddBatch }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 770 | { "nativeGetDeviceId", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 771 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 772 | (void*)android_view_MotionEvent_nativeGetDeviceId }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 773 | { "nativeGetSource", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 774 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 775 | (void*)android_view_MotionEvent_nativeGetSource }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 776 | { "nativeSetSource", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 777 | "!(JI)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 778 | (void*)android_view_MotionEvent_nativeSetSource }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 779 | { "nativeGetAction", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 780 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 781 | (void*)android_view_MotionEvent_nativeGetAction }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 782 | { "nativeSetAction", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 783 | "!(JI)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 784 | (void*)android_view_MotionEvent_nativeSetAction }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 785 | { "nativeGetActionButton", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 786 | "!(J)I", |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 787 | (void*)android_view_MotionEvent_nativeGetActionButton}, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 788 | { "nativeSetActionButton", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 789 | "!(JI)V", |
Michael Wright | 6b819b4 | 2015-06-17 21:06:03 +0100 | [diff] [blame] | 790 | (void*)android_view_MotionEvent_nativeSetActionButton}, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 791 | { "nativeIsTouchEvent", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 792 | "!(J)Z", |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 793 | (void*)android_view_MotionEvent_nativeIsTouchEvent }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 794 | { "nativeGetFlags", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 795 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 796 | (void*)android_view_MotionEvent_nativeGetFlags }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 797 | { "nativeSetFlags", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 798 | "!(JI)V", |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 799 | (void*)android_view_MotionEvent_nativeSetFlags }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 800 | { "nativeGetEdgeFlags", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 801 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 802 | (void*)android_view_MotionEvent_nativeGetEdgeFlags }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 803 | { "nativeSetEdgeFlags", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 804 | "!(JI)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 805 | (void*)android_view_MotionEvent_nativeSetEdgeFlags }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 806 | { "nativeGetMetaState", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 807 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 808 | (void*)android_view_MotionEvent_nativeGetMetaState }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 809 | { "nativeGetButtonState", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 810 | "!(J)I", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 811 | (void*)android_view_MotionEvent_nativeGetButtonState }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 812 | { "nativeSetButtonState", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 813 | "!(JI)V", |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 814 | (void*)android_view_MotionEvent_nativeSetButtonState }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 815 | { "nativeOffsetLocation", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 816 | "!(JFF)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 817 | (void*)android_view_MotionEvent_nativeOffsetLocation }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 818 | { "nativeGetXOffset", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 819 | "!(J)F", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 820 | (void*)android_view_MotionEvent_nativeGetXOffset }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 821 | { "nativeGetYOffset", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 822 | "!(J)F", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 823 | (void*)android_view_MotionEvent_nativeGetYOffset }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 824 | { "nativeGetXPrecision", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 825 | "!(J)F", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 826 | (void*)android_view_MotionEvent_nativeGetXPrecision }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 827 | { "nativeGetYPrecision", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 828 | "!(J)F", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 829 | (void*)android_view_MotionEvent_nativeGetYPrecision }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 830 | { "nativeGetDownTimeNanos", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 831 | "!(J)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 832 | (void*)android_view_MotionEvent_nativeGetDownTimeNanos }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 833 | { "nativeSetDownTimeNanos", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 834 | "!(JJ)V", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 835 | (void*)android_view_MotionEvent_nativeSetDownTimeNanos }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 836 | { "nativeGetPointerCount", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 837 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 838 | (void*)android_view_MotionEvent_nativeGetPointerCount }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 839 | { "nativeGetPointerId", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 840 | "!(JI)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 841 | (void*)android_view_MotionEvent_nativeGetPointerId }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 842 | { "nativeGetToolType", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 843 | "!(JI)I", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 844 | (void*)android_view_MotionEvent_nativeGetToolType }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 845 | { "nativeFindPointerIndex", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 846 | "!(JI)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 847 | (void*)android_view_MotionEvent_nativeFindPointerIndex }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 848 | { "nativeGetHistorySize", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 849 | "!(J)I", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 850 | (void*)android_view_MotionEvent_nativeGetHistorySize }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 851 | { "nativeGetEventTimeNanos", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 852 | "!(JI)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 853 | (void*)android_view_MotionEvent_nativeGetEventTimeNanos }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 854 | { "nativeGetRawAxisValue", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 855 | "!(JIII)F", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 856 | (void*)android_view_MotionEvent_nativeGetRawAxisValue }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 857 | { "nativeGetAxisValue", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 858 | "!(JIII)F", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 859 | (void*)android_view_MotionEvent_nativeGetAxisValue }, |
| 860 | { "nativeGetPointerCoords", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 861 | "(JIILandroid/view/MotionEvent$PointerCoords;)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 862 | (void*)android_view_MotionEvent_nativeGetPointerCoords }, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 863 | { "nativeGetPointerProperties", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 864 | "(JILandroid/view/MotionEvent$PointerProperties;)V", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 865 | (void*)android_view_MotionEvent_nativeGetPointerProperties }, |
Chris Craik | 526cf82 | 2015-10-16 17:42:57 +0000 | [diff] [blame] | 866 | { "nativeScale", |
Chris Craik | 0fc1065 | 2015-10-16 11:39:50 -0700 | [diff] [blame] | 867 | "!(JF)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 868 | (void*)android_view_MotionEvent_nativeScale }, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 869 | { "nativeTransform", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 870 | "(JLandroid/graphics/Matrix;)V", |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 871 | (void*)android_view_MotionEvent_nativeTransform }, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 872 | { "nativeReadFromParcel", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 873 | "(JLandroid/os/Parcel;)J", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 874 | (void*)android_view_MotionEvent_nativeReadFromParcel }, |
| 875 | { "nativeWriteToParcel", |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 876 | "(JLandroid/os/Parcel;)V", |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 877 | (void*)android_view_MotionEvent_nativeWriteToParcel }, |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 878 | { "nativeAxisToString", "(I)Ljava/lang/String;", |
| 879 | (void*)android_view_MotionEvent_nativeAxisToString }, |
| 880 | { "nativeAxisFromString", "(Ljava/lang/String;)I", |
| 881 | (void*)android_view_MotionEvent_nativeAxisFromString }, |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 882 | }; |
| 883 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 884 | int register_android_view_MotionEvent(JNIEnv* env) { |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 885 | int res = RegisterMethodsOrDie(env, "android/view/MotionEvent", gMotionEventMethods, |
| 886 | NELEM(gMotionEventMethods)); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 887 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 888 | gMotionEventClassInfo.clazz = FindClassOrDie(env, "android/view/MotionEvent"); |
| 889 | gMotionEventClassInfo.clazz = MakeGlobalRefOrDie(env, gMotionEventClassInfo.clazz); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 890 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 891 | gMotionEventClassInfo.obtain = GetStaticMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 892 | "obtain", "()Landroid/view/MotionEvent;"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 893 | gMotionEventClassInfo.recycle = GetMethodIDOrDie(env, gMotionEventClassInfo.clazz, |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 894 | "recycle", "()V"); |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 895 | gMotionEventClassInfo.mNativePtr = GetFieldIDOrDie(env, gMotionEventClassInfo.clazz, |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 896 | "mNativePtr", "J"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 897 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 898 | jclass clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerCoords"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 899 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 900 | gPointerCoordsClassInfo.mPackedAxisBits = GetFieldIDOrDie(env, clazz, "mPackedAxisBits", "J"); |
| 901 | gPointerCoordsClassInfo.mPackedAxisValues = GetFieldIDOrDie(env, clazz, "mPackedAxisValues", |
| 902 | "[F"); |
| 903 | gPointerCoordsClassInfo.x = GetFieldIDOrDie(env, clazz, "x", "F"); |
| 904 | gPointerCoordsClassInfo.y = GetFieldIDOrDie(env, clazz, "y", "F"); |
| 905 | gPointerCoordsClassInfo.pressure = GetFieldIDOrDie(env, clazz, "pressure", "F"); |
| 906 | gPointerCoordsClassInfo.size = GetFieldIDOrDie(env, clazz, "size", "F"); |
| 907 | gPointerCoordsClassInfo.touchMajor = GetFieldIDOrDie(env, clazz, "touchMajor", "F"); |
| 908 | gPointerCoordsClassInfo.touchMinor = GetFieldIDOrDie(env, clazz, "touchMinor", "F"); |
| 909 | gPointerCoordsClassInfo.toolMajor = GetFieldIDOrDie(env, clazz, "toolMajor", "F"); |
| 910 | gPointerCoordsClassInfo.toolMinor = GetFieldIDOrDie(env, clazz, "toolMinor", "F"); |
| 911 | gPointerCoordsClassInfo.orientation = GetFieldIDOrDie(env, clazz, "orientation", "F"); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 912 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 913 | clazz = FindClassOrDie(env, "android/view/MotionEvent$PointerProperties"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 914 | |
Andreas Gampe | 987f79f | 2014-11-18 17:29:46 -0800 | [diff] [blame] | 915 | gPointerPropertiesClassInfo.id = GetFieldIDOrDie(env, clazz, "id", "I"); |
| 916 | gPointerPropertiesClassInfo.toolType = GetFieldIDOrDie(env, clazz, "toolType", "I"); |
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 | return res; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | } // namespace android |