2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <android_runtime/AndroidRuntime.h>
22 #include <utils/misc.h>
24 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
30 const char* const kClassPathName = "android/animation/PropertyValuesHolder";
32 static jlong android_animation_PropertyValuesHolder_getIntMethod(
33 JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName)
35 const char *nativeString = env->GetStringUTFChars(methodName, 0);
36 jmethodID mid = env->GetMethodID(targetClass, nativeString, "(I)V");
37 env->ReleaseStringUTFChars(methodName, nativeString);
38 return reinterpret_cast<jlong>(mid);
41 static jlong android_animation_PropertyValuesHolder_getFloatMethod(
42 JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName)
44 const char *nativeString = env->GetStringUTFChars(methodName, 0);
45 jmethodID mid = env->GetMethodID(targetClass, nativeString, "(F)V");
46 env->ReleaseStringUTFChars(methodName, nativeString);
47 return reinterpret_cast<jlong>(mid);
50 static jlong getMultiparameterMethod(JNIEnv* env, jclass targetClass, jstring methodName,
51 jint parameterCount, char parameterType)
53 const char *nativeString = env->GetStringUTFChars(methodName, 0);
54 char *signature = new char[parameterCount + 4];
56 memset(&(signature[1]), parameterType, parameterCount);
57 strcpy(&(signature[parameterCount + 1]), ")V");
58 jmethodID mid = env->GetMethodID(targetClass, nativeString, signature);
60 env->ReleaseStringUTFChars(methodName, nativeString);
61 return reinterpret_cast<jlong>(mid);
64 static jlong android_animation_PropertyValuesHolder_getMultipleFloatMethod(
65 JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount)
67 return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'F');
70 static jlong android_animation_PropertyValuesHolder_getMultipleIntMethod(
71 JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount)
73 return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'I');
76 static void android_animation_PropertyValuesHolder_callIntMethod(
77 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jint arg)
79 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg);
82 static void android_animation_PropertyValuesHolder_callFloatMethod(
83 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloat arg)
85 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg);
88 static void android_animation_PropertyValuesHolder_callTwoFloatMethod(
89 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2)
91 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2);
94 static void android_animation_PropertyValuesHolder_callFourFloatMethod(
95 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2,
96 float arg3, float arg4)
98 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4);
101 static void android_animation_PropertyValuesHolder_callMultipleFloatMethod(
102 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloatArray arg)
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];
110 env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values);
112 env->ReleaseFloatArrayElements(arg, floatValues, JNI_ABORT);
115 static void android_animation_PropertyValuesHolder_callTwoIntMethod(
116 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2)
118 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2);
121 static void android_animation_PropertyValuesHolder_callFourIntMethod(
122 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2,
125 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4);
128 static void android_animation_PropertyValuesHolder_callMultipleIntMethod(
129 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jintArray arg)
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];
137 env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values);
139 env->ReleaseIntArrayElements(arg, intValues, JNI_ABORT);
142 static JNINativeMethod gMethods[] = {
143 { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)J",
144 (void*)android_animation_PropertyValuesHolder_getIntMethod },
145 { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)J",
146 (void*)android_animation_PropertyValuesHolder_getFloatMethod },
147 { "nGetMultipleFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J",
148 (void*)android_animation_PropertyValuesHolder_getMultipleFloatMethod },
149 { "nGetMultipleIntMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J",
150 (void*)android_animation_PropertyValuesHolder_getMultipleIntMethod },
151 { "nCallIntMethod", "(Ljava/lang/Object;JI)V",
152 (void*)android_animation_PropertyValuesHolder_callIntMethod },
153 { "nCallFloatMethod", "(Ljava/lang/Object;JF)V",
154 (void*)android_animation_PropertyValuesHolder_callFloatMethod },
155 { "nCallTwoFloatMethod", "(Ljava/lang/Object;JFF)V",
156 (void*)android_animation_PropertyValuesHolder_callTwoFloatMethod },
157 { "nCallFourFloatMethod", "(Ljava/lang/Object;JFFFF)V",
158 (void*)android_animation_PropertyValuesHolder_callFourFloatMethod },
159 { "nCallMultipleFloatMethod", "(Ljava/lang/Object;J[F)V",
160 (void*)android_animation_PropertyValuesHolder_callMultipleFloatMethod },
161 { "nCallTwoIntMethod", "(Ljava/lang/Object;JII)V",
162 (void*)android_animation_PropertyValuesHolder_callTwoIntMethod },
163 { "nCallFourIntMethod", "(Ljava/lang/Object;JIIII)V",
164 (void*)android_animation_PropertyValuesHolder_callFourIntMethod },
165 { "nCallMultipleIntMethod", "(Ljava/lang/Object;J[I)V",
166 (void*)android_animation_PropertyValuesHolder_callMultipleIntMethod },
169 int register_android_animation_PropertyValuesHolder(JNIEnv* env)
171 return AndroidRuntime::registerNativeMethods(env,
172 kClassPathName, gMethods, NELEM(gMethods));