From 915f348b35cb66ed9696a51c9250f9b25799fb82 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 9 Jan 2013 12:56:55 +0900 Subject: [PATCH] Cancel update batch input timer whenever MotionEvent is received Bug: 7911739 Change-Id: Id2cd98385371fd98435943ed66ec5381dfaa48e0 --- .../inputmethod/keyboard/MainKeyboardView.java | 5 +++++ .../inputmethod/keyboard/PointerTracker.java | 5 +++++ .../keyboard/internal/GestureStroke.java | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 130fad851..625575d53 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -365,6 +365,11 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mGestureRecognitionUpdateTime); } + @Override + public void cancelUpdateBatchInputTimer(final PointerTracker tracker) { + removeMessages(MSG_UPDATE_BATCH_INPUT, tracker); + } + @Override public void cancelAllUpdateBatchInputTimers() { removeMessages(MSG_UPDATE_BATCH_INPUT); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 59a3c99aa..60a510302 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -98,6 +98,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { public boolean isInDoubleTapTimeout(); public void cancelKeyTimers(); public void startUpdateBatchInputTimer(PointerTracker tracker); + public void cancelUpdateBatchInputTimer(PointerTracker tracker); public void cancelAllUpdateBatchInputTimers(); public static class Adapter implements TimerProxy { @@ -124,6 +125,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element { @Override public void startUpdateBatchInputTimer(PointerTracker tracker) {} @Override + public void cancelUpdateBatchInputTimer(PointerTracker tracker) {} + @Override public void cancelAllUpdateBatchInputTimers() {} } } @@ -938,6 +941,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { if (DEBUG_MOVE_EVENT) { printTouchEvent("onMoveEvent:", x, y, eventTime); } + mTimerProxy.cancelUpdateBatchInputTimer(this); if (mIsTrackingCanceled) { return; } @@ -1122,6 +1126,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { printTouchEvent("onUpEvent :", x, y, eventTime); } + mTimerProxy.cancelUpdateBatchInputTimer(this); if (!sInGesture) { if (mCurrentKey != null && mCurrentKey.isModifier()) { // Before processing an up event of modifier key, all pointers already being diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java index a43e94a75..adf223602 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java @@ -233,6 +233,10 @@ public class GestureStroke { if (lastIndex >= 0) { final int x = mXCoordinates.get(lastIndex); final int y = mYCoordinates.get(lastIndex); + if (DEBUG) { + Log.d(TAG, String.format("[%d] duplicateLastPointWith: %d,%d|%d", mPointerId, + x, y, time)); + } // TODO: Have appendMajorPoint() appendPoint(x, y, time); updateIncrementalRecognitionSize(x, y, time); @@ -251,6 +255,16 @@ public class GestureStroke { } private void appendPoint(final int x, final int y, final int time) { + final int lastIndex = mEventTimes.getLength() - 1; + // The point that is created by {@link duplicateLastPointWith(int)} may have later event + // time than the next {@link MotionEvent}. To maintain the monotonicity of the event time, + // drop the successive point here. + if (lastIndex >= 0 && mEventTimes.get(lastIndex) > time) { + Log.w(TAG, String.format("[%d] drop stale event: %d,%d|%d last: %d,%d|%d", mPointerId, + x, y, time, mXCoordinates.get(lastIndex), mYCoordinates.get(lastIndex), + mEventTimes.get(lastIndex))); + return; + } mEventTimes.add(time); mXCoordinates.add(x); mYCoordinates.add(y);