aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java72
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java18
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java13
-rw-r--r--java/src/com/android/inputmethod/latin/Settings.java24
-rw-r--r--java/src/com/android/inputmethod/latin/SettingsValues.java25
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java81
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java5
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FormatSpec.java3
9 files changed, 178 insertions, 67 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 2bde8d2c5..03d610a39 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -47,8 +47,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private static boolean sGestureHandlingEnabledByInputField = false;
private static boolean sGestureHandlingEnabledByUser = false;
- private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
-
public interface KeyEventHandler {
/**
* Get KeyDetector object that is used for this PointerTracker.
@@ -562,7 +560,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mGestureStrokeWithPreviewPoints.appendIncrementalBatchPoints(sAggregratedPointers);
final int size = sAggregratedPointers.getPointerSize();
if (size > sLastRecognitionPointSize
- && eventTime > sLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) {
+ && GestureStroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) {
sLastRecognitionPointSize = size;
sLastRecognitionTime = eventTime;
if (DEBUG_LISTENER) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
index 093a530d5..f0be0ee94 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
@@ -31,14 +31,23 @@ public class GestureStroke {
private int mLastPointX;
private int mLastPointY;
- private int mMinGestureLength;
- private int mMinGestureSampleLength;
+ private int mMinGestureLength; // pixel
+ private int mMinGestureSampleLength; // pixel
+ private int mGestureRecognitionThreshold; // pixel / sec
// TODO: Move some of these to resource.
private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f;
- private static final int MIN_GESTURE_DURATION = 100; // msec
+ private static final int MIN_GESTURE_START_DURATION = 100; // msec
+ private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec
private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH = 1.0f / 6.0f;
- private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec
+ private static final float GESTURE_RECOGNITION_SPEED_THRESHOLD_RATIO_TO_KEY_WIDTH =
+ 5.5f; // keyWidth / sec
+ private static final int MSEC_PER_SEC = 1000;
+
+ public static final boolean hasRecognitionTimePast(
+ final long currentTime, final long lastRecognitionTime) {
+ return currentTime > lastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME;
+ }
public GestureStroke(final int pointerId) {
mPointerId = pointerId;
@@ -48,12 +57,14 @@ public class GestureStroke {
// TODO: Find an appropriate base metric for these length. Maybe diagonal length of the key?
mMinGestureLength = (int)(keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH);
mMinGestureSampleLength = (int)(keyWidth * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH);
+ mGestureRecognitionThreshold =
+ (int)(keyWidth * GESTURE_RECOGNITION_SPEED_THRESHOLD_RATIO_TO_KEY_WIDTH);
}
public boolean isStartOfAGesture() {
final int size = mEventTimes.getLength();
final int downDuration = (size > 0) ? mEventTimes.get(size - 1) : 0;
- return downDuration > MIN_GESTURE_DURATION && mLength > mMinGestureLength;
+ return downDuration > MIN_GESTURE_START_DURATION && mLength > mMinGestureLength;
}
public void reset() {
@@ -66,44 +77,41 @@ public class GestureStroke {
mYCoordinates.setLength(0);
}
- private void updateLastPoint(final int x, final int y, final int time) {
- mLastPointTime = time;
- mLastPointX = x;
- mLastPointY = y;
- }
-
public void addPoint(final int x, final int y, final int time, final boolean isHistorical) {
+ final boolean needsSampling;
final int size = mEventTimes.getLength();
if (size == 0) {
- mEventTimes.add(time);
- mXCoordinates.add(x);
- mYCoordinates.add(y);
- if (!isHistorical) {
- updateLastPoint(x, y, time);
- }
- return;
+ needsSampling = true;
+ } else {
+ final int lastIndex = size - 1;
+ final int lastX = mXCoordinates.get(lastIndex);
+ final int lastY = mYCoordinates.get(lastIndex);
+ final float dist = getDistance(lastX, lastY, x, y);
+ needsSampling = dist > mMinGestureSampleLength;
+ mLength += dist;
}
-
- final int lastX = mXCoordinates.get(size - 1);
- final int lastY = mYCoordinates.get(size - 1);
- final float dist = getDistance(lastX, lastY, x, y);
- if (dist > mMinGestureSampleLength) {
+ if (needsSampling) {
mEventTimes.add(time);
mXCoordinates.add(x);
mYCoordinates.add(y);
- mLength += dist;
}
-
if (!isHistorical) {
- final int duration = (int)(time - mLastPointTime);
- if (mLastPointTime != 0 && duration > 0) {
- final float speed = getDistance(mLastPointX, mLastPointY, x, y) / duration;
- if (speed < GESTURE_RECOG_SPEED_THRESHOLD) {
- mIncrementalRecognitionSize = size;
- }
+ updateIncrementalRecognitionSize(x, y, time);
+ }
+ }
+
+ private void updateIncrementalRecognitionSize(final int x, final int y, final int time) {
+ final int msecs = (int)(time - mLastPointTime);
+ if (msecs > 0) {
+ final int pixels = (int)getDistance(mLastPointX, mLastPointY, x, y);
+ // Equivalent to (pixels / msecs < mGestureRecognitionThreshold / MSEC_PER_SEC)
+ if (pixels * MSEC_PER_SEC < mGestureRecognitionThreshold * msecs) {
+ mIncrementalRecognitionSize = mEventTimes.getLength();
}
- updateLastPoint(x, y, time);
}
+ mLastPointTime = time;
+ mLastPointX = x;
+ mLastPointY = y;
}
public void appendAllBatchPoints(final InputPointers out) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
index 075a9bb0c..15170e040 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
@@ -46,7 +46,6 @@ public class PreviewPlacerView extends RelativeLayout {
private final float mGestureFloatingPreviewHorizontalPadding;
private final float mGestureFloatingPreviewVerticalPadding;
private final float mGestureFloatingPreviewRoundRadius;
- /* package */ final int mGestureFloatingPreviewTextLingerTimeout;
private int mXOrigin;
private int mYOrigin;
@@ -78,11 +77,14 @@ public class PreviewPlacerView extends RelativeLayout {
private static final int MSG_UPDATE_GESTURE_PREVIEW_TRAIL = 1;
private final Params mGesturePreviewTrailParams;
+ private final int mGestureFloatingPreviewTextLingerTimeout;
public DrawingHandler(final PreviewPlacerView outerInstance,
- final Params gesturePreviewTrailParams) {
+ final Params gesturePreviewTrailParams,
+ final int getstureFloatinPreviewTextLinerTimeout) {
super(outerInstance);
mGesturePreviewTrailParams = gesturePreviewTrailParams;
+ mGestureFloatingPreviewTextLingerTimeout = getstureFloatinPreviewTextLinerTimeout;
}
@Override
@@ -105,10 +107,8 @@ public class PreviewPlacerView extends RelativeLayout {
public void dismissGestureFloatingPreviewText() {
cancelDismissGestureFloatingPreviewText();
- final PreviewPlacerView placerView = getOuterInstance();
- sendMessageDelayed(
- obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT),
- placerView.mGestureFloatingPreviewTextLingerTimeout);
+ sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT),
+ mGestureFloatingPreviewTextLingerTimeout);
}
private void cancelUpdateGestureTrailPreview() {
@@ -122,7 +122,6 @@ public class PreviewPlacerView extends RelativeLayout {
}
public void cancelAllMessages() {
- cancelDismissGestureFloatingPreviewText();
cancelUpdateGestureTrailPreview();
}
}
@@ -151,12 +150,13 @@ public class PreviewPlacerView extends RelativeLayout {
R.styleable.KeyboardView_gestureFloatingPreviewVerticalPadding, 0.0f);
mGestureFloatingPreviewRoundRadius = keyboardViewAttr.getDimension(
R.styleable.KeyboardView_gestureFloatingPreviewRoundRadius, 0.0f);
- mGestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt(
+ final int gestureFloatingPreviewTextLingerTimeout = keyboardViewAttr.getInt(
R.styleable.KeyboardView_gestureFloatingPreviewTextLingerTimeout, 0);
mGesturePreviewTrailParams = new Params(keyboardViewAttr);
keyboardViewAttr.recycle();
- mDrawingHandler = new DrawingHandler(this, mGesturePreviewTrailParams);
+ mDrawingHandler = new DrawingHandler(this, mGesturePreviewTrailParams,
+ gestureFloatingPreviewTextLingerTimeout);
final Paint gesturePaint = new Paint();
gesturePaint.setAntiAlias(true);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index bf64b4f08..9252b0980 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1401,7 +1401,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
Stats.onAutoCorrection("", mWordComposer.getTypedWord(), " ", mWordComposer);
}
}
- commitTyped(LastComposedWord.NOT_A_SEPARATOR);
+ if (mWordComposer.size() <= 1) {
+ // We auto-correct the previous (typed, not gestured) string iff it's one character
+ // long. The reason for this is, even in the middle of gesture typing, you'll still
+ // tap one-letter words and you want them auto-corrected (typically, "i" in English
+ // should become "I"). However for any longer word, we assume that the reason for
+ // tapping probably is that the word you intend to type is not in the dictionary,
+ // so we do not attempt to correct, on the assumption that if that was a dictionary
+ // word, the user would probably have gestured instead.
+ commitCurrentAutoCorrection(LastComposedWord.NOT_A_SEPARATOR);
+ } else {
+ commitTyped(LastComposedWord.NOT_A_SEPARATOR);
+ }
mExpectingUpdateSelection = true;
// The following is necessary for the case where the user typed something but didn't
// manual pick it and didn't input any separator.
diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java
index c2dec2593..9479a88a7 100644
--- a/java/src/com/android/inputmethod/latin/Settings.java
+++ b/java/src/com/android/inputmethod/latin/Settings.java
@@ -42,7 +42,7 @@ import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
import com.android.inputmethodcommon.InputMethodSettingsFragment;
-public class Settings extends InputMethodSettingsFragment
+public final class Settings extends InputMethodSettingsFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final boolean ENABLE_INTERNAL_SETTINGS = ProductionFlag.IS_INTERNAL;
@@ -63,8 +63,8 @@ public class Settings extends InputMethodSettingsFragment
"last_user_dictionary_write_time";
public static final String PREF_ADVANCED_SETTINGS = "pref_advanced_settings";
public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict";
- public static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
- "pref_suppress_language_switch_key";
+ public static final String PREF_SHOW_LANGUAGE_SWITCH_KEY =
+ "pref_show_language_switch_key";
public static final String PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST =
"pref_include_other_imes_in_language_switch_list";
public static final String PREF_CUSTOM_INPUT_STYLES = "custom_input_styles";
@@ -97,7 +97,7 @@ public class Settings extends InputMethodSettingsFragment
private TextView mKeypressVibrationDurationSettingsTextView;
private TextView mKeypressSoundVolumeSettingsTextView;
- private static void setPreferenceEnabled(Preference preference, boolean enabled) {
+ private static void setPreferenceEnabled(final Preference preference, final boolean enabled) {
if (preference != null) {
preference.setEnabled(enabled);
}
@@ -111,7 +111,7 @@ public class Settings extends InputMethodSettingsFragment
}
@Override
- public void onCreate(Bundle icicle) {
+ public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
setInputMethodSettingsCategoryTitle(R.string.language_selection_title);
setSubtypeEnablerTitle(R.string.select_language);
@@ -192,7 +192,7 @@ public class Settings extends InputMethodSettingsFragment
}
setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST),
- !SettingsValues.isLanguageSwitchKeySupressed(prefs));
+ SettingsValues.showsLanguageSwitchKey(prefs));
final PreferenceScreen dictionaryLink =
(PreferenceScreen) findPreference(PREF_CONFIGURE_DICTIONARIES_KEY);
@@ -288,14 +288,14 @@ public class Settings extends InputMethodSettingsFragment
}
@Override
- public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+ public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
(new BackupManager(getActivity())).dataChanged();
if (key.equals(PREF_POPUP_ON)) {
setPreferenceEnabled(findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY),
prefs.getBoolean(PREF_POPUP_ON, true));
- } else if (key.equals(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) {
+ } else if (key.equals(PREF_SHOW_LANGUAGE_SWITCH_KEY)) {
setPreferenceEnabled(findPreference(PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST),
- !SettingsValues.isLanguageSwitchKeySupressed(prefs));
+ SettingsValues.showsLanguageSwitchKey(prefs));
} else if (key.equals(PREF_GESTURE_INPUT)) {
final boolean gestureInputEnabledByConfig = getResources().getBoolean(
R.bool.config_gesture_input_enabled_by_build_config);
@@ -352,7 +352,7 @@ public class Settings extends InputMethodSettingsFragment
}
private void refreshEnablingsOfKeypressSoundAndVibrationSettings(
- SharedPreferences sp, Resources res) {
+ final SharedPreferences sp, final Resources res) {
if (mKeypressVibrationDurationSettingsPref != null) {
final boolean hasVibratorHardware = VibratorUtils.getInstance(getActivity())
.hasVibrator();
@@ -370,7 +370,7 @@ public class Settings extends InputMethodSettingsFragment
}
private void updateKeypressVibrationDurationSettingsSummary(
- SharedPreferences sp, Resources res) {
+ final SharedPreferences sp, final Resources res) {
if (mKeypressVibrationDurationSettingsPref != null) {
mKeypressVibrationDurationSettingsPref.setSummary(
SettingsValues.getCurrentVibrationDuration(sp, res)
@@ -428,7 +428,7 @@ public class Settings extends InputMethodSettingsFragment
builder.create().show();
}
- private void updateKeypressSoundVolumeSummary(SharedPreferences sp, Resources res) {
+ private void updateKeypressSoundVolumeSummary(final SharedPreferences sp, final Resources res) {
if (mKeypressSoundVolumeSettingsPref != null) {
mKeypressSoundVolumeSettingsPref.setSummary(String.valueOf(
(int)(SettingsValues.getCurrentKeypressSoundVolume(sp, res) * 100)));
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index d9cf2700b..9d8379a7a 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -72,7 +72,7 @@ public final class SettingsValues {
@SuppressWarnings("unused") // TODO: Use this
private final boolean mUsabilityStudyMode;
public final boolean mIncludesOtherImesInLanguageSwitchList;
- public final boolean mIsLanguageSwitchKeySuppressed;
+ public final boolean mShowsLanguageSwitchKey;
@SuppressWarnings("unused") // TODO: Use this
private final String mKeyPreviewPopupDismissDelayRawValue;
public final boolean mUseContactsDict;
@@ -151,7 +151,7 @@ public final class SettingsValues {
mUsabilityStudyMode = getUsabilityStudyMode(prefs);
mIncludesOtherImesInLanguageSwitchList = prefs.getBoolean(
Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST, false);
- mIsLanguageSwitchKeySuppressed = isLanguageSwitchKeySupressed(prefs);
+ mShowsLanguageSwitchKey = showsLanguageSwitchKey(prefs);
mKeyPreviewPopupDismissDelayRawValue = prefs.getString(
Settings.PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY,
Integer.toString(res.getInteger(R.integer.config_key_preview_linger_timeout)));
@@ -336,12 +336,25 @@ public final class SettingsValues {
return mVoiceKeyOnMain;
}
- public static boolean isLanguageSwitchKeySupressed(final SharedPreferences prefs) {
- return prefs.getBoolean(Settings.PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false);
+ // This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
+ // This is being used only for the backward compatibility.
+ private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =
+ "pref_suppress_language_switch_key";
+
+ public static boolean showsLanguageSwitchKey(final SharedPreferences prefs) {
+ if (prefs.contains(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY)) {
+ final boolean suppressLanguageSwitchKey = prefs.getBoolean(
+ PREF_SUPPRESS_LANGUAGE_SWITCH_KEY, false);
+ final SharedPreferences.Editor editor = prefs.edit();
+ editor.remove(PREF_SUPPRESS_LANGUAGE_SWITCH_KEY);
+ editor.putBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, !suppressLanguageSwitchKey);
+ editor.apply();
+ }
+ return prefs.getBoolean(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY, true);
}
public boolean isLanguageSwitchKeyEnabled(final Context context) {
- if (mIsLanguageSwitchKeySuppressed) {
+ if (!mShowsLanguageSwitchKey) {
return false;
}
if (mIncludesOtherImesInLanguageSwitchList) {
@@ -353,7 +366,7 @@ public final class SettingsValues {
}
}
- public boolean isFullscreenModeAllowed(final Resources res) {
+ public static boolean isFullscreenModeAllowed(final Resources res) {
return res.getBoolean(R.bool.config_use_fullscreen_mode);
}
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
index 1a85e71ce..406071071 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictIOUtils.java
@@ -16,10 +16,11 @@
package com.android.inputmethod.latin.makedict;
-import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
+import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
import java.io.IOException;
import java.util.ArrayList;
@@ -91,7 +92,18 @@ public class BinaryDictIOUtils {
}
if (p.mPosition == p.mNumOfCharGroup) {
- stack.pop();
+ if (formatOptions.mHasLinkedListNode) {
+ final int forwardLinkAddress = buffer.readUnsignedInt24();
+ if (forwardLinkAddress != FormatSpec.NO_FORWARD_LINK_ADDRESS) {
+ // the node has a forward link.
+ p.mNumOfCharGroup = Position.NOT_READ_GROUPCOUNT;
+ p.mAddress = forwardLinkAddress;
+ } else {
+ stack.pop();
+ }
+ } else {
+ stack.pop();
+ }
} else {
// the node has more groups.
p.mAddress = buffer.position();
@@ -124,4 +136,69 @@ public class BinaryDictIOUtils {
readUnigramsAndBigramsBinaryInner(buffer, header.mHeaderSize, words, frequencies, bigrams,
header.mFormatOptions);
}
+
+ /**
+ * Gets the address of the last CharGroup of the exact matching word in the dictionary.
+ * If no match is found, returns NOT_VALID_WORD.
+ *
+ * @param buffer the buffer to read.
+ * @param word the word we search for.
+ * @return the address of the terminal node.
+ * @throws IOException
+ * @throws UnsupportedFormatException
+ */
+ public static int getTerminalPosition(final FusionDictionaryBufferInterface buffer,
+ final String word) throws IOException, UnsupportedFormatException {
+ if (word == null) return FormatSpec.NOT_VALID_WORD;
+ if (buffer.position() != 0) buffer.position(0);
+
+ final FileHeader header = BinaryDictInputOutput.readHeader(buffer);
+ int wordPos = 0;
+ final int wordLen = word.codePointCount(0, word.length());
+ for (int depth = 0; depth < Constants.Dictionary.MAX_WORD_LENGTH; ++depth) {
+ if (wordPos >= wordLen) return FormatSpec.NOT_VALID_WORD;
+ int groupOffset = buffer.position() - header.mHeaderSize;
+ final int charGroupCount = BinaryDictInputOutput.readCharGroupCount(buffer);
+ groupOffset += BinaryDictInputOutput.getGroupCountSize(charGroupCount);
+
+ for (int i = 0; i < charGroupCount; ++i) {
+ final int charGroupPos = buffer.position();
+ final CharGroupInfo currentInfo = BinaryDictInputOutput.readCharGroup(buffer,
+ buffer.position(), header.mFormatOptions);
+ boolean same = true;
+ for (int p = 0, j = word.offsetByCodePoints(0, wordPos);
+ p < currentInfo.mCharacters.length;
+ ++p, j = word.offsetByCodePoints(j, 1)) {
+ if (wordPos + p >= wordLen
+ || word.codePointAt(j) != currentInfo.mCharacters[p]) {
+ same = false;
+ break;
+ }
+ }
+
+ if (same) {
+ if (wordPos + currentInfo.mCharacters.length == wordLen) {
+ if (currentInfo.mFrequency == CharGroup.NOT_A_TERMINAL) {
+ return FormatSpec.NOT_VALID_WORD;
+ } else {
+ return charGroupPos;
+ }
+ }
+ wordPos += currentInfo.mCharacters.length;
+ if (currentInfo.mChildrenAddress == FormatSpec.NO_CHILDREN_ADDRESS) {
+ return FormatSpec.NOT_VALID_WORD;
+ }
+ buffer.position(currentInfo.mChildrenAddress);
+ break;
+ }
+ groupOffset = currentInfo.mEndAddress;
+
+ // not found
+ if (i >= charGroupCount - 1) {
+ return FormatSpec.NOT_VALID_WORD;
+ }
+ }
+ }
+ return FormatSpec.NOT_VALID_WORD;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index c865702d6..1d3e94bb7 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -1242,8 +1242,9 @@ public class BinaryDictInputOutput {
* @param formatOptions file format options.
* @return the word, as a string.
*/
- private static String getWordAtAddress(final FusionDictionaryBufferInterface buffer,
- final int headerSize, final int address, final FormatOptions formatOptions) {
+ /* packages for tests */ static String getWordAtAddress(
+ final FusionDictionaryBufferInterface buffer, final int headerSize, final int address,
+ final FormatOptions formatOptions) {
final String cachedString = wordCache.get(address);
if (null != cachedString) return cachedString;
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
index f8f13b197..adc6037bb 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -207,6 +207,9 @@ public final class FormatSpec {
static final int MAX_TERMINAL_FREQUENCY = 255;
static final int MAX_BIGRAM_FREQUENCY = 15;
+ // This option needs to be the same numeric value as the one in binary_format.h.
+ static final int NOT_VALID_WORD = -99;
+
/**
* Options about file format.
*/