am adb89c10: Merge "Move ignore special key code out from LatinIME to PointerTracker"

* commit 'adb89c109e6ecf5c221e60fa705d69f1f9c35455':
  Move ignore special key code out from LatinIME to PointerTracker
main
Tadashi G. Takaoka 2011-11-22 17:59:39 -08:00 committed by Android Git Automerger
commit 0d9f87f1bd
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_LONGPRESS_KEY = 2;
private static final int MSG_IGNORE_DOUBLE_TAP = 3;
private static final int MSG_KEY_TYPED = 4;
private boolean mInKeyRepeat;
@ -137,6 +138,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
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
public void cancelKeyTimers() {
cancelKeyRepeatTimer();

View File

@ -74,12 +74,18 @@ public class PointerTracker {
}
public interface TimerProxy {
public void startKeyTypedTimer(long delay);
public boolean isIgnoringSpecialKey();
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker);
public void startLongPressTimer(long delay, int keyIndex, PointerTracker tracker);
public void cancelLongPressTimer();
public void cancelKeyTimers();
public static class Adapter implements TimerProxy {
@Override
public void startKeyTypedTimer(long delay) {}
@Override
public boolean isIgnoringSpecialKey() { return false; }
@Override
public void startKeyRepeatTimer(long delay, int keyIndex, PointerTracker tracker) {}
@Override
@ -98,6 +104,7 @@ public class PointerTracker {
private static int sLongPressKeyTimeout;
private static int sLongPressShiftKeyTimeout;
private static int sLongPressSpaceKeyTimeout;
private static int sIgnoreSpecialKeyTimeout;
private static int sTouchNoiseThresholdMillis;
private static int sTouchNoiseThresholdDistanceSquared;
@ -168,7 +175,9 @@ public class PointerTracker {
sLongPressKeyTimeout = res.getInteger(R.integer.config_long_press_key_timeout);
sLongPressShiftKeyTimeout = res.getInteger(R.integer.config_long_press_shift_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);
final float touchNoiseThresholdDistance = res.getDimension(
R.dimen.config_touch_noise_threshold_distance);
sTouchNoiseThresholdDistanceSquared = (int)(
@ -233,8 +242,9 @@ public class PointerTracker {
if (DEBUG_LISTENER)
Log.d(TAG, "onPress : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding
+ " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey)
if (ignoreModifierKey) {
return false;
}
if (key.isEnabled()) {
mListener.onPress(key.mCode, withSliding);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
@ -254,15 +264,17 @@ public class PointerTracker {
+ " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey)
return;
if (key.isEnabled())
if (key.isEnabled()) {
mListener.onCodeInput(primaryCode, keyCodes, x, y);
}
}
private void callListenerOnTextInput(Key key) {
if (DEBUG_LISTENER)
Log.d(TAG, "onTextInput: text=" + key.mOutputText);
if (key.isEnabled())
if (key.isEnabled()) {
mListener.onTextInput(key.mOutputText);
}
}
// Note that we need primaryCode argument because the keyboard may in shifted state and the
@ -274,8 +286,9 @@ public class PointerTracker {
+ withSliding + " ignoreModifier=" + ignoreModifierKey);
if (ignoreModifierKey)
return;
if (key.isEnabled())
if (key.isEnabled()) {
mListener.onRelease(primaryCode, withSliding);
}
}
private void callListenerOnCancelInput() {
@ -700,8 +713,8 @@ public class PointerTracker {
}
}
private void detectAndSendKey(int index, int x, int y) {
final Key key = getKey(index);
private void detectAndSendKey(int keyIndex, int x, int y) {
final Key key = getKey(keyIndex);
if (key == null) {
callListenerOnCancelInput();
return;
@ -709,6 +722,8 @@ public class PointerTracker {
if (key.mOutputText != null) {
callListenerOnTextInput(key);
callListenerOnRelease(key, key.mCode, false);
// TODO: "text" input key could have a special action too
mTimerProxy.startKeyTypedTimer(sIgnoreSpecialKeyTimeout);
} else {
int code = key.mCode;
final int[] codes = mKeyDetector.newCodeArray();
@ -728,8 +743,18 @@ public class PointerTracker {
codes[1] = codes[0];
codes[0] = code;
}
callListenerOnCodeInput(key, code, codes, x, y);
// 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);
}
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_DISMISS_LANGUAGE_ON_SPACEBAR = 4;
private static final int MSG_SPACE_TYPED = 5;
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 static final int MSG_SET_BIGRAM_PREDICTIONS = 6;
private static final int MSG_PENDING_IMS_CALLBACK = 7;
private int mDelayBeforeFadeoutLanguageOnSpacebar;
private int mDelayUpdateSuggestions;
@ -261,7 +260,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private int mDurationOfFadeoutLanguageOnSpacebar;
private float mFinalFadeoutFactorOfLanguageOnSpacebar;
private long mDoubleSpacesTurnIntoPeriodTimeout;
private long mIgnoreSpecialKeyTimeout;
public UIHandler(LatinIME 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;
mDoubleSpacesTurnIntoPeriodTimeout = res.getInteger(
R.integer.config_double_spaces_turn_into_period_timeout);
mIgnoreSpecialKeyTimeout = res.getInteger(
R.integer.config_ignore_special_key_timeout);
}
@Override
@ -394,15 +390,6 @@ 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;
@ -1323,7 +1310,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHandler.cancelDoubleSpacesTimer();
}
boolean shouldStartKeyTypedTimer = true;
switch (primaryCode) {
case Keyboard.CODE_DELETE:
mSpaceState = SPACE_STATE_NONE;
@ -1337,14 +1323,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!distinctMultiTouch) {
switcher.toggleShift();
}
shouldStartKeyTypedTimer = false;
break;
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
if (!distinctMultiTouch) {
switcher.changeKeyboardMode();
}
shouldStartKeyTypedTimer = false;
break;
case Keyboard.CODE_CANCEL:
if (!isShowingOptionDialog()) {
@ -1352,20 +1336,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
break;
case Keyboard.CODE_SETTINGS:
if (!mHandler.isIgnoringSpecialKey()) {
onSettingsKeyPressed();
}
shouldStartKeyTypedTimer = false;
onSettingsKeyPressed();
break;
case Keyboard.CODE_CAPSLOCK:
switcher.toggleCapsLock();
hapticAndAudioFeedback(primaryCode);
break;
case Keyboard.CODE_SHORTCUT:
if (!mHandler.isIgnoringSpecialKey()) {
mSubtypeSwitcher.switchToShortcutIME();
}
shouldStartKeyTypedTimer = false;
mSubtypeSwitcher.switchToShortcutIME();
break;
case Keyboard.CODE_TAB:
handleTab();
@ -1391,9 +1369,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
switcher.onKey(primaryCode);
// Reset after any single keystroke
mEnteredText = null;
if (shouldStartKeyTypedTimer) {
mHandler.startKeyTypedTimer();
}
}
@Override
@ -1410,7 +1385,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
mSpaceState = SPACE_STATE_NONE;
mEnteredText = text;
mHandler.startKeyTypedTimer();
}
@Override