aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/PointerTracker.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java382
1 files changed, 207 insertions, 175 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index f9e78bfd9..52f190e77 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -55,10 +55,37 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private static boolean sGestureHandlingEnabledByInputField = false;
private static boolean sGestureHandlingEnabledByUser = false;
+ public interface KeyEventHandler {
+ /**
+ * Get KeyDetector object that is used for this PointerTracker.
+ * @return the KeyDetector object that is used for this PointerTracker
+ */
+ public KeyDetector getKeyDetector();
+
+ /**
+ * Get KeyboardActionListener object that is used to register key code and so on.
+ * @return the KeyboardActionListner for this PointerTracke
+ */
+ public KeyboardActionListener getKeyboardActionListener();
+
+ /**
+ * Get DrawingProxy object that is used for this PointerTracker.
+ * @return the DrawingProxy object that is used for this PointerTracker
+ */
+ public DrawingProxy getDrawingProxy();
+
+ /**
+ * Get TimerProxy object that handles key repeat and long press timer event for this
+ * PointerTracker.
+ * @return the TimerProxy object that handles key repeat and long press timer event.
+ */
+ public TimerProxy getTimerProxy();
+ }
+
public interface DrawingProxy {
public void invalidateKey(Key key);
- public void showKeyPreview(Key key);
- public void dismissKeyPreview(Key key);
+ public void showKeyPreview(PointerTracker tracker);
+ public void dismissKeyPreview(PointerTracker tracker);
public void showSlidingKeyInputPreview(PointerTracker tracker);
public void dismissSlidingKeyInputPreview();
public void showGestureTrail(PointerTracker tracker, boolean showsFloatingPreviewText);
@@ -67,13 +94,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public interface TimerProxy {
public void startTypingStateTimer(Key typedKey);
public boolean isTypingState();
- public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay);
- public void startLongPressTimerOf(PointerTracker tracker, int delay);
- public void cancelLongPressTimerOf(PointerTracker tracker);
- public void cancelKeyTimersOf(PointerTracker tracker);
+ public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay);
+ public void startLongPressTimer(PointerTracker tracker, int delay);
+ public void cancelLongPressTimer();
public void startDoubleTapShiftKeyTimer();
public void cancelDoubleTapShiftKeyTimer();
public boolean isInDoubleTapShiftKeyTimeout();
+ public void cancelKeyTimers();
public void startUpdateBatchInputTimer(PointerTracker tracker);
public void cancelUpdateBatchInputTimer(PointerTracker tracker);
public void cancelAllUpdateBatchInputTimers();
@@ -84,13 +111,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override
public boolean isTypingState() { return false; }
@Override
- public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay) {}
- @Override
- public void startLongPressTimerOf(PointerTracker tracker, int delay) {}
+ public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay) {}
@Override
- public void cancelLongPressTimerOf(PointerTracker tracker) {}
+ public void startLongPressTimer(PointerTracker tracker, int delay) {}
@Override
- public void cancelKeyTimersOf(PointerTracker tracker) {}
+ public void cancelLongPressTimer() {}
@Override
public void startDoubleTapShiftKeyTimer() {}
@Override
@@ -98,6 +123,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override
public boolean isInDoubleTapShiftKeyTimeout() { return false; }
@Override
+ public void cancelKeyTimers() {}
+ @Override
public void startUpdateBatchInputTimer(PointerTracker tracker) {}
@Override
public void cancelUpdateBatchInputTimer(PointerTracker tracker) {}
@@ -107,7 +134,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
static final class PointerTrackerParams {
- public final boolean mKeySelectionByDraggingFinger;
+ public final boolean mSlidingKeyInputEnabled;
public final int mTouchNoiseThresholdTime;
public final int mTouchNoiseThresholdDistance;
public final int mSuppressKeyPreviewAfterBatchInputDuration;
@@ -115,9 +142,21 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public final int mKeyRepeatInterval;
public final int mLongPressShiftLockTimeout;
+ public static final PointerTrackerParams DEFAULT = new PointerTrackerParams();
+
+ private PointerTrackerParams() {
+ mSlidingKeyInputEnabled = false;
+ mTouchNoiseThresholdTime = 0;
+ mTouchNoiseThresholdDistance = 0;
+ mSuppressKeyPreviewAfterBatchInputDuration = 0;
+ mKeyRepeatStartTimeout = 0;
+ mKeyRepeatInterval = 0;
+ mLongPressShiftLockTimeout = 0;
+ }
+
public PointerTrackerParams(final TypedArray mainKeyboardViewAttr) {
- mKeySelectionByDraggingFinger = mainKeyboardViewAttr.getBoolean(
- R.styleable.MainKeyboardView_keySelectionByDraggingFinger, false);
+ mSlidingKeyInputEnabled = mainKeyboardViewAttr.getBoolean(
+ R.styleable.MainKeyboardView_slidingKeyInputEnable, false);
mTouchNoiseThresholdTime = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_touchNoiseThresholdTime, 0);
mTouchNoiseThresholdDistance = mainKeyboardViewAttr.getDimensionPixelSize(
@@ -150,14 +189,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public final int mPointerId;
- private static DrawingProxy sDrawingProxy;
- private static TimerProxy sTimerProxy;
- private static KeyDetector sDefaultKeyDetector;
+ private DrawingProxy mDrawingProxy;
+ private TimerProxy mTimerProxy;
private KeyDetector mKeyDetector;
- private static KeyboardActionListener sListener = KeyboardActionListener.EMPTY_LISTENER;
+ private KeyboardActionListener mListener = KeyboardActionListener.EMPTY_LISTENER;
private Keyboard mKeyboard;
- private int mPhantomSuddenMoveThreshold;
+ private int mPhantonSuddenMoveThreshold;
private final BogusMoveEventDetector mBogusMoveEventDetector = new BogusMoveEventDetector();
private boolean mIsDetectingGesture = false; // per PointerTracker.
@@ -303,16 +341,16 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private MoreKeysPanel mMoreKeysPanel;
private static final int MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT = 3;
- // true if this pointer is in the dragging finger mode.
- boolean mIsInDraggingFinger;
- // true if this pointer is sliding from a modifier key and in the sliding key input mode,
- // so that further modifier keys should be ignored.
+ // true if this pointer is in a sliding key input.
boolean mIsInSlidingKeyInput;
+ // true if this pointer is in a sliding key input from a modifier key,
+ // so that further modifier keys should be ignored.
+ boolean mIsInSlidingKeyInputFromModifier;
// if not a NOT_A_CODE, the key of this code is repeating
private int mCurrentRepeatingKeyCode = Constants.NOT_A_CODE;
- // true if dragging finger is allowed.
- private boolean mIsAllowedDraggingFinger;
+ // true if a sliding key input is allowed.
+ private boolean mIsAllowedSlidingKeyInput;
private final GestureStrokeWithPreviewPoints mGestureStrokeWithPreviewPoints;
@@ -339,26 +377,22 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return needsTheHack;
}
- // TODO: Add PointerTrackerFactory singleton and move some class static methods into it.
- public static void init(final TypedArray mainKeyboardViewAttr, final TimerProxy timerProxy,
- final DrawingProxy drawingProxy, final KeyDetector defaultKeyDetector) {
- sParams = new PointerTrackerParams(mainKeyboardViewAttr);
- sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
- sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
- sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
-
- final Resources res = mainKeyboardViewAttr.getResources();
+ public static void init(final Resources res) {
sNeedsPhantomSuddenMoveEventHack = Boolean.parseBoolean(
ResourceUtils.getDeviceOverrideValue(
res, R.array.phantom_sudden_move_event_device_list));
sNeedsProximateBogusDownMoveUpEventHack = needsProximateBogusDownMoveUpEventHack(res);
+ sParams = PointerTrackerParams.DEFAULT;
sGestureStrokeParams = GestureStrokeParams.DEFAULT;
sGesturePreviewParams = GestureStrokePreviewParams.DEFAULT;
sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
+ }
- sTimerProxy = timerProxy;
- sDrawingProxy = drawingProxy;
- sDefaultKeyDetector = defaultKeyDetector;
+ public static void setParameters(final TypedArray mainKeyboardViewAttr) {
+ sParams = new PointerTrackerParams(mainKeyboardViewAttr);
+ sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr);
+ sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr);
+ sTimeRecorder = new TimeRecorder(sParams, sGestureStrokeParams);
}
private static void updateGestureHandlingMode() {
@@ -379,20 +413,20 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
updateGestureHandlingMode();
}
- public static PointerTracker getPointerTracker(final int id) {
+ public static PointerTracker getPointerTracker(final int id, final KeyEventHandler handler) {
final ArrayList<PointerTracker> trackers = sTrackers;
// Create pointer trackers until we can get 'id+1'-th tracker, if needed.
for (int i = trackers.size(); i <= id; i++) {
- final PointerTracker tracker = new PointerTracker(i);
+ final PointerTracker tracker = new PointerTracker(i, handler);
trackers.add(tracker);
}
return trackers.get(id);
}
- public static boolean isAnyInDraggingFinger() {
- return sPointerTrackerQueue.isAnyInDraggingFinger();
+ public static boolean isAnyInSlidingKeyInput() {
+ return sPointerTrackerQueue.isAnyInSlidingKeyInput();
}
public static void cancelAllPointerTrackers() {
@@ -400,7 +434,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
public static void setKeyboardActionListener(final KeyboardActionListener listener) {
- sListener = listener;
+ final int trackersSize = sTrackers.size();
+ for (int i = 0; i < trackersSize; ++i) {
+ final PointerTracker tracker = sTrackers.get(i);
+ tracker.mListener = listener;
+ }
}
public static void setKeyDetector(final KeyDetector keyDetector) {
@@ -408,6 +446,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
tracker.setKeyDetectorInner(keyDetector);
+ // Mark that keyboard layout has been changed.
+ tracker.mKeyboardLayoutHasBeenChanged = true;
}
final Keyboard keyboard = keyDetector.getKeyboard();
sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput();
@@ -418,7 +458,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
- tracker.setReleasedKeyGraphics(tracker.getKey());
+ tracker.setReleasedKeyGraphics(tracker.mCurrentKey);
}
}
@@ -426,15 +466,28 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final int trackersSize = sTrackers.size();
for (int i = 0; i < trackersSize; ++i) {
final PointerTracker tracker = sTrackers.get(i);
- tracker.dismissMoreKeysPanel();
+ if (tracker.isShowingMoreKeysPanel()) {
+ tracker.mMoreKeysPanel.dismissMoreKeysPanel();
+ tracker.mMoreKeysPanel = null;
+ }
}
}
- private PointerTracker(final int id) {
+ private PointerTracker(final int id, final KeyEventHandler handler) {
+ if (handler == null) {
+ throw new NullPointerException();
+ }
mPointerId = id;
mGestureStrokeWithPreviewPoints = new GestureStrokeWithPreviewPoints(
id, sGestureStrokeParams, sGesturePreviewParams);
- setKeyDetectorInner(sDefaultKeyDetector);
+ setKeyEventHandler(handler);
+ }
+
+ private void setKeyEventHandler(final KeyEventHandler handler) {
+ setKeyDetectorInner(handler.getKeyDetector());
+ mListener = handler.getKeyboardActionListener();
+ mDrawingProxy = handler.getDrawingProxy();
+ mTimerProxy = handler.getTimerProxy();
}
// Returns true if keyboard has been changed by this callback.
@@ -447,7 +500,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
return false;
}
- final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
+ final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onPress : %s%s%s%s", mPointerId,
KeyDetector.printableCode(key),
@@ -459,10 +512,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return false;
}
if (key.isEnabled()) {
- sListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
+ mListener.onPressKey(key.getCode(), repeatCount, getActivePointerTrackerCount() == 1);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
mKeyboardLayoutHasBeenChanged = false;
- sTimerProxy.startTypingStateTimer(key);
+ mTimerProxy.startTypingStateTimer(key);
return keyboardLayoutHasBeenChanged;
}
return false;
@@ -472,8 +525,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
// primaryCode is different from {@link Key#mCode}.
private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
final int y, final long eventTime) {
- final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
- final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
+ final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
+ final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
final int code = altersCode ? key.getAltCode() : primaryCode;
if (DEBUG_LISTENER) {
final String output = code == Constants.CODE_OUTPUT_TEXT
@@ -493,9 +546,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (key.isEnabled() || altersCode) {
sTimeRecorder.onCodeInput(code, eventTime);
if (code == Constants.CODE_OUTPUT_TEXT) {
- sListener.onTextInput(key.getOutputText());
+ mListener.onTextInput(key.getOutputText());
} else if (code != Constants.CODE_UNSPECIFIED) {
- sListener.onCodeInput(code, x, y);
+ mListener.onCodeInput(code, x, y);
}
}
}
@@ -508,7 +561,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (sInGesture || mIsDetectingGesture || mIsTrackingForActionDisabled) {
return;
}
- final boolean ignoreModifierKey = mIsInDraggingFinger && key.isModifier();
+ final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onRelease : %s%s%s%s", mPointerId,
Constants.printableCode(primaryCode),
@@ -523,7 +576,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return;
}
if (key.isEnabled()) {
- sListener.onReleaseKey(primaryCode, withSliding);
+ mListener.onReleaseKey(primaryCode, withSliding);
}
}
@@ -531,7 +584,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onFinishSlidingInput", mPointerId));
}
- sListener.onFinishSlidingInput();
+ mListener.onFinishSlidingInput();
}
private void callListenerOnCancelInput() {
@@ -541,7 +594,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.pointerTracker_callListenerOnCancelInput();
}
- sListener.onCancelInput();
+ mListener.onCancelInput();
}
private void setKeyDetectorInner(final KeyDetector keyDetector) {
@@ -551,25 +604,23 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard();
- // Mark that keyboard layout has been changed.
- mKeyboardLayoutHasBeenChanged = true;
final int keyWidth = mKeyboard.mMostCommonKeyWidth;
final int keyHeight = mKeyboard.mMostCommonKeyHeight;
mGestureStrokeWithPreviewPoints.setKeyboardGeometry(keyWidth, mKeyboard.mOccupiedHeight);
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
if (newKey != mCurrentKey) {
- if (sDrawingProxy != null) {
+ if (mDrawingProxy != null) {
setReleasedKeyGraphics(mCurrentKey);
}
// Keep {@link #mCurrentKey} that comes from previous keyboard.
}
- mPhantomSuddenMoveThreshold = (int)(keyWidth * PHANTOM_SUDDEN_MOVE_THRESHOLD);
+ mPhantonSuddenMoveThreshold = (int)(keyWidth * PHANTOM_SUDDEN_MOVE_THRESHOLD);
mBogusMoveEventDetector.setKeyboardGeometry(keyWidth, keyHeight);
}
@Override
- public boolean isInDraggingFinger() {
- return mIsInDraggingFinger;
+ public boolean isInSlidingKeyInput() {
+ return mIsInSlidingKeyInput;
}
public Key getKey() {
@@ -586,7 +637,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
private void setReleasedKeyGraphics(final Key key) {
- sDrawingProxy.dismissKeyPreview(key);
+ mDrawingProxy.dismissKeyPreview(this);
if (key == null) {
return;
}
@@ -627,14 +678,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
// Even if the key is disabled, it should respond if it is in the altCodeWhileTyping state.
- final boolean altersCode = key.altCodeWhileTyping() && sTimerProxy.isTypingState();
+ final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
final boolean needsToUpdateGraphics = key.isEnabled() || altersCode;
if (!needsToUpdateGraphics) {
return;
}
if (!key.noKeyPreview() && !sInGesture && !needsToSuppressKeyPreviewPopup(eventTime)) {
- sDrawingProxy.showKeyPreview(key);
+ mDrawingProxy.showKeyPreview(this);
}
updatePressKeyGraphics(key);
@@ -646,7 +697,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
- if (key.altCodeWhileTyping() && sTimerProxy.isTypingState()) {
+ if (key.altCodeWhileTyping() && mTimerProxy.isTypingState()) {
final int altCode = key.getAltCode();
final Key altKey = mKeyboard.getKey(altCode);
if (altKey != null) {
@@ -660,14 +711,14 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
- private static void updateReleaseKeyGraphics(final Key key) {
+ private void updateReleaseKeyGraphics(final Key key) {
key.onReleased();
- sDrawingProxy.invalidateKey(key);
+ mDrawingProxy.invalidateKey(key);
}
- private static void updatePressKeyGraphics(final Key key) {
+ private void updatePressKeyGraphics(final Key key) {
key.onPressed();
- sDrawingProxy.invalidateKey(key);
+ mDrawingProxy.invalidateKey(key);
}
public GestureStrokeWithPreviewPoints getGestureStrokeWithPreviewPoints() {
@@ -715,7 +766,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return newKey;
}
- /* package */ static int getActivePointerTrackerCount() {
+ private static int getActivePointerTrackerCount() {
return sPointerTrackerQueue.size();
}
@@ -738,12 +789,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sAggregratedPointers.reset();
sLastRecognitionPointSize = 0;
sLastRecognitionTime = 0;
- sListener.onStartBatchInput();
+ mListener.onStartBatchInput();
dismissAllMoreKeysPanels();
}
- sTimerProxy.cancelLongPressTimerOf(this);
+ mTimerProxy.cancelLongPressTimer();
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
- sDrawingProxy.showGestureTrail(
+ mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
@@ -761,7 +812,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return;
}
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
- sDrawingProxy.showGestureTrail(
+ mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
@@ -776,8 +827,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
size));
}
- sTimerProxy.startUpdateBatchInputTimer(this);
- sListener.onUpdateBatchInput(sAggregratedPointers);
+ mTimerProxy.startUpdateBatchInputTimer(this);
+ mListener.onUpdateBatchInput(sAggregratedPointers);
// The listener may change the size of the pointers (when auto-committing
// for example), so we need to get the size from the pointers again.
sLastRecognitionPointSize = sAggregratedPointers.getPointerSize();
@@ -792,13 +843,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (getActivePointerTrackerCount() == 1) {
sInGesture = false;
sTimeRecorder.onEndBatchInput(eventTime);
- sTimerProxy.cancelAllUpdateBatchInputTimers();
+ mTimerProxy.cancelAllUpdateBatchInputTimers();
if (!mIsTrackingForActionDisabled) {
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onEndBatchInput : batchPoints=%d",
mPointerId, sAggregratedPointers.getPointerSize()));
}
- sListener.onEndBatchInput(sAggregratedPointers);
+ mListener.onEndBatchInput(sAggregratedPointers);
}
}
}
@@ -806,7 +857,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return;
}
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
- sDrawingProxy.showGestureTrail(
+ mDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
}
@@ -820,26 +871,19 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_LISTENER) {
Log.d(TAG, String.format("[%d] onCancelBatchInput", mPointerId));
}
- sListener.onCancelBatchInput();
+ mListener.onCancelBatchInput();
}
- public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) {
+ public void processMotionEvent(final MotionEvent me, final KeyEventHandler handler) {
final int action = me.getActionMasked();
final long eventTime = me.getEventTime();
if (action == MotionEvent.ACTION_MOVE) {
- // When this pointer is the only active pointer and is showing a more keys panel,
- // we should ignore other pointers' motion event.
- final boolean shouldIgnoreOtherPointers =
- isShowingMoreKeysPanel() && getActivePointerTrackerCount() == 1;
final int pointerCount = me.getPointerCount();
for (int index = 0; index < pointerCount; index++) {
final int id = me.getPointerId(index);
- if (shouldIgnoreOtherPointers && id != mPointerId) {
- continue;
- }
+ final PointerTracker tracker = getPointerTracker(id, handler);
final int x = (int)me.getX(index);
final int y = (int)me.getY(index);
- final PointerTracker tracker = getPointerTracker(id);
tracker.onMoveEvent(x, y, eventTime, me);
}
return;
@@ -850,7 +894,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
- onDownEvent(x, y, eventTime, keyDetector);
+ onDownEvent(x, y, eventTime, handler);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
@@ -863,11 +907,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
private void onDownEvent(final int x, final int y, final long eventTime,
- final KeyDetector keyDetector) {
+ final KeyEventHandler handler) {
if (DEBUG_EVENT) {
printTouchEvent("onDownEvent:", x, y, eventTime);
}
- setKeyDetectorInner(keyDetector);
+ setKeyEventHandler(handler);
// Naive up-to-down noise filter.
final long deltaT = eventTime - mUpTime;
if (deltaT < sParams.mTouchNoiseThresholdTime) {
@@ -910,29 +954,20 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
- /* package */ boolean isShowingMoreKeysPanel() {
+ private boolean isShowingMoreKeysPanel() {
return (mMoreKeysPanel != null);
}
- private void dismissMoreKeysPanel() {
- if (isShowingMoreKeysPanel()) {
- mMoreKeysPanel.dismissMoreKeysPanel();
- mMoreKeysPanel = null;
- }
- }
-
private void onDownEventInternal(final int x, final int y, final long eventTime) {
Key key = onDownKey(x, y, eventTime);
- // Key selection by dragging finger is allowed when 1) key selection by dragging finger is
- // enabled by configuration, 2) this pointer starts dragging from modifier key, or 3) this
- // pointer's KeyDetector always allows key selection by dragging finger, such as
- // {@link MoreKeysKeyboard}.
- mIsAllowedDraggingFinger = sParams.mKeySelectionByDraggingFinger
+ // Sliding key is allowed when 1) enabled by configuration, 2) this pointer starts sliding
+ // from modifier key, or 3) this pointer's KeyDetector always allows sliding input.
+ mIsAllowedSlidingKeyInput = sParams.mSlidingKeyInputEnabled
|| (key != null && key.isModifier())
- || mKeyDetector.alwaysAllowsKeySelectionByDraggingFinger();
+ || mKeyDetector.alwaysAllowsSlidingInput();
mKeyboardLayoutHasBeenChanged = false;
mIsTrackingForActionDisabled = false;
- resetKeySelectionByDraggingFinger();
+ resetSlidingKeyInput();
if (key != null) {
// This onPress call may have changed keyboard layout. Those cases are detected at
// {@link #setKeyboard}. In those cases, we should update key according to the new
@@ -947,17 +982,17 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
- private void startKeySelectionByDraggingFinger(final Key key) {
- if (!mIsInDraggingFinger) {
- mIsInSlidingKeyInput = key.isModifier();
+ private void startSlidingKeyInput(final Key key) {
+ if (!mIsInSlidingKeyInput) {
+ mIsInSlidingKeyInputFromModifier = key.isModifier();
}
- mIsInDraggingFinger = true;
+ mIsInSlidingKeyInput = true;
}
- private void resetKeySelectionByDraggingFinger() {
- mIsInDraggingFinger = false;
+ private void resetSlidingKeyInput() {
mIsInSlidingKeyInput = false;
- sDrawingProxy.dismissSlidingKeyInputPreview();
+ mIsInSlidingKeyInputFromModifier = false;
+ mDrawingProxy.dismissSlidingKeyInputPreview();
}
private void onGestureMoveEvent(final int x, final int y, final long eventTime,
@@ -968,7 +1003,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final boolean onValidArea = mGestureStrokeWithPreviewPoints.addPointOnKeyboard(
x, y, gestureTime, isMajorEvent);
if (mGestureStrokeWithPreviewPoints.getLength() > beforeLength) {
- sTimerProxy.startUpdateBatchInputTimer(this);
+ mTimerProxy.startUpdateBatchInputTimer(this);
}
// If the move event goes out from valid batch input area, cancel batch input.
if (!onValidArea) {
@@ -1013,15 +1048,15 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
final int translatedY = mMoreKeysPanel.translateY(y);
mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
onMoveKey(x, y);
- if (mIsInSlidingKeyInput) {
- sDrawingProxy.showSlidingKeyInputPreview(this);
+ if (mIsInSlidingKeyInputFromModifier) {
+ mDrawingProxy.showSlidingKeyInputPreview(this);
}
return;
}
onMoveEventInternal(x, y, eventTime);
}
- private void processDraggingFingerInToNewKey(final Key newKey, final int x, final int y,
+ private void processSlidingKeyInput(final Key newKey, final int x, final int y,
final long eventTime) {
// This onPress call may have changed keyboard layout. Those cases are detected
// at {@link #setKeyboard}. In those cases, we should update key according
@@ -1075,29 +1110,29 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
onDownEventInternal(x, y, eventTime);
}
- private void processDraggingFingerOutFromOldKey(final Key oldKey) {
+ private void processSildeOutFromOldKey(final Key oldKey) {
setReleasedKeyGraphics(oldKey);
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
- startKeySelectionByDraggingFinger(oldKey);
- sTimerProxy.cancelKeyTimersOf(this);
+ startSlidingKeyInput(oldKey);
+ mTimerProxy.cancelKeyTimers();
}
- private void dragFingerFromOldKeyToNewKey(final Key key, final int x, final int y,
+ private void slideFromOldKeyToNewKey(final Key key, final int x, final int y,
final long eventTime, final Key oldKey, final int lastX, final int lastY) {
// The pointer has been slid in to the new key from the previous key, we must call
// onRelease() first to notify that the previous key has been released, then call
// onPress() to notify that the new key is being pressed.
- processDraggingFingerOutFromOldKey(oldKey);
+ processSildeOutFromOldKey(oldKey);
startRepeatKey(key);
- if (mIsAllowedDraggingFinger) {
- processDraggingFingerInToNewKey(key, x, y, eventTime);
+ if (mIsAllowedSlidingKeyInput) {
+ processSlidingKeyInput(key, x, y, eventTime);
}
// HACK: On some devices, quick successive touches may be reported as a sudden move by
// touch panel firmware. This hack detects such cases and translates the move event to
// successive up and down events.
// TODO: Should find a way to balance gesture detection and this hack.
else if (sNeedsPhantomSuddenMoveEventHack
- && getDistance(x, y, lastX, lastY) >= mPhantomSuddenMoveThreshold) {
+ && getDistance(x, y, lastX, lastY) >= mPhantonSuddenMoveThreshold) {
processPhantomSuddenMoveHack(key, x, y, eventTime, oldKey, lastX, lastY);
}
// HACK: On some devices, quick successive proximate touches may be reported as a bogus
@@ -1128,11 +1163,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
}
- private void dragFingerOutFromOldKey(final Key oldKey, final int x, final int y) {
+ private void slideOutFromOldKey(final Key oldKey, final int x, final int y) {
// The pointer has been slid out from the previous key, we must call onRelease() to
// notify that the previous key has been released.
- processDraggingFingerOutFromOldKey(oldKey);
- if (mIsAllowedDraggingFinger) {
+ processSildeOutFromOldKey(oldKey);
+ if (mIsAllowedSlidingKeyInput) {
onMoveToNewKey(null, x, y);
} else {
if (!mIsDetectingGesture) {
@@ -1159,19 +1194,19 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (newKey != null) {
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
- dragFingerFromOldKeyToNewKey(newKey, x, y, eventTime, oldKey, lastX, lastY);
+ slideFromOldKeyToNewKey(newKey, x, y, eventTime, oldKey, lastX, lastY);
} else if (oldKey == null) {
// The pointer has been slid in to the new key, but the finger was not on any keys.
// In this case, we must call onPress() to notify that the new key is being pressed.
- processDraggingFingerInToNewKey(newKey, x, y, eventTime);
+ processSlidingKeyInput(newKey, x, y, eventTime);
}
} else { // newKey == null
if (oldKey != null && isMajorEnoughMoveToBeOnNewKey(x, y, eventTime, newKey)) {
- dragFingerOutFromOldKey(oldKey, x, y);
+ slideOutFromOldKey(oldKey, x, y);
}
}
- if (mIsInSlidingKeyInput) {
- sDrawingProxy.showSlidingKeyInputPreview(this);
+ if (mIsInSlidingKeyInputFromModifier) {
+ mDrawingProxy.showSlidingKeyInputPreview(this);
}
}
@@ -1180,7 +1215,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
printTouchEvent("onUpEvent :", x, y, eventTime);
}
- sTimerProxy.cancelUpdateBatchInputTimer(this);
+ mTimerProxy.cancelUpdateBatchInputTimer(this);
if (!sInGesture) {
if (mCurrentKey != null && mCurrentKey.isModifier()) {
// Before processing an up event of modifier key, all pointers already being
@@ -1202,15 +1237,18 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_EVENT) {
printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime);
}
+ if (isShowingMoreKeysPanel()) {
+ return;
+ }
onUpEventInternal(mLastX, mLastY, eventTime);
cancelTrackingForAction();
}
private void onUpEventInternal(final int x, final int y, final long eventTime) {
- sTimerProxy.cancelKeyTimersOf(this);
- final boolean isInDraggingFinger = mIsInDraggingFinger;
+ mTimerProxy.cancelKeyTimers();
final boolean isInSlidingKeyInput = mIsInSlidingKeyInput;
- resetKeySelectionByDraggingFinger();
+ final boolean isInSlidingKeyInputFromModifier = mIsInSlidingKeyInputFromModifier;
+ resetSlidingKeyInput();
mIsDetectingGesture = false;
final Key currentKey = mCurrentKey;
mCurrentKey = null;
@@ -1242,11 +1280,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
return;
}
if (currentKey != null && currentKey.isRepeatable()
- && (currentKey.getCode() == currentRepeatingKeyCode) && !isInDraggingFinger) {
+ && (currentKey.getCode() == currentRepeatingKeyCode) && !isInSlidingKeyInput) {
return;
}
detectAndSendKey(currentKey, mKeyX, mKeyY, eventTime);
- if (isInSlidingKeyInput) {
+ if (isInSlidingKeyInputFromModifier) {
callListenerOnFinishSlidingInput();
}
}
@@ -1268,7 +1306,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
public void onLongPressed() {
- resetKeySelectionByDraggingFinger();
+ resetSlidingKeyInput();
cancelTrackingForAction();
setReleasedKeyGraphics(mCurrentKey);
sPointerTrackerQueue.remove(this);
@@ -1286,9 +1324,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
private void onCancelEventInternal() {
- sTimerProxy.cancelKeyTimersOf(this);
+ mTimerProxy.cancelKeyTimers();
setReleasedKeyGraphics(mCurrentKey);
- resetKeySelectionByDraggingFinger();
+ resetSlidingKeyInput();
if (isShowingMoreKeysPanel()) {
mMoreKeysPanel.dismissMoreKeysPanel();
mMoreKeysPanel = null;
@@ -1309,7 +1347,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
// Here curKey points to the different key from newKey.
final int keyHysteresisDistanceSquared = mKeyDetector.getKeyHysteresisDistanceSquared(
- mIsInSlidingKeyInput);
+ mIsInSlidingKeyInputFromModifier);
final int distanceFromKeyEdgeSquared = curKey.squaredDistanceToEdge(x, y);
if (distanceFromKeyEdgeSquared >= keyHysteresisDistanceSquared) {
if (DEBUG_MODE) {
@@ -1320,7 +1358,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
}
return true;
}
- if (sNeedsProximateBogusDownMoveUpEventHack && !mIsAllowedDraggingFinger
+ if (sNeedsProximateBogusDownMoveUpEventHack && !mIsAllowedSlidingKeyInput
&& sTimeRecorder.isInFastTyping(eventTime)
&& mBogusMoveEventDetector.hasTraveledLongDistance(x, y)) {
if (DEBUG_MODE) {
@@ -1342,26 +1380,26 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (key == null) return;
if (!key.isLongPressEnabled()) return;
// Caveat: Please note that isLongPressEnabled() can be true even if the current key
- // doesn't have its more keys. (e.g. spacebar, globe key) If we are in the dragging finger
- // mode, we will disable long press timer of such key.
+ // doesn't have its more keys. (e.g. spacebar, globe key)
// We always need to start the long press timer if the key has its more keys regardless of
- // whether or not we are in the dragging finger mode.
- if (mIsInDraggingFinger && key.getMoreKeys() == null) return;
-
- final int delay = getLongPressTimeout(key.getCode());
- sTimerProxy.startLongPressTimerOf(this, delay);
- }
-
- private int getLongPressTimeout(final int code) {
- if (code == Constants.CODE_SHIFT) {
- return sParams.mLongPressShiftLockTimeout;
- }
- final int longpressTimeout = Settings.getInstance().getCurrent().mKeyLongpressTimeout;
- if (mIsInSlidingKeyInput) {
- // We use longer timeout for sliding finger input started from the modifier key.
- return longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
+ // whether or not we are in the sliding input mode.
+ if (mIsInSlidingKeyInput && key.getMoreKeys() == null) return;
+ final int delay;
+ switch (key.getCode()) {
+ case Constants.CODE_SHIFT:
+ delay = sParams.mLongPressShiftLockTimeout;
+ break;
+ default:
+ final int longpressTimeout = Settings.getInstance().getCurrent().mKeyLongpressTimeout;
+ if (mIsInSlidingKeyInputFromModifier) {
+ // We use longer timeout for sliding finger input started from the modifier key.
+ delay = longpressTimeout * MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
+ } else {
+ delay = longpressTimeout;
+ }
+ break;
}
- return longpressTimeout;
+ mTimerProxy.startLongPressTimer(this, delay);
}
private void detectAndSendKey(final Key key, final int x, final int y, final long eventTime) {
@@ -1379,10 +1417,10 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (sInGesture) return;
if (key == null) return;
if (!key.isRepeatable()) return;
- // Don't start key repeat when we are in the dragging finger mode.
- if (mIsInDraggingFinger) return;
+ // Don't start key repeat when we are in sliding input mode.
+ if (mIsInSlidingKeyInput) return;
final int startRepeatCount = 1;
- startKeyRepeatTimer(startRepeatCount);
+ mTimerProxy.startKeyRepeatTimer(this, startRepeatCount, sParams.mKeyRepeatStartTimeout);
}
public void onKeyRepeat(final int code, final int repeatCount) {
@@ -1394,17 +1432,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
mCurrentRepeatingKeyCode = code;
mIsDetectingGesture = false;
final int nextRepeatCount = repeatCount + 1;
- startKeyRepeatTimer(nextRepeatCount);
+ mTimerProxy.startKeyRepeatTimer(this, nextRepeatCount, sParams.mKeyRepeatInterval);
callListenerOnPressAndCheckKeyboardLayoutChange(key, repeatCount);
callListenerOnCodeInput(key, code, mKeyX, mKeyY, SystemClock.uptimeMillis());
}
- private void startKeyRepeatTimer(final int repeatCount) {
- final int delay =
- (repeatCount == 1) ? sParams.mKeyRepeatStartTimeout : sParams.mKeyRepeatInterval;
- sTimerProxy.startKeyRepeatTimerOf(this, repeatCount, delay);
- }
-
private void printTouchEvent(final String title, final int x, final int y,
final long eventTime) {
final Key key = mKeyDetector.detectHitKey(x, y);