diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 682901cbc..41884d34a 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -16,6 +16,10 @@ package com.android.inputmethod.latin; +import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE; +import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT; + import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.Context; @@ -81,49 +85,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private static final boolean TRACE = false; private static boolean DEBUG; - /** - * The private IME option used to indicate that no microphone should be - * shown for a given text field. For instance, this is specified by the - * search dialog when the dialog is already showing a voice search button. - * - * @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed. - */ - @SuppressWarnings("dep-ann") - public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm"; - - /** - * The private IME option used to indicate that no microphone should be - * shown for a given text field. For instance, this is specified by the - * search dialog when the dialog is already showing a voice search button. - */ - public static final String IME_OPTION_NO_MICROPHONE = "noMicrophoneKey"; - - /** - * The private IME option used to indicate that no settings key should be - * shown for a given text field. - */ - public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey"; - - /** - * The private IME option used to indicate that the given text field needs - * ASCII code points input. - * - * @deprecated Use {@link EditorInfo#IME_FLAG_FORCE_ASCII}. - */ - @SuppressWarnings("dep-ann") - public static final String IME_OPTION_FORCE_ASCII = "forceAscii"; - - /** - * The subtype extra value used to indicate that the subtype keyboard layout set name. - */ - public static final String SUBTYPE_EXTRA_VALUE_KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; - - /** - * 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_ASCII_CAPABLE = "AsciiCapable"; - private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100; // How many continuous deletes at which to start deleting at a higher speed. @@ -193,6 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private final SubtypeSwitcher mSubtypeSwitcher; private boolean mShouldSwitchToLastSubtype = true; + private boolean mIsMainDictionaryAvailable; private UserDictionary mUserDictionary; private UserHistoryDictionary mUserHistoryDictionary; private boolean mIsUserDictionaryAvailable; @@ -488,14 +450,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return new SettingsValues(mPrefs, LatinIME.this); } }; - mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getInputLocale()); + mSettingsValues = job.runInLocale(mResources, mSubtypeSwitcher.getCurrentSubtypeLocale()); mFeedbackManager = new AudioAndHapticFeedbackManager(this, mSettingsValues); resetContactsDictionary(null == mSuggest ? null : mSuggest.getContactsDictionary()); } private void initSuggest() { - final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); - final Locale keyboardLocale = mSubtypeSwitcher.getInputLocale(); + final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); + final String localeStr = subtypeLocale.toString(); final Dictionary oldContactsDictionary; if (mSuggest != null) { @@ -504,11 +466,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { oldContactsDictionary = null; } - mSuggest = new Suggest(this, keyboardLocale); + mSuggest = new Suggest(this, subtypeLocale); if (mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } + mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); + mUserDictionary = new UserDictionary(this, localeStr); mSuggest.setUserDictionary(mUserDictionary); mIsUserDictionaryAvailable = mUserDictionary.isEnabled(); @@ -550,7 +514,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } else { if (USE_BINARY_CONTACTS_DICTIONARY) { dictionaryToUse = new ContactsBinaryDictionary(this, Suggest.DIC_CONTACTS, - mSubtypeSwitcher.getInputLocale()); + mSubtypeSwitcher.getCurrentSubtypeLocale()); } else { dictionaryToUse = new ContactsDictionary(this, Suggest.DIC_CONTACTS); } @@ -562,7 +526,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } /* package private */ void resetSuggestMainDict() { - mSuggest.resetMainDict(this, mSubtypeSwitcher.getInputLocale()); + final Locale subtypeLocale = mSubtypeSwitcher.getCurrentSubtypeLocale(); + mSuggest.resetMainDict(this, subtypeLocale); + mIsMainDictionaryAvailable = DictionaryFactory.isDictionaryAvailable(this, subtypeLocale); } @Override @@ -642,13 +608,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { - SubtypeSwitcher.getInstance().updateSubtype(subtype); + mSubtypeSwitcher.updateSubtype(subtype); } private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) { super.onStartInput(editorInfo, restarting); } + @SuppressWarnings("deprecation") private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) { super.onStartInputView(editorInfo, restarting); final KeyboardSwitcher switcher = mKeyboardSwitcher; @@ -669,12 +636,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onStartInputViewInternal(editorInfo); } - if (StringUtils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { + if (InputAttributes.inPrivateImeOptions(null, NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); - Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead"); + Log.w(TAG, "Use " + getPackageName() + "." + NO_MICROPHONE + " instead"); } - if (StringUtils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { + if (InputAttributes.inPrivateImeOptions(getPackageName(), FORCE_ASCII, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); @@ -1077,7 +1044,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic == null) return false; final CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 - && StringUtils.canBeFollowedByPeriod(lastThree.charAt(0)) + && canBeFollowedByPeriod(lastThree.charAt(0)) && lastThree.charAt(1) == Keyboard.CODE_SPACE && lastThree.charAt(2) == Keyboard.CODE_SPACE && mHandler.isAcceptingDoubleSpaces()) { @@ -1093,6 +1060,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return false; } + private static boolean canBeFollowedByPeriod(final int codePoint) { + // TODO: Check again whether there really ain't a better way to check this. + // TODO: This should probably be language-dependant... + return Character.isLetterOrDigit(codePoint) + || codePoint == Keyboard.CODE_SINGLE_QUOTE + || codePoint == Keyboard.CODE_DOUBLE_QUOTE + || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS + || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET + || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET + || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; + } + // "ic" may be null private static void removeTrailingSpaceWhileInBatchEdit(final InputConnection ic) { if (ic == null) return; @@ -1920,7 +1899,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mSettingsValues.mEnableSuggestionSpanInsertion) { final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( - this, bestWord, suggestedWords, mSubtypeSwitcher.isDictionaryAvailable()), + this, bestWord, suggestedWords, mIsMainDictionaryAvailable), 1); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_commitText(bestWord); @@ -1998,7 +1977,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } final String secondWord; if (mWordComposer.isAutoCapitalized() && !mWordComposer.isMostlyCaps()) { - secondWord = suggestion.toString().toLowerCase(mSubtypeSwitcher.getInputLocale()); + secondWord = suggestion.toString().toLowerCase( + mSubtypeSwitcher.getCurrentSubtypeLocale()); } else { secondWord = suggestion.toString(); } @@ -2326,8 +2306,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private void showOptionDialogInternal(AlertDialog dialog) { - final IBinder windowToken = KeyboardSwitcher.getInstance().getKeyboardView() - .getWindowToken(); + final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken(); if (windowToken == null) return; dialog.setCancelable(true); |