Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright (C) 2011 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 #define LOG_TAG "LatinIME: jni: ProximityInfo"
     18 
     19 #include "com_android_inputmethod_keyboard_ProximityInfo.h"
     20 
     21 #include "defines.h"
     22 #include "jni.h"
     23 #include "jni_common.h"
     24 #include "suggest/core/layout/proximity_info.h"
     25 
     26 namespace latinime {
     27 
     28 static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jclass clazz,
     29         jint displayWidth, jint displayHeight, jint gridWidth, jint gridHeight,
     30         jint mostCommonkeyWidth, jint mostCommonkeyHeight, jintArray proximityChars, jint keyCount,
     31         jintArray keyXCoordinates, jintArray keyYCoordinates, jintArray keyWidths,
     32         jintArray keyHeights, jintArray keyCharCodes, jfloatArray sweetSpotCenterXs,
     33         jfloatArray sweetSpotCenterYs, jfloatArray sweetSpotRadii) {
     34     ProximityInfo *proximityInfo = new ProximityInfo(env, displayWidth, displayHeight,
     35             gridWidth, gridHeight, mostCommonkeyWidth, mostCommonkeyHeight, proximityChars,
     36             keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
     37             sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
     38     return reinterpret_cast<jlong>(proximityInfo);
     39 }
     40 
     41 static void latinime_Keyboard_release(JNIEnv *env, jclass clazz, jlong proximityInfo) {
     42     ProximityInfo *pi = reinterpret_cast<ProximityInfo *>(proximityInfo);
     43     delete pi;
     44 }
     45 
     46 static const JNINativeMethod sMethods[] = {
     47     {
     48         const_cast<char *>("setProximityInfoNative"),
     49         const_cast<char *>("(IIIIII[II[I[I[I[I[I[F[F[F)J"),
     50         reinterpret_cast<void *>(latinime_Keyboard_setProximityInfo)
     51     },
     52     {
     53         const_cast<char *>("releaseProximityInfoNative"),
     54         const_cast<char *>("(J)V"),
     55         reinterpret_cast<void *>(latinime_Keyboard_release)
     56     }
     57 };
     58 
     59 int register_ProximityInfo(JNIEnv *env) {
     60     const char *const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
     61     return registerNativeMethods(env, kClassPathName, sMethods, NELEMS(sMethods));
     62 }
     63 } // namespace latinime
     64