diff options
Diffstat (limited to 'java/src')
4 files changed, 19 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 03c216474..cb120a33e 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -52,7 +52,7 @@ import java.util.Locale; /** * Class for describing the position and characteristics of a single key in the keyboard. */ -public class Key { +public class Key implements Comparable<Key> { private static final String TAG = Key.class.getSimpleName(); /** @@ -410,7 +410,7 @@ public class Key { }); } - private boolean equals(final Key o) { + private boolean equalsInternal(final Key o) { if (this == o) return true; return o.mX == mX && o.mY == mY @@ -428,13 +428,20 @@ public class Key { } @Override + public int compareTo(Key o) { + if (equalsInternal(o)) return 0; + if (mHashCode > o.mHashCode) return 1; + return -1; + } + + @Override public int hashCode() { return mHashCode; } @Override public boolean equals(final Object o) { - return o instanceof Key && equals((Key)o); + return o instanceof Key && equalsInternal((Key)o); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java index ab5d31d42..e6fe50e02 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java @@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.latin.CollectionUtils; import java.util.ArrayList; -import java.util.HashSet; +import java.util.TreeSet; public class KeyboardParams { public KeyboardId mId; @@ -58,7 +58,7 @@ public class KeyboardParams { public int GRID_WIDTH; public int GRID_HEIGHT; - public final HashSet<Key> mKeys = CollectionUtils.newHashSet(); + public final TreeSet<Key> mKeys = CollectionUtils.newTreeSet(); // ordered set public final ArrayList<Key> mShiftKeys = CollectionUtils.newArrayList(); public final ArrayList<Key> mAltCodeKeysWhileTyping = CollectionUtils.newArrayList(); public final KeyboardIconsSet mIconsSet = new KeyboardIconsSet(); diff --git a/java/src/com/android/inputmethod/latin/AutoCorrection.java b/java/src/com/android/inputmethod/latin/AutoCorrection.java index 01ba30077..f425e360a 100644 --- a/java/src/com/android/inputmethod/latin/AutoCorrection.java +++ b/java/src/com/android/inputmethod/latin/AutoCorrection.java @@ -73,11 +73,11 @@ public class AutoCorrection { return maxFreq; } - // Returns true if this isn't in any dictionary. - public static boolean isNotAWord( + // Returns true if this is in any of the dictionaries. + public static boolean isInTheDictionary( final ConcurrentHashMap<String, Dictionary> dictionaries, final CharSequence word, final boolean ignoreCase) { - return !isValidWord(dictionaries, word, ignoreCase); + return isValidWord(dictionaries, word, ignoreCase); } public static boolean suggestionExceedsAutoCorrectionThreshold(SuggestedWordInfo suggestion, diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 51ed09604..f922bc9e0 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -214,10 +214,12 @@ public class Suggest { whitelistedWord = suggestionsSet.first().mWord; } + // The word can be auto-corrected if it has a whitelist entry that is not itself, + // or if it's a 2+ characters non-word (i.e. it's not in the dictionary). final boolean allowsToBeAutoCorrected = (null != whitelistedWord && !whitelistedWord.equals(consideredWord)) - || AutoCorrection.isNotAWord(mDictionaries, consideredWord, - wordComposer.isFirstCharCapitalized()); + || (consideredWord.length() > 1 && !AutoCorrection.isInTheDictionary(mDictionaries, + consideredWord, wordComposer.isFirstCharCapitalized())); final boolean hasAutoCorrection; // TODO: using isCorrectionEnabled here is not very good. It's probably useless, because |