diff options
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/PointerTracker.java')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/PointerTracker.java | 60 |
1 files changed, 45 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 4f6af98ca..ea4d93a4a 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -22,6 +22,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.TextView; +import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.keyboard.internal.GestureStroke; import com.android.inputmethod.keyboard.internal.PointerTrackerQueue; import com.android.inputmethod.latin.InputPointers; @@ -39,8 +40,9 @@ public class PointerTracker { private static boolean DEBUG_MODE = LatinImeLogger.sDBG; // TODO: There should be an option to turn on/off the gesture input. - private static final boolean GESTURE_ON = true; - private static final int MIN_RECOGNITION_TIME = 100; // msec + private static boolean sIsGestureEnabled = true; + + private static final int MIN_GESTURE_RECOGNITION_TIME = 100; // msec public interface KeyEventHandler { /** @@ -116,9 +118,14 @@ public class PointerTracker { private static LatinKeyboardView.PointerTrackerParams sParams; private static int sTouchNoiseThresholdDistanceSquared; private static boolean sNeedsPhantomSuddenMoveEventHack; + private static boolean sConfigGestureInputEnabledByBuildConfig; private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>(); 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; @@ -135,6 +142,7 @@ public class PointerTracker { private boolean mIsPossibleGesture = false; private boolean mInGesture = false; + // TODO: Remove these variables private int mLastRecognitionPointSize = 0; private long mLastRecognitionTime = 0; @@ -177,15 +185,18 @@ public class PointerTracker { private final GestureStroke mGestureStroke; public static void init(boolean hasDistinctMultitouch, - boolean needsPhantomSuddenMoveEventHack) { + boolean needsPhantomSuddenMoveEventHack, + boolean gestureInputEnabledByBuildConfig) { if (hasDistinctMultitouch) { sPointerTrackerQueue = new PointerTrackerQueue(); } else { sPointerTrackerQueue = null; } sNeedsPhantomSuddenMoveEventHack = needsPhantomSuddenMoveEventHack; + sConfigGestureInputEnabledByBuildConfig = gestureInputEnabledByBuildConfig; setParameters(LatinKeyboardView.PointerTrackerParams.DEFAULT); + updateGestureInputEnabledState(null); } public static void setParameters(LatinKeyboardView.PointerTrackerParams params) { @@ -194,6 +205,16 @@ public class PointerTracker { params.mTouchNoiseThresholdDistance * params.mTouchNoiseThresholdDistance); } + private static void updateGestureInputEnabledState(Keyboard keyboard) { + if (!sConfigGestureInputEnabledByBuildConfig + || AccessibilityUtils.getInstance().isTouchExplorationEnabled() + || (keyboard != null && keyboard.mId.passwordInput())) { + sIsGestureEnabled = false; + } else { + sIsGestureEnabled = true; + } + } + public static PointerTracker getPointerTracker(final int id, KeyEventHandler handler) { final ArrayList<PointerTracker> trackers = sTrackers; @@ -222,6 +243,8 @@ public class PointerTracker { // Mark that keyboard layout has been changed. tracker.mKeyboardLayoutHasBeenChanged = true; } + final Keyboard keyboard = keyDetector.getKeyboard(); + updateGestureInputEnabledState(keyboard); } public static void dismissAllKeyPreviews() { @@ -234,9 +257,8 @@ public class PointerTracker { // TODO: To handle multi-touch gestures we may want to move this method to // {@link PointerTrackerQueue}. private static InputPointers getIncrementalBatchPoints() { - final InputPointers pointers = new InputPointers(); - // TODO: Add a default capacity parameter for the InputPointers' constructor. // TODO: Avoid creating a new instance here? + final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY); for (final PointerTracker tracker : sTrackers) { tracker.mGestureStroke.appendIncrementalBatchPoints(pointers); } @@ -246,9 +268,8 @@ public class PointerTracker { // TODO: To handle multi-touch gestures we may want to move this method to // {@link PointerTrackerQueue}. private static InputPointers getAllBatchPoints() { - // TODO: Add a default capacity parameter for the InputPointers' constructor. // TODO: Avoid creating a new instance here? - final InputPointers pointers = new InputPointers(); + final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY); for (final PointerTracker tracker : sTrackers) { tracker.mGestureStroke.appendAllBatchPoints(pointers); } @@ -257,7 +278,7 @@ public class PointerTracker { // TODO: To handle multi-touch gestures we may want to move this method to // {@link PointerTrackerQueue}. - public static void clearBatchInputPoints() { + public static void clearBatchInputPointsOfAllPointerTrackers() { for (final PointerTracker tracker : sTrackers) { tracker.mGestureStroke.reset(); } @@ -534,18 +555,26 @@ public class PointerTracker { Log.d(TAG, "onEndBatchInput: batchPoints=" + batchPoints.getPointerSize()); } mListener.onEndBatchInput(batchPoints); - mInGesture = false; - clearBatchInputPoints(); + clearBatchInputRecognitionStateOfThisPointerTracker(); + clearBatchInputPointsOfAllPointerTrackers(); + sWasInGesture = true; } private void abortBatchInput() { + clearBatchInputRecognitionStateOfThisPointerTracker(); + clearBatchInputPointsOfAllPointerTrackers(); + } + + private void clearBatchInputRecognitionStateOfThisPointerTracker() { mIsPossibleGesture = false; mInGesture = false; + mLastRecognitionPointSize = 0; + mLastRecognitionTime = 0; } private boolean updateBatchInputRecognitionState(long eventTime, int size) { if (size > mLastRecognitionPointSize - && eventTime > mLastRecognitionTime + MIN_RECOGNITION_TIME) { + && eventTime > mLastRecognitionTime + MIN_GESTURE_RECOGNITION_TIME) { mLastRecognitionPointSize = size; mLastRecognitionTime = eventTime; return true; @@ -613,7 +642,7 @@ public class PointerTracker { if (queue != null && queue.size() == 1) { mIsPossibleGesture = false; // A gesture should start only from the letter key. - if (GESTURE_ON && mIsAlphabetKeyboard && key != null + if (sIsGestureEnabled && mIsAlphabetKeyboard && key != null && Keyboard.isLetterCode(key.mCode)) { mIsPossibleGesture = true; mGestureStroke.addPoint(x, y, 0, false); @@ -656,10 +685,10 @@ public class PointerTracker { private void onGestureMoveEvent(PointerTracker tracker, int x, int y, long eventTime, boolean isHistorical, Key key) { final int gestureTime = (int)(eventTime - tracker.getDownTime()); - if (GESTURE_ON && mIsPossibleGesture) { + if (sIsGestureEnabled && mIsPossibleGesture) { final GestureStroke stroke = mGestureStroke; stroke.addPoint(x, y, gestureTime, isHistorical); - if (!mInGesture && stroke.isStartOfAGesture(gestureTime)) { + if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) { startBatchInput(); } } @@ -849,10 +878,10 @@ public class PointerTracker { } public void onShowMoreKeysPanel(int x, int y, KeyEventHandler handler) { + abortBatchInput(); onLongPressed(); onDownEvent(x, y, SystemClock.uptimeMillis(), handler); mIsShowingMoreKeysPanel = true; - abortBatchInput(); } public void onLongPressed() { @@ -931,6 +960,7 @@ public class PointerTracker { 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) { |