Rename KeyboardActionListener methods

* Rename KeyboardActionListener.onPress to onPressKey
* Rename KeyboardActionListener.onRelease to onReleaseKey
* Merge KeyboardSwicther.onPressShift, onPressSymbol, and onPressOtherKey to onPressKey.
* Merge KeyboardSwitcher.onReleaseShift and onReleaseSymbol to onReleaseKey.
* Merge KeyboardState.onPressShift, onPressSymbol, and onPressOtherKey to onPressKey.
* Merge KeyboardState.onReleaseShift and onReleaseSymbol to onReleaseKey.

Change-Id: Icf28fd18e238c5e534c292893e4ab5b6b98e72f8
main
Tadashi G. Takaoka 2012-01-17 17:08:26 +09:00
parent c9fade6b87
commit 2a88440419
12 changed files with 230 additions and 219 deletions

View File

@ -434,9 +434,10 @@ public class Keyboard {
case CODE_SHORTCUT: return "shortcut";
case CODE_UNSPECIFIED: return "unspec";
default:
if (code < 0) Log.w(TAG, "Unknow negative key code=" + code);
if (code < 0x100) return String.format("\\u%02x", code);
return String.format("\\u04x", code);
if (code <= 0) Log.w(TAG, "Unknown non-positive key code=" + code);
if (code < CODE_SPACE) return String.format("'\\u%02x'", code);
if (code < 0x100) return String.format("'%c'", code);
return String.format("'\\u%04x'", code);
}
}

View File

