Merge "Handling key repeat by emulating key press and code input"

main
Tadashi G. Takaoka 2013-07-02 10:58:06 +00:00 committed by Android (Google) Code Review
commit d365d82d51
11 changed files with 206 additions and 115 deletions

View File

@ -20,7 +20,6 @@ import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;
public interface KeyboardActionListener {
/**
* Called when the user presses a key. This is sent before the {@link #onCodeInput} is called.
* For keys that repeat, this is only called once.
@ -99,9 +98,9 @@ public interface KeyboardActionListener {
*/
public boolean onCustomRequest(int requestCode);
public static class Adapter implements KeyboardActionListener {
public static final Adapter EMPTY_LISTENER = new Adapter();
public static final KeyboardActionListener EMPTY_LISTENER = new Adapter();
public static class Adapter implements KeyboardActionListener {
@Override
public void onPressKey(int primaryCode, boolean isSinglePointer) {}
@Override

View File

@ -31,7 +31,6 @@ import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
import com.android.inputmethod.keyboard.internal.KeyboardState;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputView;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
@ -210,7 +209,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
public void onPressKey(final int code, final boolean isSinglePointer) {
hapticAndAudioFeedback(code);
mState.onPressKey(code, isSinglePointer, mLatinIME.getCurrentAutoCapsState());
}
@ -299,13 +297,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
? keyboardView.getTimerProxy().isInDoubleTapShiftKeyTimeout() : false;
}
private void hapticAndAudioFeedback(final int code) {
if (mKeyboardView == null || mKeyboardView.isInSlidingKeyInput()) {
return;
}
AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, mKeyboardView);
}
/**
* Updates state machine to figure out when to automatically switch back to the previous mode.
*/

View File

@ -57,10 +57,8 @@ import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams;
import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview;
import com.android.inputmethod.keyboard.internal.TouchScreenRegulator;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.DebugSettings;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.Settings;
@ -240,11 +238,15 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
break;
case MSG_REPEAT_KEY:
final Key currentKey = tracker.getKey();
if (currentKey != null && currentKey.mCode == msg.arg1) {
tracker.onRepeatKey(currentKey);
AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(
currentKey.mCode, keyboardView);
final int code = msg.arg1;
if (currentKey != null && currentKey.mCode == code) {
startKeyRepeatTimer(tracker, mKeyRepeatInterval);
startTypingStateTimer(currentKey);
final KeyboardActionListener listener =
keyboardView.getKeyboardActionListener();
listener.onPressKey(code, true /* isSinglePointer */);
listener.onCodeInput(code,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
}
break;
case MSG_LONGPRESS_KEY:
@ -564,6 +566,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
altCodeKeyWhileTypingFadeoutAnimatorResId, this);
mAltCodeKeyWhileTypingFadeinAnimator = loadObjectAnimator(
altCodeKeyWhileTypingFadeinAnimatorResId, this);
mKeyboardActionListener = KeyboardActionListener.EMPTY_LISTENER;
}
private ObjectAnimator loadObjectAnimator(final int resId, final Object target) {
@ -977,39 +981,28 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.mainKeyboardView_onLongPress();
}
final int code = key.mCode;
final KeyboardActionListener listener = mKeyboardActionListener;
if (key.hasNoPanelAutoMoreKey()) {
final int embeddedCode = key.mMoreKeys[0].mCode;
final int moreKeyCode = key.mMoreKeys[0].mCode;
tracker.onLongPressed();
invokeCodeInput(embeddedCode);
invokeReleaseKey(code);
AudioAndHapticFeedbackManager.getInstance().hapticAndAudioFeedback(code, this);
listener.onPressKey(moreKeyCode, true /* isSinglePointer */);
listener.onCodeInput(moreKeyCode,
Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
listener.onReleaseKey(moreKeyCode, false /* withSliding */);
return;
}
final int code = key.mCode;
if (code == Constants.CODE_SPACE || code == Constants.CODE_LANGUAGE_SWITCH) {
// Long pressing the space key invokes IME switcher dialog.
if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) {
if (listener.onCustomRequest(Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER)) {
tracker.onLongPressed();
invokeReleaseKey(code);
listener.onReleaseKey(code, false /* withSliding */);
return;
}
}
openMoreKeysPanel(key, tracker);
}
private boolean invokeCustomRequest(final int requestCode) {
return mKeyboardActionListener.onCustomRequest(requestCode);
}
private void invokeCodeInput(final int code) {
mKeyboardActionListener.onCodeInput(
code, Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
}
private void invokeReleaseKey(final int code) {
mKeyboardActionListener.onReleaseKey(code, false);
}
private void openMoreKeysPanel(final Key key, final PointerTracker tracker) {
final MoreKeysPanel moreKeysPanel = onCreateMoreKeysPanel(key, getContext());
if (moreKeysPanel == null) {

View File

@ -175,7 +175,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private DrawingProxy mDrawingProxy;
private TimerProxy mTimerProxy;
private KeyDetector mKeyDetector;
private KeyboardActionListener mListener = KeyboardActionListener.Adapter.EMPTY_LISTENER;
private KeyboardActionListener mListener = KeyboardActionListener.EMPTY_LISTENER;
private Keyboard mKeyboard;
private int mPhantonSuddenMoveThreshold;
@ -1263,13 +1263,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (!key.isRepeatable()) return;
// Don't start key repeat when we are in sliding input mode.
if (mIsInSlidingKeyInput) return;
onRepeatKey(key);
mTimerProxy.startKeyRepeatTimer(this);
}
public void onRepeatKey(final Key key) {
detectAndSendKey(key, key.mX, key.mY, SystemClock.uptimeMillis());
mTimerProxy.startTypingStateTimer(key);
mTimerProxy.startKeyRepeatTimer(this);
}
private boolean isMajorEnoughMoveToBeOnNewKey(final int x, final int y, final long eventTime,

View File

@ -81,9 +81,6 @@ public final class KeyboardState {
private boolean mPrevSymbolsKeyboardWasShifted;
private int mRecapitalizeMode;
// For handling long press.
private boolean mLongPressShiftLockFired;
// For handling double tap.
private boolean mIsInAlphabetUnshiftedFromShifted;
private boolean mIsInDoubleTapShiftKey;
@ -325,10 +322,11 @@ public final class KeyboardState {
}
if (code == Constants.CODE_SHIFT) {
onPressShift();
} else if (code == Constants.CODE_CAPSLOCK) {
// Nothing to do here. See {@link #onReleaseKey(int,boolean)}.
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
onPressSymbol();
} else {
mLongPressShiftLockFired = false;
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
// It is required to reset the auto caps state when all of the following conditions
@ -356,6 +354,8 @@ public final class KeyboardState {
}
if (code == Constants.CODE_SHIFT) {
onReleaseShift(withSliding);
} else if (code == Constants.CODE_CAPSLOCK) {
setShiftLocked(!mAlphabetShiftState.isShiftLocked());
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
onReleaseSymbol(withSliding);
}
@ -437,7 +437,6 @@ public final class KeyboardState {
}
private void onPressShift() {
mLongPressShiftLockFired = false;
// If we are recapitalizing, we don't do any of the normal processing, including
// importantly the double tap timer.
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
@ -499,8 +498,6 @@ public final class KeyboardState {
// Double tap shift key has been handled in {@link #onPressShift}, so that just
// ignore this release shift key here.
mIsInDoubleTapShiftKey = false;
} else if (mLongPressShiftLockFired) {
setShiftLocked(!mAlphabetShiftState.isShiftLocked());
} else if (mShiftKeyState.isChording()) {
if (mAlphabetShiftState.isShiftLockShifted()) {
// After chording input while shift locked state.
@ -610,12 +607,6 @@ public final class KeyboardState {
break;
}
if (code == Constants.CODE_CAPSLOCK) {
// Changing shift lock state will be handled at {@link #onPressShift()} when the shift
// key is released.
mLongPressShiftLockFired = true;
}
// If the code is a letter, update keyboard shift state.
if (Constants.isLetterCode(code)) {
updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);

View File

@ -148,6 +148,13 @@ public final class Constants {
return coordinate >= 0;
}
/**
* Custom request code used in
* {@link com.android.inputmethod.keyboard.KeyboardActionListener#onCustomRequest(int)}.
*/
// The code to show input method picker.
public static final int CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER = 1;
/**
* Some common keys code. Must be positive.
*/

View File

@ -1360,14 +1360,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
showSubtypeSelectorAndSettings();
}
// Virtual codes representing custom requests. These are used in onCustomRequest() below.
public static final int CODE_SHOW_INPUT_METHOD_PICKER = 1;
@Override
public boolean onCustomRequest(final int requestCode) {
if (isShowingOptionDialog()) return false;
switch (requestCode) {
case CODE_SHOW_INPUT_METHOD_PICKER:
case Constants.CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER:
if (mRichImm.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) {
mRichImm.getInputMethodManager().showInputMethodPicker();
return true;
@ -2678,15 +2675,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
// Callback called by PointerTracker through the KeyboardActionListener. This is called when a
// key is depressed; release matching call is onReleaseKey below.
// 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) {
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);
}
}
// Callback by PointerTracker through the KeyboardActionListener. This is called when a key
// is released; press matching call is onPressKey above.
// Callback of the {@link KeyboardActionListener}. This is called when a key is released;
// press matching call is {@link #onPressKey(int,boolean)} above.
@Override
public void onReleaseKey(final int primaryCode, final boolean withSliding) {
mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);

View File

@ -191,6 +191,10 @@ public final class RichInputConnection {
return mIC.getSelectedText(flags);
}
public boolean canDeleteCharacters() {
return mCurrentCursorPosition > 0;
}
/**
* Gets the caps modes we should be in after this specific string.
*

View File

@ -60,7 +60,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Chording input in shift locked.
public void testChordingShiftLocked() {
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press shift key and hold, enter into choring shift state.
@ -119,7 +119,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -137,7 +137,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -196,7 +196,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -216,7 +216,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -397,29 +397,29 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
public void testLongPressShiftAndChording() {
// Long press shift key, enter maybe shift locked.
longPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Press/release letter key, remain in manual shifted.
chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Release shift key, back to alphabet (not shift locked).
releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Long press shift key, enter maybe alphabet.
longPressKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED);
longPressShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED);
// Press/release letter key, remain in manual shifted.
chordingPressAndReleaseKey('A', ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED);
// Release shift key, back to shift locked (not alphabet).
releaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCKED);
// Long press shift key, enter alphabet
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
ALPHABET_UNSHIFTED);
// Press/release shift key, enter alphabet shifted.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Long press shift key, enter maybe alphabet.
longPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Press/release letter key, remain in manual shifted.
chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Release shift key, back to alphabet shifted (not alphabet).
@ -430,7 +430,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
// Long press shift key, enter maybe shift locked.
longPressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
longPressShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Press/release letter key, remain in manual shifted.
chordingPressAndReleaseKey('A', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Release shift key, back to alphabet (not shift locked).
@ -449,7 +449,7 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
//
// // Long press shift key, enter alphabet shift locked.
// longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
// longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
// ALPHABET_SHIFT_LOCKED);
// // First shift key tap.
// pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);

View File

@ -91,7 +91,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Switching between alphabet shift locked and symbols.
public void testAlphabetShiftLockedAndSymbols() {
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
@ -133,7 +133,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Automatic switch back to alphabet shift locked test by space key.
public void testSwitchBackBySpaceShiftLocked() {
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
@ -196,13 +196,13 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard, should be in alphabet.
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release shift key, back to alphabet.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release letter key, remain in shift locked.
pressAndReleaseKey('A', ALPHABET_SHIFT_LOCKED, ALPHABET_SHIFT_LOCKED);
@ -212,16 +212,16 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Long press shift key, back to alphabet.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
ALPHABET_UNSHIFTED);
// Press/release shift key, enter alphabet shifted.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release shift key, back to alphabet.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);
@ -231,7 +231,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release shift key, back to alphabet.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);
@ -293,12 +293,12 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
updateShiftState(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Update shift state, remained in alphabet shift locked.
updateShiftState(ALPHABET_SHIFT_LOCKED);
// Long press shift key, back to alphabet.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
ALPHABET_UNSHIFTED);
// Press/release "?123" key, enter into symbols.
@ -326,12 +326,12 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Update shift state, remained in alphabet shift locked (not automatic shifted).
updateShiftState(ALPHABET_SHIFT_LOCKED);
// Long press shift key, back to alphabet.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_SHIFT_LOCK_SHIFTED,
ALPHABET_UNSHIFTED);
// Load keyboard, should be in automatic shifted.
@ -383,7 +383,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Alphabet shift locked -> shift key + letter -> alphabet shift locked.
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press and slide from "123?" key, enter symbols.
pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -441,7 +441,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Alphabet shift locked -> shift key + letter -> cancel -> alphabet shift locked.
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press and slide from "123?" key, enter symbols.
pressAndSlideFromKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -500,7 +500,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -517,7 +517,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -574,7 +574,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -592,7 +592,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -651,7 +651,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -670,7 +670,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -733,7 +733,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -753,7 +753,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Load keyboard
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release "?123" key, enter into symbols.
pressAndReleaseKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
@ -777,7 +777,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Change focus to new text field.
loadKeyboard(ALPHABET_UNSHIFTED);
@ -808,7 +808,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Change focus to new text field.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
@ -852,7 +852,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Alphabet shift locked -> rotate -> alphabet shift locked.
// Long press shift key, enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Rotate device, remain in alphabet shift locked.
rotateDevice(ALPHABET_SHIFT_LOCKED);
@ -936,7 +936,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
// Long press shift key to enter alphabet shift locked.
longPressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
longPressAndReleaseShiftKey(ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED,
ALPHABET_SHIFT_LOCKED);
// Press/release shift key
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);

View File

@ -34,6 +34,11 @@ public class KeyboardStateTestsBase extends AndroidTestCase
loadKeyboard(ALPHABET_UNSHIFTED);
}
/**
* Set auto caps mode.
*
* @param autoCaps the auto cap mode.
*/
public void setAutoCapsMode(final int autoCaps) {
mSwitcher.setAutoCapsMode(autoCaps);
}
@ -44,17 +49,32 @@ public class KeyboardStateTestsBase extends AndroidTestCase
expected == actual);
}
/**
* Emulate update keyboard shift state.
*
* @param afterUpdate the keyboard state after updating the keyboard shift state.
*/
public void updateShiftState(final int afterUpdate) {
mSwitcher.updateShiftState();
assertLayout("afterUpdate", afterUpdate, mSwitcher.getLayoutId());
}
/**
* Emulate load default keyboard.
*
* @param afterLoad the keyboard state after loading default keyboard.
*/
public void loadKeyboard(final int afterLoad) {
mSwitcher.loadKeyboard();
mSwitcher.updateShiftState();
assertLayout("afterLoad", afterLoad, mSwitcher.getLayoutId());
}
/**
* Emulate rotate device.
*
* @param afterRotate the keyboard state after rotating device.
*/
public void rotateDevice(final int afterRotate) {
mSwitcher.saveKeyboardState();
mSwitcher.loadKeyboard();
@ -67,45 +87,97 @@ public class KeyboardStateTestsBase extends AndroidTestCase
assertLayout("afterPress", afterPress, mSwitcher.getLayoutId());
}
/**
* Emulate key press.
*
* @param code the key code to press.
* @param afterPress the keyboard state after pressing the key.
*/
public void pressKey(final int code, final int afterPress) {
mSwitcher.expireDoubleTapTimeout();
pressKeyWithoutTimerExpire(code, true, afterPress);
}
/**
* Emulate key release and register.
*
* @param code the key code to release and register
* @param afterRelease the keyboard state after releasing the key.
*/
public void releaseKey(final int code, final int afterRelease) {
mSwitcher.onCodeInput(code);
mSwitcher.onReleaseKey(code, NOT_SLIDING);
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
}
/**
* Emulate key press and release.
*
* @param code the key code to press and release.
* @param afterPress the keyboard state after pressing the key.
* @param afterRelease the keyboard state after releasing the key.
*/
public void pressAndReleaseKey(final int code, final int afterPress, final int afterRelease) {
pressKey(code, afterPress);
releaseKey(code, afterRelease);
}
/**
* Emulate chording key press.
*
* @param code the chording key code.
* @param afterPress the keyboard state after pressing chording key.
*/
public void chordingPressKey(final int code, final int afterPress) {
mSwitcher.expireDoubleTapTimeout();
pressKeyWithoutTimerExpire(code, false, afterPress);
}
/**
* Emulate chording key release.
*
* @param code the cording key code.
* @param afterRelease the keyboard state after releasing chording key.
*/
public void chordingReleaseKey(final int code, final int afterRelease) {
mSwitcher.onCodeInput(code);
mSwitcher.onReleaseKey(code, NOT_SLIDING);
assertLayout("afterRelease", afterRelease, mSwitcher.getLayoutId());
}
/**
* Emulate chording key press and release.
*
* @param code the chording key code.
* @param afterPress the keyboard state after pressing chording key.
* @param afterRelease the keyboard state after releasing chording key.
*/
public void chordingPressAndReleaseKey(final int code, final int afterPress,
final int afterRelease) {
chordingPressKey(code, afterPress);
chordingReleaseKey(code, afterRelease);
}
/**
* Emulate start of the sliding key input.
*
* @param code the key code to start sliding.
* @param afterPress the keyboard state after pressing the key.
* @param afterSlide the keyboard state after releasing the key with sliding input.
*/
public void pressAndSlideFromKey(final int code, final int afterPress, final int afterSlide) {
pressKey(code, afterPress);
mSwitcher.onReleaseKey(code, SLIDING);
assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId());
}
/**
* Emulate end of the sliding key input.
*
* @param code the key code to stop sliding.
* @param afterPress the keyboard state after pressing the key.
* @param afterSlide the keyboard state after releasing the key and stop sliding.
*/
public void stopSlidingOnKey(final int code, final int afterPress, final int afterSlide) {
pressKey(code, afterPress);
mSwitcher.onCodeInput(code);
@ -114,32 +186,67 @@ public class KeyboardStateTestsBase extends AndroidTestCase
assertLayout("afterSlide", afterSlide, mSwitcher.getLayoutId());
}
/**
* Emulate cancel the sliding key input.
*
* @param afterCancelSliding the keyboard state after canceling sliding input.
*/
public void stopSlidingAndCancel(final int afterCancelSliding) {
mSwitcher.onFinishSlidingInput();
assertLayout("afterCancelSliding", afterCancelSliding, mSwitcher.getLayoutId());
}
public void longPressKey(final int code, final int afterPress, final int afterLongPress) {
pressKey(code, afterPress);
/**
* Emulate long press shift key.
*
* @param afterPress the keyboard state after pressing shift key.
* @param afterLongPress the keyboard state after long press fired.
*/
public void longPressShiftKey(final int afterPress, final int afterLongPress) {
// Long press shift key will register {@link Constants#CODE_CAPS_LOCK}. See
// {@link R.xml#key_styles_common} and its baseForShiftKeyStyle. We thus emulate the
// behavior here.
final int longPressCode = code == CODE_SHIFT ? Constants.CODE_CAPSLOCK : code;
mSwitcher.onCodeInput(longPressCode);
// behavior that is implemented in {@link MainKeyboardView#onLongPress(PointerTracker)}.
pressKey(Constants.CODE_SHIFT, afterPress);
mSwitcher.onPressKey(Constants.CODE_CAPSLOCK, true /* isSinglePointer */);
mSwitcher.onCodeInput(Constants.CODE_CAPSLOCK);
assertLayout("afterLongPress", afterLongPress, mSwitcher.getLayoutId());
}
public void longPressAndReleaseKey(final int code, final int afterPress,
final int afterLongPress, final int afterRelease) {
longPressKey(code, afterPress, afterLongPress);
releaseKey(code, afterRelease);
/**
* Emulate long press shift key and release.
*
* @param afterPress the keyboard state after pressing shift key.
* @param afterLongPress the keyboard state after long press fired.
* @param afterRelease the keyboard state after shift key is released.
*/
public void longPressAndReleaseShiftKey(final int afterPress, final int afterLongPress,
final int afterRelease) {
// Long press shift key will register {@link Constants#CODE_CAPS_LOCK}. See
// {@link R.xml#key_styles_common} and its baseForShiftKeyStyle. We thus emulate the
// behavior that is implemented in {@link MainKeyboardView#onLongPress(PointerTracker)}.
longPressShiftKey(afterPress, afterLongPress);
releaseKey(Constants.CODE_CAPSLOCK, afterRelease);
}
public void secondPressKey(int code, int afterPress) {
/**
* Emulate the second press of the double tap.
*
* @param code the key code to double tap.
* @param afterPress the keyboard state after pressing the second tap.
*/
public void secondPressKey(final int code, final int afterPress) {
pressKeyWithoutTimerExpire(code, true, afterPress);
}
public void secondPressAndReleaseKey(int code, int afterPress, int afterRelease) {
/**
* Emulate the second tap of the double tap.
*
* @param code the key code to double tap.
* @param afterPress the keyboard state after pressing the second tap.
* @param afterRelease the keyboard state after releasing the second tap.
*/
public void secondPressAndReleaseKey(final int code, final int afterPress,
final int afterRelease) {
secondPressKey(code, afterPress);
releaseKey(code, afterRelease);
}