From 6455172a707a1137eb15db8073774982db9dd1fa Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 16 Jul 2013 12:29:50 +0900 Subject: [PATCH] Distinguish key press in repeat key Bug: 9859367 Change-Id: Iad643f9785b193e1918a8363de4fefc3b7558bdf --- .../keyboard/KeyboardActionListener.java | 5 ++-- .../keyboard/MainKeyboardView.java | 4 +-- .../inputmethod/keyboard/PointerTracker.java | 3 ++- .../android/inputmethod/latin/LatinIME.java | 26 ++++++++++++------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java index 00ea20d2c..b26698665 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java @@ -26,9 +26,10 @@ public interface KeyboardActionListener { * * @param primaryCode the unicode of the key being pressed. If the touch is not on a valid key, * the value will be zero. + * @param isRepeatKey true if pressing has occurred while key repeat input. * @param isSinglePointer true if pressing has occurred while no other key is being pressed. */ - public void onPressKey(int primaryCode, boolean isSinglePointer); + public void onPressKey(int primaryCode, boolean isRepeatKey, boolean isSinglePointer); /** * Called when the user releases a key. This is sent after the {@link #onCodeInput} is called. @@ -102,7 +103,7 @@ public interface KeyboardActionListener { public static class Adapter implements KeyboardActionListener { @Override - public void onPressKey(int primaryCode, boolean isSinglePointer) {} + public void onPressKey(int primaryCode, boolean isRepeatKey, boolean isSinglePointer) {} @Override public void onReleaseKey(int primaryCode, boolean withSliding) {} @Override diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index f85e60449..8cd5b1a63 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -246,7 +246,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack startTypingStateTimer(currentKey); final KeyboardActionListener listener = keyboardView.getKeyboardActionListener(); - listener.onPressKey(code, true /* isSinglePointer */); + listener.onPressKey(code, true /* isRepeatKey */, true /* isSinglePointer */); listener.onCodeInput(code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); } @@ -987,7 +987,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack if (key.hasNoPanelAutoMoreKey()) { final int moreKeyCode = key.mMoreKeys[0].mCode; tracker.onLongPressed(); - listener.onPressKey(moreKeyCode, true /* isSinglePointer */); + listener.onPressKey(moreKeyCode, false /* isRepeatKey */, true /* isSinglePointer */); listener.onCodeInput(moreKeyCode, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE); listener.onReleaseKey(moreKeyCode, false /* withSliding */); diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 53207597a..0f4dbd5e0 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -456,7 +456,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element { return false; } if (key.isEnabled()) { - mListener.onPressKey(key.mCode, getActivePointerTrackerCount() == 1); + mListener.onPressKey(key.mCode, false /* isRepeatKey */, + getActivePointerTrackerCount() == 1); final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged; mKeyboardLayoutHasBeenChanged = false; mTimerProxy.startTypingStateTimer(key); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8f5e57182..7890dbb3f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2677,22 +2677,30 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } + private void hapticAndAudioFeedback(final int code, final boolean isRepeatKey) { + final MainKeyboardView keyboardView = mKeyboardSwitcher.getMainKeyboardView(); + if (keyboardView != null && keyboardView.isInSlidingKeyInput()) { + // No need to feedback while sliding input. + return; + } + if (isRepeatKey && code == Constants.CODE_DELETE && !mConnection.canDeleteCharacters()) { + // No need to feedback when repeating delete key will have no effect. + return; + } + AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, keyboardView); + } + // Callback of the {@link KeyboardActionListener}. This is called when a key is depressed; // release matching call is {@link #onReleaseKey(int,boolean)} below. @Override - public void onPressKey(final int primaryCode, final boolean isSinglePointer) { + public void onPressKey(final int primaryCode, final boolean isRepeatKey, + final boolean isSinglePointer) { mKeyboardSwitcher.onPressKey(primaryCode, isSinglePointer); - final MainKeyboardView mKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); - final boolean noFeedback = (mKeyboardView != null && mKeyboardView.isInSlidingKeyInput()) - || (primaryCode == Constants.CODE_DELETE && !mConnection.canDeleteCharacters()); - if (!noFeedback) { - AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback( - primaryCode, mKeyboardView); - } + hapticAndAudioFeedback(primaryCode, isRepeatKey); } // Callback of the {@link KeyboardActionListener}. This is called when a key is released; - // press matching call is {@link #onPressKey(int,boolean)} above. + // press matching call is {@link #onPressKey(int,boolean,boolean)} above. @Override public void onReleaseKey(final int primaryCode, final boolean withSliding) { mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);