From 175acb8205fcc2a91de4059e8a12af49484af784 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 16 Nov 2011 15:58:42 -0800 Subject: [PATCH] Ignore microphone and settings key while typing Bug: 5560766 Change-Id: I38b21d49b7e803bf94805ba8e13849b3c734e010 --- java/res/values/config.xml | 1 + .../android/inputmethod/latin/LatinIME.java | 87 +++++++++++++------ .../android/inputmethod/latin/Settings.java | 18 ---- 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/java/res/values/config.xml b/java/res/values/config.xml index e2422d231..3f676ab25 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -63,6 +63,7 @@ @integer/config_long_press_key_timeout 40 1100 + 700 2.0mm 5 diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index d57154ad5..d3eddfb23 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -241,11 +241,36 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 3; private static final int MSG_DISMISS_LANGUAGE_ON_SPACEBAR = 4; private static final int MSG_SPACE_TYPED = 5; - private static final int MSG_SET_BIGRAM_PREDICTIONS = 6; - private static final int MSG_PENDING_IMS_CALLBACK = 7; + private static final int MSG_KEY_TYPED = 6; + private static final int MSG_SET_BIGRAM_PREDICTIONS = 7; + private static final int MSG_PENDING_IMS_CALLBACK = 8; + + private final int mDelayBeforeFadeoutLanguageOnSpacebar; + private final int mDelayUpdateSuggestions; + private final int mDelayUpdateShiftState; + private final int mDurationOfFadeoutLanguageOnSpacebar; + private final float mFinalFadeoutFactorOfLanguageOnSpacebar; + private final long mDoubleSpacesTurnIntoPeriodTimeout; + private final long mIgnoreSpecialKeyTimeout; public UIHandler(LatinIME outerInstance) { super(outerInstance); + + final Resources res = outerInstance.getResources(); + mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_delay_before_fadeout_language_on_spacebar); + mDelayUpdateSuggestions = + res.getInteger(R.integer.config_delay_update_suggestions); + mDelayUpdateShiftState = + res.getInteger(R.integer.config_delay_update_shift_state); + mDurationOfFadeoutLanguageOnSpacebar = res.getInteger( + R.integer.config_duration_of_fadeout_language_on_spacebar); + mFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger( + R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; + mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger( + R.integer.config_double_spaces_turn_into_period_timeout); + mIgnoreSpecialKeyTimeout = res.getInteger( + R.integer.config_ignore_special_key_timeout); } @Override @@ -270,17 +295,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: if (inputView != null) { inputView.setSpacebarTextFadeFactor( - (1.0f + latinIme.mSettingsValues. - mFinalFadeoutFactorOfLanguageOnSpacebar) / 2, + (1.0f + mFinalFadeoutFactorOfLanguageOnSpacebar) / 2, (LatinKeyboard)msg.obj); } sendMessageDelayed(obtainMessage(MSG_DISMISS_LANGUAGE_ON_SPACEBAR, msg.obj), - latinIme.mSettingsValues.mDurationOfFadeoutLanguageOnSpacebar); + mDurationOfFadeoutLanguageOnSpacebar); break; case MSG_DISMISS_LANGUAGE_ON_SPACEBAR: if (inputView != null) { - inputView.setSpacebarTextFadeFactor( - latinIme.mSettingsValues.mFinalFadeoutFactorOfLanguageOnSpacebar, + inputView.setSpacebarTextFadeFactor(mFinalFadeoutFactorOfLanguageOnSpacebar, (LatinKeyboard)msg.obj); } break; @@ -289,8 +312,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void postUpdateSuggestions() { removeMessages(MSG_UPDATE_SUGGESTIONS); - sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), - getOuterInstance().mSettingsValues.mDelayUpdateSuggestions); + sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions); } public void cancelUpdateSuggestions() { @@ -303,8 +325,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void postUpdateShiftKeyState() { removeMessages(MSG_UPDATE_SHIFT_STATE); - sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), - getOuterInstance().mSettingsValues.mDelayUpdateShiftState); + sendMessageDelayed(obtainMessage(MSG_UPDATE_SHIFT_STATE), mDelayUpdateShiftState); } public void cancelUpdateShiftState() { @@ -313,8 +334,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void postUpdateBigramPredictions() { removeMessages(MSG_SET_BIGRAM_PREDICTIONS); - sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), - getOuterInstance().mSettingsValues.mDelayUpdateSuggestions); + sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), mDelayUpdateSuggestions); } public void cancelUpdateBigramPredictions() { @@ -334,26 +354,24 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final LatinKeyboard keyboard = latinIme.mKeyboardSwitcher.getLatinKeyboard(); // The language is always displayed when the delay is negative. final boolean needsToDisplayLanguage = localeChanged - || latinIme.mSettingsValues.mDelayBeforeFadeoutLanguageOnSpacebar < 0; + || mDelayBeforeFadeoutLanguageOnSpacebar < 0; // The language is never displayed when the delay is zero. - if (latinIme.mSettingsValues.mDelayBeforeFadeoutLanguageOnSpacebar != 0) { + if (mDelayBeforeFadeoutLanguageOnSpacebar != 0) { inputView.setSpacebarTextFadeFactor(needsToDisplayLanguage ? 1.0f - : latinIme.mSettingsValues.mFinalFadeoutFactorOfLanguageOnSpacebar, + : mFinalFadeoutFactorOfLanguageOnSpacebar, keyboard); } // The fadeout animation will start when the delay is positive. - if (localeChanged - && latinIme.mSettingsValues.mDelayBeforeFadeoutLanguageOnSpacebar > 0) { + if (localeChanged && mDelayBeforeFadeoutLanguageOnSpacebar > 0) { sendMessageDelayed(obtainMessage(MSG_FADEOUT_LANGUAGE_ON_SPACEBAR, keyboard), - latinIme.mSettingsValues.mDelayBeforeFadeoutLanguageOnSpacebar); + mDelayBeforeFadeoutLanguageOnSpacebar); } } } public void startDoubleSpacesTimer() { removeMessages(MSG_SPACE_TYPED); - sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED), - getOuterInstance().mSettingsValues.mDoubleSpacesTurnIntoPeriodTimeout); + sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED), mDoubleSpacesTurnIntoPeriodTimeout); } public void cancelDoubleSpacesTimer() { @@ -364,6 +382,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return hasMessages(MSG_SPACE_TYPED); } + public void startKeyTypedTimer() { + removeMessages(MSG_KEY_TYPED); + sendMessageDelayed(obtainMessage(MSG_KEY_TYPED), mIgnoreSpecialKeyTimeout); + } + + public boolean isIgnoringSpecialKey() { + return hasMessages(MSG_KEY_TYPED); + } + // Working variables for the following methods. private boolean mIsOrientationChanging; private boolean mPendingSuccesiveImsCallback; @@ -1246,15 +1273,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Implementation of {@link KeyboardActionListener}. @Override public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) { - long when = SystemClock.uptimeMillis(); + final long when = SystemClock.uptimeMillis(); if (primaryCode != Keyboard.CODE_DELETE || when > mLastKeyTime + QUICK_PRESS) { mDeleteCount = 0; } mLastKeyTime = when; - KeyboardSwitcher switcher = mKeyboardSwitcher; + final KeyboardSwitcher switcher = mKeyboardSwitcher; final boolean distinctMultiTouch = switcher.hasDistinctMultitouch(); final boolean lastStateOfJustReplacedDoubleSpace = mJustReplacedDoubleSpace; mJustReplacedDoubleSpace = false; + boolean shouldStartKeyTypedTimer = true; switch (primaryCode) { case Keyboard.CODE_DELETE: handleBackspace(lastStateOfJustReplacedDoubleSpace); @@ -1278,7 +1306,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } break; case Keyboard.CODE_SETTINGS: - onSettingsKeyPressed(); + if (!mHandler.isIgnoringSpecialKey()) { + onSettingsKeyPressed(); + } + shouldStartKeyTypedTimer = false; break; case Keyboard.CODE_CAPSLOCK: switcher.toggleCapsLock(); @@ -1289,7 +1320,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar playKeyClick(primaryCode); break; case Keyboard.CODE_SHORTCUT: - mSubtypeSwitcher.switchToShortcutIME(); + if (!mHandler.isIgnoringSpecialKey()) { + mSubtypeSwitcher.switchToShortcutIME(); + } + shouldStartKeyTypedTimer = false; break; case Keyboard.CODE_TAB: handleTab(); @@ -1314,6 +1348,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar switcher.onKey(primaryCode); // Reset after any single keystroke mEnteredText = null; + if (shouldStartKeyTypedTimer) { + mHandler.startKeyTypedTimer(); + } } @Override diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index eeb0299b1..773efe709 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -102,13 +102,7 @@ public class Settings extends InputMethodSettingsActivity public static class Values { // From resources: - public final int mDelayBeforeFadeoutLanguageOnSpacebar; - public final int mDelayUpdateSuggestions; public final int mDelayUpdateOldSuggestions; - public final int mDelayUpdateShiftState; - public final int mDurationOfFadeoutLanguageOnSpacebar; - public final float mFinalFadeoutFactorOfLanguageOnSpacebar; - public final long mDoubleSpacesTurnIntoPeriodTimeout; public final String mWordSeparators; public final String mMagicSpaceStrippers; public final String mMagicSpaceSwappers; @@ -147,20 +141,8 @@ public class Settings extends InputMethodSettingsActivity } // Get the resources - mDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger( - R.integer.config_delay_before_fadeout_language_on_spacebar); - mDelayUpdateSuggestions = - res.getInteger(R.integer.config_delay_update_suggestions); mDelayUpdateOldSuggestions = res.getInteger( R.integer.config_delay_update_old_suggestions); - mDelayUpdateShiftState = - res.getInteger(R.integer.config_delay_update_shift_state); - mDurationOfFadeoutLanguageOnSpacebar = res.getInteger( - R.integer.config_duration_of_fadeout_language_on_spacebar); - mFinalFadeoutFactorOfLanguageOnSpacebar = res.getInteger( - R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; - mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger( - R.integer.config_double_spaces_turn_into_period_timeout); mMagicSpaceStrippers = res.getString(R.string.magic_space_stripping_symbols); mMagicSpaceSwappers = res.getString(R.string.magic_space_swapping_symbols); String wordSeparators = mMagicSpaceStrippers + mMagicSpaceSwappers