Merge key preview handling into key graphics handling

Change-Id: I7b0ba38d833362817c607f6abffbaf0a07f52832
This commit is contained in:
Tadashi G. Takaoka 2011-07-23 01:27:49 -07:00
parent ebebaed713
commit d3002aa8cd
3 changed files with 30 additions and 55 deletions

View file

@ -171,10 +171,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
}
public void cancelDismissKeyPreview(PointerTracker tracker) {
removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
}
public void cancelAllDismissKeyPreviews() {
removeMessages(MSG_DISMISS_KEY_PREVIEW);
}

View file

@ -199,8 +199,7 @@ public class PointerTracker {
public static void dismissAllKeyPreviews() {
for (final PointerTracker tracker : sTrackers) {
tracker.setReleasedKeyGraphics();
tracker.dismissKeyPreview();
tracker.setReleasedKeyGraphics(tracker.mKeyIndex);
}
}
@ -323,11 +322,8 @@ public class PointerTracker {
return key != null && key.mCode == Keyboard.CODE_SPACE;
}
public void setReleasedKeyGraphics() {
setReleasedKeyGraphics(mKeyIndex);
}
private void setReleasedKeyGraphics(int keyIndex) {
mDrawingProxy.dismissKeyPreview(this);
final Key key = getKey(keyIndex);
if (key != null) {
key.onReleased();
@ -336,6 +332,9 @@ public class PointerTracker {
}
private void setPressedKeyGraphics(int keyIndex) {
if (isKeyPreviewRequired(keyIndex)) {
mDrawingProxy.showKeyPreview(keyIndex, this);
}
final Key key = getKey(keyIndex);
if (key != null && key.isEnabled()) {
key.onPressed();
@ -343,6 +342,18 @@ public class PointerTracker {
}
}
// The modifier key, such as shift key, should not show its key preview.
private boolean isKeyPreviewRequired(int keyIndex) {
final Key key = getKey(keyIndex);
if (key == null || !key.isEnabled())
return false;
final int code = key.mCode;
if (isModifierCode(code) || code == Keyboard.CODE_DELETE
|| code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE)
return false;
return true;
}
public int getLastX() {
return mLastX;
}
@ -438,7 +449,6 @@ public class PointerTracker {
startRepeatKey(keyIndex);
startLongPressTimer(keyIndex);
showKeyPreview(keyIndex);
setPressedKeyGraphics(keyIndex);
}
}
@ -471,7 +481,6 @@ public class PointerTracker {
keyIndex = onMoveKey(x, y);
onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex);
showKeyPreview(keyIndex);
setPressedKeyGraphics(keyIndex);
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
// The pointer has been slid in to the new key from the previous key, we must call
@ -491,7 +500,6 @@ public class PointerTracker {
onMoveToNewKey(keyIndex, x, y);
startLongPressTimer(keyIndex);
setPressedKeyGraphics(keyIndex);
showKeyPreview(keyIndex);
} else {
// 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
@ -503,11 +511,10 @@ public class PointerTracker {
if (DEBUG_MODE)
Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
onUpEventInternal(lastX, lastY, eventTime, true);
onUpEventInternal(lastX, lastY, eventTime);
onDownEventInternal(x, y, eventTime);
} else {
mKeyAlreadyProcessed = true;
dismissKeyPreview();
setReleasedKeyGraphics(oldKeyIndex);
}
}
@ -524,7 +531,6 @@ public class PointerTracker {
onMoveToNewKey(keyIndex, x, y);
} else {
mKeyAlreadyProcessed = true;
dismissKeyPreview();
}
}
}
@ -539,27 +545,26 @@ public class PointerTracker {
if (isModifier()) {
// Before processing an up event of modifier key, all pointers already being
// tracked should be released.
queue.releaseAllPointersExcept(this, eventTime, true);
queue.releaseAllPointersExcept(this, eventTime);
} else {
queue.releaseAllPointersOlderThan(this, eventTime);
}
queue.remove(this);
}
onUpEventInternal(x, y, eventTime, true);
onUpEventInternal(x, y, eventTime);
}
// Let this pointer tracker know that one of newer-than-this pointer trackers got an up event.
// This pointer tracker needs to keep the key top graphics "pressed", but needs to get a
// "virtual" up event.
public void onPhantomUpEvent(int x, int y, long eventTime, boolean updateReleasedKeyGraphics) {
public void onPhantomUpEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onPhntEvent:", x, y, eventTime);
onUpEventInternal(x, y, eventTime, updateReleasedKeyGraphics);
onUpEventInternal(x, y, eventTime);
mKeyAlreadyProcessed = true;
}
private void onUpEventInternal(int x, int y, long eventTime,
boolean updateReleasedKeyGraphics) {
private void onUpEventInternal(int x, int y, long eventTime) {
mTimerProxy.cancelKeyTimers();
mDrawingProxy.cancelShowKeyPreview(this);
mIsInSlidingKeyInput = false;
@ -573,8 +578,6 @@ public class PointerTracker {
keyY = mKeyY;
}
final int keyIndex = onUpKey(keyX, keyY, eventTime);
dismissKeyPreview();
if (updateReleasedKeyGraphics)
setReleasedKeyGraphics(keyIndex);
if (mKeyAlreadyProcessed)
return;
@ -585,8 +588,7 @@ public class PointerTracker {
public void onLongPressed() {
mKeyAlreadyProcessed = true;
setReleasedKeyGraphics();
dismissKeyPreview();
setReleasedKeyGraphics(mKeyIndex);
final PointerTrackerQueue queue = sPointerTrackerQueue;
if (queue != null) {
queue.remove(this);
@ -599,7 +601,7 @@ public class PointerTracker {
final PointerTrackerQueue queue = sPointerTrackerQueue;
if (queue != null) {
queue.releaseAllPointersExcept(this, eventTime, true);
queue.releaseAllPointersExcept(this, eventTime);
queue.remove(this);
}
onCancelEventInternal();
@ -608,7 +610,6 @@ public class PointerTracker {
private void onCancelEventInternal() {
mTimerProxy.cancelKeyTimers();
mDrawingProxy.cancelShowKeyPreview(this);
dismissKeyPreview();
setReleasedKeyGraphics(mKeyIndex);
mIsInSlidingKeyInput = false;
}
@ -616,7 +617,6 @@ public class PointerTracker {
private void startRepeatKey(int keyIndex) {
final Key key = getKey(keyIndex);
if (key != null && key.mRepeatable) {
dismissKeyPreview();
onRepeatKey(keyIndex);
mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this);
mIsRepeatableKey = true;
@ -646,26 +646,6 @@ public class PointerTracker {
}
}
// The modifier key, such as shift key, should not show its key preview.
private boolean isKeyPreviewNotRequired(int keyIndex) {
final Key key = getKey(keyIndex);
if (key == null || !key.isEnabled())
return true;
final int code = key.mCode;
return isModifierCode(code) || code == Keyboard.CODE_DELETE
|| code == Keyboard.CODE_ENTER || code == Keyboard.CODE_SPACE;
}
private void showKeyPreview(int keyIndex) {
if (isKeyPreviewNotRequired(keyIndex))
return;
mDrawingProxy.showKeyPreview(keyIndex, this);
}
private void dismissKeyPreview() {
mDrawingProxy.dismissKeyPreview(this);
}
private void startLongPressTimer(int keyIndex) {
Key key = getKey(keyIndex);
if (key.mCode == Keyboard.CODE_SHIFT) {

View file

@ -37,22 +37,21 @@ public class PointerTrackerQueue {
if (t.isModifier()) {
oldestPos++;
} else {
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, true);
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
queue.remove(oldestPos);
}
}
}
public void releaseAllPointers(long eventTime) {
releaseAllPointersExcept(null, eventTime, true);
releaseAllPointersExcept(null, eventTime);
}
public void releaseAllPointersExcept(PointerTracker tracker, long eventTime,
boolean updateReleasedKeyGraphics) {
public void releaseAllPointersExcept(PointerTracker tracker, long eventTime) {
for (PointerTracker t : mQueue) {
if (t == tracker)
continue;
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, updateReleasedKeyGraphics);
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
}
mQueue.clear();
if (tracker != null)