Skip to content
Snippets Groups Projects
Commit 1a9bf159 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Don't triger onPress and startLongPressTimer when gesture is canceled"

parents 508ab248 13d5da8b
No related branches found
No related tags found
No related merge requests found
...@@ -318,8 +318,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -318,8 +318,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// true if keyboard layout has been changed. // true if keyboard layout has been changed.
private boolean mKeyboardLayoutHasBeenChanged; private boolean mKeyboardLayoutHasBeenChanged;
// true if this pointer is no longer tracking touch event. // true if this pointer is no longer triggering any action because it has been canceled.
private boolean mIsTrackingCanceled; private boolean mIsTrackingForActionDisabled;
// the more keys panel currently being shown. equals null if no panel is active. // the more keys panel currently being shown. equals null if no panel is active.
private MoreKeysPanel mMoreKeysPanel; private MoreKeysPanel mMoreKeysPanel;
...@@ -441,7 +441,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -441,7 +441,11 @@ 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) {
if (sInGesture || mIsDetectingGesture) { // 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>
// are set to false. To keep this method is a no-operation,
// <code>mIsTrackingForActionDisabled</code> should also be taken account of.
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
return false; return false;
} }
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier(); final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
...@@ -500,7 +504,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -500,7 +504,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// primaryCode is different from {@link Key#mCode}. // primaryCode is different from {@link Key#mCode}.
private void callListenerOnRelease(final Key key, final int primaryCode, private void callListenerOnRelease(final Key key, final int primaryCode,
final boolean withSliding) { final boolean withSliding) {
if (sInGesture || mIsDetectingGesture) { // See the comment at {@link #callListenerOnPressAndCheckKeyboardLayoutChange(Key}}.
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
return; return;
} }
final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier(); final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
...@@ -745,7 +750,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -745,7 +750,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (key != null) { if (key != null) {
updateBatchInput(eventTime); updateBatchInput(eventTime);
} }
if (mIsTrackingCanceled) { if (mIsTrackingForActionDisabled) {
return; return;
} }
mDrawingProxy.showGesturePreviewTrail(this); mDrawingProxy.showGesturePreviewTrail(this);
...@@ -777,7 +782,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -777,7 +782,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sInGesture = false; sInGesture = false;
sTimeRecorder.onEndBatchInput(eventTime); sTimeRecorder.onEndBatchInput(eventTime);
mTimerProxy.cancelAllUpdateBatchInputTimers(); mTimerProxy.cancelAllUpdateBatchInputTimers();
if (!mIsTrackingCanceled) { if (!mIsTrackingForActionDisabled) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d", Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d",
mPointerId, sAggregratedPointers.getPointerSize())); mPointerId, sAggregratedPointers.getPointerSize()));
...@@ -786,7 +791,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -786,7 +791,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
} }
} }
if (mIsTrackingCanceled) { if (mIsTrackingForActionDisabled) {
return; return;
} }
mDrawingProxy.showGesturePreviewTrail(this); mDrawingProxy.showGesturePreviewTrail(this);
...@@ -846,7 +851,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -846,7 +851,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.pointerTracker_onDownEvent(deltaT, distance * distance); ResearchLogger.pointerTracker_onDownEvent(deltaT, distance * distance);
} }
cancelTracking(); cancelTrackingForAction();
return; return;
} }
} }
...@@ -887,7 +892,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -887,7 +892,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
|| (key != null && key.isModifier()) || (key != null && key.isModifier())
|| mKeyDetector.alwaysAllowsSlidingInput(); || mKeyDetector.alwaysAllowsSlidingInput();
mKeyboardLayoutHasBeenChanged = false; mKeyboardLayoutHasBeenChanged = false;
mIsTrackingCanceled = false; mIsTrackingForActionDisabled = false;
resetSlidingKeyInput(); resetSlidingKeyInput();
if (key != null) { 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
...@@ -947,7 +952,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -947,7 +952,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_MOVE_EVENT) { if (DEBUG_MOVE_EVENT) {
printTouchEvent("onMoveEvent:", x, y, eventTime); printTouchEvent("onMoveEvent:", x, y, eventTime);
} }
if (mIsTrackingCanceled) { if (mIsTrackingForActionDisabled) {
return; return;
} }
...@@ -985,6 +990,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -985,6 +990,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
key = onMoveKey(x, y); key = onMoveKey(x, y);
} }
onMoveToNewKey(key, x, y); onMoveToNewKey(key, x, y);
if (mIsTrackingForActionDisabled) {
return;
}
startLongPressTimer(key); startLongPressTimer(key);
setPressedKeyGraphics(key, eventTime); setPressedKeyGraphics(key, eventTime);
} }
...@@ -1069,11 +1077,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1069,11 +1077,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
+ " detected sliding finger while multi touching", mPointerId)); + " detected sliding finger while multi touching", mPointerId));
} }
onUpEvent(x, y, eventTime); onUpEvent(x, y, eventTime);
cancelTracking(); cancelTrackingForAction();
setReleasedKeyGraphics(oldKey); setReleasedKeyGraphics(oldKey);
} else { } else {
if (!mIsDetectingGesture) { if (!mIsDetectingGesture) {
cancelTracking(); cancelTrackingForAction();
} }
setReleasedKeyGraphics(oldKey); setReleasedKeyGraphics(oldKey);
} }
...@@ -1087,7 +1095,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1087,7 +1095,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
onMoveToNewKey(null, x, y); onMoveToNewKey(null, x, y);
} else { } else {
if (!mIsDetectingGesture) { if (!mIsDetectingGesture) {
cancelTracking(); cancelTrackingForAction();
} }
} }
} }
...@@ -1155,7 +1163,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1155,7 +1163,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return; return;
} }
onUpEventInternal(mLastX, mLastY, eventTime); onUpEventInternal(mLastX, mLastY, eventTime);
cancelTracking(); cancelTrackingForAction();
} }
private void onUpEventInternal(final int x, final int y, final long eventTime) { private void onUpEventInternal(final int x, final int y, final long eventTime) {
...@@ -1168,7 +1176,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1168,7 +1176,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
setReleasedKeyGraphics(currentKey); setReleasedKeyGraphics(currentKey);
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
if (!mIsTrackingCanceled) { if (!mIsTrackingForActionDisabled) {
final int translatedX = mMoreKeysPanel.translateX(x); final int translatedX = mMoreKeysPanel.translateX(x);
final int translatedY = mMoreKeysPanel.translateY(y); final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime); mMoreKeysPanel.onUpEvent(translatedX, translatedY, mPointerId, eventTime);
...@@ -1186,7 +1194,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1186,7 +1194,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return; return;
} }
if (mIsTrackingCanceled) { if (mIsTrackingForActionDisabled) {
return; return;
} }
if (currentKey != null && !currentKey.isRepeatable()) { if (currentKey != null && !currentKey.isRepeatable()) {
...@@ -1203,16 +1211,16 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1203,16 +1211,16 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
@Override @Override
public void cancelTracking() { public void cancelTrackingForAction() {
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
return; return;
} }
mIsTrackingCanceled = true; mIsTrackingForActionDisabled = true;
} }
public void onLongPressed() { public void onLongPressed() {
resetSlidingKeyInput(); resetSlidingKeyInput();
cancelTracking(); cancelTrackingForAction();
setReleasedKeyGraphics(mCurrentKey); setReleasedKeyGraphics(mCurrentKey);
sPointerTrackerQueue.remove(this); sPointerTrackerQueue.remove(this);
} }
...@@ -1316,6 +1324,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element { ...@@ -1316,6 +1324,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final Key key = mKeyDetector.detectHitKey(x, y); final Key key = mKeyDetector.detectHitKey(x, y);
final String code = KeyDetector.printableCode(key); final String code = KeyDetector.printableCode(key);
Log.d(TAG, String.format("[%d]%s%s %4d %4d %5d %s", mPointerId, Log.d(TAG, String.format("[%d]%s%s %4d %4d %5d %s", mPointerId,
(mIsTrackingCanceled ? "-" : " "), title, x, y, eventTime, code)); (mIsTrackingForActionDisabled ? "-" : " "), title, x, y, eventTime, code));
} }
} }
...@@ -30,7 +30,7 @@ public final class PointerTrackerQueue { ...@@ -30,7 +30,7 @@ public final class PointerTrackerQueue {
public boolean isModifier(); public boolean isModifier();
public boolean isInSlidingKeyInput(); public boolean isInSlidingKeyInput();
public void onPhantomUpEvent(long eventTime); public void onPhantomUpEvent(long eventTime);
public void cancelTracking(); public void cancelTrackingForAction();
} }
private static final int INITIAL_CAPACITY = 10; private static final int INITIAL_CAPACITY = 10;
...@@ -206,7 +206,7 @@ public final class PointerTrackerQueue { ...@@ -206,7 +206,7 @@ public final class PointerTrackerQueue {
final int arraySize = mArraySize; final int arraySize = mArraySize;
for (int index = 0; index < arraySize; index++) { for (int index = 0; index < arraySize; index++) {
final Element element = expandableArray.get(index); final Element element = expandableArray.get(index);
element.cancelTracking(); element.cancelTrackingForAction();
} }
} }
} }
......
...@@ -51,7 +51,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase { ...@@ -51,7 +51,7 @@ public class PointerTrackerQueueTests extends AndroidTestCase {
} }
@Override @Override
public void cancelTracking() {} public void cancelTrackingForAction() {}
@Override @Override
public String toString() { public String toString() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment