Suppress haptic feedback while sliding key input

Bug: 3298222
Change-Id: I9507a98cc833fc6403cf9abf23457748a2bf89de
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 0fb9014..76cb8ff 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -525,6 +525,10 @@
         return mAutoModeSwitchState == AUTO_MODE_SWITCH_STATE_MOMENTARY;
     }
 
+    public boolean isVibrateAndSoundFeedbackRequired() {
+        return mInputView == null || !mInputView.isInSlidingKeyInput();
+    }
+
     private int getPointerCount() {
         return mInputView == null ? 0 : mInputView.getPointerCount();
     }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 47d4d1a..11b7ec2 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -1308,6 +1308,14 @@
         return pointers.get(id);
     }
 
+    public boolean isInSlidingKeyInput() {
+        if (mMiniKeyboard != null) {
+            return mMiniKeyboard.isInSlidingKeyInput();
+        } else {
+            return mPointerQueue.isInSlidingKeyInput();
+        }
+    }
+
     public int getPointerCount() {
         return mOldPointerCount;
     }
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 15eab8f..e4312a8 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -69,6 +69,9 @@
     // true if this pointer is repeatable key
     private boolean mIsRepeatableKey;
 
+    // true if this pointer is in sliding key input
+    private boolean mIsInSlidingKeyInput;
+
     // true if sliding key is allowed.
     private boolean mIsAllowedSlidingKeyInput;
 
@@ -168,6 +171,10 @@
         mKeyState.onSetKeyboard();
     }
 
+    public boolean isInSlidingKeyInput() {
+        return mIsInSlidingKeyInput;
+    }
+
     private boolean isValidKeyIndex(int keyIndex) {
         return keyIndex >= 0 && keyIndex < mKeys.length;
     }
@@ -258,6 +265,7 @@
                 || mKeyDetector instanceof MiniKeyboardKeyDetector;
         mKeyAlreadyProcessed = false;
         mIsRepeatableKey = false;
+        mIsInSlidingKeyInput = false;
         checkMultiTap(eventTime, keyIndex);
         if (isValidKeyIndex(keyIndex)) {
             callListenerOnPress(mKeys[keyIndex].mCodes[0]);
@@ -295,6 +303,7 @@
                 // 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.mCodes[0]);
                 mHandler.cancelLongPressTimers();
                 if (mIsAllowedSlidingKeyInput) {
@@ -312,6 +321,7 @@
             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.mCodes[0]);
                 mHandler.cancelLongPressTimers();
                 if (mIsAllowedSlidingKeyInput) {
@@ -332,9 +342,10 @@
         int y = pointY;
         if (DEBUG_EVENT)
             printTouchEvent("onUpEvent  :", x, y, eventTime);
-        showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
         mHandler.cancelKeyTimers();
         mHandler.cancelPopupPreview();
+        showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
+        mIsInSlidingKeyInput = false;
         if (mKeyAlreadyProcessed)
             return;
         final PointerTrackerKeyState keyState = mKeyState;
@@ -359,6 +370,7 @@
         mHandler.cancelKeyTimers();
         mHandler.cancelPopupPreview();
         showKeyPreviewAndUpdateKeyGraphics(NOT_A_KEY);
+        mIsInSlidingKeyInput = false;
         int keyIndex = mKeyState.getKeyIndex();
         if (isValidKeyIndex(keyIndex))
            mProxy.invalidateKey(mKeys[keyIndex]);
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java
index e559b4c..236c9d5 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTrackerQueue.java
@@ -65,6 +65,14 @@
         mQueue.remove(tracker);
     }
 
+    public boolean isInSlidingKeyInput() {
+        for (final PointerTracker tracker : mQueue) {
+            if (tracker.isInSlidingKeyInput())
+                return true;
+        }
+        return false;
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder("[");
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3a3a000..45785ab 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1887,8 +1887,10 @@
 
     @Override
     public void onPress(int primaryCode) {
-        vibrate();
-        playKeyClick(primaryCode);
+        if (mKeyboardSwitcher.isVibrateAndSoundFeedbackRequired()) {
+            vibrate();
+            playKeyClick(primaryCode);
+        }
         KeyboardSwitcher switcher = mKeyboardSwitcher;
         final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
         if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {