com_android_inputmethod_keyboard_ProximityInfo.cpp revision ce9e52a12a6af8fca0eba42aaae24602fbd5c998
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 jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
32        jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
33        jint gridHeight, jintArray proximityCharsArray) {
34    jint* proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
35    ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
36            displayHeight, gridWidth, gridHeight, (const uint32_t *)proximityChars);
37    env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0);
38    return (jint)proximityInfo;
39}
40
41static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximityInfo) {
42    ProximityInfo *pi = (ProximityInfo*)proximityInfo;
43    if (!pi) return;
44    delete pi;
45}
46
47static JNINativeMethod sKeyboardMethods[] = {
48    {"setProximityInfoNative", "(IIIII[I)I", (void*)latinime_Keyboard_setProximityInfo},
49    {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release}
50};
51
52int register_ProximityInfo(JNIEnv *env) {
53    const char* const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
54    return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
55            sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
56}
57
58} // namespace latinime
59