Remove mPreviousKey in PointerTracker

This change also introduces PointerTracker.onLongPressed.

Change-Id: I079eb52175d8fe8b88ce3f13e31493d34d00ad5e
main
Tadashi G. Takaoka 2011-04-18 19:07:20 +09:00
parent 7751ac3bdb
commit d2c2b4d112
4 changed files with 63 additions and 59 deletions

View File

@ -881,7 +881,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
// TODO: clean up this method. // TODO: clean up this method.
private void dismissKeyPreview() { private void dismissKeyPreview() {
for (PointerTracker tracker : mPointerTrackers) for (PointerTracker tracker : mPointerTrackers)
tracker.releaseKey(); tracker.setReleasedKeyGraphics();
showPreview(KeyDetector.NOT_A_KEY, null); showPreview(KeyDetector.NOT_A_KEY, null);
} }
@ -1034,16 +1034,13 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
if (result) { if (result) {
dismissKeyPreview(); dismissKeyPreview();
mMiniKeyboardTrackerId = tracker.mPointerId; mMiniKeyboardTrackerId = tracker.mPointerId;
// Mark this tracker "already processed" and remove it from the pointer queue tracker.onLongPressed(mPointerQueue);
tracker.setAlreadyProcessed();
mPointerQueue.remove(tracker);
} }
return result; return result;
} }
private void onLongPressShiftKey(PointerTracker tracker) { private void onLongPressShiftKey(PointerTracker tracker) {
tracker.setAlreadyProcessed(); tracker.onLongPressed(mPointerQueue);
mPointerQueue.remove(tracker);
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0); mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
} }

View File

