Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -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 | #include <stdio.h> |
| 18 | #include <assert.h> |
| 19 | |
| 20 | #include "jni.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 21 | #include "core_jni_helpers.h" |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 22 | #include <utils/misc.h> |
| 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // ---------------------------------------------------------------------------- |
| 29 | |
| 30 | const char* const kClassPathName = "android/animation/PropertyValuesHolder"; |
| 31 | |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 32 | static jlong android_animation_PropertyValuesHolder_getIntMethod( |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 33 | JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName) |
| 34 | { |
| 35 | const char *nativeString = env->GetStringUTFChars(methodName, 0); |
| 36 | jmethodID mid = env->GetMethodID(targetClass, nativeString, "(I)V"); |
| 37 | env->ReleaseStringUTFChars(methodName, nativeString); |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 38 | return reinterpret_cast<jlong>(mid); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 41 | static jlong android_animation_PropertyValuesHolder_getFloatMethod( |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 42 | JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName) |
| 43 | { |
| 44 | const char *nativeString = env->GetStringUTFChars(methodName, 0); |
| 45 | jmethodID mid = env->GetMethodID(targetClass, nativeString, "(F)V"); |
| 46 | env->ReleaseStringUTFChars(methodName, nativeString); |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 47 | return reinterpret_cast<jlong>(mid); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 50 | static jlong getMultiparameterMethod(JNIEnv* env, jclass targetClass, jstring methodName, |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 51 | jint parameterCount, char parameterType) |
| 52 | { |
| 53 | const char *nativeString = env->GetStringUTFChars(methodName, 0); |
| 54 | char *signature = new char[parameterCount + 4]; |
| 55 | signature[0] = '('; |
| 56 | memset(&(signature[1]), parameterType, parameterCount); |
| 57 | strcpy(&(signature[parameterCount + 1]), ")V"); |
| 58 | jmethodID mid = env->GetMethodID(targetClass, nativeString, signature); |
| 59 | delete[] signature; |
| 60 | env->ReleaseStringUTFChars(methodName, nativeString); |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 61 | return reinterpret_cast<jlong>(mid); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 64 | static jlong android_animation_PropertyValuesHolder_getMultipleFloatMethod( |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 65 | JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount) |
| 66 | { |
| 67 | return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'F'); |
| 68 | } |
| 69 | |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 70 | static jlong android_animation_PropertyValuesHolder_getMultipleIntMethod( |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 71 | JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount) |
| 72 | { |
| 73 | return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'I'); |
| 74 | } |
| 75 | |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 76 | static void android_animation_PropertyValuesHolder_callIntMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 77 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jint arg) |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 78 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 79 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void android_animation_PropertyValuesHolder_callFloatMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 83 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloat arg) |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 84 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 85 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 86 | } |
| 87 | |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 88 | static void android_animation_PropertyValuesHolder_callTwoFloatMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 89 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2) |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 90 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 91 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void android_animation_PropertyValuesHolder_callFourFloatMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 95 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2, |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 96 | float arg3, float arg4) |
| 97 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 98 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void android_animation_PropertyValuesHolder_callMultipleFloatMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 102 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloatArray arg) |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 103 | { |
| 104 | jsize parameterCount = env->GetArrayLength(arg); |
| 105 | jfloat *floatValues = env->GetFloatArrayElements(arg, NULL); |
| 106 | jvalue* values = new jvalue[parameterCount]; |
| 107 | for (int i = 0; i < parameterCount; i++) { |
| 108 | values[i].f = floatValues[i]; |
| 109 | } |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 110 | env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 111 | delete[] values; |
| 112 | env->ReleaseFloatArrayElements(arg, floatValues, JNI_ABORT); |
| 113 | } |
| 114 | |
| 115 | static void android_animation_PropertyValuesHolder_callTwoIntMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 116 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2) |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 117 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 118 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static void android_animation_PropertyValuesHolder_callFourIntMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 122 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2, |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 123 | int arg3, int arg4) |
| 124 | { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 125 | env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | static void android_animation_PropertyValuesHolder_callMultipleIntMethod( |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 129 | JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jintArray arg) |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 130 | { |
| 131 | jsize parameterCount = env->GetArrayLength(arg); |
| 132 | jint *intValues = env->GetIntArrayElements(arg, NULL); |
| 133 | jvalue* values = new jvalue[parameterCount]; |
| 134 | for (int i = 0; i < parameterCount; i++) { |
| 135 | values[i].i = intValues[i]; |
| 136 | } |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 137 | env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values); |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 138 | delete[] values; |
| 139 | env->ReleaseIntArrayElements(arg, intValues, JNI_ABORT); |
| 140 | } |
| 141 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 142 | static const JNINativeMethod gMethods[] = { |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 143 | { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)J", |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 144 | (void*)android_animation_PropertyValuesHolder_getIntMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 145 | { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)J", |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 146 | (void*)android_animation_PropertyValuesHolder_getFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 147 | { "nGetMultipleFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 148 | (void*)android_animation_PropertyValuesHolder_getMultipleFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 149 | { "nGetMultipleIntMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 150 | (void*)android_animation_PropertyValuesHolder_getMultipleIntMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 151 | { "nCallIntMethod", "(Ljava/lang/Object;JI)V", |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 152 | (void*)android_animation_PropertyValuesHolder_callIntMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 153 | { "nCallFloatMethod", "(Ljava/lang/Object;JF)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 154 | (void*)android_animation_PropertyValuesHolder_callFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 155 | { "nCallTwoFloatMethod", "(Ljava/lang/Object;JFF)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 156 | (void*)android_animation_PropertyValuesHolder_callTwoFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 157 | { "nCallFourFloatMethod", "(Ljava/lang/Object;JFFFF)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 158 | (void*)android_animation_PropertyValuesHolder_callFourFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 159 | { "nCallMultipleFloatMethod", "(Ljava/lang/Object;J[F)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 160 | (void*)android_animation_PropertyValuesHolder_callMultipleFloatMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 161 | { "nCallTwoIntMethod", "(Ljava/lang/Object;JII)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 162 | (void*)android_animation_PropertyValuesHolder_callTwoIntMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 163 | { "nCallFourIntMethod", "(Ljava/lang/Object;JIIII)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 164 | (void*)android_animation_PropertyValuesHolder_callFourIntMethod }, |
Ashok Bhat | fbb35fb | 2014-01-17 16:44:27 +0000 | [diff] [blame] | 165 | { "nCallMultipleIntMethod", "(Ljava/lang/Object;J[I)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame] | 166 | (void*)android_animation_PropertyValuesHolder_callMultipleIntMethod }, |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | int register_android_animation_PropertyValuesHolder(JNIEnv* env) |
| 170 | { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 171 | return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | }; |