blob: 73347ea5226f6b2d3e20e60ae26857f6b833bbfa [file] [log] [blame]
Chet Haase6e0ecb42010-11-03 19:41:18 -07001/*
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
26namespace android {
27
28// ----------------------------------------------------------------------------
29
30const char* const kClassPathName = "android/animation/PropertyValuesHolder";
31
32static 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
41static 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 Mount4eed5292013-08-30 13:56:01 -070050static 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
64static 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
70static 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 Haase6e0ecb42010-11-03 19:41:18 -070076static 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
82static 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 Mount4eed5292013-08-30 13:56:01 -070088static 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
94static 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
101static 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
115static 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
121static 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
128static 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 Haase6e0ecb42010-11-03 19:41:18 -0700142static 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 Mount4eed5292013-08-30 13:56:01 -0700147 { "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 Haase6e0ecb42010-11-03 19:41:18 -0700151 { "nCallIntMethod", "(Ljava/lang/Object;II)V",
152 (void*)android_animation_PropertyValuesHolder_callIntMethod },
153 { "nCallFloatMethod", "(Ljava/lang/Object;IF)V",
George Mount4eed5292013-08-30 13:56:01 -0700154 (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 Haase6e0ecb42010-11-03 19:41:18 -0700167};
168
169int register_android_animation_PropertyValuesHolder(JNIEnv* env)
170{
171 return AndroidRuntime::registerNativeMethods(env,
172 kClassPathName, gMethods, NELEM(gMethods));
173}
174
175};