Merge "Merge key preview handling into key graphics handling"
This commit is contained in:
commit
bdf3789811
3 changed files with 30 additions and 55 deletions
|
@ -171,10 +171,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
|
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, tracker), delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelDismissKeyPreview(PointerTracker tracker) {
|
|
||||||
removeMessages(MSG_DISMISS_KEY_PREVIEW, tracker);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cancelAllDismissKeyPreviews() {
|
public void cancelAllDismissKeyPreviews() {
|
||||||
removeMessages(MSG_DISMISS_KEY_PREVIEW);
|
removeMessages(MSG_DISMISS_KEY_PREVIEW);
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,8 +199,7 @@ public class PointerTracker {
|
||||||
|
|
||||||
public static void dismissAllKeyPreviews() {
|
public static void dismissAllKeyPreviews() {
|
||||||
for (final PointerTracker tracker : sTrackers) {
|
for (final PointerTracker tracker : sTrackers) {
|
||||||
tracker.setReleasedKeyGraphics();
|
tracker.setReleasedKeyGraphics(tracker.mKeyIndex);
|
||||||
tracker.dismissKeyPreview();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,11 +322,8 @@ public class PointerTracker {
|
||||||
return key != null && key.mCode == Keyboard.CODE_SPACE;
|
return key != null && key.mCode == Keyboard.CODE_SPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReleasedKeyGraphics() {
|
|
||||||
setReleasedKeyGraphics(mKeyIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setReleasedKeyGraphics(int keyIndex) {
|
private void setReleasedKeyGraphics(int keyIndex) {
|
||||||
|
mDrawingProxy.dismissKeyPreview(this);
|
||||||
final Key key = getKey(keyIndex);
|
final Key key = getKey(keyIndex);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
key.onReleased();
|
key.onReleased();
|
||||||
|
@ -336,6 +332,9 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPressedKeyGraphics(int keyIndex) {
|
private void setPressedKeyGraphics(int keyIndex) {
|
||||||
|
if (isKeyPreviewRequired(keyIndex)) {
|
||||||
|
mDrawingProxy.showKeyPreview(keyIndex, this);
|
||||||
|
}
|
||||||
final Key key = getKey(keyIndex);
|
final Key key = getKey(keyIndex);
|
||||||
if (key != null && key.isEnabled()) {
|
if (key != null && key.isEnabled()) {
|
||||||
key.onPressed();
|
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() {
|
public int getLastX() {
|
||||||
return mLastX;
|
return mLastX;
|
||||||
}
|
}
|
||||||
|
@ -438,7 +449,6 @@ public class PointerTracker {
|
||||||
|
|
||||||
startRepeatKey(keyIndex);
|
startRepeatKey(keyIndex);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
showKeyPreview(keyIndex);
|
|
||||||
setPressedKeyGraphics(keyIndex);
|
setPressedKeyGraphics(keyIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,7 +481,6 @@ public class PointerTracker {
|
||||||
keyIndex = onMoveKey(x, y);
|
keyIndex = onMoveKey(x, y);
|
||||||
onMoveToNewKey(keyIndex, x, y);
|
onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
showKeyPreview(keyIndex);
|
|
||||||
setPressedKeyGraphics(keyIndex);
|
setPressedKeyGraphics(keyIndex);
|
||||||
} else if (isMajorEnoughMoveToBeOnNewKey(x, y, keyIndex)) {
|
} else if (isMajorEnoughMoveToBeOnNewKey(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
|
||||||
|
@ -491,7 +500,6 @@ public class PointerTracker {
|
||||||
onMoveToNewKey(keyIndex, x, y);
|
onMoveToNewKey(keyIndex, x, y);
|
||||||
startLongPressTimer(keyIndex);
|
startLongPressTimer(keyIndex);
|
||||||
setPressedKeyGraphics(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
|
||||||
|
@ -503,11 +511,10 @@ public class PointerTracker {
|
||||||
if (DEBUG_MODE)
|
if (DEBUG_MODE)
|
||||||
Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
|
Log.w(TAG, String.format("onMoveEvent: sudden move is translated to "
|
||||||
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
|
+ "up[%d,%d]/down[%d,%d] events", lastX, lastY, x, y));
|
||||||
onUpEventInternal(lastX, lastY, eventTime, true);
|
onUpEventInternal(lastX, lastY, eventTime);
|
||||||
onDownEventInternal(x, y, eventTime);
|
onDownEventInternal(x, y, eventTime);
|
||||||
} else {
|
} else {
|
||||||
mKeyAlreadyProcessed = true;
|
mKeyAlreadyProcessed = true;
|
||||||
dismissKeyPreview();
|
|
||||||
setReleasedKeyGraphics(oldKeyIndex);
|
setReleasedKeyGraphics(oldKeyIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -524,7 +531,6 @@ public class PointerTracker {
|
||||||
onMoveToNewKey(keyIndex, x, y);
|
onMoveToNewKey(keyIndex, x, y);
|
||||||
} else {
|
} else {
|
||||||
mKeyAlreadyProcessed = true;
|
mKeyAlreadyProcessed = true;
|
||||||
dismissKeyPreview();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,27 +545,26 @@ public class PointerTracker {
|
||||||
if (isModifier()) {
|
if (isModifier()) {
|
||||||
// Before processing an up event of modifier key, all pointers already being
|
// Before processing an up event of modifier key, all pointers already being
|
||||||
// tracked should be released.
|
// tracked should be released.
|
||||||
queue.releaseAllPointersExcept(this, eventTime, true);
|
queue.releaseAllPointersExcept(this, eventTime);
|
||||||
} else {
|
} else {
|
||||||
queue.releaseAllPointersOlderThan(this, eventTime);
|
queue.releaseAllPointersOlderThan(this, eventTime);
|
||||||
}
|
}
|
||||||
queue.remove(this);
|
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.
|
// 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
|
// This pointer tracker needs to keep the key top graphics "pressed", but needs to get a
|
||||||
// "virtual" up event.
|
// "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)
|
if (DEBUG_EVENT)
|
||||||
printTouchEvent("onPhntEvent:", x, y, eventTime);
|
printTouchEvent("onPhntEvent:", x, y, eventTime);
|
||||||
onUpEventInternal(x, y, eventTime, updateReleasedKeyGraphics);
|
onUpEventInternal(x, y, eventTime);
|
||||||
mKeyAlreadyProcessed = true;
|
mKeyAlreadyProcessed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onUpEventInternal(int x, int y, long eventTime,
|
private void onUpEventInternal(int x, int y, long eventTime) {
|
||||||
boolean updateReleasedKeyGraphics) {
|
|
||||||
mTimerProxy.cancelKeyTimers();
|
mTimerProxy.cancelKeyTimers();
|
||||||
mDrawingProxy.cancelShowKeyPreview(this);
|
mDrawingProxy.cancelShowKeyPreview(this);
|
||||||
mIsInSlidingKeyInput = false;
|
mIsInSlidingKeyInput = false;
|
||||||
|
@ -573,9 +578,7 @@ public class PointerTracker {
|
||||||
keyY = mKeyY;
|
keyY = mKeyY;
|
||||||
}
|
}
|
||||||
final int keyIndex = onUpKey(keyX, keyY, eventTime);
|
final int keyIndex = onUpKey(keyX, keyY, eventTime);
|
||||||
dismissKeyPreview();
|
setReleasedKeyGraphics(keyIndex);
|
||||||
if (updateReleasedKeyGraphics)
|
|
||||||
setReleasedKeyGraphics(keyIndex);
|
|
||||||
if (mKeyAlreadyProcessed)
|
if (mKeyAlreadyProcessed)
|
||||||
return;
|
return;
|
||||||
if (!mIsRepeatableKey) {
|
if (!mIsRepeatableKey) {
|
||||||
|
@ -585,8 +588,7 @@ public class PointerTracker {
|
||||||
|
|
||||||
public void onLongPressed() {
|
public void onLongPressed() {
|
||||||
mKeyAlreadyProcessed = true;
|
mKeyAlreadyProcessed = true;
|
||||||
setReleasedKeyGraphics();
|
setReleasedKeyGraphics(mKeyIndex);
|
||||||
dismissKeyPreview();
|
|
||||||
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
queue.remove(this);
|
queue.remove(this);
|
||||||
|
@ -599,7 +601,7 @@ public class PointerTracker {
|
||||||
|
|
||||||
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
final PointerTrackerQueue queue = sPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
queue.releaseAllPointersExcept(this, eventTime, true);
|
queue.releaseAllPointersExcept(this, eventTime);
|
||||||
queue.remove(this);
|
queue.remove(this);
|
||||||
}
|
}
|
||||||
onCancelEventInternal();
|
onCancelEventInternal();
|
||||||
|
@ -608,7 +610,6 @@ public class PointerTracker {
|
||||||
private void onCancelEventInternal() {
|
private void onCancelEventInternal() {
|
||||||
mTimerProxy.cancelKeyTimers();
|
mTimerProxy.cancelKeyTimers();
|
||||||
mDrawingProxy.cancelShowKeyPreview(this);
|
mDrawingProxy.cancelShowKeyPreview(this);
|
||||||
dismissKeyPreview();
|
|
||||||
setReleasedKeyGraphics(mKeyIndex);
|
setReleasedKeyGraphics(mKeyIndex);
|
||||||
mIsInSlidingKeyInput = false;
|
mIsInSlidingKeyInput = false;
|
||||||
}
|
}
|
||||||
|
@ -616,7 +617,6 @@ public class PointerTracker {
|
||||||
private void startRepeatKey(int keyIndex) {
|
private void startRepeatKey(int keyIndex) {
|
||||||
final Key key = getKey(keyIndex);
|
final Key key = getKey(keyIndex);
|
||||||
if (key != null && key.mRepeatable) {
|
if (key != null && key.mRepeatable) {
|
||||||
dismissKeyPreview();
|
|
||||||
onRepeatKey(keyIndex);
|
onRepeatKey(keyIndex);
|
||||||
mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this);
|
mTimerProxy.startKeyRepeatTimer(sDelayBeforeKeyRepeatStart, keyIndex, this);
|
||||||
mIsRepeatableKey = true;
|
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) {
|
private void startLongPressTimer(int keyIndex) {
|
||||||
Key key = getKey(keyIndex);
|
Key key = getKey(keyIndex);
|
||||||
if (key.mCode == Keyboard.CODE_SHIFT) {
|
if (key.mCode == Keyboard.CODE_SHIFT) {
|
||||||
|
|
|
@ -37,22 +37,21 @@ public class PointerTrackerQueue {
|
||||||
if (t.isModifier()) {
|
if (t.isModifier()) {
|
||||||
oldestPos++;
|
oldestPos++;
|
||||||
} else {
|
} else {
|
||||||
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, true);
|
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
|
||||||
queue.remove(oldestPos);
|
queue.remove(oldestPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseAllPointers(long eventTime) {
|
public void releaseAllPointers(long eventTime) {
|
||||||
releaseAllPointersExcept(null, eventTime, true);
|
releaseAllPointersExcept(null, eventTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseAllPointersExcept(PointerTracker tracker, long eventTime,
|
public void releaseAllPointersExcept(PointerTracker tracker, long eventTime) {
|
||||||
boolean updateReleasedKeyGraphics) {
|
|
||||||
for (PointerTracker t : mQueue) {
|
for (PointerTracker t : mQueue) {
|
||||||
if (t == tracker)
|
if (t == tracker)
|
||||||
continue;
|
continue;
|
||||||
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime, updateReleasedKeyGraphics);
|
t.onPhantomUpEvent(t.getLastX(), t.getLastY(), eventTime);
|
||||||
}
|
}
|
||||||
mQueue.clear();
|
mQueue.clear();
|
||||||
if (tracker != null)
|
if (tracker != null)
|
||||||
|
|
Loading…
Reference in a new issue