Refactor calling KeyboardSwitcher.setKeyboardMode

This change also eliminates unnecessary recursive call in
KeyboardSwitcher.setKeyboardMode.

Change-Id: Iff25fe23b34227d526dee0bbe8710842545c2afa
main
Tadashi G. Takaoka 2010-11-08 23:24:19 -08:00
parent e302b19ddd
commit f8e30a9153
2 changed files with 17 additions and 19 deletions

View File

@ -298,8 +298,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
mImeOptions = imeOptions; mImeOptions = imeOptions;
makeSymbolsKeyboardIds(); makeSymbolsKeyboardIds();
if (enableVoice != mHasVoice) { if (enableVoice != mHasVoice) {
// TODO clean up this unnecessary recursive call. mKeyboards.clear();
setVoiceMode(enableVoice, mVoiceOnPrimary); mHasVoice = enableVoice;
} }
mIsSymbols = isSymbols; mIsSymbols = isSymbols;

View File

@ -585,9 +585,6 @@ public class LatinIME extends InputMethodService
mPasswordText = true; mPasswordText = true;
} }
mEnableVoiceButton = shouldShowVoiceButton(makeFieldContext(), attribute);
final boolean enableVoiceButton = mEnableVoiceButton && mEnableVoice;
mAfterVoiceInput = false; mAfterVoiceInput = false;
mImmediatelyAfterVoiceInput = false; mImmediatelyAfterVoiceInput = false;
mShowingVoiceSuggestions = false; mShowingVoiceSuggestions = false;
@ -598,6 +595,7 @@ public class LatinIME extends InputMethodService
mCompletions = null; mCompletions = null;
mEnteredText = null; mEnteredText = null;
final int mode;
switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) { switch (attribute.inputType & EditorInfo.TYPE_MASK_CLASS) {
case EditorInfo.TYPE_CLASS_NUMBER: case EditorInfo.TYPE_CLASS_NUMBER:
case EditorInfo.TYPE_CLASS_DATETIME: case EditorInfo.TYPE_CLASS_DATETIME:
@ -606,12 +604,9 @@ public class LatinIME extends InputMethodService
// a dedicated number entry keypad. // a dedicated number entry keypad.
// TODO: Use a dedicated number entry keypad here when we get one. // TODO: Use a dedicated number entry keypad here when we get one.
case EditorInfo.TYPE_CLASS_PHONE: case EditorInfo.TYPE_CLASS_PHONE:
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_PHONE, mode = KeyboardSwitcher.MODE_PHONE;
attribute.imeOptions, enableVoiceButton);
break; break;
case EditorInfo.TYPE_CLASS_TEXT: case EditorInfo.TYPE_CLASS_TEXT:
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_TEXT,
attribute.imeOptions, enableVoiceButton);
//startPrediction(); //startPrediction();
mPredictionOn = true; mPredictionOn = true;
// Make sure that passwords are not displayed in candidate view // Make sure that passwords are not displayed in candidate view
@ -626,25 +621,24 @@ public class LatinIME extends InputMethodService
} }
if (isEmailVariation(variation)) { if (isEmailVariation(variation)) {
mPredictionOn = false; mPredictionOn = false;
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_EMAIL, mode = KeyboardSwitcher.MODE_EMAIL;
attribute.imeOptions, enableVoiceButton);
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_URI) { } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_URI) {
mPredictionOn = false; mPredictionOn = false;
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_URL, mode = KeyboardSwitcher.MODE_URL;
attribute.imeOptions, enableVoiceButton);
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE) {
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_IM, mode = KeyboardSwitcher.MODE_IM;
attribute.imeOptions, enableVoiceButton);
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) { } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_FILTER) {
mPredictionOn = false; mPredictionOn = false;
mode = KeyboardSwitcher.MODE_TEXT;
} else if (variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) { } else if (variation == EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT) {
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_WEB, mode = KeyboardSwitcher.MODE_WEB;
attribute.imeOptions, enableVoiceButton);
// If it's a browser edit field and auto correct is not ON explicitly, then // If it's a browser edit field and auto correct is not ON explicitly, then
// disable auto correction, but keep suggestions on. // disable auto correction, but keep suggestions on.
if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) { if ((attribute.inputType & EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT) == 0) {
mInputTypeNoAutoCorrect = true; mInputTypeNoAutoCorrect = true;
} }
} else {
mode = KeyboardSwitcher.MODE_TEXT;
} }
// If NO_SUGGESTIONS is set, don't do prediction. // If NO_SUGGESTIONS is set, don't do prediction.
@ -663,15 +657,19 @@ public class LatinIME extends InputMethodService
} }
break; break;
default: default:
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_TEXT, mode = KeyboardSwitcher.MODE_TEXT;
attribute.imeOptions, enableVoiceButton); break;
} }
inputView.closing(); inputView.closing();
mComposing.setLength(0); mComposing.setLength(0);
mPredicting = false; mPredicting = false;
mDeleteCount = 0; mDeleteCount = 0;
mJustAddedAutoSpace = false; mJustAddedAutoSpace = false;
loadSettings(); loadSettings();
mEnableVoiceButton = shouldShowVoiceButton(makeFieldContext(), attribute);
mKeyboardSwitcher.setKeyboardMode(mode, attribute.imeOptions,
mEnableVoiceButton && mEnableVoice);
updateShiftKeyState(attribute); updateShiftKeyState(attribute);
setCandidatesViewShownInternal(isCandidateStripVisible() || mCompletionOn, setCandidatesViewShownInternal(isCandidateStripVisible() || mCompletionOn,