Distinguish key press in repeat key

Bug: 9859367
Change-Id: Iad643f9785b193e1918a8363de4fefc3b7558bdf
main
Tadashi G. Takaoka 2013-07-16 12:29:50 +09:00
parent 488659e154
commit 6455172a70
4 changed files with 24 additions and 14 deletions

View File

@ -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

View File

@ -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 */);

View File

@ -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);

View File

@ -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);