diff options
Diffstat (limited to 'java/src')
10 files changed, 124 insertions, 85 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 25ef847cd..42af8a8d6 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -174,12 +174,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private void loadKeyboardInternal(int mode, int imeOptions, boolean voiceButtonEnabled, boolean voiceButtonOnPrimary, boolean isSymbols) { if (mInputView == null) return; - final Keyboard oldKeyboard = mInputView.getKeyboard(); - final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); - if (oldKeyboard != null && oldKeyboard.mId.equals(id)) - return; - - mInputView.setPreviewEnabled(mInputMethodService.getPopupOn()); mMode = mode; mImeOptions = imeOptions; @@ -188,9 +182,15 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha mIsSymbols = isSymbols; // Update the settings key state because number of enabled IMEs could have been changed mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService); - makeSymbolsKeyboardIds(); + final KeyboardId id = getKeyboardId(mode, imeOptions, isSymbols); + final Keyboard oldKeyboard = mInputView.getKeyboard(); + if (oldKeyboard != null && oldKeyboard.mId.equals(id)) + return; + + makeSymbolsKeyboardIds(); mCurrentId = id; + mInputView.setPreviewEnabled(mInputMethodService.getPopupOn()); mInputView.setKeyboard(getKeyboard(id)); } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index a952acf8b..b1815a146 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -298,8 +298,6 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView); - LayoutInflater inflate = - (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); int previewLayout = 0; int keyTextSize = 0; @@ -365,7 +363,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { mPreviewPopup = new PopupWindow(context); if (previewLayout != 0) { - mPreviewText = (TextView) inflate.inflate(previewLayout, null); + mPreviewText = (TextView) LayoutInflater.from(context).inflate(previewLayout, null); mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large); mPreviewPopup.setContentView(mPreviewText); mPreviewPopup.setBackgroundDrawable(null); @@ -1080,9 +1078,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { private View inflateMiniKeyboardContainer(Key popupKey) { int popupKeyboardResId = mKeyboard.getPopupKeyboardResId(); - LayoutInflater inflater = (LayoutInflater)getContext().getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - View container = inflater.inflate(mPopupLayout, null); + View container = LayoutInflater.from(getContext()).inflate(mPopupLayout, null); if (container == null) throw new NullPointerException(); @@ -1408,7 +1404,9 @@ public class KeyboardView extends View implements PointerTracker.UIProxy { dismissPopupKeyboard(); mBuffer = null; mCanvas = null; + mKeyboard = null; mMiniKeyboardCache.clear(); + requestLayout(); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index db8934049..888375b93 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -70,7 +70,6 @@ public class LatinKeyboard extends Keyboard { private static final float SPACEBAR_POPUP_MIN_RATIO = 0.4f; // Height in space key the language name will be drawn. (proportional to space key height) public static final float SPACEBAR_LANGUAGE_BASELINE = 0.6f; - private static final float SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON = 0.65f; // If the full language name needs to be smaller than this value to be drawn on space key, // its short language name will be used instead. private static final float MINIMUM_SCALE_OF_LANGUAGE_NAME = 0.8f; @@ -225,9 +224,12 @@ public class LatinKeyboard extends Keyboard { allowVariableTextSize); // Draw language text with shadow - final float baseline = height * (mSpaceIcon != null ? SPACEBAR_LANGUAGE_BASELINE - : SPACEBAR_LANGUAGE_BASELINE_WITHOUT_ICON); + // In case there is no space icon, we will place the language text at the center of + // spacebar. final float descent = paint.descent(); + final float textHeight = -paint.ascent() + descent; + final float baseline = (mSpaceIcon != null) ? height * SPACEBAR_LANGUAGE_BASELINE + : height / 2 + textHeight / 2; paint.setColor(getSpacebarTextColor(mSpacebarTextShadowColor, mSpacebarTextFadeFactor)); canvas.drawText(language, width / 2, baseline - descent - 1, paint); paint.setColor(getSpacebarTextColor(mSpacebarTextColor, mSpacebarTextFadeFactor)); diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index f7e67673a..813f7d32f 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -42,6 +42,7 @@ public class BinaryDictionary extends Dictionary { private static final int TYPED_LETTER_MULTIPLIER = 2; + private static final BinaryDictionary sInstance = new BinaryDictionary(); private int mDicTypeId; private int mNativeDict; private long mDictLength; @@ -59,16 +60,24 @@ public class BinaryDictionary extends Dictionary { } } + private BinaryDictionary() { + } + /** - * Create a dictionary from a raw resource file + * Initialize a dictionary from a raw resource file * @param context application context for reading resources * @param resId the resource containing the raw binary dictionary + * @return initialized instance of BinaryDictionary */ - public BinaryDictionary(Context context, int resId, int dicTypeId) { - if (resId != 0) { - loadDictionary(context, resId); + public static BinaryDictionary initDictionary(Context context, int resId, int dicTypeId) { + synchronized (sInstance) { + sInstance.closeInternal(); + if (resId != 0) { + sInstance.loadDictionary(context, resId); + sInstance.mDicTypeId = dicTypeId; + } } - mDicTypeId = dicTypeId; + return sInstance; } private native int openNative(String sourceDir, long dictOffset, long dictSize, @@ -104,6 +113,8 @@ public class BinaryDictionary extends Dictionary { @Override public void getBigrams(final WordComposer codes, final CharSequence previousWord, final WordCallback callback, int[] nextLettersFrequencies) { + if (mNativeDict == 0) return; + char[] chars = previousWord.toString().toCharArray(); Arrays.fill(mOutputChars_bigrams, (char) 0); Arrays.fill(mFrequencies_bigrams, 0); @@ -135,6 +146,8 @@ public class BinaryDictionary extends Dictionary { @Override public void getWords(final WordComposer codes, final WordCallback callback, int[] nextLettersFrequencies) { + if (mNativeDict == 0) return; + final int codesSize = codes.size(); // Won't deal with really long words. if (codesSize > MAX_WORD_LENGTH - 1) return; @@ -179,6 +192,10 @@ public class BinaryDictionary extends Dictionary { @Override public synchronized void close() { + closeInternal(); + } + + private void closeInternal() { if (mNativeDict != 0) { closeNative(mNativeDict); mNativeDict = 0; @@ -188,7 +205,10 @@ public class BinaryDictionary extends Dictionary { @Override protected void finalize() throws Throwable { - close(); - super.finalize(); + try { + closeInternal(); + } finally { + super.finalize(); + } } } diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java index faee38eda..a9f2c2c22 100644 --- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java @@ -107,7 +107,7 @@ public class InputLanguageSelection extends PreferenceActivity { res.updateConfiguration(conf, res.getDisplayMetrics()); int mainDicResId = LatinIME.getMainDictionaryResourceId(res); - BinaryDictionary bd = new BinaryDictionary(this, mainDicResId, Suggest.DIC_MAIN); + BinaryDictionary bd = BinaryDictionary.initDictionary(this, mainDicResId, Suggest.DIC_MAIN); // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of // 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words. diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f839a806c..5766f6b38 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -154,6 +154,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean mConfigSwipeDownDismissKeyboardEnabled; private int mConfigDelayBeforeFadeoutLanguageOnSpacebar; private int mConfigDurationOfFadeoutLanguageOnSpacebar; + private float mConfigFinalFadeoutFactorOfLanugageOnSpacebar; private int mCorrectionMode; private int mCommittedLength; @@ -267,13 +268,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen break; case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: if (inputView != null) - inputView.setSpacebarTextFadeFactor(0.5f, (LatinKeyboard)msg.obj); + inputView.setSpacebarTextFadeFactor( + (1.0f + mConfigFinalFadeoutFactorOfLanugageOnSpacebar) / 2, + (LatinKeyboard)msg.obj); sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), mConfigDurationOfFadeoutLanguageOnSpacebar); break; case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: if (inputView != null) - inputView.setSpacebarTextFadeFactor(0.0f, (LatinKeyboard)msg.obj); + inputView.setSpacebarTextFadeFactor( + mConfigFinalFadeoutFactorOfLanugageOnSpacebar, (LatinKeyboard)msg.obj); break; } } @@ -356,6 +360,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen R.integer.config_delay_before_fadeout_language_on_spacebar); mConfigDurationOfFadeoutLanguageOnSpacebar = res.getInteger( R.integer.config_duration_of_fadeout_language_on_spacebar); + mConfigFinalFadeoutFactorOfLanugageOnSpacebar = res.getInteger( + R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; Utils.GCUtils.getInstance().reset(); boolean tryGC = true; @@ -438,6 +444,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onConfigurationChanged(Configuration conf) { + mSubtypeSwitcher.onConfigurationChanged(conf); // If orientation changed while predicting, commit the change if (conf.orientation != mOrientation) { InputConnection ic = getCurrentInputConnection(); @@ -608,7 +615,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen checkReCorrectionOnStart(); inputView.setForeground(true); - mVoiceConnector.onStartInputView(mKeyboardSwitcher.getInputView().getWindowToken()); + mVoiceConnector.onStartInputView(inputView.getWindowToken()); if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f04f3efe7..21c99fe09 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -134,7 +134,7 @@ public class SubtypeSwitcher { private void updateEnabledSubtypes() { boolean foundCurrentSubtypeBecameDisabled = true; mAllEnabledSubtypesOfCurrentInputMethod = mImm.getEnabledInputMethodSubtypeList( - null, false); + null, true); mEnabledLanguagesOfCurrentInputMethod.clear(); mEnabledKeyboardSubtypesOfCurrentInputMethod.clear(); for (InputMethodSubtype ims: mAllEnabledSubtypesOfCurrentInputMethod) { @@ -370,6 +370,23 @@ public class SubtypeSwitcher { } } + public void onConfigurationChanged(Configuration conf) { + final Locale systemLocale = conf.locale; + // If system configuration was changed, update all parameters. + if (!TextUtils.equals(systemLocale.toString(), mSystemLocale.toString())) { + if (mConfigUseSpacebarLanguageSwitcher) { + // If the system locale changes and is different from the saved + // locale (mSystemLocale), then reload the input locale list from the + // latin ime settings (shared prefs) and reset the input locale + // to the first one. + mLanguageSwitcher.loadLocales(mPrefs); + mLanguageSwitcher.setSystemLocale(systemLocale); + } else { + updateAllParameters(); + } + } + } + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (mConfigUseSpacebarLanguageSwitcher) { if (Settings.PREF_SELECTED_LANGUAGES.equals(key)) { diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 9ea9c2f3e..a8454b23e 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -103,7 +103,7 @@ public class Suggest implements Dictionary.WordCallback { private int mCorrectionMode = CORRECTION_BASIC; public Suggest(Context context, int dictionaryResId) { - mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN); + mMainDict = BinaryDictionary.initDictionary(context, dictionaryResId, DIC_MAIN); initPool(); } @@ -127,7 +127,7 @@ public class Suggest implements Dictionary.WordCallback { } public boolean hasMainDictionary() { - return mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD; + return mMainDict != null && mMainDict.getSize() > LARGE_DICTIONARY_THRESHOLD; } public int getApproxMaxWordLength() { @@ -276,7 +276,7 @@ public class Suggest implements Dictionary.WordCallback { mHaveCorrection = true; } } - mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); + if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); if ((mCorrectionMode == CORRECTION_FULL || mCorrectionMode == CORRECTION_FULL_BIGRAM) && mSuggestions.size() > 0 && mPriorities.length > 0) { // TODO: when the normalized score of the first suggestion is nearly equals to @@ -496,7 +496,7 @@ public class Suggest implements Dictionary.WordCallback { } public boolean isValidWord(final CharSequence word) { - if (word == null || word.length() == 0) { + if (word == null || word.length() == 0 || mMainDict == null) { return false; } return mMainDict.isValidWord(word) diff --git a/java/src/com/android/inputmethod/voice/RecognitionView.java b/java/src/com/android/inputmethod/voice/RecognitionView.java index 12d0de852..d6d0721e2 100644 --- a/java/src/com/android/inputmethod/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/voice/RecognitionView.java @@ -103,9 +103,7 @@ public class RecognitionView { public RecognitionView(Context context, OnClickListener clickListener) { mUiHandler = new Handler(); - LayoutInflater inflater = (LayoutInflater) context.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - mView = inflater.inflate(R.layout.recognition_status, null); + mView = LayoutInflater.from(context).inflate(R.layout.recognition_status, null); ContentResolver cr = context.getContentResolver(); mMinMicrophoneLevel = SettingsUtil.getSettingsFloat( cr, SettingsUtil.LATIN_IME_MIN_MICROPHONE_LEVEL, 15.f); diff --git a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java index 1ac4391f1..715486147 100644 --- a/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java +++ b/java/src/com/android/inputmethod/voice/VoiceIMEConnector.java @@ -16,6 +16,7 @@ package com.android.inputmethod.voice; +import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; @@ -91,7 +92,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { private boolean mVoiceInputHighlighted; private InputMethodManager mImm; - private LatinIME mContext; + private LatinIME mService; private AlertDialog mVoiceWarningDialog; private VoiceInput mVoiceInput; private final VoiceResults mVoiceResults = new VoiceResults(); @@ -111,21 +112,19 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { return sInstance; } - private void initInternal(LatinIME context, SharedPreferences prefs, UIHandler h) { - mContext = context; + private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { + mService = service; mHandler = h; - mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); + mImm = (InputMethodManager) service.getSystemService(Context.INPUT_METHOD_SERVICE); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (VOICE_INSTALLED) { - mVoiceInput = new VoiceInput(context, this); - mHints = new Hints(context, prefs, new Hints.Display() { + mVoiceInput = new VoiceInput(service, this); + mHints = new Hints(service, prefs, new Hints.Display() { @Override public void showHint(int viewResource) { - LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(viewResource, null); - mContext.setCandidatesView(view); - mContext.setCandidatesViewShown(true); + View view = LayoutInflater.from(mService).inflate(viewResource, null); + mService.setCandidatesView(view); + mService.setCandidatesViewShown(true); mIsShowingHint = true; } }); @@ -161,7 +160,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mVoiceInput.flushAllTextModificationCounters(); // send this intent AFTER logging any prior aggregated edits. mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index, - wordSeparators, mContext.getCurrentInputConnection()); + wordSeparators, mService.getCurrentInputConnection()); } } @@ -170,7 +169,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { return; } - AlertDialog.Builder builder = new AlertDialog.Builder(mContext); + AlertDialog.Builder builder = new AlertDialog.Builder(mService); builder.setCancelable(true); builder.setIcon(R.drawable.ic_mic_dialog); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -199,13 +198,13 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { final CharSequence message; if (mLocaleSupportedForVoiceInput) { message = TextUtils.concat( - mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", - mContext.getText(R.string.voice_warning_how_to_turn_off)); + mService.getText(R.string.voice_warning_may_not_understand), "\n\n", + mService.getText(R.string.voice_warning_how_to_turn_off)); } else { message = TextUtils.concat( - mContext.getText(R.string.voice_warning_locale_not_supported), "\n\n", - mContext.getText(R.string.voice_warning_may_not_understand), "\n\n", - mContext.getText(R.string.voice_warning_how_to_turn_off)); + mService.getText(R.string.voice_warning_locale_not_supported), "\n\n", + mService.getText(R.string.voice_warning_may_not_understand), "\n\n", + mService.getText(R.string.voice_warning_how_to_turn_off)); } builder.setMessage(message); @@ -296,7 +295,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } public void showPunctuationHintIfNecessary() { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { if (mHints.showPunctuationHintIfNecessary(ic)) { mVoiceInput.logPunctuationHintDisplayed(); @@ -364,17 +363,17 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } private void revertVoiceInput() { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); - mContext.updateSuggestions(); + mService.updateSuggestions(); mVoiceInputHighlighted = false; } public void commitVoiceInput() { if (VOICE_INSTALLED && mVoiceInputHighlighted) { - InputConnection ic = mContext.getCurrentInputConnection(); + InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.finishComposingText(); - mContext.updateSuggestions(); + mService.updateSuggestions(); mVoiceInputHighlighted = false; } } @@ -394,7 +393,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (mShowingVoiceSuggestions) { // Retain the replaced word in the alternatives array. String wordToBeReplaced = EditingUtils.getWordAtCursor( - mContext.getCurrentInputConnection(), wordSeparators); + mService.getCurrentInputConnection(), wordSeparators); if (!mWordToSuggestions.containsKey(wordToBeReplaced)) { wordToBeReplaced = wordToBeReplaced.toLowerCase(); } @@ -438,8 +437,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { builder.addWords(suggestions); } builder.setTypedWordValid(true).setHasMinimalSuggestion(true); - mContext.setSuggestions(builder.build()); - mContext.setCandidatesViewShown(true); + mService.setSuggestions(builder.build()); + mService.setCandidatesViewShown(true); return true; } return false; @@ -486,15 +485,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true; - InputConnection ic = mContext.getCurrentInputConnection(); - if (!mContext.isFullscreenMode()) { + InputConnection ic = mService.getCurrentInputConnection(); + if (!mService.isFullscreenMode()) { // Start listening for updates to the text from typing, etc. if (ic != null) { ExtractedTextRequest req = new ExtractedTextRequest(); ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR); } } - mContext.vibrate(); + mService.vibrate(); final List<CharSequence> nBest = new ArrayList<CharSequence>(); for (String c : mVoiceResults.candidates) { @@ -511,7 +510,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mHints.registerVoiceResult(bestResult); if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text - mContext.commitTyped(ic); + mService.commitTyped(ic); EditingUtils.appendText(ic, bestResult); if (ic != null) ic.endBatchEdit(); @@ -525,15 +524,15 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { mHandler.post(new Runnable() { @Override public void run() { - mContext.setCandidatesViewShown(false); + mService.setCandidatesViewShown(false); mRecognizing = true; View v = mVoiceInput.getView(); ViewParent p = v.getParent(); if (p != null && p instanceof ViewGroup) { ((ViewGroup)p).removeView(v); } - mContext.setInputView(v); - mContext.updateInputViewShown(); + mService.setInputView(v); + mService.updateInputViewShown(); if (configChanged) { mVoiceInput.onConfigurationChanged(); } @@ -541,7 +540,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { } private void switchToLastInputMethod() { - IBinder token = mContext.getWindow().getWindow().getAttributes().token; + IBinder token = mService.getWindow().getWindow().getAttributes().token; mImm.switchToLastInputMethod(token); } @@ -553,7 +552,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // The user has started a voice input, so remember that in the // future (so we don't show the warning dialog after the first run). SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mContext).edit(); + PreferenceManager.getDefaultSharedPreferences(mService).edit(); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true); SharedPreferencesCompat.apply(editor); mHasUsedVoiceInput = true; @@ -563,14 +562,14 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // The user has started a voice input from an unsupported locale, so remember that // in the future (so we don't show the warning dialog the next time they do this). SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mContext).edit(); + PreferenceManager.getDefaultSharedPreferences(mService).edit(); editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true); SharedPreferencesCompat.apply(editor); mHasUsedVoiceInputUnsupportedLocale = true; } // Clear N-best suggestions - mContext.clearSuggestions(); + mService.clearSuggestions(); FieldContext context = makeFieldContext(); mVoiceInput.startListening(context, swipe); @@ -579,7 +578,6 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { public void startListening(final boolean swipe, IBinder token, final boolean configurationChanging) { - // TODO: remove swipe which is no longer used. if (VOICE_INSTALLED) { if (needsToShowWarningDialog()) { // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. @@ -601,7 +599,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !(attribute != null && IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions)) - && SpeechRecognizer.isRecognitionAvailable(mContext); + && SpeechRecognizer.isRecognitionAvailable(mService); } public void loadSettings(EditorInfo attribute, SharedPreferences sp) { @@ -614,10 +612,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { if (VOICE_INSTALLED) { final String voiceMode = sp.getString(PREF_VOICE_MODE, - mContext.getString(R.string.voice_mode_main)); - mVoiceButtonEnabled = !voiceMode.equals(mContext.getString(R.string.voice_mode_off)) + mService.getString(R.string.voice_mode_main)); + mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) && shouldShowVoiceButton(makeFieldContext(), attribute); - mVoiceButtonOnPrimary = voiceMode.equals(mContext.getString(R.string.voice_mode_main)); + mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); } } @@ -631,11 +629,10 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // If IME is in voice mode, but still needs to show the voice warning dialog, // keep showing the warning. if (mSubtypeSwitcher.isVoiceMode() && token != null) { - if (needsToShowWarningDialog()) { - showVoiceWarningDialog(false, token, false); - } else { - startListening(false, token, false); - } + // Close keyboard view if it is been shown. + if (KeyboardSwitcher.getInstance().isInputViewShown()) + KeyboardSwitcher.getInstance().getInputView().closing(); + startListening(false, token, false); } // If we have no token, onAttachedToWindow will take care of showing dialog and start // listening. @@ -668,7 +665,7 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { // onCurrentInputMethodSubtypeChanged() will be called first. LatinIME will know // that it's in keyboard mode and SubtypeSwitcher will call onCancelVoice(). mRecognizing = false; - mContext.switchToKeyboardView(); + mService.switchToKeyboardView(); } } } @@ -686,8 +683,8 @@ public class VoiceIMEConnector implements VoiceInput.UiListener { public FieldContext makeFieldContext() { SubtypeSwitcher switcher = SubtypeSwitcher.getInstance(); - return new FieldContext(mContext.getCurrentInputConnection(), - mContext.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), + return new FieldContext(mService.getCurrentInputConnection(), + mService.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), switcher.getEnabledLanguages()); } |