diff --git a/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/src/com/android/inputmethod/latin/KeyboardSwitcher.java index 38979edde..4322997e8 100644 --- a/src/com/android/inputmethod/latin/KeyboardSwitcher.java +++ b/src/com/android/inputmethod/latin/KeyboardSwitcher.java @@ -178,12 +178,13 @@ public class KeyboardSwitcher { mPreferSymbols); } - void setKeyboardMode(int mode, int imeOptions, - boolean enableVoice, boolean isSymbols) { + void setKeyboardMode(int mode, int imeOptions, boolean enableVoice, boolean isSymbols) { if (mInputView == null) return; mMode = mode; mImeOptions = imeOptions; - mHasVoice = enableVoice; + if (enableVoice != mHasVoice) { + setVoiceMode(mHasVoice, mVoiceOnPrimary); + } mIsSymbols = isSymbols; mInputView.setPreviewEnabled(true); @@ -211,7 +212,8 @@ public class KeyboardSwitcher { conf.locale = mInputLocale; orig.updateConfiguration(conf, null); LatinKeyboard keyboard = new LatinKeyboard( - mContext, id.mXml, id.mKeyboardMode, id.mHasVoice); + mContext, id.mXml, id.mKeyboardMode); + keyboard.setVoiceMode(hasVoiceButton(id.mXml == R.xml.kbd_symbols), mHasVoice); keyboard.setLanguageSwitcher(mLanguageSwitcher); if (id.mKeyboardMode == KEYBOARDMODE_NORMAL || id.mKeyboardMode == KEYBOARDMODE_URL diff --git a/src/com/android/inputmethod/latin/LatinIME.java b/src/com/android/inputmethod/latin/LatinIME.java index 0757f1bb6..4c81b33b1 100644 --- a/src/com/android/inputmethod/latin/LatinIME.java +++ b/src/com/android/inputmethod/latin/LatinIME.java @@ -790,7 +790,7 @@ public class LatinIME extends InputMethodService } mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher); if (mInputView != null) { - mKeyboardSwitcher.setVoiceMode(mEnableVoice, mVoiceOnPrimary); + mKeyboardSwitcher.setVoiceMode(mEnableVoice && mEnableVoiceButton, mVoiceOnPrimary); } mKeyboardSwitcher.makeKeyboards(true); } @@ -1829,8 +1829,10 @@ public class LatinIME extends InputMethodService mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true); if (VOICE_INSTALLED) { - final String voiceMode = sp.getString(PREF_VOICE_MODE, ""); - boolean enableVoice = !voiceMode.equals(getString(R.string.voice_mode_off)); + final String voiceMode = sp.getString(PREF_VOICE_MODE, + getString(R.string.voice_mode_main)); + boolean enableVoice = !voiceMode.equals(getString(R.string.voice_mode_off)) + && mEnableVoiceButton; boolean voiceOnPrimary = voiceMode.equals(getString(R.string.voice_mode_main)); if (mKeyboardSwitcher != null && (enableVoice != mEnableVoice || voiceOnPrimary != mVoiceOnPrimary)) { diff --git a/src/com/android/inputmethod/latin/LatinKeyboard.java b/src/com/android/inputmethod/latin/LatinKeyboard.java index 9b742a5f9..58e1dc767 100644 --- a/src/com/android/inputmethod/latin/LatinKeyboard.java +++ b/src/com/android/inputmethod/latin/LatinKeyboard.java @@ -69,7 +69,12 @@ public class LatinKeyboard extends Keyboard { private Resources mRes; private Context mContext; private int mMode; - private boolean mHasVoice; + // Whether this keyboard has voice icon on it + private boolean mHasVoiceButton; + // Whether voice icon is enabled at all + private boolean mVoiceEnabled; + private boolean mIsAlphaKeyboard; + private CharSequence m123Label; private boolean mCurrentlyInSpace; private SlidingLocaleDrawable mSlidingLocaleIcon; private Rect mBounds = new Rect(); @@ -95,16 +100,15 @@ public class LatinKeyboard extends Keyboard { static int sSpacebarVerticalCorrection; public LatinKeyboard(Context context, int xmlLayoutResId) { - this(context, xmlLayoutResId, 0, false); + this(context, xmlLayoutResId, 0); } - public LatinKeyboard(Context context, int xmlLayoutResId, int mode, boolean hasVoice) { + public LatinKeyboard(Context context, int xmlLayoutResId, int mode) { super(context, xmlLayoutResId, mode); final Resources res = context.getResources(); mContext = context; mMode = mode; mRes = res; - mHasVoice = hasVoice; mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked); mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked); mShiftLockPreviewIcon.setBounds(0, 0, @@ -122,7 +126,7 @@ public class LatinKeyboard extends Keyboard { setDefaultBounds(m123MicPreviewIcon); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( R.dimen.spacebar_vertical_correction); - setF1Key(xmlLayoutResId == R.xml.kbd_qwerty); + mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty; mSpaceKeyIndex = indexOf((int) ' '); } @@ -147,6 +151,7 @@ public class LatinKeyboard extends Keyboard { break; case KEYCODE_MODE_CHANGE: m123Key = key; + m123Label = key.label; break; } return key; @@ -284,23 +289,36 @@ public class LatinKeyboard extends Keyboard { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); } - private void setF1Key(boolean isAlphaKeyboard) { + public void setVoiceMode(boolean hasVoiceButton, boolean hasVoice) { + mHasVoiceButton = hasVoiceButton; + mVoiceEnabled = hasVoice; + updateF1Key(); + } + + private void updateF1Key() { if (mF1Key == null) return; - if (!mHasVoice) { - mF1Key.label = ","; - mF1Key.codes = new int[] { ',' }; - mF1Key.icon = null; - mF1Key.iconPreview = null; - if (isAlphaKeyboard && m123Key != null) { + if (m123Key != null && mIsAlphaKeyboard) { + if (mVoiceEnabled && !mHasVoiceButton) { m123Key.icon = m123MicIcon; m123Key.iconPreview = m123MicPreviewIcon; m123Key.label = null; + } else { + m123Key.icon = null; + m123Key.iconPreview = null; + m123Key.label = m123Label; } - } else { + } + + if (mHasVoiceButton && mVoiceEnabled) { mF1Key.codes = new int[] { LatinKeyboardView.KEYCODE_VOICE }; mF1Key.label = null; mF1Key.icon = mMicIcon; mF1Key.iconPreview = mMicPreviewIcon; + } else { + mF1Key.label = ","; + mF1Key.codes = new int[] { ',' }; + mF1Key.icon = null; + mF1Key.iconPreview = null; } }