Disable successive modifier key while sliding input

When user starts sliding key input, sliding through successive
modifier key will be ignored.

Bug: 4181843
Depends: I082885bd2376ae26bdfc378c14add2b5d6be1d4e

Change-Id: Ibe890b9cc1183dbe9f68a421650fcd97e7ff221c
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 7468578..1c918b9 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -87,6 +87,9 @@
     // true if sliding key is allowed.
     private boolean mIsAllowedSlidingKeyInput;
 
+    // ignore modifier key if true
+    private boolean mIgnoreModifierKey;
+
     // pressed key
     private int mPreviousKey = NOT_A_KEY;
 
@@ -139,8 +142,12 @@
 
     // Returns true if keyboard has been changed by this callback.
     private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) {
+        final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
         if (DEBUG_LISTENER)
-            Log.d(TAG, "onPress    : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding);
+            Log.d(TAG, "onPress    : " + keyCodePrintable(key.mCode) + " sliding=" + withSliding
+                    + " ignoreModifier=" + ignoreModifierKey);
+        if (ignoreModifierKey)
+            return false;
         if (key.mEnabled) {
             mListener.onPress(key.mCode, withSliding);
             final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
@@ -153,9 +160,13 @@
     // Note that we need primaryCode argument because the keyboard may in shifted state and the
     // primaryCode is different from {@link Key#mCode}.
     private void callListenerOnCodeInput(Key key, int primaryCode, int[] keyCodes, int x, int y) {
+        final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
         if (DEBUG_LISTENER)
             Log.d(TAG, "onCodeInput: " + keyCodePrintable(primaryCode)
-                    + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y);
+                    + " codes="+ Arrays.toString(keyCodes) + " x=" + x + " y=" + y
+                    + " ignoreModifier=" + ignoreModifierKey);
+        if (ignoreModifierKey)
+            return;
         if (key.mEnabled)
             mListener.onCodeInput(primaryCode, keyCodes, x, y);
     }
@@ -170,8 +181,12 @@
     // Note that we need primaryCode argument because the keyboard may in shifted state and the
     // primaryCode is different from {@link Key#mCode}.
     private void callListenerOnRelease(Key key, int primaryCode, boolean withSliding) {
+        final boolean ignoreModifierKey = mIgnoreModifierKey && isModifierCode(key.mCode);
         if (DEBUG_LISTENER)
-            Log.d(TAG, "onRelease  : " + keyCodePrintable(primaryCode) + " sliding=" + withSliding);
+            Log.d(TAG, "onRelease  : " + keyCodePrintable(primaryCode) + " sliding="
+                    + withSliding + " ignoreModifier=" + ignoreModifierKey);
+        if (ignoreModifierKey)
+            return;
         if (key.mEnabled)
             mListener.onRelease(primaryCode, withSliding);
     }
@@ -329,17 +344,18 @@
         mKeyAlreadyProcessed = false;
         mIsRepeatableKey = false;
         mIsInSlidingKeyInput = false;
-        if (isValidKeyIndex(keyIndex)) {
+        mIgnoreModifierKey = false;
+        final Key key = getKey(keyIndex);
+        if (key != null) {
             // This onPress call may have changed keyboard layout. Those cases are detected at
             // {@link #setKeyboard}. In those cases, we should update keyIndex according to the new
             // keyboard layout.
-            if (callListenerOnPressAndCheckKeyboardLayoutChange(mKeys[keyIndex], false))
+            if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false))
                 keyIndex = mKeyState.onDownKey(x, y, eventTime);
-        }
-        if (isValidKeyIndex(keyIndex)) {
+
             // Accessibility disables key repeat because users may need to pause on a key to hear
             // its spoken description.
-            if (mKeys[keyIndex].mRepeatable && !mIsAccessibilityEnabled) {
+            if (key.mRepeatable && !mIsAccessibilityEnabled) {
                 repeatKey(keyIndex);
                 mHandler.startKeyRepeatTimer(mDelayBeforeKeyRepeatStart, keyIndex, this);
                 mIsRepeatableKey = true;
@@ -349,6 +365,12 @@
         showKeyPreviewAndUpdateKeyGraphics(keyIndex);
     }
 
+    private void startSlidingKeyInput(Key key) {
+        if (!mIsInSlidingKeyInput)
+            mIgnoreModifierKey = isModifierCode(key.mCode);
+        mIsInSlidingKeyInput = true;
+    }
+
     public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
         if (ENABLE_ASSERTION) checkAssertion(queue);
         if (DEBUG_MOVE_EVENT)
@@ -376,8 +398,8 @@
                 // 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.
-                mIsInSlidingKeyInput = true;
                 callListenerOnRelease(oldKey, oldKey.mCode, true);
+                startSlidingKeyInput(oldKey);
                 mHandler.cancelLongPressTimers();
                 if (mIsAllowedSlidingKeyInput) {
                     // This onPress call may have changed keyboard layout. Those cases are detected
@@ -411,8 +433,8 @@
             if (oldKey != null && !isMinorMoveBounce(x, y, keyIndex)) {
                 // The pointer has been slid out from the previous key, we must call onRelease() to
                 // notify that the previous key has been released.
-                mIsInSlidingKeyInput = true;
                 callListenerOnRelease(oldKey, oldKey.mCode, true);
+                startSlidingKeyInput(oldKey);
                 mHandler.cancelLongPressTimers();
                 if (mIsAllowedSlidingKeyInput) {
                     keyState.onMoveToNewKey(keyIndex, x ,y);
@@ -423,7 +445,7 @@
                 }
             }
         }
-        showKeyPreviewAndUpdateKeyGraphics(mKeyState.getKeyIndex());
+        showKeyPreviewAndUpdateKeyGraphics(keyState.getKeyIndex());
     }
 
     public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {