aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
authorKen Wakasa <kwakasa@google.com>2011-01-07 15:01:51 +0900
committerKen Wakasa <kwakasa@google.com>2011-01-07 19:51:45 +0900
commite90b333017c68e888a5e3d351f07ea29036457d0 (patch)
treedd51657376f1c571df581b7016be891d09246be5 /java/src/com/android/inputmethod/latin/Suggest.java
parentf16028b92e15c0fdf3fdc364d7888cf024723b00 (diff)
downloadlatinime-e90b333017c68e888a5e3d351f07ea29036457d0.tar.gz
latinime-e90b333017c68e888a5e3d351f07ea29036457d0.tar.xz
latinime-e90b333017c68e888a5e3d351f07ea29036457d0.zip
Load main dic in native
Follow up to Id57dce51 bug: 3219819 Change-Id: I00e11ef21d0252ffa88c12dffb9c55b0f2e19a66
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java41
1 files changed, 26 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 9f979fffd..9ea9c2f3e 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -1,12 +1,12 @@
/*
* Copyright (C) 2008 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
@@ -22,12 +22,11 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
/**
- * This class loads a dictionary and provides a list of suggestions for a given sequence of
+ * This class loads a dictionary and provides a list of suggestions for a given sequence of
* characters. This includes corrections and completions.
*/
public class Suggest implements Dictionary.WordCallback {
@@ -108,11 +107,6 @@ public class Suggest implements Dictionary.WordCallback {
initPool();
}
- public Suggest(Context context, ByteBuffer byteBuffer) {
- mMainDict = new BinaryDictionary(context, byteBuffer, DIC_MAIN);
- initPool();
- }
-
private void initPool() {
for (int i = 0; i < mPrefMaxSuggestions; i++) {
StringBuilder sb = new StringBuilder(getApproxMaxWordLength());
@@ -154,7 +148,7 @@ public class Suggest implements Dictionary.WordCallback {
public void setContactsDictionary(Dictionary userDictionary) {
mContactsDictionary = userDictionary;
}
-
+
public void setAutoDictionary(Dictionary autoDictionary) {
mAutoDictionary = autoDictionary;
}
@@ -232,7 +226,7 @@ public class Suggest implements Dictionary.WordCallback {
if (!TextUtils.isEmpty(prevWordForBigram)) {
CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase();
- if (mMainDict.isValidWord(lowerPrevWord)) {
+ if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) {
prevWordForBigram = lowerPrevWord;
}
if (mUserBigramDictionary != null) {
@@ -383,7 +377,7 @@ public class Suggest implements Dictionary.WordCallback {
return mHaveCorrection;
}
- private boolean compareCaseInsensitive(final String mLowerOriginalWord,
+ private boolean compareCaseInsensitive(final String mLowerOriginalWord,
final char[] word, final int offset, final int length) {
final int originalLength = mLowerOriginalWord.length();
if (originalLength == length && Character.isUpperCase(word[offset])) {
@@ -456,7 +450,7 @@ public class Suggest implements Dictionary.WordCallback {
System.arraycopy(priorities, pos, priorities, pos + 1, prefMaxSuggestions - pos - 1);
priorities[pos] = freq;
int poolSize = mStringPool.size();
- StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
+ StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength());
sb.setLength(0);
if (mIsAllUpperCase) {
@@ -510,7 +504,7 @@ public class Suggest implements Dictionary.WordCallback {
|| (mAutoDictionary != null && mAutoDictionary.isValidWord(word))
|| (mContactsDictionary != null && mContactsDictionary.isValidWord(word));
}
-
+
private void collectGarbage(ArrayList<CharSequence> suggestions, int prefMaxSuggestions) {
int poolSize = mStringPool.size();
int garbageSize = suggestions.size();
@@ -531,6 +525,23 @@ public class Suggest implements Dictionary.WordCallback {
public void close() {
if (mMainDict != null) {
mMainDict.close();
+ mMainDict = null;
+ }
+ if (mUserDictionary != null) {
+ mUserDictionary.close();
+ mUserDictionary = null;
+ }
+ if (mUserBigramDictionary != null) {
+ mUserBigramDictionary.close();
+ mUserBigramDictionary = null;
+ }
+ if (mContactsDictionary != null) {
+ mContactsDictionary.close();
+ mContactsDictionary = null;
+ }
+ if (mAutoDictionary != null) {
+ mAutoDictionary.close();
+ mAutoDictionary = null;
}
}
}