aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/PointerTracker.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/PointerTracker.java')
-rw-r--r--java/src/com/android/inputmethod/latin/PointerTracker.java112
1 files changed, 75 insertions, 37 deletions
diff --git a/java/src/com/android/inputmethod/latin/PointerTracker.java b/java/src/com/android/inputmethod/latin/PointerTracker.java
index 10f51bd48..a4447d58b 100644
--- a/java/src/com/android/inputmethod/latin/PointerTracker.java
+++ b/java/src/com/android/inputmethod/latin/PointerTracker.java
@@ -27,13 +27,11 @@ import android.view.ViewConfiguration;
public class PointerTracker {
private static final String TAG = "PointerTracker";
private static final boolean DEBUG = false;
+ private static final boolean DEBUG_MOVE = DEBUG && true;
public interface UIProxy {
public void invalidateKey(Key key);
public void showPreview(int keyIndex, PointerTracker tracker);
- // TODO: These methods might be temporary.
- public void dismissPopupKeyboard();
- public boolean isMiniKeyboardOnScreen();
}
public final int mPointerId;
@@ -60,6 +58,10 @@ public class PointerTracker {
private int mCurrentKey = NOT_A_KEY;
private int mStartX;
private int mStartY;
+ private long mDownTime;
+
+ // true if event is already translated to a key action (long press or mini-keyboard)
+ private boolean mKeyAlreadyProcessed;
// for move de-bouncing
private int mLastCodeX;
@@ -138,12 +140,18 @@ public class PointerTracker {
}
}
- public void onDownEvent(int touchX, int touchY, long eventTime) {
- int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
+ public void setAlreadyProcessed() {
+ mKeyAlreadyProcessed = true;
+ }
+
+ public void onDownEvent(int x, int y, long eventTime) {
+ int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
mCurrentKey = keyIndex;
- mStartX = touchX;
- mStartY = touchY;
- startMoveDebouncing(touchX, touchY);
+ mStartX = x;
+ mStartY = y;
+ mDownTime = eventTime;
+ mKeyAlreadyProcessed = false;
+ startMoveDebouncing(x, y);
startTimeDebouncing(eventTime);
checkMultiTap(eventTime, keyIndex);
if (mListener != null) {
@@ -155,32 +163,44 @@ public class PointerTracker {
repeatKey(keyIndex);
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex, this);
}
- mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
+ mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this);
}
showKeyPreviewAndUpdateKey(keyIndex);
- updateMoveDebouncing(touchX, touchY);
+ updateMoveDebouncing(x, y);
if (DEBUG)
- Log.d(TAG, "onDownEvent: [" + mPointerId + "] modifier=" + isModifier());
+ debugLog("onDownEvent:", x, y);
}
- public void onMoveEvent(int touchX, int touchY, long eventTime) {
- int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
+ public void onMoveEvent(int x, int y, long eventTime) {
+ int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
if (isValidKeyIndex(keyIndex)) {
if (mCurrentKey == NOT_A_KEY) {
updateTimeDebouncing(eventTime);
mCurrentKey = keyIndex;
- mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
- } else if (isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
+ mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this);
+ } else if (isMinorMoveBounce(x, y, keyIndex, mCurrentKey)) {
updateTimeDebouncing(eventTime);
} else {
resetMultiTap();
resetTimeDebouncing(eventTime, mCurrentKey);
resetMoveDebouncing();
mCurrentKey = keyIndex;
- mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
+ mHandler.startLongPressTimer(LONGPRESS_TIMEOUT, keyIndex, this);
}
} else {
- mHandler.cancelLongPressTimer();
+ if (mCurrentKey != NOT_A_KEY) {
+ updateTimeDebouncing(eventTime);
+ mCurrentKey = keyIndex;
+ mHandler.cancelLongPressTimer();
+ } else if (isMinorMoveBounce(x, y, keyIndex, mCurrentKey)) {
+ updateTimeDebouncing(eventTime);
+ } else {
+ resetMultiTap();
+ resetTimeDebouncing(eventTime, mCurrentKey);
+ resetMoveDebouncing();
+ mCurrentKey = keyIndex;
+ mHandler.cancelLongPressTimer();
+ }
}
/*
* While time debouncing is in effect, mCurrentKey holds the new key and this tracker
@@ -189,17 +209,19 @@ public class PointerTracker {
* should not be showed as popup preview.
*/
showKeyPreviewAndUpdateKey(isMinorTimeBounce() ? mLastKey : mCurrentKey);
- updateMoveDebouncing(touchX, touchY);
+ updateMoveDebouncing(x, y);
+ if (DEBUG_MOVE)
+ debugLog("onMoveEvent:", x, y);
}
- public void onUpEvent(int touchX, int touchY, long eventTime) {
+ public void onUpEvent(int x, int y, long eventTime) {
if (DEBUG)
- Log.d(TAG, "onUpEvent: [" + mPointerId + "] modifier=" + isModifier());
- int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
+ debugLog("onUpEvent :", x, y);
+ int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(x, y, null);
boolean wasInKeyRepeat = mHandler.isInKeyRepeat();
mHandler.cancelKeyTimers();
mHandler.cancelPopupPreview();
- if (isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
+ if (isMinorMoveBounce(x, y, keyIndex, mCurrentKey)) {
updateTimeDebouncing(eventTime);
} else {
resetMultiTap();
@@ -208,24 +230,23 @@ public class PointerTracker {
}
if (isMinorTimeBounce()) {
mCurrentKey = mLastKey;
- touchX = mLastCodeX;
- touchY = mLastCodeY;
+ x = mLastCodeX;
+ y = mLastCodeY;
}
showKeyPreviewAndUpdateKey(NOT_A_KEY);
// If we're not on a repeating key (which sends on a DOWN event)
- if (!wasInKeyRepeat && !mProxy.isMiniKeyboardOnScreen()) {
- detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
+ if (!wasInKeyRepeat && !mKeyAlreadyProcessed) {
+ detectAndSendKey(mCurrentKey, (int)x, (int)y, eventTime);
}
if (isValidKeyIndex(keyIndex))
mProxy.invalidateKey(mKeys[keyIndex]);
}
- public void onCancelEvent(int touchX, int touchY, long eventTime) {
+ public void onCancelEvent(int x, int y, long eventTime) {
if (DEBUG)
- Log.d(TAG, "onCancelEvent: [" + mPointerId + "]");
+ debugLog("onCancelEvt:", x, y);
mHandler.cancelKeyTimers();
mHandler.cancelPopupPreview();
- mProxy.dismissPopupKeyboard();
showKeyPreviewAndUpdateKey(NOT_A_KEY);
int keyIndex = mCurrentKey;
if (isValidKeyIndex(keyIndex))
@@ -241,6 +262,18 @@ public class PointerTracker {
}
}
+ public int getLastX() {
+ return mLastX;
+ }
+
+ public int getLastY() {
+ return mLastY;
+ }
+
+ public long getDownTime() {
+ return mDownTime;
+ }
+
// These package scope methods are only for debugging purpose.
/* package */ int getStartX() {
return mStartX;
@@ -250,14 +283,6 @@ public class PointerTracker {
return mStartY;
}
- /* package */ int getLastX() {
- return mLastX;
- }
-
- /* package */ int getLastY() {
- return mLastY;
- }
-
private void startMoveDebouncing(int x, int y) {
mLastCodeX = x;
mLastCodeY = y;
@@ -412,4 +437,17 @@ public class PointerTracker {
resetMultiTap();
}
}
+
+ private void debugLog(String title, int x, int y) {
+ Key key = getKey(mCurrentKey);
+ final String code;
+ if (key == null) {
+ code = "----";
+ } else {
+ int primaryCode = key.codes[0];
+ code = String.format((primaryCode < 0) ? "%4d" : "0x%02x", primaryCode);
+ }
+ Log.d(TAG, String.format("%s [%d] %3d,%3d %s %s", title, mPointerId, x, y, code,
+ isModifier() ? "modifier" : ""));
+ }
} \ No newline at end of file