@ -91,9 +91,6 @@ public class PointerTracker {
// ignore modifier key if true // ignore modifier key if true
private boolean mIgnoreModifierKey; private boolean mIgnoreModifierKey;
// pressed key
private int mPreviousKey = NOT_A_KEY;
// Empty {@link KeyboardActionListener} // Empty {@link KeyboardActionListener}
private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() { private static final KeyboardActionListener EMPTY_LISTENER = new KeyboardActionListener() {
@Override @Override
@ -250,29 +247,24 @@ public class PointerTracker {
return key != null && key.mCode == Keyboard.CODE_SPACE; return key != null && key.mCode == Keyboard.CODE_SPACE;
} }
public void releaseKey() { public void setReleasedKeyGraphics() {
updateKeyGraphics(NOT_A_KEY); setReleasedKeyGraphics(mKeyState.getKeyIndex());
} }
private void updateKeyGraphics(int keyIndex) { private void setReleasedKeyGraphics(int keyIndex) {
int oldKeyIndex = mPreviousKey; final Key key = getKey(keyIndex);
mPreviousKey = keyIndex; if (key != null) {
if (keyIndex != oldKeyIndex) { key.onReleased();
if (isValidKeyIndex(oldKeyIndex)) { mProxy.invalidateKey(key);
final Key oldKey = mKeys.get(oldKeyIndex);
oldKey.onReleased();
mProxy.invalidateKey(oldKey);
}
if (isValidKeyIndex(keyIndex)) {
final Key newKey = mKeys.get(keyIndex);
newKey.onPressed();
mProxy.invalidateKey(newKey);
}
} }
} }
public void setAlreadyProcessed() { private void setPressedKeyGraphics(int keyIndex) {
mKeyAlreadyProcessed = true; final Key key = getKey(keyIndex);
if (key != null && key.mEnabled) {
key.onPressed();
mProxy.invalidateKey(key);
}
} }
private void checkAssertion(PointerTrackerQueue queue) { private void checkAssertion(PointerTrackerQueue queue) {
@ -318,7 +310,7 @@ public class PointerTracker {
if (DEBUG_MODE) if (DEBUG_MODE)
Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT Log.w(TAG, "onDownEvent: ignore potential noise: time=" + deltaT
+ " distance=" + distanceSquared); + " distance=" + distanceSquared);
setAlreadyProcessed(); mKeyAlreadyProcessed = true;
return; return;
} }
} }
@ -346,24 +338,25 @@ public class PointerTracker {
mIsRepeatableKey = false; mIsRepeatableKey = false;
mIsInSlidingKeyInput = false; mIsInSlidingKeyInput = false;
mIgnoreModifierKey = false; mIgnoreModifierKey = false;
final Key key = getKey(keyIndex); if (isValidKeyIndex(keyIndex)) {
if (key != null) {
// 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 keyIndex according to the new // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new
// keyboard layout. // keyboard layout.
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false)) if (callListenerOnPressAndCheckKeyboardLayoutChange(getKey(keyIndex), false))
keyIndex = mKeyState.onDownKey(x, y, eventTime); keyIndex = mKeyState.onDownKey(x, y, eventTime);
// Accessibility disables key repeat because users may need to pause on a key to hear // Accessibility disables key repeat because users may need to pause on a key to hear
// its spoken description. // its spoken description.
if (key.mRepeatable && !mIsAccessibilityEnabled) { final Key key = getKey(keyIndex);
if (key != null && key.mRepeatable && !mIsAccessibilityEnabled) {
repeatKey(keyIndex); repeatKey(keyIndex);
mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this); mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this);
mIsRepeatableKey = true; mIsRepeatableKey = true;
} }
startLongPressTimer(keyIndex); startLongPressTimer(keyIndex);
showKeyPreview(keyIndex);
setPressedKeyGraphics(keyIndex);
} }
showKeyPreviewAndUpdateKeyGraphics(keyIndex);
} }
private void startSlidingKeyInput(Key key) { private void startSlidingKeyInput(Key key) {
@ -382,8 +375,9 @@ public class PointerTracker {
final int lastX = keyState.getLastX(); final int lastX = keyState.getLastX();
final int lastY = keyState.getLastY(); final int lastY = keyState.getLastY();
final int oldKeyIndex = keyState.getKeyIndex();
final Key oldKey = getKey(oldKeyIndex);
int keyIndex = keyState.onMoveKey(x, y); int keyIndex = keyState.onMoveKey(x, y);
final Key oldKey = getKey(keyState.getKeyIndex());
if (isValidKeyIndex(keyIndex)) { if (isValidKeyIndex(keyIndex)) {
if (oldKey == null) { if (oldKey == null) {
// The pointer has been slid in to the new key, but the finger was not on any keys. // The pointer has been slid in to the new key, but the finger was not on any keys.
@ -395,10 +389,13 @@ public class PointerTracker {
keyIndex = keyState.onMoveKey(x, y); keyIndex = keyState.onMoveKey(x, y);
keyState.onMoveToNewKey(keyIndex, x, y); keyState.onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex); startLongPressTimer(keyIndex);
showKeyPreview(keyIndex);
setPressedKeyGraphics(keyIndex);
} else if (!isMinorMoveBounce(x, y, keyIndex)) { } else if (!isMinorMoveBounce(x, y, keyIndex)) {
// The pointer has been slid in to the new key from the previous key, we must call // The pointer has been slid in to the new key from the previous key, we must call
// onRelease() first to notify that the previous key has been released, then call // onRelease() first to notify that the previous key has been released, then call
// onPress() to notify that the new key is being pressed. // onPress() to notify that the new key is being pressed.
setReleasedKeyGraphics(oldKeyIndex);
callListenerOnRelease(oldKey, oldKey.mCode, true); callListenerOnRelease(oldKey, oldKey.mCode, true);
startSlidingKeyInput(oldKey); startSlidingKeyInput(oldKey);
mHandler.cancelLongPressTimers(); mHandler.cancelLongPressTimers();
@ -410,6 +407,8 @@ public class PointerTracker {
keyIndex = keyState.onMoveKey(x, y); keyIndex = keyState.onMoveKey(x, y);
keyState.onMoveToNewKey(keyIndex, x, y); keyState.onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex); startLongPressTimer(keyIndex);
setPressedKeyGraphics(keyIndex);
showKeyPreview(keyIndex);
} else { } else {
// HACK: On some devices, quick successive touches may be translated to sudden // HACK: On some devices, quick successive touches may be translated to sudden
// move by touch panel firmware. This hack detects the case and translates the // move by touch panel firmware. This hack detects the case and translates the
@ -424,8 +423,9 @@ public class PointerTracker {
onUpEventInternal(lastX, lastY, eventTime); onUpEventInternal(lastX, lastY, eventTime);
onDownEventInternal(x, y, eventTime); onDownEventInternal(x, y, eventTime);
} else { } else {
setAlreadyProcessed(); mKeyAlreadyProcessed = true;
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); showKeyPreview(NOT_A_KEY);
setReleasedKeyGraphics(oldKeyIndex);
} }
return; return;
} }
@ -434,19 +434,19 @@ public class PointerTracker {
if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) { if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) {
// The pointer has been slid out from the previous key, we must call onRelease() to // The pointer has been slid out from the previous key, we must call onRelease() to
// notify that the previous key has been released. // notify that the previous key has been released.
setReleasedKeyGraphics(oldKeyIndex);
callListenerOnRelease(oldKey, oldKey.mCode, true); callListenerOnRelease(oldKey, oldKey.mCode, true);
startSlidingKeyInput(oldKey); startSlidingKeyInput(oldKey);
mHandler.cancelLongPressTimers(); mHandler.cancelLongPressTimers();
if (mIsAllowedSlidingKeyInput) { if (mIsAllowedSlidingKeyInput) {
keyState.onMoveToNewKey(keyIndex, x ,y); keyState.onMoveToNewKey(keyIndex, x, y);
} else { } else {
setAlreadyProcessed(); mKeyAlreadyProcessed = true;
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); showKeyPreview(NOT_A_KEY);
return; return;
} }
} }
} }
showKeyPreviewAndUpdateKeyGraphics(keyState.getKeyIndex());
} }
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
@ -469,30 +469,38 @@ public class PointerTracker {
public void onUpEventForRelease(int x, int y, long eventTime) { public void onUpEventForRelease(int x, int y, long eventTime) {
onUpEventInternal(x, y, eventTime); onUpEventInternal(x, y, eventTime);
mKeyAlreadyProcessed = true;
} }
private void onUpEventInternal(int pointX, int pointY, long eventTime) { private void onUpEventInternal(int x, int y, long eventTime) {
int x = pointX;
int y = pointY;
mHandler.cancelKeyTimers(); mHandler.cancelKeyTimers();
mHandler.cancelPopupPreview(); mHandler.cancelPopupPreview();
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
mIsInSlidingKeyInput = false; mIsInSlidingKeyInput = false;
final PointerTrackerKeyState keyState = mKeyState;
final int keyX, keyY;
if (!isMinorMoveBounce(x, y, keyState.onMoveKey(x, y))) {
keyX = x;
keyY = y;
} else {
// Use previous fixed key coordinates.
keyX = keyState.getKeyX();
keyY = keyState.getKeyY();
}
final int keyIndex = keyState.onUpKey(keyX, keyY, eventTime);
showKeyPreview(NOT_A_KEY);
setReleasedKeyGraphics(keyIndex);
if (mKeyAlreadyProcessed) if (mKeyAlreadyProcessed)
return; return;
final PointerTrackerKeyState keyState = mKeyState;
int keyIndex = keyState.onUpKey(x, y, eventTime);
if (isMinorMoveBounce(x, y, keyIndex)) {
// Use previous fixed key index and coordinates.
keyIndex = keyState.getKeyIndex();
x = keyState.getKeyX();
y = keyState.getKeyY();
}
if (!mIsRepeatableKey) { if (!mIsRepeatableKey) {
detectAndSendKey(keyIndex, x, y); detectAndSendKey(keyIndex, keyX, keyY);
} }
} }
public void onLongPressed(PointerTrackerQueue queue) {
mKeyAlreadyProcessed = true;
queue.remove(this);
}
public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue); if (ENABLE_ASSERTION) checkAssertion(queue);
if (DEBUG_EVENT) if (DEBUG_EVENT)
@ -506,7 +514,8 @@ public class PointerTracker {
private void onCancelEventInternal() { private void onCancelEventInternal() {
mHandler.cancelKeyTimers(); mHandler.cancelKeyTimers();
mHandler.cancelPopupPreview(); mHandler.cancelPopupPreview();
showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY); showKeyPreview(NOT_A_KEY);
setReleasedKeyGraphics(mKeyState.getKeyIndex());
mIsInSlidingKeyInput = false; mIsInSlidingKeyInput = false;
} }
@ -542,7 +551,7 @@ public class PointerTracker {
} }
} }
private void showKeyPreviewAndUpdateKeyGraphics(int keyIndex) { private void showKeyPreview(int keyIndex) {
final Key key = getKey(keyIndex); final Key key = getKey(keyIndex);
if (key != null && !key.mEnabled) if (key != null && !key.mEnabled)
return; return;
@ -555,7 +564,6 @@ public class PointerTracker {
} else { } else {
mProxy.showPreview(keyIndex, this); mProxy.showPreview(keyIndex, this);
} }
updateKeyGraphics(keyIndex);
} }
private void startLongPressTimer(int keyIndex) { private void startLongPressTimer(int keyIndex) {

View File

@ -92,6 +92,7 @@ package com.android.inputmethod.keyboard;
public int onUpKey(int x, int y, long eventTime) { public int onUpKey(int x, int y, long eventTime) {
mUpTime = eventTime; mUpTime = eventTime;
mKeyIndex = KeyDetector.NOT_A_KEY;
return onMoveKeyInternal(x, y); return onMoveKeyInternal(x, y);
} }
} }

