diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
4 files changed, 34 insertions, 13 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 4dbfb44d6..543f74fc4 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -207,6 +207,7 @@ public final class BinaryDictionary extends Dictionary { private static native boolean addUnigramWordNative(long dict, int[] word, int probability, int[] shortcutTarget, int shortcutProbability, boolean isBeginningOfSentence, boolean isNotAWord, boolean isBlacklisted, int timestamp); + private static native boolean removeUnigramWordNative(long dict, int[] word); private static native boolean addBigramWordsNative(long dict, int[] word0, boolean isBeginningOfSentence, int[] word1, int probability, int timestamp); private static native boolean removeBigramWordsNative(long dict, int[] word0, @@ -436,6 +437,19 @@ public final class BinaryDictionary extends Dictionary { return true; } + // Remove a unigram entry from the binary dictionary in native code. + public boolean removeUnigramEntry(final String word) { + if (TextUtils.isEmpty(word)) { + return false; + } + final int[] codePoints = StringUtils.toCodePointArray(word); + if (!removeUnigramWordNative(mNativeDict, codePoints)) { + return false; + } + mHasUpdated = true; + return true; + } + // Add an n-gram entry to the binary dictionary with timestamp in native code. public boolean addNgramEntry(final PrevWordsInfo prevWordsInfo, final String word, final int probability, final int timestamp) { diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 4dbfa0bac..b1966bffc 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -122,6 +122,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { return mBinaryDictionary.isValidDictionary(); } + // TODO: Remove and always enable beginning of sentence prediction. Currently, this is enabled + // only for ContextualDictionary. + protected boolean enableBeginningOfSentencePrediction() { + return false; + } + /** * Creates a new expandable binary dictionary. * @@ -398,6 +404,10 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { if (mBinaryDictionary == null) { return null; } + if (composer.size() == 0 && prevWordsInfo.mIsBeginningOfSentence + && !enableBeginningOfSentencePrediction()) { + return null; + } final ArrayList<SuggestedWordInfo> suggestions = mBinaryDictionary.getSuggestions(composer, prevWordsInfo, proximityInfo, blockOffensiveWords, additionalFeaturesOptions, sessionId, diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java index cbdc4b9eb..7758ac78e 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java @@ -409,21 +409,12 @@ public final class RichInputMethodManager { public boolean shouldOfferSwitchingToNextInputMethod(final IBinder binder, boolean defaultValue) { - // Use the default value instead on Jelly Bean MR2 and previous, where - // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available. - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { + // Use the default value instead on Jelly Bean MR2 and previous where + // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} isn't yet available + // and on KitKat where the API is still just a stub to return true always. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { return defaultValue; } - // Use the default value instead on KitKat as well, where - // {@link InputMethodManager#shouldOfferSwitchingToNextInputMethod} is still just a stub to - // return true always. - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { - // Make sure this is actually KitKat. - // TODO: Consider to remove this check once the *next* version becomes available. - if (Build.VERSION.CODENAME.equals("REL")) { - return defaultValue; - } - } return mImmWrapper.shouldOfferSwitchingToNextInputMethod(binder); } } diff --git a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java index 536554d98..a96018fe9 100644 --- a/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/ContextualDictionary.java @@ -35,6 +35,7 @@ public class ContextualDictionary extends ExpandableBinaryDictionary { // Always reset the contents. clear(); } + @UsedForTesting public static ContextualDictionary getDictionary(final Context context, final Locale locale, final File dictFile, final String dictNamePrefix) { @@ -42,6 +43,11 @@ public class ContextualDictionary extends ExpandableBinaryDictionary { } @Override + protected boolean enableBeginningOfSentencePrediction() { + return true; + } + + @Override public boolean isValidWord(final String word) { // Strings out of this dictionary should not be considered existing words. return false; |