Merge "Move key repeat function to PointerTracker"

main
Tadashi G. Takaoka 2013-08-01 07:06:44 +00:00 committed by Android (Google) Code Review
commit c83da06939
2 changed files with 43 additions and 44 deletions

View File

@ -193,8 +193,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 3; private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 3;
private static final int MSG_UPDATE_BATCH_INPUT = 4; private static final int MSG_UPDATE_BATCH_INPUT = 4;
private final int mKeyRepeatStartTimeout;
private final int mKeyRepeatInterval;
private final int mIgnoreAltCodeKeyTimeout; private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime; private final int mGestureRecognitionUpdateTime;
@ -202,10 +200,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
final TypedArray mainKeyboardViewAttr) { final TypedArray mainKeyboardViewAttr) {
super(outerInstance); super(outerInstance);
mKeyRepeatStartTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt( mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0); R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt( mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
@ -224,17 +218,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
startWhileTypingFadeinAnimation(keyboardView); startWhileTypingFadeinAnimation(keyboardView);
break; break;
case MSG_REPEAT_KEY: case MSG_REPEAT_KEY:
final Key currentKey = tracker.getKey(); tracker.onKeyRepeat(msg.arg1);
final int code = msg.arg1;
if (currentKey != null && currentKey.mCode == code) {
startKeyRepeatTimer(tracker, mKeyRepeatInterval);
startTypingStateTimer(currentKey);
final KeyboardActionListener listener =
keyboardView.getKeyboardActionListener();
listener.onPressKey(code, true /* isRepeatKey */, true /* isSinglePointer */);
listener.onCodeInput(code,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
}
break; break;
case MSG_LONGPRESS_KEY: case MSG_LONGPRESS_KEY:
keyboardView.onLongPress(tracker); keyboardView.onLongPress(tracker);
@ -246,19 +230,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
} }
} }
private void startKeyRepeatTimer(final PointerTracker tracker, final long delay) { @Override
public void startKeyRepeatTimer(final PointerTracker tracker, final int delay) {
final Key key = tracker.getKey(); final Key key = tracker.getKey();
if (key == null) { if (key == null || delay == 0) {
return; return;
} }
sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay); sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY, key.mCode, 0, tracker), delay);
} }
@Override
public void startKeyRepeatTimer(final PointerTracker tracker) {
startKeyRepeatTimer(tracker, mKeyRepeatStartTimeout);
}
public void cancelKeyRepeatTimer() { public void cancelKeyRepeatTimer() {
removeMessages(MSG_REPEAT_KEY); removeMessages(MSG_REPEAT_KEY);
} }

View File

