diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 184011ffe..7d565a64f 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -34,7 +34,7 @@ import com.android.inputmethod.research.ResearchLogger; import java.util.ArrayList; -public class PointerTracker implements PointerTrackerQueue.ElementActions { +public class PointerTracker implements PointerTrackerQueue.Element { private static final String TAG = PointerTracker.class.getSimpleName(); private static final boolean DEBUG_EVENT = false; private static final boolean DEBUG_MOVE_EVENT = false; @@ -43,6 +43,9 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { /** True if {@link PointerTracker}s should handle gesture events. */ private static boolean sShouldHandleGesture = false; + private static boolean sMainDictionaryAvailable = false; + private static boolean sGestureHandlingEnabledByInputField = false; + private static boolean sGestureHandlingEnabledByUser = false; private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec @@ -126,10 +129,6 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { private static final InputPointers sAggregratedPointers = new InputPointers( GestureStroke.DEFAULT_CAPACITY); private static PointerTrackerQueue sPointerTrackerQueue; - // HACK: Change gesture detection criteria depending on this variable. - // TODO: Find more comprehensive ways to detect a gesture start. - // True when the previous user input was a gesture input, not a typing input. - private static boolean sWasInGesture; public final int mPointerId; @@ -198,7 +197,6 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; setParameters(MainKeyboardView.PointerTrackerParams.DEFAULT); - updateGestureHandlingMode(null, false /* shouldHandleGesture */); } public static void setParameters(MainKeyboardView.PointerTrackerParams params) { @@ -207,14 +205,22 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); } - private static void updateGestureHandlingMode(Keyboard keyboard, boolean shouldHandleGesture) { - if (!shouldHandleGesture - || AccessibilityUtils.getInstance().isTouchExplorationEnabled() - || (keyboard != null && keyboard.mId.passwordInput())) { - sShouldHandleGesture = false; - } else { - sShouldHandleGesture = true; - } + private static void updateGestureHandlingMode() { + sShouldHandleGesture = sMainDictionaryAvailable + && sGestureHandlingEnabledByInputField + && sGestureHandlingEnabledByUser + && !AccessibilityUtils.getInstance().isTouchExplorationEnabled(); + } + + // Note that this method is called from a non-UI thread. + public static void setMainDictionaryAvailability(boolean mainDictionaryAvailable) { + sMainDictionaryAvailable = mainDictionaryAvailable; + updateGestureHandlingMode(); + } + + public static void setGestureHandlingEnabledByUser(boolean gestureHandlingEnabledByUser) { + sGestureHandlingEnabledByUser = gestureHandlingEnabledByUser; + updateGestureHandlingMode(); } public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { @@ -241,7 +247,7 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { } } - public static void setKeyDetector(KeyDetector keyDetector, boolean shouldHandleGesture) { + public static void setKeyDetector(KeyDetector keyDetector) { final int trackersSize = sTrackers.size(); for (int i = 0; i < trackersSize; ++i) { final PointerTracker tracker = sTrackers.get(i); @@ -250,7 +256,8 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { tracker.mKeyboardLayoutHasBeenChanged = true; } final Keyboard keyboard = keyDetector.getKeyboard(); - updateGestureHandlingMode(keyboard, shouldHandleGesture); + sGestureHandlingEnabledByInputField = !keyboard.mId.passwordInput(); + updateGestureHandlingMode(); } public static void dismissAllKeyPreviews() { @@ -401,8 +408,7 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { mKeyDetector = keyDetector; mKeyboard = keyDetector.getKeyboard(); mIsAlphabetKeyboard = mKeyboard.mId.isAlphabetKeyboard(); - mGestureStroke.setGestureSampleLength( - mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight); + mGestureStroke.setGestureSampleLength(mKeyboard.mMostCommonKeyWidth); final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY); if (newKey != mCurrentKey) { if (mDrawingProxy != null) { @@ -514,7 +520,7 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { public void drawGestureTrail(Canvas canvas, Paint paint) { if (mInGesture) { - mGestureStroke.drawGestureTrail(canvas, paint, mLastX, mLastY); + mGestureStroke.drawGestureTrail(canvas, paint); } } @@ -574,7 +580,6 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { mListener.onEndBatchInput(batchPoints); clearBatchInputRecognitionStateOfThisPointerTracker(); clearBatchInputPointsOfAllPointerTrackers(); - sWasInGesture = true; } private void abortBatchInput() { @@ -707,7 +712,7 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { if (sShouldHandleGesture && mIsPossibleGesture) { final GestureStroke stroke = mGestureStroke; stroke.addPoint(x, y, gestureTime, isHistorical); - if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) { + if (!mInGesture && stroke.isStartOfAGesture()) { startBatchInput(); } } @@ -990,7 +995,6 @@ public class PointerTracker implements PointerTrackerQueue.ElementActions { int code = key.mCode; callListenerOnCodeInput(key, code, x, y); callListenerOnRelease(key, code, false); - sWasInGesture = false; } private void printTouchEvent(String title, int x, int y, long eventTime) { |