Move ignore special key code out from LatinIME to PointerTracker

Bug: 5560766
Bug: 5639503
Change-Id: I34c9eea833516adf6ef1db58f1a64a5ef5322fa9
This commit is contained in:
Tadashi G. Takaoka 2011-11-21 16:41:01 -08:00
parent 6d1cbbc2ff
commit 9324665263
3 changed files with 48 additions and 37 deletions

View file

@ -89,6 +89,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
private static final int MSG_REPEAT_KEY = 1; private static final int MSG_REPEAT_KEY = 1;
private static final int MSG_LONGPRESS_KEY = 2; private static final int MSG_LONGPRESS_KEY = 2;
private static final int MSG_IGNORE_DOUBLE_TAP = 3; private static final int MSG_IGNORE_DOUBLE_TAP = 3;
private static final int MSG_KEY_TYPED = 4;
private boolean mInKeyRepeat; private boolean mInKeyRepeat;
@ -137,6 +138,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
removeMessages(MSG_LONGPRESS_KEY); removeMessages(MSG_LONGPRESS_KEY);
} }
@Override
public void startKeyTypedTimer(long delay) {
removeMessages(MSG_KEY_TYPED);
sendMessageDelayed(obtainMessage(MSG_KEY_TYPED), delay);
}
@Override
public boolean isIgnoringSpecialKey() {
return hasMessages(MSG_KEY_TYPED);
}
@Override @Override
public void cancelKeyTimers() { public void cancelKeyTimers() {
cancelKeyRepeatTimer(); cancelKeyRepeatTimer();

View file

@ -74,12 +74,18 @@ public class PointerTracker {
} }
public interface TimerProxy { public interface TimerProxy {
public void startKeyTypedTimer(long delay);
public boolean isIgnoringSpecialKey();
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker); public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker);
public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker); public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker);
public void cancelLongPressTimer(); public void cancelLongPressTimer();
public void cancelKeyTimers(); public void cancelKeyTimers();
public static class Adapter implements TimerProxy { public static class Adapter implements TimerProxy {
@Override
public void startKeyTypedTimer(long delay) {}
@Override
public boolean isIgnoringSpecialKey() { return false; }
@Override @Override
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {} public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {}
@Override @Override
@ -98,6 +104,7 @@ public class PointerTracker {
private static int sLongPressKeyTimeout; private static int sLongPressKeyTimeout;
private static int sLongPressShiftKeyTimeout; private static int sLongPressShiftKeyTimeout;
private static int sLongPressSpaceKeyTimeout; private static int sLongPressSpaceKeyTimeout;
private static int sIgnoreSpecialKeyTimeout;
private static int sTouchNoiseThresholdMillis; private static int sTouchNoiseThresholdMillis;
private static int sTouchNoiseThresholdDistanceSquared; private static int sTouchNoiseThresholdDistanceSquared;
@ -168,7 +175,9 @@ public class PointerTracker {
sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout); sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout);
sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout); sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_key_timeout);
sLongPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout); sLongPressSpaceKeyTimeout = res.getInteger(R.integer.config_long_press_space_key_timeout);
sIgnoreSpecialKeyTimeout = res.getInteger(R.integer.config_ignore_special_key_timeout);
sTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis); sTouchNoiseThresholdMillis = res.getInteger(R.integer.config_touch_noise_threshold_millis);
final float touchNoiseThresholdDistance = res.getDimension( final float touchNoiseThresholdDistance = res.getDimension(
R.dimen.config_touch_noise_threshold_distance); R.dimen.config_touch_noise_threshold_distance);
sTouchNoiseThresholdDistanceSquared = (int)( sTouchNoiseThresholdDistanceSquared = (int)(
@ -233,8 +242,9 @@ public class PointerTracker {
if (DEBUG_LISTENER) if (DEBUG_LISTENER)
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding
+ " ignoreModifier=" + ignoreModifierKey); + " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey) if (ignoreModifierKey) {
return false; return false;
}
if (key.isEnabled()) { if (key.isEnabled()) {
mListener.onPress(key.mCode, withSliding); mListener.onPress(key.mCode, withSliding);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
@ -254,16 +264,18 @@ public class PointerTracker {
+ " ignoreModifier=" + ignoreModifierKey); + " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey) if (ignoreModifierKey)
return; return;
if (key.isEnabled()) if (key.isEnabled()) {
mListener.onCodeInput(primaryCode, keyCodes, x, y); mListener.onCodeInput(primaryCode, keyCodes, x, y);
} }
}
private void callListenerOnTextInput(Key key) { private void callListenerOnTextInput(Key key) {
if (DEBUG_LISTENER) if (DEBUG_LISTENER)
Log.d(TAG, "onTextInput: text=" + key.mOutputText); Log.d(TAG, "onTextInput: text=" + key.mOutputText);
if (key.isEnabled()) if (key.isEnabled()) {
mListener.onTextInput(key.mOutputText); mListener.onTextInput(key.mOutputText);
} }
}
// Note that we need primaryCode argument because the keyboard may in shifted state and the // Note that we need primaryCode argument because the keyboard may in shifted state and the
// primaryCode is different from {@link Key#mCode}. // primaryCode is different from {@link Key#mCode}.
@ -274,9 +286,10 @@ public class PointerTracker {
+ withSliding + " ignoreModifier=" + ignoreModifierKey); + withSliding + " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey) if (ignoreModifierKey)
return; return;
if (key.isEnabled()) if (key.isEnabled()) {
mListener.onRelease(primaryCode, withSliding); mListener.onRelease(primaryCode, withSliding);
} }
}
private void callListenerOnCancelInput() { private void callListenerOnCancelInput() {
if (DEBUG_LISTENER) if (DEBUG_LISTENER)
@ -700,8 +713,8 @@ public class PointerTracker {
} }
} }
private void detectAndSendKey(int index, int x, int y) { private void detectAndSendKey(int keyIndex, int x, int y) {
final Key key = getKey(index); final Key key = getKey(keyIndex);
if (key == null) { if (key == null) {
callListenerOnCancelInput(); callListenerOnCancelInput();
return; return;
@ -709,6 +722,8 @@ public class PointerTracker {
if (key.mOutputText != null) { if (key.mOutputText != null) {
callListenerOnTextInput(key); callListenerOnTextInput(key);
callListenerOnRelease(key, key.mCode, false); callListenerOnRelease(key, key.mCode, false);
// TODO: "text" input key could have a special action too
mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout);
} else { } else {
int code = key.mCode; int code = key.mCode;
final int[] codes = mKeyDetector.newCodeArray(); final int[] codes = mKeyDetector.newCodeArray();
@ -728,8 +743,18 @@ public class PointerTracker {
codes[1] = codes[0]; codes[1] = codes[0];
codes[0] = code; codes[0] = code;
} }
// TODO: Move this special action to Key.keyActionFlags
final boolean specialCode = (
code == Keyboard.CODE_SETTINGS || code == Keyboard.CODE_SHORTCUT);
final boolean ignoreSpecialCode = specialCode && mTimerProxy.isIgnoringSpecialKey();
final boolean shouldStartKeyTypedTyper = !(specialCode || isModifierCode(code));
if (!ignoreSpecialCode) {
callListenerOnCodeInput(key, code, codes, x, y); callListenerOnCodeInput(key, code, codes, x, y);
}
callListenerOnRelease(key, code, false); callListenerOnRelease(key, code, false);
if (shouldStartKeyTypedTyper) {
mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout);
}
} }
} }

