Add reset method for dic travserse session
Change-Id: Ia3dd924f92549da2cf8302ef77c629902d4f275b
This commit is contained in:
parent
877157e1f5
commit
9d29871605
3 changed files with 30 additions and 5 deletions
|
@ -22,20 +22,30 @@ public class DicTraverseSession {
|
|||
static {
|
||||
JniUtils.loadNativeLibrary();
|
||||
}
|
||||
private native long setDicTraverseSessionNative(String locale);
|
||||
private native void initDicTraverseSessionNative(
|
||||
long nativeDicTraverseSession, int[] previousWord, int previwousWordLength);
|
||||
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
|
||||
|
||||
private long mNativeDicTraverseSession;
|
||||
|
||||
public DicTraverseSession(Locale locale) {
|
||||
mNativeDicTraverseSession = createNativeDicTraverseSession(
|
||||
locale != null ? locale.toString() : "");
|
||||
initSession();
|
||||
}
|
||||
|
||||
public long getSession() {
|
||||
return mNativeDicTraverseSession;
|
||||
}
|
||||
|
||||
private native long setDicTraverseSessionNative(String locale);
|
||||
private native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
|
||||
public void initSession() {
|
||||
initSession(null, 0);
|
||||
}
|
||||
|
||||
public void initSession(int[] previousWord, int previousWordLength) {
|
||||
initDicTraverseSessionNative(mNativeDicTraverseSession, previousWord, previousWordLength);
|
||||
}
|
||||
|
||||
private final long createNativeDicTraverseSession(String locale) {
|
||||
return setDicTraverseSessionNative(locale);
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
namespace latinime {
|
||||
void *(*DicTraverseWrapper::sDicTraverseSessionFactoryMethod)() = 0;
|
||||
void (*DicTraverseWrapper::sDicTraverseSessionReleaseMethod)(void *) = 0;
|
||||
void (*DicTraverseWrapper::sDicTraverseSessionInitMethod)(
|
||||
JNIEnv *, void *, const jintArray, const jint) = 0;
|
||||
|
||||
static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
|
||||
jstring localejStr) {
|
||||
|
@ -30,15 +32,21 @@ static jlong latinime_setDicTraverseSession(JNIEnv *env, jobject object,
|
|||
return reinterpret_cast<jlong>(traverseSession);
|
||||
}
|
||||
|
||||
static void latinime_initDicTraverseSession(JNIEnv *env, jlong traverseSession,
|
||||
jintArray previousWord, jint previousWordLength) {
|
||||
void *ts = reinterpret_cast<void*>(traverseSession);
|
||||
DicTraverseWrapper::initDicTraverseSession(env, ts, previousWord, previousWordLength);
|
||||
}
|
||||
|
||||
static void latinime_DicTraverseSession_release(
|
||||
JNIEnv *env, jobject object, jlong traverseSession) {
|
||||
void *pi = reinterpret_cast<void*>(traverseSession);
|
||||
if (!pi) return;
|
||||
DicTraverseWrapper::releaseDicTraverseSession(pi);
|
||||
void *ts = reinterpret_cast<void*>(traverseSession);
|
||||
DicTraverseWrapper::releaseDicTraverseSession(ts);
|
||||
}
|
||||
|
||||
static JNINativeMethod sMethods[] = {
|
||||
{"setDicTraverseSessionNative", "(Ljava/lang/String;)J", (void*)latinime_setDicTraverseSession},
|
||||
{"initDicTraverseSessionNative", "(J[II)V", (void*)latinime_initDicTraverseSession},
|
||||
{"releaseDicTraverseSessionNative", "(J)V", (void*)latinime_DicTraverseSession_release}
|
||||
};
|
||||
|
||||
|
|
|
@ -31,6 +31,12 @@ class DicTraverseWrapper {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
static void initDicTraverseSession(JNIEnv *env, void *traverseSession,
|
||||
const jintArray prevWord, const jint prevWordLength) {
|
||||
if (sDicTraverseSessionInitMethod) {
|
||||
sDicTraverseSessionInitMethod(env, traverseSession, prevWord, prevWordLength);
|
||||
}
|
||||
}
|
||||
static void releaseDicTraverseSession(void *traverseSession) {
|
||||
if (sDicTraverseSessionReleaseMethod) {
|
||||
sDicTraverseSessionReleaseMethod(traverseSession);
|
||||
|
@ -39,6 +45,7 @@ class DicTraverseWrapper {
|
|||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper);
|
||||
static void *(*sDicTraverseSessionFactoryMethod)();
|
||||
static void (*sDicTraverseSessionInitMethod)(JNIEnv *, void *, const jintArray, const jint);
|
||||
static void (*sDicTraverseSessionReleaseMethod)(void *);
|
||||
};
|
||||
int register_DicTraverseSession(JNIEnv *env);
|
||||
|
|
Loading…
Reference in a new issue