blob: d11774189901d1cc8db1e2bda77a8238147205f8 [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"
Andreas Gampeed6b9df2014-11-20 22:02:20 -080021#include "core_jni_helpers.h"
Chet Haase6e0ecb42010-11-03 19:41:18 -070022#include <utils/misc.h>
23
24// ----------------------------------------------------------------------------
25
26namespace android {
27
28// ----------------------------------------------------------------------------
29
30const char* const kClassPathName = "android/animation/PropertyValuesHolder";
31
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000032static jlong android_animation_PropertyValuesHolder_getIntMethod(
Chet Haase6e0ecb42010-11-03 19:41:18 -070033 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 Bhatfbb35fb2014-01-17 16:44:27 +000038 return reinterpret_cast<jlong>(mid);
Chet Haase6e0ecb42010-11-03 19:41:18 -070039}
40
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000041static jlong android_animation_PropertyValuesHolder_getFloatMethod(
Chet Haase6e0ecb42010-11-03 19:41:18 -070042 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 Bhatfbb35fb2014-01-17 16:44:27 +000047 return reinterpret_cast<jlong>(mid);
Chet Haase6e0ecb42010-11-03 19:41:18 -070048}
49
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000050static jlong getMultiparameterMethod(JNIEnv* env, jclass targetClass, jstring methodName,
George Mount4eed5292013-08-30 13:56:01 -070051 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 Bhatfbb35fb2014-01-17 16:44:27 +000061 return reinterpret_cast<jlong>(mid);
George Mount4eed5292013-08-30 13:56:01 -070062}
63
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000064static jlong android_animation_PropertyValuesHolder_getMultipleFloatMethod(
George Mount4eed5292013-08-30 13:56:01 -070065 JNIEnv* env, jclass pvhClass, jclass targetClass, jstring methodName, jint parameterCount)
66{
67 return getMultiparameterMethod(env, targetClass, methodName, parameterCount, 'F');
68}
69
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000070static jlong android_animation_PropertyValuesHolder_getMultipleIntMethod(
George Mount4eed5292013-08-30 13:56:01 -070071 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(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000077 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jint arg)
Chet Haase6e0ecb42010-11-03 19:41:18 -070078{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000079 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg);
Chet Haase6e0ecb42010-11-03 19:41:18 -070080}
81
82static void android_animation_PropertyValuesHolder_callFloatMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000083 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloat arg)
Chet Haase6e0ecb42010-11-03 19:41:18 -070084{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000085 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg);
Chet Haase6e0ecb42010-11-03 19:41:18 -070086}
87
George Mount4eed5292013-08-30 13:56:01 -070088static void android_animation_PropertyValuesHolder_callTwoFloatMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000089 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2)
George Mount4eed5292013-08-30 13:56:01 -070090{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000091 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2);
George Mount4eed5292013-08-30 13:56:01 -070092}
93
94static void android_animation_PropertyValuesHolder_callFourFloatMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000095 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, float arg1, float arg2,
George Mount4eed5292013-08-30 13:56:01 -070096 float arg3, float arg4)
97{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +000098 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4);
George Mount4eed5292013-08-30 13:56:01 -070099}
100
101static void android_animation_PropertyValuesHolder_callMultipleFloatMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000102 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jfloatArray arg)
George Mount4eed5292013-08-30 13:56:01 -0700103{
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 Bhatfbb35fb2014-01-17 16:44:27 +0000110 env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values);
George Mount4eed5292013-08-30 13:56:01 -0700111 delete[] values;
112 env->ReleaseFloatArrayElements(arg, floatValues, JNI_ABORT);
113}
114
115static void android_animation_PropertyValuesHolder_callTwoIntMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000116 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2)
George Mount4eed5292013-08-30 13:56:01 -0700117{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000118 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2);
George Mount4eed5292013-08-30 13:56:01 -0700119}
120
121static void android_animation_PropertyValuesHolder_callFourIntMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000122 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, int arg1, int arg2,
George Mount4eed5292013-08-30 13:56:01 -0700123 int arg3, int arg4)
124{
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000125 env->CallVoidMethod(target, reinterpret_cast<jmethodID>(methodID), arg1, arg2, arg3, arg4);
George Mount4eed5292013-08-30 13:56:01 -0700126}
127
128static void android_animation_PropertyValuesHolder_callMultipleIntMethod(
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000129 JNIEnv* env, jclass pvhObject, jobject target, jlong methodID, jintArray arg)
George Mount4eed5292013-08-30 13:56:01 -0700130{
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 Bhatfbb35fb2014-01-17 16:44:27 +0000137 env->CallVoidMethodA(target, reinterpret_cast<jmethodID>(methodID), values);
George Mount4eed5292013-08-30 13:56:01 -0700138 delete[] values;
139 env->ReleaseIntArrayElements(arg, intValues, JNI_ABORT);
140}
141
Chet Haase6e0ecb42010-11-03 19:41:18 -0700142static JNINativeMethod gMethods[] = {
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000143 { "nGetIntMethod", "(Ljava/lang/Class;Ljava/lang/String;)J",
Chet Haase6e0ecb42010-11-03 19:41:18 -0700144 (void*)android_animation_PropertyValuesHolder_getIntMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000145 { "nGetFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;)J",
Chet Haase6e0ecb42010-11-03 19:41:18 -0700146 (void*)android_animation_PropertyValuesHolder_getFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000147 { "nGetMultipleFloatMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J",
George Mount4eed5292013-08-30 13:56:01 -0700148 (void*)android_animation_PropertyValuesHolder_getMultipleFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000149 { "nGetMultipleIntMethod", "(Ljava/lang/Class;Ljava/lang/String;I)J",
George Mount4eed5292013-08-30 13:56:01 -0700150 (void*)android_animation_PropertyValuesHolder_getMultipleIntMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000151 { "nCallIntMethod", "(Ljava/lang/Object;JI)V",
Chet Haase6e0ecb42010-11-03 19:41:18 -0700152 (void*)android_animation_PropertyValuesHolder_callIntMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000153 { "nCallFloatMethod", "(Ljava/lang/Object;JF)V",
George Mount4eed5292013-08-30 13:56:01 -0700154 (void*)android_animation_PropertyValuesHolder_callFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000155 { "nCallTwoFloatMethod", "(Ljava/lang/Object;JFF)V",
George Mount4eed5292013-08-30 13:56:01 -0700156 (void*)android_animation_PropertyValuesHolder_callTwoFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000157 { "nCallFourFloatMethod", "(Ljava/lang/Object;JFFFF)V",
George Mount4eed5292013-08-30 13:56:01 -0700158 (void*)android_animation_PropertyValuesHolder_callFourFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000159 { "nCallMultipleFloatMethod", "(Ljava/lang/Object;J[F)V",
George Mount4eed5292013-08-30 13:56:01 -0700160 (void*)android_animation_PropertyValuesHolder_callMultipleFloatMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000161 { "nCallTwoIntMethod", "(Ljava/lang/Object;JII)V",
George Mount4eed5292013-08-30 13:56:01 -0700162 (void*)android_animation_PropertyValuesHolder_callTwoIntMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000163 { "nCallFourIntMethod", "(Ljava/lang/Object;JIIII)V",
George Mount4eed5292013-08-30 13:56:01 -0700164 (void*)android_animation_PropertyValuesHolder_callFourIntMethod },
Ashok Bhatfbb35fb2014-01-17 16:44:27 +0000165 { "nCallMultipleIntMethod", "(Ljava/lang/Object;J[I)V",
George Mount4eed5292013-08-30 13:56:01 -0700166 (void*)android_animation_PropertyValuesHolder_callMultipleIntMethod },
Chet Haase6e0ecb42010-11-03 19:41:18 -0700167};
168
169int register_android_animation_PropertyValuesHolder(JNIEnv* env)
170{
Andreas Gampeed6b9df2014-11-20 22:02:20 -0800171 return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods));
Chet Haase6e0ecb42010-11-03 19:41:18 -0700172}
173
174};