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" |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | #include <utils/misc.h> |
| 23 | |
| 24 | // ---------------------------------------------------------------------------- |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // ---------------------------------------------------------------------------- |
| 29 | |
| 30 | const char* const kClassPathName = "android/animation/PropertyValuesHolder"; |
| 31 | |
| 32 | static jmethodID android_animation_PropertyValuesHolder_getIntMethod( |
| 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); |
| 38 | return mid; |
| 39 | } |
| 40 | |
| 41 | static jmethodID android_animation_PropertyValuesHolder_getFloatMethod( |
| 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); |
| 47 | return mid; |
| 48 | } |
| 49 | |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame^] | 50 | static jmethodID getMultiparameterMethod(JNIEnv* env, jclass targetClass, jstring methodName, |
| 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); |
| 61 | return mid; |
| 62 | } |
| 63 | |
| 64 | static jmethodID android_animation_PropertyValuesHolder_getMultipleFloatMethod( |
| 65 | JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount) |
| 66 | { |
| 67 | return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'F'); |
| 68 | } |
| 69 | |
| 70 | static jmethodID android_animation_PropertyValuesHolder_getMultipleIntMethod( |
| 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( |
| 77 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, int arg) |
| 78 | { |
| 79 | env->CallVoidMethod(target, methodID, arg); |
| 80 | } |
| 81 | |
| 82 | static void android_animation_PropertyValuesHolder_callFloatMethod( |
| 83 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, float arg) |
| 84 | { |
| 85 | env->CallVoidMethod(target, methodID, arg); |
| 86 | } |
| 87 | |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame^] | 88 | static void android_animation_PropertyValuesHolder_callTwoFloatMethod( |
| 89 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, float arg1, float arg2) |
| 90 | { |
| 91 | env->CallVoidMethod(target, methodID, arg1, arg2); |
| 92 | } |
| 93 | |
| 94 | static void android_animation_PropertyValuesHolder_callFourFloatMethod( |
| 95 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, float arg1, float arg2, |
| 96 | float arg3, float arg4) |
| 97 | { |
| 98 | env->CallVoidMethod(target, methodID, arg1, arg2, arg3, arg4); |
| 99 | } |
| 100 | |
| 101 | static void android_animation_PropertyValuesHolder_callMultipleFloatMethod( |
| 102 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, jfloatArray arg) |
| 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 | } |
| 110 | env->CallVoidMethodA(target, methodID, values); |
| 111 | delete[] values; |
| 112 | env->ReleaseFloatArrayElements(arg, floatValues, JNI_ABORT); |
| 113 | } |
| 114 | |
| 115 | static void android_animation_PropertyValuesHolder_callTwoIntMethod( |
| 116 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, int arg1, int arg2) |
| 117 | { |
| 118 | env->CallVoidMethod(target, methodID, arg1, arg2); |
| 119 | } |
| 120 | |
| 121 | static void android_animation_PropertyValuesHolder_callFourIntMethod( |
| 122 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, int arg1, int arg2, |
| 123 | int arg3, int arg4) |
| 124 | { |
| 125 | env->CallVoidMethod(target, methodID, arg1, arg2, arg3, arg4); |
| 126 | } |
| 127 | |
| 128 | static void android_animation_PropertyValuesHolder_callMultipleIntMethod( |
| 129 | JNIEnv* env, jclass pvhObject, jobject target, jmethodID methodID, jintArray arg) |
| 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 | } |
| 137 | env->CallVoidMethodA(target, methodID, values); |
| 138 | delete[] values; |
| 139 | env->ReleaseIntArrayElements(arg, intValues, JNI_ABORT); |
| 140 | } |
| 141 | |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 142 | static JNINativeMethod gMethods[] = { |
| 143 | { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)I", |
| 144 | (void*)android_animation_PropertyValuesHolder_getIntMethod }, |
| 145 | { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)I", |
| 146 | (void*)android_animation_PropertyValuesHolder_getFloatMethod }, |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame^] | 147 | { "nGetMultipleFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;I)I", |
| 148 | (void*)android_animation_PropertyValuesHolder_getMultipleFloatMethod }, |
| 149 | { "nGetMultipleIntMethod", "(Ljava/lang/Class;Ljava/lang/String;I)I", |
| 150 | (void*)android_animation_PropertyValuesHolder_getMultipleIntMethod }, |
Chet Haase | 6e0ecb4 | 2010-11-03 19:41:18 -0700 | [diff] [blame] | 151 | { "nCallIntMethod", "(Ljava/lang/Object;II)V", |
| 152 | (void*)android_animation_PropertyValuesHolder_callIntMethod }, |
| 153 | { "nCallFloatMethod", "(Ljava/lang/Object;IF)V", |
George Mount | 4eed529 | 2013-08-30 13:56:01 -0700 | [diff] [blame^] | 154 | (void*)android_animation_PropertyValuesHolder_callFloatMethod }, |
| 155 | { "nCallTwoFloatMethod", "(Ljava/lang/Object;IFF)V", |
| 156 | (void*)android_animation_PropertyValuesHolder_callTwoFloatMethod }, |
| 157 | { "nCallFourFloatMethod", "(Ljava/lang/Object;IFFFF)V", |
| 158 | (void*)android_animation_PropertyValuesHolder_callFourFloatMethod }, |
| 159 | { "nCallMultipleFloatMethod", "(Ljava/lang/Object;I[F)V", |
| 160 | (void*)android_animation_PropertyValuesHolder_callMultipleFloatMethod }, |
| 161 | { "nCallTwoIntMethod", "(Ljava/lang/Object;III)V", |
| 162 | (void*)android_animation_PropertyValuesHolder_callTwoIntMethod }, |
| 163 | { "nCallFourIntMethod", "(Ljava/lang/Object;IIIII)V", |
| 164 | (void*)android_animation_PropertyValuesHolder_callFourIntMethod }, |
| 165 | { "nCallMultipleIntMethod", "(Ljava/lang/Object;I[I)V", |
| 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 | { |
| 171 | return AndroidRuntime::registerNativeMethods(env, |
| 172 | kClassPathName, gMethods, NELEM(gMethods)); |
| 173 | } |
| 174 | |
| 175 | }; |