diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
9 files changed, 76 insertions, 62 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index db57044e9..f5c09974e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -115,16 +115,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; /** - * The subtype extra value used to indicate that the subtype keyboard layout is capable for - * typing ASCII characters. + * The subtype extra value used to indicate that the subtype keyboard layout set name. */ - public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; + public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; /** - * The subtype extra value used to indicate that the subtype keyboard layout should be loaded - * from the specified locale. + * The subtype extra value used to indicate that the subtype keyboard layout is capable for + * typing ASCII characters. */ - public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE = "KeyboardLocale"; + public static final String SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE = "AsciiCapable"; private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100; @@ -713,9 +712,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(editorInfo, mSettingsValues); - } + switcher.loadKeyboard(editorInfo, mSettingsValues); if (mSuggestionsView != null) mSuggestionsView.clear(); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 7b98a7188..6bc049894 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -66,8 +66,8 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; - public static final String PREF_BIGRAM_SUGGESTION = "bigram_suggestion"; - public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction"; + public static final String PREF_BIGRAM_SUGGESTION = "next_word_suggestion"; + public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_KEY_ENABLE_SPAN_INSERT = "enable_span_insert"; public static final String PREF_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; @@ -167,7 +167,7 @@ public class Settings extends InputMethodSettingsActivity } final boolean showBigramSuggestionsOption = res.getBoolean( - R.bool.config_enable_bigram_suggestions_option); + R.bool.config_enable_next_word_suggestions_option); if (!showBigramSuggestionsOption) { textCorrectionGroup.removePreference(mBigramSuggestion); if (null != mBigramPrediction) { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 103678403..49ab7f9d7 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -236,18 +236,18 @@ public class SettingsValues { private static boolean isBigramSuggestionEnabled(final SharedPreferences sp, final Resources resources, final boolean autoCorrectEnabled) { final boolean showBigramSuggestionsOption = resources.getBoolean( - R.bool.config_enable_bigram_suggestions_option); + R.bool.config_enable_next_word_suggestions_option); if (!showBigramSuggestionsOption) { return autoCorrectEnabled; } return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTION, resources.getBoolean( - R.bool.config_default_bigram_suggestions)); + R.bool.config_default_next_word_suggestions)); } private static boolean isBigramPredictionEnabled(final SharedPreferences sp, final Resources resources) { return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean( - R.bool.config_default_bigram_prediction)); + R.bool.config_default_next_word_prediction)); } private static double getAutoCorrectionThreshold(final Resources resources, diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java index 7000e4633..42fce53d0 100644 --- a/java/src/com/android/inputmethod/latin/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -22,6 +22,7 @@ import android.view.inputmethod.EditorInfo; import com.android.inputmethod.keyboard.Keyboard; import java.util.ArrayList; +import java.util.Locale; public class StringUtils { private StringUtils() { @@ -149,4 +150,20 @@ public class StringUtils { i++; } } + + public static String toTitleCase(String s, Locale locale) { + if (s.length() <= 1) { + // TODO: is this really correct? Shouldn't this be s.toUpperCase()? + return s; + } + // TODO: fix the bugs below + // - This does not work for Greek, because it returns upper case instead of title case. + // - It does not work for Serbian, because it fails to account for the "lj" character, + // which should be "Lj" in title case and "LJ" in upper case. + // - It does not work for Dutch, because it fails to account for the "ij" digraph, which + // are two different characters but both should be capitalized as "IJ" as if they were + // a single letter. + // - It also does not work with unicode surrogate code points. + return s.toUpperCase(locale).charAt(0) + s.substring(1); + } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index ba67f3358..2bc22a6f9 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -19,6 +19,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.res.Resources; + import java.util.Locale; public class SubtypeLocale { @@ -68,10 +69,10 @@ public class SubtypeLocale { } final String value = lookupExceptionalLocale(key); if (value == null) { - return toTitleCase(locale.getDisplayName(locale), locale); + return StringUtils.toTitleCase(locale.getDisplayName(locale), locale); } if (value.indexOf("%s") >= 0) { - final String languageName = toTitleCase(locale.getDisplayLanguage(locale), locale); + final String languageName = StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); return String.format(value, languageName); } return value; @@ -87,7 +88,7 @@ public class SubtypeLocale { if (NO_LANGUAGE.equals(locale.getLanguage())) { return lookupExceptionalLocale(locale.getCountry()); } else { - return toTitleCase(locale.getDisplayLanguage(locale), locale); + return StringUtils.toTitleCase(locale.getDisplayLanguage(locale), locale); } } @@ -101,23 +102,7 @@ public class SubtypeLocale { if (NO_LANGUAGE.equals(locale.getLanguage())) { return locale.getCountry(); } else { - return toTitleCase(locale.getLanguage(), locale); - } - } - - public static String toTitleCase(String s, Locale locale) { - if (s.length() <= 1) { - // TODO: is this really correct? Shouldn't this be s.toUpperCase()? - return s; + return StringUtils.toTitleCase(locale.getLanguage(), locale); } - // TODO: fix the bugs below - // - This does not work for Greek, because it returns upper case instead of title case. - // - It does not work for Serbian, because it fails to account for the "lj" character, - // which should be "Lj" in title case and "LJ" in upper case. - // - It does not work for Dutch, because it fails to account for the "ij" digraph, which - // are two different characters but both should be capitalized as "IJ" as if they were - // a single letter. - // - It also does not work with unicode surrogate code points. - return s.toUpperCase(locale).charAt(0) + s.substring(1); } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 7541bd31b..dfb01a24c 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -33,6 +33,7 @@ import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.keyboard.KeyboardLayoutSet; import com.android.inputmethod.keyboard.KeyboardSwitcher; import java.util.ArrayList; @@ -68,6 +69,7 @@ public class SubtypeSwitcher { private InputMethodInfo mShortcutInputMethodInfo; private InputMethodSubtype mShortcutSubtype; private List<InputMethodSubtype> mAllEnabledSubtypesOfCurrentInputMethod; + private InputMethodSubtype mNoLanguageSubtype; // Note: This variable is always non-null after {@link #initialize(LatinIME)}. private InputMethodSubtype mCurrentSubtype; private Locale mSystemLocale; @@ -104,6 +106,8 @@ public class SubtypeSwitcher { mInputLocaleStr = null; mCurrentSubtype = mImm.getCurrentInputMethodSubtype(); mAllEnabledSubtypesOfCurrentInputMethod = null; + mNoLanguageSubtype = SubtypeUtils.findSubtypeByKeyboardLayoutSetLocale( + service, SubtypeLocale.LOCALE_NO_LANGUAGE_QWERTY); final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); @@ -133,7 +137,7 @@ public class SubtypeSwitcher { mEnabledLanguagesOfCurrentInputMethod.clear(); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); for (InputMethodSubtype ims : mAllEnabledSubtypesOfCurrentInputMethod) { - final String locale = getSubtypeLocale(ims); + final String locale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(ims); final String mode = ims.getMode(); mLocaleSplitter.setString(locale); if (mLocaleSplitter.hasNext()) { @@ -162,7 +166,8 @@ public class SubtypeSwitcher { Log.d(TAG, "Update shortcut IME from : " + (mShortcutInputMethodInfo == null ? "<null>" : mShortcutInputMethodInfo.getId()) + ", " - + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype) + + (mShortcutSubtype == null ? "<null>" : ( + KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype) + ", " + mShortcutSubtype.getMode()))); } // TODO: Update an icon for shortcut IME @@ -184,20 +189,15 @@ public class SubtypeSwitcher { Log.d(TAG, "Update shortcut IME to : " + (mShortcutInputMethodInfo == null ? "<null>" : mShortcutInputMethodInfo.getId()) + ", " - + (mShortcutSubtype == null ? "<null>" : (getSubtypeLocale(mShortcutSubtype) + + (mShortcutSubtype == null ? "<null>" : ( + KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(mShortcutSubtype) + ", " + mShortcutSubtype.getMode()))); } } - private static String getSubtypeLocale(InputMethodSubtype subtype) { - final String keyboardLocale = subtype.getExtraValueOf( - LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE); - return keyboardLocale != null ? keyboardLocale : subtype.getLocale(); - } - // Update the current subtype. LatinIME.onCurrentInputMethodSubtypeChanged calls this function. public void updateSubtype(InputMethodSubtype newSubtype) { - final String newLocale = getSubtypeLocale(newSubtype); + final String newLocale = KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(newSubtype); final String newMode = newSubtype.getMode(); final String oldMode = getCurrentSubtypeMode(); if (DBG) { @@ -301,7 +301,8 @@ public class SubtypeSwitcher { final String imiPackageName = imi.getPackageName(); if (DBG) { Log.d(TAG, "Update icons of IME: " + imiPackageName + "," - + getSubtypeLocale(subtype) + "," + subtype.getMode()); + + KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype) + "," + + subtype.getMode()); } if (subtype != null) { return pm.getDrawable(imiPackageName, subtype.getIconResId(), @@ -419,30 +420,27 @@ public class SubtypeSwitcher { } } - public boolean isKeyboardMode() { + // TODO: Remove this method + private boolean isKeyboardMode() { return KEYBOARD_MODE.equals(getCurrentSubtypeMode()); } - ///////////////////////////// - // Other utility functions // - ///////////////////////////// - - public String getCurrentSubtypeExtraValue() { - // If null, return what an empty ExtraValue would return : the empty string. - return mCurrentSubtype.getExtraValue(); + // TODO: Remove this method + private String getCurrentSubtypeMode() { + return mCurrentSubtype.getMode(); } + // TODO: Remove this method public boolean currentSubtypeContainsExtraValueKey(String key) { // If null, return what an empty ExtraValue would return : false. return mCurrentSubtype.containsExtraValueKey(key); } - public String getCurrentSubtypeExtraValueOf(String key) { - // If null, return what an empty ExtraValue would return : null. - return mCurrentSubtype.getExtraValueOf(key); + public InputMethodSubtype getCurrentSubtype() { + return mCurrentSubtype; } - public String getCurrentSubtypeMode() { - return mCurrentSubtype.getMode(); + public InputMethodSubtype getNoLanguageSubtype() { + return mNoLanguageSubtype; } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java index 2c5d58200..a747c9ad7 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeUtils.java +++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java @@ -21,9 +21,11 @@ import android.view.inputmethod.InputMethodInfo; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.keyboard.KeyboardLayoutSet; import java.util.Collections; import java.util.List; +import java.util.Locale; public class SubtypeUtils { private SubtypeUtils() { @@ -129,4 +131,18 @@ public class SubtypeUtils { } throw new RuntimeException("Can not find input method id for " + packageName); } + + public static InputMethodSubtype findSubtypeByKeyboardLayoutSetLocale( + Context context, Locale locale) { + final String localeString = locale.toString(); + final InputMethodInfo imi = SubtypeUtils.getInputMethodInfo(context.getPackageName()); + final int count = imi.getSubtypeCount(); + for (int i = 0; i < count; i++) { + final InputMethodSubtype subtype = imi.getSubtypeAt(i); + if (localeString.equals(KeyboardLayoutSet.getKeyboardLayoutSetLocaleString(subtype))) { + return subtype; + } + } + throw new RuntimeException("Can not find subtype of locale " + localeString); + } } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 4004f6930..44c4bc768 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -261,7 +261,9 @@ public class Suggest implements Dictionary.WordCallback { SuggestedWordInfo.removeDups(mSuggestions); return new SuggestedWords(mSuggestions, - false /* typedWordValid */, + // TODO: Just assuming the suggestions that came from the bigram prediction are + // valid now. Need to assign a correct value for typedWordValid. + true /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index cd01bb146..1fc945f3c 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -37,7 +37,6 @@ import com.android.inputmethod.latin.Flag; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StringUtils; -import com.android.inputmethod.latin.SubtypeLocale; import com.android.inputmethod.latin.SynchronouslyLoadedContactsDictionary; import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary; import com.android.inputmethod.latin.WhitelistDictionary; @@ -326,7 +325,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService } else if (CAPITALIZE_FIRST == capitalizeType) { for (int i = 0; i < mSuggestions.size(); ++i) { // Likewise - mSuggestions.set(i, SubtypeLocale.toTitleCase( + mSuggestions.set(i, StringUtils.toTitleCase( mSuggestions.get(i).toString(), locale)); } } |