View file

@ -251,9 +251,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private static final int MSG_FADEOUT_LANGUAGE_ON_SPACEBAR = 3; 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_DISMISS_LANGUAGE_ON_SPACEBAR = 4;
private static final int MSG_SPACE_TYPED = 5; private static final int MSG_SPACE_TYPED = 5;
private static final int MSG_KEY_TYPED = 6; private static final int MSG_SET_BIGRAM_PREDICTIONS = 6;
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7; private static final int MSG_PENDING_IMS_CALLBACK = 7;
private static final int MSG_PENDING_IMS_CALLBACK = 8;
private int mDelayBeforeFadeoutLanguageOnSpacebar; private int mDelayBeforeFadeoutLanguageOnSpacebar;
private int mDelayUpdateSuggestions; private int mDelayUpdateSuggestions;
@ -261,7 +260,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private int mDurationOfFadeoutLanguageOnSpacebar; private int mDurationOfFadeoutLanguageOnSpacebar;
private float mFinalFadeoutFactorOfLanguageOnSpacebar; private float mFinalFadeoutFactorOfLanguageOnSpacebar;
private long mDoubleSpacesTurnIntoPeriodTimeout; private long mDoubleSpacesTurnIntoPeriodTimeout;
private long mIgnoreSpecialKeyTimeout;
public UIHandler(LatinIME outerInstance) { public UIHandler(LatinIME outerInstance) {
super(outerInstance); super(outerInstance);
@ -281,8 +279,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f; R.integer.config_final_fadeout_percentage_of_language_on_spacebar) / 100.0f;
mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger( mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger(
R.integer.config_double_spaces_turn_into_period_timeout); R.integer.config_double_spaces_turn_into_period_timeout);
mIgnoreSpecialKeyTimeout = res.getInteger(
R.integer.config_ignore_special_key_timeout);
} }
@Override @Override
@ -394,15 +390,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return hasMessages(MSG_SPACE_TYPED); 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. // Working variables for the following methods.
private boolean mIsOrientationChanging; private boolean mIsOrientationChanging;
private boolean mPendingSuccesiveImsCallback; private boolean mPendingSuccesiveImsCallback;
@ -1323,7 +1310,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHandler.cancelDoubleSpacesTimer(); mHandler.cancelDoubleSpacesTimer();
} }
boolean shouldStartKeyTypedTimer = true;
switch (primaryCode) { switch (primaryCode) {
case Keyboard.CODE_DELETE: case Keyboard.CODE_DELETE:
mSpaceState = SPACE_STATE_NONE; mSpaceState = SPACE_STATE_NONE;
@ -1337,14 +1323,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!distinctMultiTouch) { if (!distinctMultiTouch) {
switcher.toggleShift(); switcher.toggleShift();
} }
shouldStartKeyTypedTimer = false;
break; break;
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL: case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
// Symbol key is handled in onPress() when device has distinct multi-touch panel. // Symbol key is handled in onPress() when device has distinct multi-touch panel.
if (!distinctMultiTouch) { if (!distinctMultiTouch) {
switcher.changeKeyboardMode(); switcher.changeKeyboardMode();
} }
shouldStartKeyTypedTimer = false;
break; break;
case Keyboard.CODE_CANCEL: case Keyboard.CODE_CANCEL:
if (!isShowingOptionDialog()) { if (!isShowingOptionDialog()) {
@ -1352,20 +1336,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
break; break;
case Keyboard.CODE_SETTINGS: case Keyboard.CODE_SETTINGS:
if (!mHandler.isIgnoringSpecialKey()) {
onSettingsKeyPressed(); onSettingsKeyPressed();
}
shouldStartKeyTypedTimer = false;
break; break;
case Keyboard.CODE_CAPSLOCK: case Keyboard.CODE_CAPSLOCK:
switcher.toggleCapsLock(); switcher.toggleCapsLock();
hapticAndAudioFeedback(primaryCode); hapticAndAudioFeedback(primaryCode);
break; break;
case Keyboard.CODE_SHORTCUT: case Keyboard.CODE_SHORTCUT:
if (!mHandler.isIgnoringSpecialKey()) {
mSubtypeSwitcher.switchToShortcutIME(); mSubtypeSwitcher.switchToShortcutIME();
}
shouldStartKeyTypedTimer = false;
break; break;
case Keyboard.CODE_TAB: case Keyboard.CODE_TAB:
handleTab(); handleTab();
@ -1391,9 +1369,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
switcher.onKey(primaryCode); switcher.onKey(primaryCode);
// Reset after any single keystroke // Reset after any single keystroke
mEnteredText = null; mEnteredText = null;
if (shouldStartKeyTypedTimer) {
mHandler.startKeyTypedTimer();
}
} }
@Override @Override
@ -1410,7 +1385,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY); mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
mSpaceState = SPACE_STATE_NONE; mSpaceState = SPACE_STATE_NONE;
mEnteredText = text; mEnteredText = text;
mHandler.startKeyTypedTimer();
} }
@Override @Override