blob: 595ea2fdcd7920b463fa1c653db40fa298a3afbf [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
2**
3** Copyright 2011, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "LatinIME: jni: ProximityInfo"
19
20#include "com_android_inputmethod_keyboard_ProximityInfo.h"
21#include "jni.h"
Ken Wakasace9e52a2011-06-18 13:09:55 +090022#include "jni_common.h"
satok8fbd5522011-02-22 17:28:55 +090023#include "proximity_info.h"
24
25#include <assert.h>
26#include <errno.h>
27#include <stdio.h>
28
satok8fbd5522011-02-22 17:28:55 +090029namespace latinime {
30
satok8fbd5522011-02-22 17:28:55 +090031static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
32 jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
Yusuke Nojima0e1f6562011-09-21 12:02:47 +090033 jint gridHeight, jintArray proximityCharsArray, jint keyCount,
34 jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray,
Yusuke Nojimaad358352011-09-29 16:44:54 +090035 jintArray keyHeightArray, jintArray keyCharCodeArray,
36 jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray,
37 jfloatArray sweetSpotRadiusArray) {
Yusuke Nojimade2f8422011-09-27 11:15:18 +090038 jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
39 jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray);
40 jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray);
41 jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray);
42 jint *keyHeights = safeGetIntArrayElements(env, keyHeightArray);
43 jint *keyCharCodes = safeGetIntArrayElements(env, keyCharCodeArray);
Yusuke Nojimaad358352011-09-29 16:44:54 +090044 jfloat *sweetSpotCenterXs = safeGetFloatArrayElements(env, sweetSpotCenterXArray);
45 jfloat *sweetSpotCenterYs = safeGetFloatArrayElements(env, sweetSpotCenterYArray);
46 jfloat *sweetSpotRadii = safeGetFloatArrayElements(env, sweetSpotRadiusArray);
satok8fbd5522011-02-22 17:28:55 +090047 ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
Yusuke Nojimade2f8422011-09-27 11:15:18 +090048 displayHeight, gridWidth, gridHeight, (const uint32_t*)proximityChars,
49 keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates,
Yusuke Nojima1c923d82011-09-28 11:38:34 +090050 (const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes,
Yusuke Nojimaad358352011-09-29 16:44:54 +090051 (const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs,
52 (const float*)sweetSpotRadii);
53 safeReleaseFloatArrayElements(env, sweetSpotRadiusArray, sweetSpotRadii);
54 safeReleaseFloatArrayElements(env, sweetSpotCenterYArray, sweetSpotCenterYs);
55 safeReleaseFloatArrayElements(env, sweetSpotCenterXArray, sweetSpotCenterXs);
Yusuke Nojimade2f8422011-09-27 11:15:18 +090056 safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes);
57 safeReleaseIntArrayElements(env, keyHeightArray, keyHeights);
58 safeReleaseIntArrayElements(env, keyWidthArray, keyWidths);
59 safeReleaseIntArrayElements(env, keyYCoordinateArray, keyYCoordinates);
60 safeReleaseIntArrayElements(env, keyXCoordinateArray, keyXCoordinates);
satok8fbd5522011-02-22 17:28:55 +090061 env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0);
62 return (jint)proximityInfo;
63}
64
65static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximityInfo) {
66 ProximityInfo *pi = (ProximityInfo*)proximityInfo;
67 if (!pi) return;
68 delete pi;
69}
70
satok8fbd5522011-02-22 17:28:55 +090071static JNINativeMethod sKeyboardMethods[] = {
Yusuke Nojimaad358352011-09-29 16:44:54 +090072 {"setProximityInfoNative", "(IIIII[II[I[I[I[I[I[F[F[F)I",
73 (void*)latinime_Keyboard_setProximityInfo},
satok8fbd5522011-02-22 17:28:55 +090074 {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release}
75};
76
satok8fbd5522011-02-22 17:28:55 +090077int register_ProximityInfo(JNIEnv *env) {
Yusuke Nojimade2f8422011-09-27 11:15:18 +090078 const char *const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
satok8fbd5522011-02-22 17:28:55 +090079 return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
80 sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
81}
82
Ken Wakasace9e52a2011-06-18 13:09:55 +090083} // namespace latinime