Use onCustomRequest to request haptick and audio feedback

Change-Id: I958f274d8cfebb1551cdf08f1bada50c20fb9ca0
This commit is contained in:
Tadashi G. Takaoka 2011-10-26 20:49:57 +09:00
parent d726d09389
commit d999ea4480
3 changed files with 16 additions and 11 deletions

View file

@ -75,7 +75,6 @@ public class Keyboard {
public static final int CODE_DELETE = -5; public static final int CODE_DELETE = -5;
public static final int CODE_SETTINGS = -6; public static final int CODE_SETTINGS = -6;
public static final int CODE_SHORTCUT = -7; public static final int CODE_SHORTCUT = -7;
public static final int CODE_HAPTIC_AND_AUDIO_FEEDBACK_ONLY = -98;
// Code value representing the code is not specified. // Code value representing the code is not specified.
public static final int CODE_UNSPECIFIED = -99; public static final int CODE_UNSPECIFIED = -99;

View file

@ -349,9 +349,11 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
// When shift key is double tapped, the first tap is correctly processed as usual tap. And // When shift key is double tapped, the first tap is correctly processed as usual tap. And
// the second tap is treated as this double tap event, so that we need not mark tracker // the second tap is treated as this double tap event, so that we need not mark tracker
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueue. // calling setAlreadyProcessed() nor remove the tracker from mPointerQueue.
final int primaryCode = ignore ? Keyboard.CODE_HAPTIC_AND_AUDIO_FEEDBACK_ONLY if (ignore) {
: Keyboard.CODE_CAPSLOCK; mKeyboardActionListener.onCustomRequest(LatinIME.CODE_HAPTIC_AND_AUDIO_FEEDBACK);
mKeyboardActionListener.onCodeInput(primaryCode, null, 0, 0); } else {
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
}
} }
// This default implementation returns a more keys panel. // This default implementation returns a more keys panel.

View file

@ -1227,6 +1227,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Virtual codes representing custom requests. These are used in onCustomRequest() below. // Virtual codes representing custom requests. These are used in onCustomRequest() below.
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1; public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
public static final int CODE_HAPTIC_AND_AUDIO_FEEDBACK = 2;
@Override @Override
public boolean onCustomRequest(int requestCode) { public boolean onCustomRequest(int requestCode) {
@ -1238,6 +1239,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
return true; return true;
} }
return false; return false;
case CODE_HAPTIC_AND_AUDIO_FEEDBACK:
hapticAndAudioFeedback(Keyboard.CODE_UNSPECIFIED);
return true;
} }
return false; return false;
} }
@ -1293,11 +1297,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
break; break;
case Keyboard.CODE_CAPSLOCK: case Keyboard.CODE_CAPSLOCK:
switcher.toggleCapsLock(); switcher.toggleCapsLock();
//$FALL-THROUGH$ hapticAndAudioFeedback(primaryCode);
case Keyboard.CODE_HAPTIC_AND_AUDIO_FEEDBACK_ONLY:
// Dummy code for haptic and audio feedbacks.
vibrate();
playKeyClick(primaryCode);
break; break;
case Keyboard.CODE_SHORTCUT: case Keyboard.CODE_SHORTCUT:
mSubtypeSwitcher.switchToShortcutIME(); mSubtypeSwitcher.switchToShortcutIME();
@ -2129,12 +2129,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
loadSettings(); loadSettings();
} }
private void hapticAndAudioFeedback(int primaryCode) {
vibrate();
playKeyClick(primaryCode);
}
@Override @Override
public void onPress(int primaryCode, boolean withSliding) { public void onPress(int primaryCode, boolean withSliding) {
final KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isVibrateAndSoundFeedbackRequired()) { if (switcher.isVibrateAndSoundFeedbackRequired()) {
vibrate(); hapticAndAudioFeedback(primaryCode);
playKeyClick(primaryCode);
} }
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch(); final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) { if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) {