com_android_inputmethod_keyboard_ProximityInfo.cpp revision a70ee6e3b3fe65acab205b935ebd52e7bb0eccb8
1/*
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"
22#include "jni_common.h"
23#include "proximity_info.h"
24
25#include <assert.h>
26#include <errno.h>
27#include <stdio.h>
28
29namespace latinime {
30
31static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
32        jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
33        jint gridHeight, jint mostCommonkeyWidth, jintArray proximityCharsArray, jint keyCount,
34        jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray,
35        jintArray keyHeightArray, jintArray keyCharCodeArray,
36        jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray,
37        jfloatArray sweetSpotRadiusArray) {
38    jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, 0);
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);
44    jfloat *sweetSpotCenterXs = safeGetFloatArrayElements(env, sweetSpotCenterXArray);
45    jfloat *sweetSpotCenterYs = safeGetFloatArrayElements(env, sweetSpotCenterYArray);
46    jfloat *sweetSpotRadii = safeGetFloatArrayElements(env, sweetSpotRadiusArray);
47    ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
48            displayHeight, gridWidth, gridHeight, mostCommonkeyWidth,
49            (const uint32_t*)proximityChars,
50            keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates,
51            (const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes,
52            (const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs,
53            (const float*)sweetSpotRadii);
54    safeReleaseFloatArrayElements(env, sweetSpotRadiusArray, sweetSpotRadii);
55    safeReleaseFloatArrayElements(env, sweetSpotCenterYArray, sweetSpotCenterYs);
56    safeReleaseFloatArrayElements(env, sweetSpotCenterXArray, sweetSpotCenterXs);
57    safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes);
58    safeReleaseIntArrayElements(env, keyHeightArray, keyHeights);
59    safeReleaseIntArrayElements(env, keyWidthArray, keyWidths);
60    safeReleaseIntArrayElements(env, keyYCoordinateArray, keyYCoordinates);
61    safeReleaseIntArrayElements(env, keyXCoordinateArray, keyXCoordinates);
62    env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0);
63    return (jlong)proximityInfo;
64}
65
66static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximityInfo) {
67    ProximityInfo *pi = (ProximityInfo*)proximityInfo;
68    if (!pi) return;
69    delete pi;
70}
71
72static JNINativeMethod sKeyboardMethods[] = {
73    {"setProximityInfoNative", "(IIIIII[II[I[I[I[I[I[F[F[F)J",
74            (void*)latinime_Keyboard_setProximityInfo},
75    {"releaseProximityInfoNative", "(J)V", (void*)latinime_Keyboard_release}
76};
77
78int register_ProximityInfo(JNIEnv *env) {
79    const char *const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
80    return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
81            sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
82}
83
84} // namespace latinime
85