@ -24,10 +24,8 @@ 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 withSliding true if pressing has occurred because the user slid finger from other key
* to this key without releasing the finger.
*/
public void onPress(int primaryCode, boolean withSliding);
public void onPressKey(int primaryCode);
/**
* Called when the user releases a key. This is sent after the {@link #onCodeInput} is called.
@ -37,7 +35,7 @@ public interface KeyboardActionListener {
* @param withSliding true if releasing has occurred because the user slid finger from the key
* to other key without releasing the finger.
*/
public void onRelease(int primaryCode, boolean withSliding);
public void onReleaseKey(int primaryCode, boolean withSliding);
/**
* Send a key code to the listener.
@ -79,9 +77,9 @@ public interface KeyboardActionListener {
public static class Adapter implements KeyboardActionListener {
@Override
public void onPress(int primaryCode, boolean withSliding) {}
public void onPressKey(int primaryCode) {}
@Override
public void onRelease(int primaryCode, boolean withSliding) {}
public void onReleaseKey(int primaryCode, boolean withSliding) {}
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {}
@Override

View File

@ -270,24 +270,12 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
mState.onUpdateShiftState(mInputMethodService.getCurrentAutoCapsState());
}
public void onPressShift(boolean withSliding) {
mState.onPressShift(withSliding);
public void onPressKey(int code) {
mState.onPressKey(code);
}
public void onReleaseShift(boolean withSliding) {
mState.onReleaseShift(withSliding);
}
public void onPressSymbol() {
mState.onPressSymbol();
}
public void onReleaseSymbol() {
mState.onReleaseSymbol();
}
public void onOtherKeyPressed() {
mState.onOtherKeyPressed();
public void onReleaseKey(int code, boolean withSliding) {
mState.onReleaseKey(code, withSliding);
}
public void onCancelInput() {

View File

@ -417,9 +417,9 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
// 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.
if (ignore) {
mKeyboardActionListener.onCustomRequest(LatinIME.CODE_HAPTIC_AND_AUDIO_FEEDBACK);
invokeCustomRequest(LatinIME.CODE_HAPTIC_AND_AUDIO_FEEDBACK);
} else {
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
invokeCodeInput(Keyboard.CODE_CAPSLOCK);
}
}
@ -479,17 +479,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
private boolean invokeCustomRequest(int code) {
return getKeyboardActionListener().onCustomRequest(code);
return mKeyboardActionListener.onCustomRequest(code);
}
private void invokeCodeInput(int primaryCode) {
getKeyboardActionListener().onCodeInput(primaryCode, null,
mKeyboardActionListener.onCodeInput(primaryCode, null,
KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
}
private void invokeReleaseKey(int primaryCode) {
getKeyboardActionListener().onRelease(primaryCode, false);
mKeyboardActionListener.onReleaseKey(primaryCode, false);
}
private boolean openMoreKeysPanel(Key parentKey, PointerTracker tracker) {
@ -514,7 +514,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
: parentKey.mX + parentKey.mWidth / 2;
final int pointY = parentKey.mY - keyboard.mVerticalGap;
moreKeysPanel.showMoreKeysPanel(
this, this, pointX, pointY, mMoreKeysWindow, getKeyboardActionListener());
this, this, pointX, pointY, mMoreKeysWindow, mKeyboardActionListener);
final int translatedX = moreKeysPanel.translateX(tracker.getLastX());
final int translatedY = moreKeysPanel.translateY(tracker.getLastY());
tracker.onShowMoreKeysPanel(translatedX, translatedY, moreKeysPanel);

View File

@ -61,12 +61,13 @@ public class MiniKeyboardView extends KeyboardView implements MoreKeysPanel {
}
@Override
public void onPress(int primaryCode, boolean withSliding) {
mListener.onPress(primaryCode, withSliding);
public void onPressKey(int primaryCode) {
mListener.onPressKey(primaryCode);
}
@Override
public void onRelease(int primaryCode, boolean withSliding) {
mListener.onRelease(primaryCode, withSliding);
public void onReleaseKey(int primaryCode, boolean withSliding) {
mListener.onReleaseKey(primaryCode, withSliding);
}
};

View File

@ -237,18 +237,18 @@ public class PointerTracker {
}
// Returns true if keyboard has been changed by this callback.
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key, boolean withSliding) {
private boolean callListenerOnPressAndCheckKeyboardLayoutChange(Key key) {
final boolean ignoreModifierKey = mIgnoreModifierKey && key.isModifier();
if (DEBUG_LISTENER) {
Log.d(TAG, "onPress : " + KeyDetector.printableCode(key)
+ " sliding=" + withSliding + " ignoreModifier=" + ignoreModifierKey
+ " ignoreModifier=" + ignoreModifierKey
+ " enabled=" + key.isEnabled());
}
if (ignoreModifierKey) {
return false;
}
if (key.isEnabled()) {
mListener.onPress(key.mCode, withSliding);
mListener.onPressKey(key.mCode);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
mKeyboardLayoutHasBeenChanged = false;
return keyboardLayoutHasBeenChanged;
@ -296,7 +296,7 @@ public class PointerTracker {
return;
}
if (key.isEnabled()) {
mListener.onRelease(primaryCode, withSliding);
mListener.onReleaseKey(primaryCode, withSliding);
}
}
@ -495,7 +495,7 @@ public class PointerTracker {
// This onPress call may have changed keyboard layout. Those cases are detected at
// {@link #setKeyboard}. In those cases, we should update key according to the new
// keyboard layout.
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, false)) {
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
key = onDownKey(x, y, eventTime);
}
@ -529,7 +529,7 @@ public class PointerTracker {
// This onPress call may have changed keyboard layout. Those cases are detected at
// {@link #setKeyboard}. In those cases, we should update key according to the
// new keyboard layout.
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, true)) {
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
key = onMoveKey(x, y);
}
onMoveToNewKey(key, x, y);
@ -548,7 +548,7 @@ public class PointerTracker {
// This onPress call may have changed keyboard layout. Those cases are detected
// at {@link #setKeyboard}. In those cases, we should update key according
// to the new keyboard layout.
if (callListenerOnPressAndCheckKeyboardLayoutChange(key, true)) {
if (callListenerOnPressAndCheckKeyboardLayoutChange(key)) {
key = onMoveKey(x, y);
}
onMoveToNewKey(key, x, y);

View File

@ -21,15 +21,13 @@ import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
// TODO: Add unit tests
/**
* Keyboard state machine.
*
* This class contains all keyboard state transition logic.
*
* The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()},
* {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()},
* {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()},
* {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)},
* {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)},
* {@link #onUpdateShiftState(boolean)}, and {@link #onToggleCapsLock()}.
*
@ -37,7 +35,8 @@ import com.android.inputmethod.keyboard.Keyboard;
*/
public class KeyboardState {
private static final String TAG = KeyboardState.class.getSimpleName();
private static final boolean DEBUG_STATE = false;
private static final boolean DEBUG_EVENT = false;
private static final boolean DEBUG_ACTION = false;
public interface SwitchActions {
public void setAlphabetKeyboard();
@ -97,7 +96,7 @@ public class KeyboardState {
}
public void onLoadKeyboard(String layoutSwitchBackSymbols, boolean hasDistinctMultitouch) {
if (DEBUG_STATE) {
if (DEBUG_EVENT) {
Log.d(TAG, "onLoadKeyboard");
}
mLayoutSwitchBackSymbols = layoutSwitchBackSymbols;
@ -122,7 +121,7 @@ public class KeyboardState {
state.mIsShifted = mIsSymbolShifted;
}
state.mIsValid = true;
if (DEBUG_STATE) {
if (DEBUG_EVENT) {
Log.d(TAG, "onSaveKeyboardState: alphabet=" + state.mIsAlphabetMode
+ " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
}
@ -130,7 +129,7 @@ public class KeyboardState {
private void onRestoreKeyboardState() {
final SavedKeyboardState state = mSavedKeyboardState;
if (DEBUG_STATE) {
if (DEBUG_EVENT) {
Log.d(TAG, "onRestoreKeyboardState: valid=" + state.mIsValid
+ " alphabet=" + state.mIsAlphabetMode
+ " shiftLocked=" + state.mIsShiftLocked + " shift=" + state.mIsShifted);
@ -162,7 +161,7 @@ public class KeyboardState {
}
private void setShifted(int shiftMode) {
if (DEBUG_STATE) {
if (DEBUG_ACTION) {
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode));
}
if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) {
@ -182,7 +181,7 @@ public class KeyboardState {
}
private void setShiftLocked(boolean shiftLocked) {
if (DEBUG_STATE) {
if (DEBUG_ACTION) {
Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked);
}
mKeyboardShiftState.setShiftLocked(shiftLocked);
@ -206,7 +205,7 @@ public class KeyboardState {
}
private void setAlphabetKeyboard() {
if (DEBUG_STATE) {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetKeyboard");
}
mSwitchActions.setAlphabetKeyboard();
@ -220,7 +219,7 @@ public class KeyboardState {
// TODO: Make this method private
public void setSymbolsKeyboard() {
if (DEBUG_STATE) {
if (DEBUG_ACTION) {
Log.d(TAG, "setSymbolsKeyboard");
}
mPrevMainKeyboardWasShiftLocked = mKeyboardShiftState.isShiftLocked();
@ -231,7 +230,7 @@ public class KeyboardState {
}
private void setSymbolsShiftedKeyboard() {
if (DEBUG_STATE) {
if (DEBUG_ACTION) {
Log.d(TAG, "setSymbolsShiftedKeyboard");
}
mSwitchActions.setSymbolsShiftedKeyboard();
@ -240,19 +239,40 @@ public class KeyboardState {
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
}
public void onPressSymbol() {
if (DEBUG_STATE) {
Log.d(TAG, "onPressSymbol: " + this);
public void onPressKey(int code) {
if (DEBUG_EVENT) {
Log.d(TAG, "onPressKey: code=" + Keyboard.printableCode(code) + " " + this);
}
if (code == Keyboard.CODE_SHIFT) {
onPressShift();
} else if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
onPressSymbol();
} else {
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
}
}
public void onReleaseKey(int code, boolean withSliding) {
if (DEBUG_EVENT) {
Log.d(TAG, "onReleaseKey: code=" + Keyboard.printableCode(code)
+ " sliding=" + withSliding + " " + this);
}
if (code == Keyboard.CODE_SHIFT) {
onReleaseShift(withSliding);
} else if (code == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
// TODO: Make use of withSliding instead of relying on mSwitchState.
onReleaseSymbol();
}
}
private void onPressSymbol() {
toggleAlphabetAndSymbols();
mSymbolKeyState.onPress();
mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL;
}
public void onReleaseSymbol() {
if (DEBUG_STATE) {
Log.d(TAG, "onReleaseSymbol: " + this);
}
private void onReleaseSymbol() {
// Snap back to the previous keyboard mode if the user chords the mode change key and
// another key, then releases the mode change key.
if (mSwitchState == SWITCH_STATE_CHORDING_ALPHA) {
@ -261,16 +281,8 @@ public class KeyboardState {
mSymbolKeyState.onRelease();
}
public void onOtherKeyPressed() {
if (DEBUG_STATE) {
Log.d(TAG, "onOtherKeyPressed: " + this);
}
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
}
public void onUpdateShiftState(boolean autoCaps) {
if (DEBUG_STATE) {
if (DEBUG_EVENT) {
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
}
onUpdateShiftStateInternal(autoCaps);
@ -294,10 +306,7 @@ public class KeyboardState {
}
}
public void onPressShift(boolean withSliding) {
if (DEBUG_STATE) {
Log.d(TAG, "onPressShift: sliding=" + withSliding + " " + this);
}
private void onPressShift() {
if (mIsAlphabetMode) {
if (mKeyboardShiftState.isShiftLocked()) {
// Shift key is pressed while caps lock state, we will treat this state as shifted
@ -326,10 +335,7 @@ public class KeyboardState {
}
}
public void onReleaseShift(boolean withSliding) {
if (DEBUG_STATE) {
Log.d(TAG, "onReleaseShift: sliding=" + withSliding + " " + this);
}
private void onReleaseShift(boolean withSliding) {
if (mIsAlphabetMode) {
final boolean isShiftLocked = mKeyboardShiftState.isShiftLocked();
if (mShiftKeyState.isMomentary()) {
@ -363,8 +369,8 @@ public class KeyboardState {
}
public void onCancelInput(boolean isSinglePointer) {
if (DEBUG_STATE) {
Log.d(TAG, "onCancelInput: isSinglePointer=" + isSinglePointer + " " + this);
if (DEBUG_EVENT) {
Log.d(TAG, "onCancelInput: single=" + isSinglePointer + " " + this);
}
// Snap back to the previous keyboard mode if the user cancels sliding input.
if (isSinglePointer) {
@ -392,8 +398,9 @@ public class KeyboardState {
}
public void onCodeInput(int code, boolean isSinglePointer, boolean autoCaps) {
if (DEBUG_STATE) {
Log.d(TAG, "onCodeInput: code=" + code + " isSinglePointer=" + isSinglePointer
if (DEBUG_EVENT) {
Log.d(TAG, "onCodeInput: code=" + Keyboard.printableCode(code)
+ " single=" + isSinglePointer
+ " autoCaps=" + autoCaps + " " + this);
}
switch (mSwitchState) {
@ -465,7 +472,7 @@ public class KeyboardState {
}
public void onToggleCapsLock() {
if (DEBUG_STATE) {
if (DEBUG_EVENT) {
Log.d(TAG, "onToggleCapsLock: " + this);
}
if (mIsAlphabetMode) {

View File

@ -1239,7 +1239,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
mLastKeyTime = when;
final KeyboardSwitcher switcher = mKeyboardSwitcher;
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
// The space state depends only on the last character pressed and its own previous
// state. Here, we revert the space state to neutral if the key is actually modifying
// the input contents (any non-shift key), which is what we should do for
@ -1262,7 +1261,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
break;
case Keyboard.CODE_SHIFT:
case Keyboard.CODE_SWITCH_ALPHA_SYMBOL:
// Shift and symbol key is handled in onPress() and onRelease().
// Shift and symbol key is handled in onPressKey() and onReleaseKey().
break;
case Keyboard.CODE_SETTINGS:
onSettingsKeyPressed();
@ -2258,28 +2257,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
@Override
public void onPress(int primaryCode, boolean withSliding) {
public void onPressKey(int primaryCode) {
final KeyboardSwitcher switcher = mKeyboardSwitcher;
if (switcher.isVibrateAndSoundFeedbackRequired()) {
hapticAndAudioFeedback(primaryCode);
}
if (primaryCode == Keyboard.CODE_SHIFT) {
switcher.onPressShift(withSliding);
} else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
switcher.onPressSymbol();
} else {
switcher.onOtherKeyPressed();
}
switcher.onPressKey(primaryCode);
}
@Override
public void onRelease(int primaryCode, boolean withSliding) {
KeyboardSwitcher switcher = mKeyboardSwitcher;
if (primaryCode == Keyboard.CODE_SHIFT) {
switcher.onReleaseShift(withSliding);
} else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) {
switcher.onReleaseSymbol();
}
public void onReleaseKey(int primaryCode, boolean withSliding) {
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);
}

View File

@ -56,13 +56,13 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
private final KeyboardActionListener mSuggestionsPaneListener =
new KeyboardActionListener.Adapter() {
@Override
public void onPress(int primaryCode, boolean withSliding) {
mListener.onPress(primaryCode, withSliding);
public void onPressKey(int primaryCode) {
mListener.onPressKey(primaryCode);
}
@Override
public void onRelease(int primaryCode, boolean withSliding) {
mListener.onRelease(primaryCode, withSliding);
public void onReleaseKey(int primaryCode, boolean withSliding) {
mListener.onReleaseKey(primaryCode, withSliding);
}
@Override

View File

@ -18,9 +18,8 @@ package com.android.inputmethod.keyboard.internal;
import android.test.AndroidTestCase;
import com.android.inputmethod.keyboard.Keyboard;
public class KeyboardStateNonDistinctTests extends AndroidTestCase {
public class KeyboardStateNonDistinctTests extends AndroidTestCase
implements MockKeyboardSwitcher.Constants {
protected MockKeyboardSwitcher mSwitcher;
public boolean hasDistinctMultitouch() {
@ -37,15 +36,6 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch());
}
// Argument for KeyboardState.onPressShift and onReleaseShift.
public static final boolean NOT_SLIDING = false;
public static final boolean SLIDING = true;
// Argument for KeyboardState.onCodeInput.
public static final boolean SINGLE = true;
public static final boolean MULTI = false;
public static final boolean NO_AUTO_CAPS = false;
public static final boolean AUTO_CAPS = true;
public void assertAlphabetNormal() {
assertTrue(mSwitcher.assertAlphabetNormal());
}
@ -78,58 +68,64 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
// Shift key in alphabet mode.
public void testShift() {
// Press/release shift key, enter into shift state.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release shift key, back to normal state.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
// Press/release shift key, enter into shift state.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release letter key, snap back to normal state.
mSwitcher.onOtherKeyPressed();
mSwitcher.onCodeInput('Z', SINGLE);
mSwitcher.onPressKey('Z');
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
}
// Shift key sliding input.
public void testShiftSliding() {
// Press shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Slide out shift key.
mSwitcher.onReleaseShift(SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertAlphabetManualShifted();
// Enter into letter key.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('Z');
assertAlphabetManualShifted();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('Z', SINGLE);
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
}
public void enterSymbolsMode() {
// Press/release "?123" key.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE);
mSwitcher.onReleaseSymbol();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertSymbolsNormal();
}
public void leaveSymbolsMode() {
// Press/release "ABC" key.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertAlphabetNormal();
mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE);
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetNormal();
}
@ -145,27 +141,28 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Press/release "ABC" key, switch back to shift locked mode.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertAlphabetShiftLocked();
mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE);
mSwitcher.onReleaseSymbol();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetShiftLocked();
}
// Symbols key sliding input.
public void testSymbolsSliding() {
// Press "123?" key.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
// Slide out from "123?" key.
mSwitcher.onReleaseSymbol();
mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING);
assertSymbolsNormal();
// Enter into letter key.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('z');
assertSymbolsNormal();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('z', SINGLE);
mSwitcher.onCodeInput('z');
mSwitcher.onReleaseKey('z');
assertAlphabetNormal();
}
@ -174,15 +171,17 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Press/release "=\<" key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertSymbolsShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsShifted();
// Press/release "?123" key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertSymbolsNormal();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsNormal();
leaveSymbolsMode();
@ -193,17 +192,18 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Press "=\<" key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertSymbolsShifted();
// Slide out "=\<" key.
mSwitcher.onReleaseShift(SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertSymbolsShifted();
// Enter into symbol shifted letter key.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('~');
assertSymbolsShifted();
// Release symbol shifted letter key, snap back to symbols.
mSwitcher.onCodeInput('~', SINGLE);
mSwitcher.onCodeInput('~');
mSwitcher.onReleaseKey('~');
assertSymbolsNormal();
}
@ -212,23 +212,25 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Press/release "=\<" key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertSymbolsShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertSymbolsShifted();
// Press "123?" key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertSymbolsNormal();
// Slide out "123?" key.
mSwitcher.onReleaseShift(SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertSymbolsNormal();
// Enter into symbol letter key.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
assertSymbolsNormal();
// Release symbol letter key, snap back to symbols shift.
mSwitcher.onCodeInput('1', SINGLE);
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsShifted();
}
@ -237,14 +239,16 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Enter a symbol letter.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
assertSymbolsNormal();
mSwitcher.onCodeInput('1', SINGLE);
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Enter space, snap back to alphabet.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey(CODE_SPACE);
assertSymbolsNormal();
mSwitcher.onCodeInput(Keyboard.CODE_SPACE, SINGLE);
mSwitcher.onCodeInput(CODE_SPACE);
mSwitcher.onReleaseKey(CODE_SPACE);
assertAlphabetNormal();
}
@ -260,14 +264,16 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
enterSymbolsMode();
// Enter a symbol letter.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
assertSymbolsNormal();
mSwitcher.onCodeInput('1', SINGLE);
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Enter snap back letter, snap back to alphabet.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey(snapBackCode);
assertSymbolsNormal();
mSwitcher.onCodeInput(snapBackCode, SINGLE);
mSwitcher.onCodeInput(snapBackCode);
mSwitcher.onReleaseKey(snapBackCode);
assertAlphabetNormal();
}
@ -279,10 +285,11 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
assertAlphabetAutomaticShifted();
// Press shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Release shift key.
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
}
@ -294,16 +301,17 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
assertAlphabetAutomaticShifted();
// Press shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Slide out shift key.
mSwitcher.onReleaseShift(SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT, SLIDING);
assertAlphabetManualShifted();
// Enter into letter key.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('Z');
assertAlphabetManualShifted();
// Release letter key, snap back to alphabet.
mSwitcher.onCodeInput('Z', SINGLE);
mSwitcher.onCodeInput('Z');
mSwitcher.onReleaseKey('Z');
assertAlphabetNormal();
}
@ -315,42 +323,43 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
assertAlphabetAutomaticShifted();
// Press "123?" key.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
// Slide out "123?" key.
mSwitcher.onReleaseSymbol();
mSwitcher.onReleaseKey(CODE_SYMBOL, SLIDING);
assertSymbolsNormal();
// Enter into symbol letter keys.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
assertSymbolsNormal();
// Release symbol letter key, snap back to alphabet.
mSwitcher.onCodeInput('1', SINGLE);
mSwitcher.onCodeInput('1');
mSwitcher.onReleaseKey('1');
assertAlphabetNormal();
}
public void enterShiftLockWithLongPressShift() {
// Long press shift key
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.toggleCapsLock();
assertAlphabetShiftLocked();
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
mSwitcher.onCodeInput(CODE_CAPSLOCK);
assertAlphabetShiftLocked();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetShiftLocked();
}
public void leaveShiftLockWithLongPressShift() {
// Press shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.toggleCapsLock();
assertAlphabetNormal();
mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
mSwitcher.onCodeInput(CODE_CAPSLOCK);
assertAlphabetNormal();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
}
@ -367,11 +376,11 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
assertAlphabetShiftLocked();
// Tap shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onCodeInput(CODE_SHIFT, SINGLE);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
}
@ -379,25 +388,25 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase {
// TODO: Move double tap recognizing timer/logic into KeyboardState.
public void testDoubleTapShift() {
// First shift key tap.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onCodeInput(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Second shift key tap.
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
mSwitcher.toggleCapsLock();
assertAlphabetShiftLocked();
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onCodeInput(CODE_CAPSLOCK);
assertAlphabetShiftLocked();
// First shift key tap.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onCodeInput(CODE_SHIFT);
assertAlphabetManualShifted();
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
// Second shift key tap.
// Second tap is ignored in LatinKeyboardView.KeyTimerHandler.

View File

@ -27,20 +27,22 @@ public class KeyboardStateTests extends KeyboardStateNonDistinctTests {
// Shift key chording input.
public void testShiftChording() {
// Press shift key and hold, enter into choring shift state.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(Keyboard.CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release letter keys.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('Z');
mSwitcher.onCodeInput('Z', MULTI);
mSwitcher.onReleaseKey('Z');
assertAlphabetManualShifted();
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('X');
mSwitcher.onCodeInput('X', MULTI);
mSwitcher.onReleaseKey('X');
assertAlphabetManualShifted();
// Release shift key, snap back to normal state.
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
mSwitcher.updateShiftState();
assertAlphabetNormal();
}
@ -48,20 +50,22 @@ public class KeyboardStateTests extends KeyboardStateNonDistinctTests {
// Symbols key chording input.
public void testSymbolsChording() {
// Press symbols key and hold, enter into choring shift state.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
// Press/release symbol letter keys.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
mSwitcher.onCodeInput('1', MULTI);
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('2');
mSwitcher.onCodeInput('2', MULTI);
mSwitcher.onReleaseKey('2');
assertSymbolsNormal();
// Release shift key, snap back to normal state.
mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE);
mSwitcher.onReleaseSymbol();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
mSwitcher.updateShiftState();
assertAlphabetNormal();
}
@ -74,15 +78,16 @@ public class KeyboardStateTests extends KeyboardStateNonDistinctTests {
assertAlphabetAutomaticShifted();
// Press shift key.
mSwitcher.onPressShift(NOT_SLIDING);
mSwitcher.onPressKey(CODE_SHIFT);
assertAlphabetManualShifted();
// Press/release letter keys.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('Z');
mSwitcher.onCodeInput('Z', MULTI);
mSwitcher.onReleaseKey('Z');
assertAlphabetManualShifted();
// Release shift key, snap back to alphabet.
mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
mSwitcher.onReleaseShift(NOT_SLIDING);
mSwitcher.onCodeInput(CODE_SHIFT);
mSwitcher.onReleaseKey(CODE_SHIFT);
assertAlphabetNormal();
}
@ -94,16 +99,17 @@ public class KeyboardStateTests extends KeyboardStateNonDistinctTests {
assertAlphabetAutomaticShifted();
// Press "123?" key.
mSwitcher.onPressSymbol();
mSwitcher.onPressKey(CODE_SYMBOL);
assertSymbolsNormal();
// Press/release symbol letter keys.
mSwitcher.onOtherKeyPressed();
mSwitcher.onPressKey('1');
assertSymbolsNormal();
mSwitcher.onCodeInput('1', MULTI);
mSwitcher.onReleaseKey('1');
assertSymbolsNormal();
// Release "123?" key, snap back to alphabet.
mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE);
mSwitcher.onReleaseSymbol();
mSwitcher.onCodeInput(CODE_SYMBOL);
mSwitcher.onReleaseKey(CODE_SYMBOL);
assertAlphabetNormal();
}

View File

@ -16,9 +16,26 @@
package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.internal.KeyboardState.SwitchActions;
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
public interface Constants {
// Argument for KeyboardState.onPressKey and onReleaseKey.
public static final boolean NOT_SLIDING = false;
public static final boolean SLIDING = true;
// Argument for KeyboardState.onCodeInput.
public static final boolean SINGLE = true;
public static final boolean MULTI = false;
public static final boolean NO_AUTO_CAPS = false;
public static final boolean AUTO_CAPS = true;
public static final int CODE_SHIFT = Keyboard.CODE_SHIFT;
public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
public static final int CODE_CAPSLOCK = Keyboard.CODE_CAPSLOCK;
public static final int CODE_SPACE = Keyboard.CODE_SPACE;
}
public static final String WORD_SEPARATORS = " ,.";
private static final int ALPHABET_UNSHIFTED = 0;
@ -30,7 +47,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
private int mLayout = ALPHABET_UNSHIFTED;
private boolean mAutoCapsMode = KeyboardStateTests.NO_AUTO_CAPS;
private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS;
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
private boolean mAutoCapsState = true;
@ -117,24 +134,20 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onLoadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch);
}
public void onPressShift(boolean withSliding) {
mState.onPressShift(withSliding);
public void onPressKey(int code) {
mState.onPressKey(code);
}
public void onReleaseShift(boolean withSliding) {
mState.onReleaseShift(withSliding);
public void onReleaseKey(int code) {
onReleaseKey(code, Constants.NOT_SLIDING);
}
public void onPressSymbol() {
mState.onPressSymbol();
public void onReleaseKey(int code, boolean withSliding) {
mState.onReleaseKey(code, withSliding);
}
public void onReleaseSymbol() {
mState.onReleaseSymbol();
}
public void onOtherKeyPressed() {
mState.onOtherKeyPressed();
public void onCodeInput(int code) {
onCodeInput(code, Constants.SINGLE);
}
public void onCodeInput(int code, boolean isSinglePointer) {