From 921a32f0a923ca00c4818d3869f0abd9a63dcf0e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 20 Dec 2013 11:56:09 +0900 Subject: [PATCH] Remove unnecessary default KeyDetector from PointerTracker Change-Id: Ib0fbb40a7040202d2a4b4ab49319d9e247a2a6ce --- .../inputmethod/keyboard/MainKeyboardView.java | 6 ++---- .../android/inputmethod/keyboard/PointerTracker.java | 9 ++++----- .../internal/NonDistinctMultitouchHelper.java | 11 ++++------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index b4609d051..992603b43 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -230,8 +230,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mKeyDetector = new KeyDetector( keyHysteresisDistance, keyHysteresisDistanceForSlidingModifier); - PointerTracker.init(mainKeyboardViewAttr, mKeyTimerHandler, this /* DrawingProxy */, - mKeyDetector); + PointerTracker.init(mainKeyboardViewAttr, mKeyTimerHandler, this /* DrawingProxy */); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final boolean forceNonDistinctMultitouch = prefs.getBoolean( @@ -240,7 +239,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT) && !forceNonDistinctMultitouch; mNonDistinctMultitouchHelper = hasDistinctMultitouch ? null - : new NonDistinctMultitouchHelper(PointerTracker.getPointerTracker(0)); + : new NonDistinctMultitouchHelper(); final int backgroundDimAlpha = mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_backgroundDimAlpha, 0); @@ -431,7 +430,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mKeyDetector.setKeyboard( keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection()); PointerTracker.setKeyDetector(mKeyDetector); - PointerTracker.setKeyboardActionListener(mKeyboardActionListener); mMoreKeysKeyboardCache.clear(); mSpaceKey = keyboard.getKey(Constants.CODE_SPACE); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index ef48da646..1c6d83996 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -155,10 +155,11 @@ public final class PointerTracker implements PointerTrackerQueue.Element { private static DrawingProxy sDrawingProxy; private static TimerProxy sTimerProxy; - private static KeyDetector sDefaultKeyDetector; - private KeyDetector mKeyDetector; private static KeyboardActionListener sListener = KeyboardActionListener.EMPTY_LISTENER; + // The {@link KeyDetector} is set whenever the down event is processed. Also this is updated + // when new {@link Keyboard} is set by {@link #setKeyDetector(KeyDetector)}. + private KeyDetector mKeyDetector; private Keyboard mKeyboard; private int mPhantomSuddenMoveThreshold; private final BogusMoveEventDetector mBogusMoveEventDetector = new BogusMoveEventDetector(); @@ -344,7 +345,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element { // 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) { + final DrawingProxy drawingProxy) { sParams = new PointerTrackerParams(mainKeyboardViewAttr); sGestureStrokeParams = new GestureStrokeParams(mainKeyboardViewAttr); sGesturePreviewParams = new GestureStrokePreviewParams(mainKeyboardViewAttr); @@ -358,7 +359,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element { sTimerProxy = timerProxy; sDrawingProxy = drawingProxy; - sDefaultKeyDetector = defaultKeyDetector; } private static void updateGestureHandlingMode() { @@ -434,7 +434,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element { mPointerId = id; mGestureStrokeWithPreviewPoints = new GestureStrokeWithPreviewPoints( id, sGestureStrokeParams, sGesturePreviewParams); - setKeyDetectorInner(sDefaultKeyDetector); } // Returns true if keyboard has been changed by this callback. diff --git a/java/src/com/android/inputmethod/keyboard/internal/NonDistinctMultitouchHelper.java b/java/src/com/android/inputmethod/keyboard/internal/NonDistinctMultitouchHelper.java index 111eb6db6..3a9aa81a3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/NonDistinctMultitouchHelper.java +++ b/java/src/com/android/inputmethod/keyboard/internal/NonDistinctMultitouchHelper.java @@ -27,16 +27,11 @@ import com.android.inputmethod.latin.utils.CoordinateUtils; public final class NonDistinctMultitouchHelper { private static final String TAG = NonDistinctMultitouchHelper.class.getSimpleName(); - // Use only main (id=0) pointer tracker. - private final PointerTracker mMainTracker; + private static final int MAIN_POINTER_TRACKER_ID = 0; private int mOldPointerCount = 1; private Key mOldKey; private int[] mLastCoords = CoordinateUtils.newInstance(); - public NonDistinctMultitouchHelper(final PointerTracker mainTracker) { - mMainTracker = mainTracker; - } - public void processMotionEvent(final MotionEvent me, final KeyDetector keyDetector) { final int pointerCount = me.getPointerCount(); final int oldPointerCount = mOldPointerCount; @@ -47,7 +42,9 @@ public final class NonDistinctMultitouchHelper { return; } - final PointerTracker mainTracker = mMainTracker; + // Use only main pointer tracker. + final PointerTracker mainTracker = PointerTracker.getPointerTracker( + MAIN_POINTER_TRACKER_ID); final int action = me.getActionMasked(); final int index = me.getActionIndex(); final long eventTime = me.getEventTime();