aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java46
1 files changed, 27 insertions, 19 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 55cd0848a..e207c33bd 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.ProximityInfo;
@@ -93,8 +94,7 @@ public class BinaryDictionary extends Dictionary {
return sInstance;
}
- // For unit test
- /* package */ static BinaryDictionary initDictionary(File dictionary, long startOffset,
+ /* package for test */ static BinaryDictionary initDictionary(File dictionary, long startOffset,
long length, int dicTypeId) {
synchronized (sInstance) {
sInstance.closeInternal();
@@ -166,11 +166,32 @@ public class BinaryDictionary extends Dictionary {
@Override
public void getWords(final WordComposer codes, final WordCallback callback) {
- if (mNativeDict == 0) return;
+ final int count = getSuggestions(codes, mKeyboardSwitcher.getLatinKeyboard());
+
+ for (int j = 0; j < count; ++j) {
+ if (mFrequencies[j] < 1) break;
+ final int start = j * MAX_WORD_LENGTH;
+ int len = 0;
+ while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
+ ++len;
+ }
+ if (len > 0) {
+ callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
+ DataType.UNIGRAM);
+ }
+ }
+ }
+
+ /* package for test */ boolean isValidDictionary() {
+ return mNativeDict != 0;
+ }
+
+ /* package for test */ int getSuggestions(final WordComposer codes, final Keyboard keyboard) {
+ if (!isValidDictionary()) return -1;
final int codesSize = codes.size();
// Won't deal with really long words.
- if (codesSize > MAX_WORD_LENGTH - 1) return;
+ if (codesSize > MAX_WORD_LENGTH - 1) return -1;
Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
for (int i = 0; i < codesSize; i++) {
@@ -181,23 +202,10 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mOutputChars, (char) 0);
Arrays.fill(mFrequencies, 0);
- int count = getSuggestionsNative(
- mNativeDict, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(),
+ return getSuggestionsNative(
+ mNativeDict, keyboard.getProximityInfo(),
codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
mOutputChars, mFrequencies);
-
- for (int j = 0; j < count; ++j) {
- if (mFrequencies[j] < 1) break;
- final int start = j * MAX_WORD_LENGTH;
- int len = 0;
- while (len < MAX_WORD_LENGTH && mOutputChars[start + len] != 0) {
- ++len;
- }
- if (len > 0) {
- callback.addWord(mOutputChars, start, len, mFrequencies[j], mDicTypeId,
- DataType.UNIGRAM);
- }
- }
}
@Override