@ -94,7 +94,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public interface TimerProxy { public interface TimerProxy {
public void startTypingStateTimer(Key typedKey); public void startTypingStateTimer(Key typedKey);
public boolean isTypingState(); public boolean isTypingState();
public void startKeyRepeatTimer(PointerTracker tracker); public void startKeyRepeatTimer(PointerTracker tracker, int delay);
public void startLongPressTimer(PointerTracker tracker, int delay); public void startLongPressTimer(PointerTracker tracker, int delay);
public void cancelLongPressTimer(); public void cancelLongPressTimer();
public void startDoubleTapShiftKeyTimer(); public void startDoubleTapShiftKeyTimer();
@ -111,7 +111,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override @Override
public boolean isTypingState() { return false; } public boolean isTypingState() { return false; }
@Override @Override
public void startKeyRepeatTimer(PointerTracker tracker) {} public void startKeyRepeatTimer(PointerTracker tracker, int delay) {}
@Override @Override
public void startLongPressTimer(PointerTracker tracker, int delay) {} public void startLongPressTimer(PointerTracker tracker, int delay) {}
@Override @Override
@ -138,6 +138,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public final int mTouchNoiseThresholdTime; public final int mTouchNoiseThresholdTime;
public final int mTouchNoiseThresholdDistance; public final int mTouchNoiseThresholdDistance;
public final int mSuppressKeyPreviewAfterBatchInputDuration; public final int mSuppressKeyPreviewAfterBatchInputDuration;
public final int mKeyRepeatStartTimeout;
public final int mKeyRepeatInterval;
public final int mLongPressShiftLockTimeout; public final int mLongPressShiftLockTimeout;
public static final PointerTrackerParams DEFAULT = new PointerTrackerParams(); public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
@ -147,6 +149,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mTouchNoiseThresholdTime = 0; mTouchNoiseThresholdTime = 0;
mTouchNoiseThresholdDistance = 0; mTouchNoiseThresholdDistance = 0;
mSuppressKeyPreviewAfterBatchInputDuration = 0; mSuppressKeyPreviewAfterBatchInputDuration = 0;
mKeyRepeatStartTimeout = 0;
mKeyRepeatInterval = 0;
mLongPressShiftLockTimeout = 0; mLongPressShiftLockTimeout = 0;
} }
@ -159,6 +163,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0); R.styleable.MainKeyboardView_touchNoiseThresholdDistance, 0);
mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt( mSuppressKeyPreviewAfterBatchInputDuration = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration, 0); R.styleable.MainKeyboardView_suppressKeyPreviewAfterBatchInputDuration, 0);
mKeyRepeatStartTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyRepeatStartTimeout, 0);
mKeyRepeatInterval = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_keyRepeatInterval, 0);
mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt( mLongPressShiftLockTimeout = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0); R.styleable.MainKeyboardView_longPressShiftLockTimeout, 0);
} }
@ -477,7 +485,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
// Returns true if keyboard has been changed by this callback. // Returns true if keyboard has been changed by this callback.
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key) { private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key,
final boolean isRepeatKey) {
// While gesture input is going on, this method should be a no-operation. But when gesture // While gesture input is going on, this method should be a no-operation. But when gesture
// input has been canceled, <code>sInGesture</code> and <code>mIsDetectingGesture</code> // input has been canceled, <code>sInGesture</code> and <code>mIsDetectingGesture</code>
// are set to false. To keep this method is a no-operation, // are set to false. To keep this method is a no-operation,
@ -487,17 +496,17 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier(); final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onPress : %s%s%s", mPointerId, Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
KeyDetector.printableCode(key), KeyDetector.printableCode(key),
ignoreModifierKey ? " ignoreModifier" : "", ignoreModifierKey ? " ignoreModifier" : "",
key.isEnabled() ? "" : " disabled")); key.isEnabled() ? "" : " disabled",
isRepeatKey ? " repeat" : ""));
} }
if (ignoreModifierKey) { if (ignoreModifierKey) {
return false; return false;
} }
if (key.isEnabled()) { if (key.isEnabled()) {
mListener.onPressKey(key.mCode, false /* isRepeatKey */, mListener.onPressKey(key.mCode, isRepeatKey, getActivePointerTrackerCount() == 1);
getActivePointerTrackerCount() == 1);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
mKeyboardLayoutHasBeenChanged = false; mKeyboardLayoutHasBeenChanged = false;
mTimerProxy.startTypingStateTimer(key); mTimerProxy.startTypingStateTimer(key);
@ -917,7 +926,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
// A gesture should start only from a non-modifier key. // A gesture should start only from a non-modifier key.
mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard() mIsDetectingGesture = (mKeyboard != null) && mKeyboard.mId.isAlphabetKeyboard()
&& key != null && !key.isModifier(); && key != null && !key.isModifier() && !key.isRepeatable();
if (mIsDetectingGesture) { if (mIsDetectingGesture) {
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
sGestureFirstDownTime = eventTime; sGestureFirstDownTime = eventTime;
@ -945,7 +954,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// This onPress call may have changed keyboard layout. Those cases are detected at // This onPress call may have changed keyboard layout. Those cases are detected at
// {@link #setKeyboard}. In those cases, we should update key according to the new // {@link #setKeyboard}. In those cases, we should update key according to the new
// keyboard layout. // keyboard layout.
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false /* isRepeatKey */)) {
key = onDownKey(x, y, eventTime); key = onDownKey(x, y, eventTime);
} }
@ -1035,7 +1044,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// at {@link #setKeyboard}. In those cases, we should update key according // at {@link #setKeyboard}. In those cases, we should update key according
// to the new keyboard layout. // to the new keyboard layout.
Key key = newKey; Key key = newKey;
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) { if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false /* isRepeatKey */)) {
key = onMoveKey(x, y); key = onMoveKey(x, y);
} }
onMoveToNewKey(key, x, y); onMoveToNewKey(key, x, y);
@ -1304,16 +1313,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
private void startRepeatKey(final Key key) {
if (sInGesture) return;
if (key == null) return;
if (!key.isRepeatable()) return;
// Don't start key repeat when we are in sliding input mode.
if (mIsInSlidingKeyInput) return;
detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis());
mTimerProxy.startKeyRepeatTimer(this);
}
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime, private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,
final Key newKey) { final Key newKey) {
if (mKeyDetector == null) { if (mKeyDetector == null) {
@ -1394,6 +1393,26 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
callListenerOnRelease(key, code, false /* withSliding */); callListenerOnRelease(key, code, false /* withSliding */);
} }
private void startRepeatKey(final Key key) {
if (sInGesture) return;
if (key == null) return;
if (!key.isRepeatable()) return;
// Don't start key repeat when we are in sliding input mode.
if (mIsInSlidingKeyInput) return;
detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis());
mTimerProxy.startKeyRepeatTimer(this, sParams.mKeyRepeatStartTimeout);
}
public void onKeyRepeat(final int code) {
final Key key = getKey();
if (key == null || key.mCode != code) {
return;
}
mTimerProxy.startKeyRepeatTimer(this, sParams.mKeyRepeatInterval);
callListenerOnPressAndCheckKeyboardLayoutChange(key, true /* isRepeatKey */);
callListenerOnCodeInput(key, code, mKeyX, mKeyY, SystemClock.uptimeMillis());
}
private void printTouchEvent(final String title, final int x, final int y, private void printTouchEvent(final String title, final int x, final int y,
final long eventTime) { final long eventTime) {
final Key key = mKeyDetector.detectHitKey(x, y); final Key key = mKeyDetector.detectHitKey(x, y);