2012-08-08 11:40:44 +01:00
|
|
|
/*
|
2013-01-08 08:57:26 +00:00
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
2012-08-08 11:40:44 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2013-01-08 08:57:26 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-08-08 11:40:44 +01:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "LatinIME: jni: Session"
|
|
|
|
|
|
|
|
#include "com_android_inputmethod_latin_DicTraverseSession.h"
|
2013-06-03 08:12:20 +01:00
|
|
|
|
2012-10-08 03:46:14 +01:00
|
|
|
#include "defines.h"
|
2012-08-08 11:40:44 +01:00
|
|
|
#include "jni.h"
|
|
|
|
#include "jni_common.h"
|
2013-06-03 08:12:20 +01:00
|
|
|
#include "suggest/core/session/dic_traverse_session.h"
|
2014-05-15 10:39:23 +01:00
|
|
|
#include "suggest/core/session/prev_words_info.h"
|
2012-08-08 11:40:44 +01:00
|
|
|
|
|
|
|
namespace latinime {
|
2012-08-10 13:04:18 +01:00
|
|
|
class Dictionary;
|
2013-09-12 10:47:56 +01:00
|
|
|
static jlong latinime_setDicTraverseSession(JNIEnv *env, jclass clazz, jstring localeJStr,
|
|
|
|
jlong dictSize) {
|
|
|
|
void *traverseSession = DicTraverseSession::getSessionInstance(env, localeJStr, dictSize);
|
2012-08-08 13:23:25 +01:00
|
|
|
return reinterpret_cast<jlong>(traverseSession);
|
2012-08-08 11:40:44 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:18:00 +00:00
|
|
|
static void latinime_initDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession,
|
2012-08-09 15:23:08 +01:00
|
|
|
jlong dictionary, jintArray previousWord, jint previousWordLength) {
|
2013-06-03 08:12:20 +01:00
|
|
|
DicTraverseSession *ts = reinterpret_cast<DicTraverseSession *>(traverseSession);
|
2014-05-15 07:36:56 +01:00
|
|
|
if (!ts) {
|
|
|
|
return;
|
|
|
|
}
|
2012-08-14 06:22:27 +01:00
|
|
|
Dictionary *dict = reinterpret_cast<Dictionary *>(dictionary);
|
2012-08-10 17:10:31 +01:00
|
|
|
if (!previousWord) {
|
2014-05-15 10:39:23 +01:00
|
|
|
PrevWordsInfo prevWordsInfo;
|
|
|
|
ts->init(dict, &prevWordsInfo, 0 /* suggestOptions */);
|
2012-08-10 17:10:31 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-08-09 15:23:08 +01:00
|
|
|
int prevWord[previousWordLength];
|
|
|
|
env->GetIntArrayRegion(previousWord, 0, previousWordLength, prevWord);
|
2014-05-15 10:39:23 +01:00
|
|
|
PrevWordsInfo prevWordsInfo(prevWord, previousWordLength, false /* isStartOfSentence */);
|
|
|
|
ts->init(dict, &prevWordsInfo, 0 /* suggestOptions */);
|
2012-08-09 04:42:12 +01:00
|
|
|
}
|
|
|
|
|
2013-01-11 16:18:00 +00:00
|
|
|
static void latinime_releaseDicTraverseSession(JNIEnv *env, jclass clazz, jlong traverseSession) {
|
2013-06-03 08:12:20 +01:00
|
|
|
DicTraverseSession *ts = reinterpret_cast<DicTraverseSession *>(traverseSession);
|
|
|
|
DicTraverseSession::releaseSessionInstance(ts);
|
2012-08-08 11:40:44 +01:00
|
|
|
}
|
|
|
|
|
2013-06-04 11:16:47 +01:00
|
|
|
static const JNINativeMethod sMethods[] = {
|
|
|
|
{
|
|
|
|
const_cast<char *>("setDicTraverseSessionNative"),
|
2013-09-12 10:47:56 +01:00
|
|
|
const_cast<char *>("(Ljava/lang/String;J)J"),
|
2013-06-04 11:16:47 +01:00
|
|
|
reinterpret_cast<void *>(latinime_setDicTraverseSession)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
const_cast<char *>("initDicTraverseSessionNative"),
|
|
|
|
const_cast<char *>("(JJ[II)V"),
|
|
|
|
reinterpret_cast<void *>(latinime_initDicTraverseSession)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
const_cast<char *>("releaseDicTraverseSessionNative"),
|
|
|
|
const_cast<char *>("(J)V"),
|
|
|
|
reinterpret_cast<void *>(latinime_releaseDicTraverseSession)
|
|
|
|
}
|
2012-08-08 11:40:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
int register_DicTraverseSession(JNIEnv *env) {
|
|
|
|
const char *const kClassPathName = "com/android/inputmethod/latin/DicTraverseSession";
|
2012-10-08 03:46:14 +01:00
|
|
|
return registerNativeMethods(env, kClassPathName, sMethods, NELEMS(sMethods));
|
2012-08-08 11:40:44 +01:00
|
|
|
}
|
|
|
|
} // namespace latinime
|