Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 56a6c8dc authored by Ken Wakasa's avatar Ken Wakasa Committed by Android (Google) Code Review
Browse files

Merge "Clean up in LatinIME native code"

parents 76427c8e ce9e52a1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ LOCAL_CFLAGS += -Wno-unused-parameter -Wno-unused-function
LOCAL_SRC_FILES := \
    jni/com_android_inputmethod_keyboard_ProximityInfo.cpp \
    jni/com_android_inputmethod_latin_BinaryDictionary.cpp \
    jni/onload.cpp \
    jni/jni_common.cpp \
    src/bigram_dictionary.cpp \
    src/char_utils.cpp \
    src/dictionary.cpp \
+2 −34
Original line number Diff line number Diff line
@@ -19,28 +19,15 @@

#include "com_android_inputmethod_keyboard_ProximityInfo.h"
#include "jni.h"
#include "jni_common.h"
#include "proximity_info.h"

#include <assert.h>
#include <errno.h>
#include <stdio.h>

// ----------------------------------------------------------------------------

namespace latinime {

//
// helper function to throw an exception
//
static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data) {
    if (jclass cls = env->FindClass(ex)) {
        char msg[1000];
        snprintf(msg, sizeof(msg), fmt, data);
        env->ThrowNew(cls, msg);
        env->DeleteLocalRef(cls);
    }
}

static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
        jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
        jint gridHeight, jintArray proximityCharsArray) {
@@ -57,34 +44,15 @@ static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximit
    delete pi;
}

// ----------------------------------------------------------------------------

static JNINativeMethod sKeyboardMethods[] = {
    {"setProximityInfoNative", "(IIIII[I)I", (void*)latinime_Keyboard_setProximityInfo},
    {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release}
};

static int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* gMethods,
        int numMethods) {
    jclass clazz;

    clazz = env->FindClass(className);
    if (clazz == NULL) {
        LOGE("Native registration unable to find class '%s'", className);
        return JNI_FALSE;
    }
    if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
        LOGE("RegisterNatives failed for '%s'", className);
        return JNI_FALSE;
    }

    return JNI_TRUE;
}

int register_ProximityInfo(JNIEnv *env) {
    const char* const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
    return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
            sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
}

}; // namespace latinime
} // namespace latinime
+2 −0
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@
#include "jni.h"

namespace latinime {

int register_ProximityInfo(JNIEnv *env);

}

#endif // _COM_ANDROID_INPUTMETHOD_KEYBOARD_PROXIMITYINFO_H
+2 −34
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "com_android_inputmethod_latin_BinaryDictionary.h"
#include "dictionary.h"
#include "jni.h"
#include "jni_common.h"
#include "proximity_info.h"

#include <assert.h>
@@ -35,22 +36,8 @@
#include <stdlib.h>
#endif // USE_MMAP_FOR_DICTIONARY

// ----------------------------------------------------------------------------

namespace latinime {

//
// helper function to throw an exception
//
static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data) {
    if (jclass cls = env->FindClass(ex)) {
        char msg[1000];
        snprintf(msg, sizeof(msg), fmt, data);
        env->ThrowNew(cls, msg);
        env->DeleteLocalRef(cls);
    }
}

static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
        jstring sourceDir, jlong dictOffset, jlong dictSize,
        jint typedLetterMultiplier, jint fullWordMultiplier, jint maxWordLength, jint maxWords,
@@ -208,8 +195,6 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jint di
    delete dictionary;
}

// ----------------------------------------------------------------------------

static JNINativeMethod sMethods[] = {
    {"openNative", "(Ljava/lang/String;JJIIIII)I", (void*)latinime_BinaryDictionary_open},
    {"closeNative", "(I)V", (void*)latinime_BinaryDictionary_close},
@@ -218,27 +203,10 @@ static JNINativeMethod sMethods[] = {
    {"getBigramsNative", "(I[CI[II[C[IIII)I", (void*)latinime_BinaryDictionary_getBigrams}
};

static int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* gMethods,
        int numMethods) {
    jclass clazz;

    clazz = env->FindClass(className);
    if (clazz == NULL) {
        LOGE("Native registration unable to find class '%s'", className);
        return JNI_FALSE;
    }
    if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
        LOGE("RegisterNatives failed for '%s'", className);
        return JNI_FALSE;
    }

    return JNI_TRUE;
}

int register_BinaryDictionary(JNIEnv *env) {
    const char* const kClassPathName = "com/android/inputmethod/latin/BinaryDictionary";
    return registerNativeMethods(env, kClassPathName, sMethods,
            sizeof(sMethods) / sizeof(sMethods[0]));
}

}; // namespace latinime
} // namespace latinime
+2 −0
Original line number Diff line number Diff line
@@ -21,7 +21,9 @@
#include "jni.h"

namespace latinime {

int register_BinaryDictionary(JNIEnv *env);

}

#endif // _COM_ANDROID_INPUTMETHOD_LATIN_BINARYDICTIONARY_H
Loading