View File

@ -29,14 +29,13 @@ public class PointerTrackerQueue {
if (mQueue.lastIndexOf(tracker) < 0) { if (mQueue.lastIndexOf(tracker) < 0) {
return; return;
} }
LinkedList<PointerTracker> queue = mQueue; final LinkedList<PointerTracker> queue = mQueue;
int oldestPos = 0; int oldestPos = 0;
for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) { for (PointerTracker t = queue.get(oldestPos); t != tracker; t = queue.get(oldestPos)) {
if (t.isModifier()) { if (t.isModifier()) {
oldestPos++; oldestPos++;
} else { } else {
t.onUpEventForRelease(t.getLastX(), t.getLastY(), eventTime); t.onUpEventForRelease(t.getLastX(), t.getLastY(), eventTime);
t.setAlreadyProcessed();
queue.remove(oldestPos); queue.remove(oldestPos);
} }
} }
@ -51,7 +50,6 @@ public class PointerTrackerQueue {
if (t == tracker) if (t == tracker)
continue; continue;
t.onUpEventForRelease(t.getLastX(), t.getLastY(), eventTime); t.onUpEventForRelease(t.getLastX(), t.getLastY(), eventTime);
t.setAlreadyProcessed();
} }
mQueue.clear(); mQueue.clear();
if (tracker != null) if (tracker != null)