diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 69 |
1 files changed, 31 insertions, 38 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 4ceabff4c..19cedc41d 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -34,7 +34,6 @@ import java.util.List; public class PointerTracker { private static final String TAG = PointerTracker.class.getSimpleName(); - private static final boolean ENABLE_ASSERTION = false; private static final boolean DEBUG_EVENT = false; private static final boolean DEBUG_MOVE_EVENT = false; private static final boolean DEBUG_LISTENER = false; @@ -56,10 +55,10 @@ public class PointerTracker { private final DrawingProxy mDrawingProxy; private final KeyTimerHandler mKeyTimerHandler; + private final PointerTrackerQueue mPointerTrackerQueue; private KeyDetector mKeyDetector; private KeyboardActionListener mListener = EMPTY_LISTENER; private final KeyboardSwitcher mKeyboardSwitcher; - private final boolean mHasDistinctMultitouch; private final boolean mConfigSlidingKeyInputEnabled; private final int mTouchNoiseThresholdMillis; @@ -107,21 +106,19 @@ public class PointerTracker { public void onTextInput(CharSequence text) {} @Override public void onCancelInput() {} - @Override - public void onSwipeDown() {} }; public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler, - KeyDetector keyDetector, DrawingProxy drawingProxy, boolean hasDistinctMultitouch) { + KeyDetector keyDetector, DrawingProxy drawingProxy, PointerTrackerQueue queue) { if (drawingProxy == null || keyTimerHandler == null || keyDetector == null) throw new NullPointerException(); mPointerId = id; mDrawingProxy = drawingProxy; mKeyTimerHandler = keyTimerHandler; - mKeyDetector = keyDetector; - mKeyboardSwitcher = KeyboardSwitcher.getInstance(); + mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device. mKeyState = new PointerTrackerKeyState(keyDetector); - mHasDistinctMultitouch = hasDistinctMultitouch; + setKeyDetectorInner(keyDetector); + mKeyboardSwitcher = KeyboardSwitcher.getInstance(); final Resources res = context.getResources(); mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled); mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start); @@ -135,7 +132,7 @@ public class PointerTracker { mSubtypeSwitcher = SubtypeSwitcher.getInstance(); } - public void setOnKeyboardActionListener(KeyboardActionListener listener) { + public void setKeyboardActionListener(KeyboardActionListener listener) { mListener = listener; } @@ -196,15 +193,19 @@ public class PointerTracker { mListener.onCancelInput(); } - public void setKeyboard(Keyboard keyboard, KeyDetector keyDetector) { - if (keyboard == null || keyDetector == null) - throw new NullPointerException(); - mKeyboard = keyboard; - mKeys = keyboard.getKeys(); + public void setKeyDetectorInner(KeyDetector keyDetector) { mKeyDetector = keyDetector; + mKeyboard = keyDetector.getKeyboard(); + mKeys = mKeyboard.getKeys(); mKeyState.setKeyDetector(keyDetector); - final int keyQuarterWidth = keyboard.getKeyWidth() / 4; + final int keyQuarterWidth = mKeyboard.getKeyWidth() / 4; mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth; + } + + public void setKeyDetector(KeyDetector keyDetector) { + if (keyDetector == null) + throw new NullPointerException(); + setKeyDetectorInner(keyDetector); // Mark that keyboard layout has been changed. mKeyboardLayoutHasBeenChanged = true; } @@ -273,36 +274,26 @@ public class PointerTracker { } } - private void checkAssertion(PointerTrackerQueue queue) { - if (mHasDistinctMultitouch && queue == null) - throw new RuntimeException( - "PointerTrackerQueue must be passed on distinct multi touch device"); - if (!mHasDistinctMultitouch && queue != null) - throw new RuntimeException( - "PointerTrackerQueue must be null on non-distinct multi touch device"); - } - - public void onTouchEvent(int action, int x, int y, long eventTime, PointerTrackerQueue queue) { + public void onTouchEvent(int action, int x, int y, long eventTime) { switch (action) { case MotionEvent.ACTION_MOVE: - onMoveEvent(x, y, eventTime, queue); + onMoveEvent(x, y, eventTime); break; case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: - onDownEvent(x, y, eventTime, queue); + onDownEvent(x, y, eventTime); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: - onUpEvent(x, y, eventTime, queue); + onUpEvent(x, y, eventTime); break; case MotionEvent.ACTION_CANCEL: - onCancelEvent(x, y, eventTime, queue); + onCancelEvent(x, y, eventTime); break; } } - public void onDownEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { - if (ENABLE_ASSERTION) checkAssertion(queue); + public void onDownEvent(int x, int y, long eventTime) { if (DEBUG_EVENT) printTouchEvent("onDownEvent:", x, y, eventTime); @@ -321,6 +312,7 @@ public class PointerTracker { } } + final PointerTrackerQueue queue = mPointerTrackerQueue; if (queue != null) { if (isOnModifierKey(x, y)) { // Before processing a down event of modifier key, all pointers already being @@ -364,8 +356,7 @@ public class PointerTracker { mIsInSlidingKeyInput = true; } - public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { - if (ENABLE_ASSERTION) checkAssertion(queue); + public void onMoveEvent(int x, int y, long eventTime) { if (DEBUG_MOVE_EVENT) printTouchEvent("onMoveEvent:", x, y, eventTime); if (mKeyAlreadyProcessed) @@ -449,6 +440,7 @@ public class PointerTracker { keyboard.updateSpacebarPreviewIcon(diff); // Display spacebar slide language switcher. showKeyPreview(keyIndex); + final PointerTrackerQueue queue = mPointerTrackerQueue; if (queue != null) queue.releaseAllPointersExcept(this, eventTime, true); } @@ -472,11 +464,11 @@ public class PointerTracker { } } - public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { - if (ENABLE_ASSERTION) checkAssertion(queue); + public void onUpEvent(int x, int y, long eventTime) { if (DEBUG_EVENT) printTouchEvent("onUpEvent :", x, y, eventTime); + final PointerTrackerQueue queue = mPointerTrackerQueue; if (queue != null) { if (isModifier()) { // Before processing an up event of modifier key, all pointers already being @@ -540,8 +532,9 @@ public class PointerTracker { } } - public void onLongPressed(PointerTrackerQueue queue) { + public void onLongPressed() { mKeyAlreadyProcessed = true; + final PointerTrackerQueue queue = mPointerTrackerQueue; if (queue != null) { // TODO: Support chording + long-press input. queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true); @@ -549,11 +542,11 @@ public class PointerTracker { } } - public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) { - if (ENABLE_ASSERTION) checkAssertion(queue); + public void onCancelEvent(int x, int y, long eventTime) { if (DEBUG_EVENT) printTouchEvent("onCancelEvt:", x, y, eventTime); + final PointerTrackerQueue queue = mPointerTrackerQueue; if (queue != null) { queue.releaseAllPointersExcept(this, eventTime, true); queue.remove(this); |