2012-08-08 10:40:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.JniUtils;
|
|
|
|
|
2012-08-08 10:40:44 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class DicTraverseSession {
|
2012-08-08 10:40:44 +00:00
|
|
|
static {
|
|
|
|
JniUtils.loadNativeLibrary();
|
|
|
|
}
|
2012-08-14 13:49:59 +00:00
|
|
|
|
2013-09-12 09:47:56 +00:00
|
|
|
private static native long setDicTraverseSessionNative(String locale, long dictSize);
|
2013-01-11 16:18:00 +00:00
|
|
|
private static native void initDicTraverseSessionNative(long nativeDicTraverseSession,
|
2012-08-10 16:10:31 +00:00
|
|
|
long dictionary, int[] previousWord, int previousWordLength);
|
2013-01-11 16:18:00 +00:00
|
|
|
private static native void releaseDicTraverseSessionNative(long nativeDicTraverseSession);
|
2012-08-08 10:40:44 +00:00
|
|
|
|
|
|
|
private long mNativeDicTraverseSession;
|
|
|
|
|
2013-09-12 09:47:56 +00:00
|
|
|
public DicTraverseSession(Locale locale, long dictionary, long dictSize) {
|
2012-08-08 10:40:44 +00:00
|
|
|
mNativeDicTraverseSession = createNativeDicTraverseSession(
|
2013-09-12 09:47:56 +00:00
|
|
|
locale != null ? locale.toString() : "", dictSize);
|
2012-08-14 13:49:59 +00:00
|
|
|
initSession(dictionary);
|
2012-08-08 10:40:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-08 12:23:25 +00:00
|
|
|
public long getSession() {
|
|
|
|
return mNativeDicTraverseSession;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:23:08 +00:00
|
|
|
public void initSession(long dictionary) {
|
|
|
|
initSession(dictionary, null, 0);
|
2012-08-09 03:42:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 14:23:08 +00:00
|
|
|
public void initSession(long dictionary, int[] previousWord, int previousWordLength) {
|
2012-08-10 16:10:31 +00:00
|
|
|
initDicTraverseSessionNative(
|
|
|
|
mNativeDicTraverseSession, dictionary, previousWord, previousWordLength);
|
2012-08-09 03:42:12 +00:00
|
|
|
}
|
2012-08-08 10:40:44 +00:00
|
|
|
|
2013-09-12 09:47:56 +00:00
|
|
|
private final long createNativeDicTraverseSession(String locale, long dictSize) {
|
|
|
|
return setDicTraverseSessionNative(locale, dictSize);
|
2012-08-08 10:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void closeInternal() {
|
|
|
|
if (mNativeDicTraverseSession != 0) {
|
|
|
|
releaseDicTraverseSessionNative(mNativeDicTraverseSession);
|
|
|
|
mNativeDicTraverseSession = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
closeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
try {
|
|
|
|
closeInternal();
|
|
|
|
} finally {
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|