From 87e025da11703af65e7bb85670adac5b54e2a367 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 17 Jan 2012 16:30:37 +0900 Subject: [PATCH] Remove toggleShift and toggleAlphabetAndSymbols from KeyboardSwitcher Change-Id: I9bb8f78b0a766cd7937d5cbe1c1e5e35898b2997 --- .../keyboard/KeyboardSwitcher.java | 16 +- .../keyboard/internal/KeyboardState.java | 25 +- .../android/inputmethod/latin/LatinIME.java | 21 +- .../KeyboardStateNonDistinctTests.java | 259 ++++++++--- .../keyboard/internal/KeyboardStateTests.java | 401 +----------------- .../internal/MockKeyboardSwitcher.java | 8 - 6 files changed, 201 insertions(+), 529 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index af1c3eeb9..9efd65e91 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -148,7 +148,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, // have separate layouts with unique KeyboardIds for alphabet and alphabet-shifted // respectively. if (mainKeyboardId.isPhoneKeyboard()) { - mState.onToggleAlphabetAndSymbols(); + mState.setSymbolsKeyboard(); } updateShiftState(); } @@ -256,13 +256,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, } } - /** - * Toggle keyboard shift state triggered by user touch event. - */ - public void toggleShift() { - mState.onToggleShift(); - } - /** * Toggle caps lock state triggered by user touch event. */ @@ -270,13 +263,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mState.onToggleCapsLock(); } - /** - * Toggle between alphabet and symbols modes triggered by user touch event. - */ - public void toggleAlphabetAndSymbols() { - mState.onToggleAlphabetAndSymbols(); - } - /** * Update keyboard shift state triggered by connected EditText status change. */ diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java index bb75111b4..a8e0bd595 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java @@ -31,8 +31,7 @@ import com.android.inputmethod.keyboard.Keyboard; * {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()}, * {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()}, * {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)}, - * {@link #onUpdateShiftState(boolean)}, {@link #onToggleShift()}, {@link #onToggleCapsLock()}, - * and {@link #onToggleAlphabetAndSymbols()}. + * {@link #onUpdateShiftState(boolean)}, and {@link #onToggleCapsLock()}. * * The actions are {@link SwitchActions}'s methods. */ @@ -219,7 +218,8 @@ public class KeyboardState { mSwitchActions.requestUpdatingShiftState(); } - private void setSymbolsKeyboard() { + // TODO: Make this method private + public void setSymbolsKeyboard() { if (DEBUG_STATE) { Log.d(TAG, "setSymbolsKeyboard"); } @@ -464,18 +464,6 @@ public class KeyboardState { } } - public void onToggleShift() { - if (DEBUG_STATE) { - Log.d(TAG, "onToggleShift: " + this); - } - if (mIsAlphabetMode) { - setShifted(mKeyboardShiftState.isShiftedOrShiftLocked() - ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT); - } else { - toggleShiftInSymbols(); - } - } - public void onToggleCapsLock() { if (DEBUG_STATE) { Log.d(TAG, "onToggleCapsLock: " + this); @@ -492,13 +480,6 @@ public class KeyboardState { } } - public void onToggleAlphabetAndSymbols() { - if (DEBUG_STATE) { - Log.d(TAG, "onToggleAlphabetAndSymbols: " + this); - } - toggleAlphabetAndSymbols(); - } - private static String shiftModeToString(int shiftMode) { switch (shiftMode) { case SwitchActions.UNSHIFT: return "UNSHIFT"; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 02391da9c..cd58df6bb 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1261,16 +1261,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.logOnDelete(); break; case Keyboard.CODE_SHIFT: - // Shift key is handled in onPress() when device has distinct multi-touch panel. - if (!distinctMultiTouch) { - switcher.toggleShift(); - } - break; case Keyboard.CODE_SWITCH_ALPHA_SYMBOL: - // Symbol key is handled in onPress() when device has distinct multi-touch panel. - if (!distinctMultiTouch) { - switcher.toggleAlphabetAndSymbols(); - } + // Shift and symbol key is handled in onPress() and onRelease(). break; case Keyboard.CODE_SETTINGS: onSettingsKeyPressed(); @@ -2252,10 +2244,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (switcher.isVibrateAndSoundFeedbackRequired()) { hapticAndAudioFeedback(primaryCode); } - final boolean distinctMultiTouch = switcher.hasDistinctMultitouch(); - if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) { + if (primaryCode == Keyboard.CODE_SHIFT) { switcher.onPressShift(withSliding); - } else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { + } else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { switcher.onPressSymbol(); } else { switcher.onOtherKeyPressed(); @@ -2265,11 +2256,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onRelease(int primaryCode, boolean withSliding) { KeyboardSwitcher switcher = mKeyboardSwitcher; - // Reset any drag flags in the keyboard - final boolean distinctMultiTouch = switcher.hasDistinctMultitouch(); - if (distinctMultiTouch && primaryCode == Keyboard.CODE_SHIFT) { + if (primaryCode == Keyboard.CODE_SHIFT) { switcher.onReleaseShift(withSliding); - } else if (distinctMultiTouch && primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { + } else if (primaryCode == Keyboard.CODE_SWITCH_ALPHA_SYMBOL) { switcher.onReleaseSymbol(); } } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java index 729e41e9f..11808644a 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateNonDistinctTests.java @@ -21,7 +21,11 @@ import android.test.AndroidTestCase; import com.android.inputmethod.keyboard.Keyboard; public class KeyboardStateNonDistinctTests extends AndroidTestCase { - private MockKeyboardSwitcher mSwitcher; + protected MockKeyboardSwitcher mSwitcher; + + public boolean hasDistinctMultitouch() { + return false; + } @Override protected void setUp() throws Exception { @@ -30,40 +34,39 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { mSwitcher = new MockKeyboardSwitcher(); final String layoutSwitchBackSymbols = ""; - final boolean hasDistinctMultitouch = false; - mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch); + mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch()); } // Argument for KeyboardState.onPressShift and onReleaseShift. - private static final boolean NOT_SLIDING = false; - private static final boolean SLIDING = true; + public static final boolean NOT_SLIDING = false; + public static final boolean SLIDING = true; // Argument for KeyboardState.onCodeInput. - private static final boolean SINGLE = true; - private static final boolean MULTI = false; - static final boolean NO_AUTO_CAPS = false; - private static final boolean AUTO_CAPS = true; + 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; - private void assertAlphabetNormal() { + public void assertAlphabetNormal() { assertTrue(mSwitcher.assertAlphabetNormal()); } - private void assertAlphabetManualShifted() { + public void assertAlphabetManualShifted() { assertTrue(mSwitcher.assertAlphabetManualShifted()); } - private void assertAlphabetAutomaticShifted() { + public void assertAlphabetAutomaticShifted() { assertTrue(mSwitcher.assertAlphabetAutomaticShifted()); } - private void assertAlphabetShiftLocked() { + public void assertAlphabetShiftLocked() { assertTrue(mSwitcher.assertAlphabetShiftLocked()); } - private void assertSymbolsNormal() { + public void assertSymbolsNormal() { assertTrue(mSwitcher.assertSymbolsNormal()); } - private void assertSymbolsShifted() { + public void assertSymbolsShifted() { assertTrue(mSwitcher.assertSymbolsShifted()); } @@ -75,23 +78,20 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { // Shift key in alphabet mode. public void testShift() { // Press/release shift key, enter into shift state. - mSwitcher.onOtherKeyPressed(); - assertAlphabetNormal(); - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetManualShifted(); // Press/release shift key, back to normal state. - mSwitcher.onOtherKeyPressed(); + mSwitcher.onPressShift(NOT_SLIDING); assertAlphabetManualShifted(); - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetNormal(); // Press/release shift key, enter into shift state. - mSwitcher.onOtherKeyPressed(); - assertAlphabetNormal(); - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetManualShifted(); // Press/release letter key, snap back to normal state. mSwitcher.onOtherKeyPressed(); @@ -99,20 +99,36 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { assertAlphabetNormal(); } - private void enterSymbolsMode() { - // Press/release "?123" key. + // Shift key sliding input. + public void testShiftSliding() { + // Press shift key. + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); + // Slide out shift key. + mSwitcher.onReleaseShift(SLIDING); + assertAlphabetManualShifted(); + + // Enter into letter key. mSwitcher.onOtherKeyPressed(); + assertAlphabetManualShifted(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('Z', SINGLE); assertAlphabetNormal(); - mSwitcher.toggleAlphabetAndSymbols(); + } + + public void enterSymbolsMode() { + // Press/release "?123" key. + mSwitcher.onPressSymbol(); + assertSymbolsNormal(); mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); + mSwitcher.onReleaseSymbol(); assertSymbolsNormal(); } - private void leaveSymbolsMode() { + public void leaveSymbolsMode() { // Press/release "ABC" key. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.toggleAlphabetAndSymbols(); + mSwitcher.onPressSymbol(); + assertAlphabetNormal(); mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); assertAlphabetNormal(); } @@ -126,20 +142,31 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { // Switching between alphabet shift locked and symbols. public void testAlphabetShiftLockedAndSymbols() { enterShiftLockWithLongPressShift(); - - // Press/release "?123" key. - mSwitcher.onOtherKeyPressed(); - assertAlphabetShiftLocked(); - mSwitcher.toggleAlphabetAndSymbols(); - mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); - assertSymbolsNormal(); + enterSymbolsMode(); // Press/release "ABC" key, switch back to shift locked mode. + mSwitcher.onPressSymbol(); + assertAlphabetShiftLocked(); + mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); + mSwitcher.onReleaseSymbol(); + assertAlphabetShiftLocked(); + } + + // Symbols key sliding input. + public void testSymbolsSliding() { + // Press "123?" key. + mSwitcher.onPressSymbol(); + assertSymbolsNormal(); + // Slide out from "123?" key. + mSwitcher.onReleaseSymbol(); + assertSymbolsNormal(); + + // Enter into letter key. mSwitcher.onOtherKeyPressed(); assertSymbolsNormal(); - mSwitcher.toggleAlphabetAndSymbols(); - mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); - assertAlphabetShiftLocked(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('z', SINGLE); + assertAlphabetNormal(); } // Switching between symbols and symbols shifted. @@ -147,23 +174,64 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { enterSymbolsMode(); // Press/release "=\<" key. - // Press/release shift key, enter into shift state. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onPressShift(NOT_SLIDING); + assertSymbolsShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertSymbolsShifted(); // Press/release "?123" key. - mSwitcher.onOtherKeyPressed(); - assertSymbolsShifted(); - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onPressShift(NOT_SLIDING); + assertSymbolsNormal(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertSymbolsNormal(); leaveSymbolsMode(); } + // Symbols shift sliding input + public void testSymbolsShiftSliding() { + enterSymbolsMode(); + + // Press "=\<" key. + mSwitcher.onPressShift(NOT_SLIDING); + assertSymbolsShifted(); + // Slide out "=\<" key. + mSwitcher.onReleaseShift(SLIDING); + assertSymbolsShifted(); + + // Enter into symbol shifted letter key. + mSwitcher.onOtherKeyPressed(); + assertSymbolsShifted(); + // Release symbol shifted letter key, snap back to symbols. + mSwitcher.onCodeInput('~', SINGLE); + assertSymbolsNormal(); + } + + // Symbols shift sliding input from symbols shifted. + public void testSymbolsShiftSliding2() { + enterSymbolsMode(); + + // Press/release "=\<" key. + mSwitcher.onPressShift(NOT_SLIDING); + assertSymbolsShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); + assertSymbolsShifted(); + + // Press "123?" key. + mSwitcher.onPressShift(NOT_SLIDING); + assertSymbolsNormal(); + // Slide out "123?" key. + mSwitcher.onReleaseShift(SLIDING); + assertSymbolsNormal(); + + // Enter into symbol letter key. + mSwitcher.onOtherKeyPressed(); + assertSymbolsNormal(); + // Release symbol letter key, snap back to symbols shift. + mSwitcher.onCodeInput('1', SINGLE); + assertSymbolsShifted(); + } + // Automatic snap back to alphabet from symbols by space key. public void testSnapBackBySpace() { enterSymbolsMode(); @@ -178,10 +246,10 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { assertSymbolsNormal(); mSwitcher.onCodeInput(Keyboard.CODE_SPACE, SINGLE); assertAlphabetNormal(); - - // TODO: Add automatic snap back to shift locked test. } + // TODO: Add automatic snap back to shift locked test. + // Automatic snap back to alphabet from symbols by registered letters. public void testSnapBack() { final String snapBackChars = "'"; @@ -211,31 +279,79 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { assertAlphabetAutomaticShifted(); // Press shift key. - mSwitcher.onOtherKeyPressed(); - assertAlphabetAutomaticShifted(); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); // Release shift key. - mSwitcher.toggleShift(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetNormal(); } - private void enterShiftLockWithLongPressShift() { + // Sliding from shift key in automatic upper case. + public void testAutomaticUpperCaseSliding() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + // Press shift key. + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); + // Slide out shift key. + mSwitcher.onReleaseShift(SLIDING); + assertAlphabetManualShifted(); + // Enter into letter key. mSwitcher.onOtherKeyPressed(); + assertAlphabetManualShifted(); + // Release letter key, snap back to alphabet. + mSwitcher.onCodeInput('Z', SINGLE); assertAlphabetNormal(); + } + + // Sliding from symbol key in automatic upper case. + public void testAutomaticUpperCaseSliding2() { + mSwitcher.setAutoCapsMode(AUTO_CAPS); + // Update shift state with auto caps enabled. + mSwitcher.updateShiftState(); + assertAlphabetAutomaticShifted(); + + // Press "123?" key. + mSwitcher.onPressSymbol(); + assertSymbolsNormal(); + // Slide out "123?" key. + mSwitcher.onReleaseSymbol(); + assertSymbolsNormal(); + // Enter into symbol letter keys. + mSwitcher.onOtherKeyPressed(); + assertSymbolsNormal(); + // Release symbol letter key, snap back to alphabet. + mSwitcher.onCodeInput('1', SINGLE); + assertAlphabetNormal(); + } + + public void enterShiftLockWithLongPressShift() { + // Long press shift key + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); // Long press recognized in LatinKeyboardView.KeyTimerHandler. mSwitcher.toggleCapsLock(); + assertAlphabetShiftLocked(); mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE); assertAlphabetShiftLocked(); + mSwitcher.onReleaseShift(NOT_SLIDING); + assertAlphabetShiftLocked(); } - private void leaveShiftLockWithLongPressShift() { + public void leaveShiftLockWithLongPressShift() { // Press shift key. - mSwitcher.onOtherKeyPressed(); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); // Long press recognized in LatinKeyboardView.KeyTimerHandler. mSwitcher.toggleCapsLock(); + assertAlphabetNormal(); mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE); assertAlphabetNormal(); + mSwitcher.onReleaseShift(NOT_SLIDING); + assertAlphabetNormal(); } // Long press shift key. @@ -251,10 +367,11 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { assertAlphabetShiftLocked(); // Tap shift key. - mSwitcher.onOtherKeyPressed(); - assertAlphabetShiftLocked(); - mSwitcher.toggleShift(); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + assertAlphabetManualShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetNormal(); } @@ -262,11 +379,12 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { // TODO: Move double tap recognizing timer/logic into KeyboardState. public void testDoubleTapShift() { // First shift key tap. - mSwitcher.onOtherKeyPressed(); - assertAlphabetNormal(); - mSwitcher.toggleShift(); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); assertAlphabetManualShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); + assertAlphabetManualShifted(); // Second shift key tap. // Double tap recognized in LatinKeyboardView.KeyTimerHandler. mSwitcher.toggleCapsLock(); @@ -275,10 +393,11 @@ public class KeyboardStateNonDistinctTests extends AndroidTestCase { assertAlphabetShiftLocked(); // First shift key tap. - mSwitcher.onOtherKeyPressed(); - assertAlphabetShiftLocked(); - mSwitcher.toggleShift(); + mSwitcher.onPressShift(NOT_SLIDING); + assertAlphabetManualShifted(); mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); + assertAlphabetManualShifted(); + mSwitcher.onReleaseShift(NOT_SLIDING); assertAlphabetNormal(); // Second shift key tap. // Second tap is ignored in LatinKeyboardView.KeyTimerHandler. diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java index 89c089444..2330a6a45 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTests.java @@ -16,84 +16,12 @@ package com.android.inputmethod.keyboard.internal; -import android.test.AndroidTestCase; - import com.android.inputmethod.keyboard.Keyboard; -public class KeyboardStateTests extends AndroidTestCase { - private MockKeyboardSwitcher mSwitcher; - +public class KeyboardStateTests extends KeyboardStateNonDistinctTests { @Override - protected void setUp() throws Exception { - super.setUp(); - - mSwitcher = new MockKeyboardSwitcher(); - - final String layoutSwitchBackSymbols = ""; - final boolean hasDistinctMultitouch = true; - mSwitcher.loadKeyboard(layoutSwitchBackSymbols, hasDistinctMultitouch); - } - - // Argument for KeyboardState.onPressShift and onReleaseShift. - private static final boolean NOT_SLIDING = false; - private static final boolean SLIDING = true; - // Argument for KeyboardState.onCodeInput. - private static final boolean SINGLE = true; - private static final boolean MULTI = false; - static final boolean NO_AUTO_CAPS = false; - private static final boolean AUTO_CAPS = true; - - private void assertAlphabetNormal() { - assertTrue(mSwitcher.assertAlphabetNormal()); - } - - private void assertAlphabetManualShifted() { - assertTrue(mSwitcher.assertAlphabetManualShifted()); - } - - private void assertAlphabetAutomaticShifted() { - assertTrue(mSwitcher.assertAlphabetAutomaticShifted()); - } - - private void assertAlphabetShiftLocked() { - assertTrue(mSwitcher.assertAlphabetShiftLocked()); - } - - private void assertSymbolsNormal() { - assertTrue(mSwitcher.assertSymbolsNormal()); - } - - private void assertSymbolsShifted() { - assertTrue(mSwitcher.assertSymbolsShifted()); - } - - // Initial state test. - public void testLoadKeyboard() { - assertAlphabetNormal(); - } - - // Shift key in alphabet mode. - public void testShift() { - // Press/release shift key, enter into shift state. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Press/release shift key, back to normal state. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - - // Press/release shift key, enter into shift state. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Press/release letter key, snap back to normal state. - mSwitcher.onOtherKeyPressed(); - mSwitcher.onCodeInput('Z', SINGLE); - assertAlphabetNormal(); + public boolean hasDistinctMultitouch() { + return true; } // Shift key chording input. @@ -117,59 +45,6 @@ public class KeyboardStateTests extends AndroidTestCase { assertAlphabetNormal(); } - // Shift key sliding input. - public void testShiftSliding() { - // Press shift key. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Slide out shift key. - mSwitcher.onReleaseShift(SLIDING); - assertAlphabetManualShifted(); - - // Enter into letter key. - mSwitcher.onOtherKeyPressed(); - assertAlphabetManualShifted(); - // Release letter key, snap back to alphabet. - mSwitcher.onCodeInput('Z', SINGLE); - assertAlphabetNormal(); - } - - private void enterSymbolsMode() { - // Press/release "?123" key. - mSwitcher.onPressSymbol(); - assertSymbolsNormal(); - mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); - mSwitcher.onReleaseSymbol(); - assertSymbolsNormal(); - } - - private void leaveSymbolsMode() { - // Press/release "ABC" key. - mSwitcher.onPressSymbol(); - assertAlphabetNormal(); - mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); - assertAlphabetNormal(); - } - - // Switching between alphabet and symbols. - public void testAlphabetAndSymbols() { - enterSymbolsMode(); - leaveSymbolsMode(); - } - - // Switching between alphabet shift locked and symbols. - public void testAlphabetShiftLockedAndSymbols() { - enterShiftLockWithLongPressShift(); - enterSymbolsMode(); - - // Press/release "ABC" key, switch back to shift locked mode. - mSwitcher.onPressSymbol(); - assertAlphabetShiftLocked(); - mSwitcher.onCodeInput(Keyboard.CODE_SWITCH_ALPHA_SYMBOL, SINGLE); - mSwitcher.onReleaseSymbol(); - assertAlphabetShiftLocked(); - } - // Symbols key chording input. public void testSymbolsChording() { // Press symbols key and hold, enter into choring shift state. @@ -191,138 +66,6 @@ public class KeyboardStateTests extends AndroidTestCase { assertAlphabetNormal(); } - // Symbols key sliding input. - public void testSymbolsSliding() { - // Press "123?" key. - mSwitcher.onPressSymbol(); - assertSymbolsNormal(); - // Slide out from "123?" key. - mSwitcher.onReleaseSymbol(); - assertSymbolsNormal(); - - // Enter into letter key. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - // Release letter key, snap back to alphabet. - mSwitcher.onCodeInput('z', SINGLE); - assertAlphabetNormal(); - } - - // Switching between symbols and symbols shifted. - public void testSymbolsAndSymbolsShifted() { - enterSymbolsMode(); - - // Press/release "=\<" key. - mSwitcher.onPressShift(NOT_SLIDING); - assertSymbolsShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertSymbolsShifted(); - - // Press/release "?123" key. - mSwitcher.onPressShift(NOT_SLIDING); - assertSymbolsNormal(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertSymbolsNormal(); - - leaveSymbolsMode(); - } - - // Symbols shift sliding input - public void testSymbolsShiftSliding() { - enterSymbolsMode(); - - // Press "=\<" key. - mSwitcher.onPressShift(NOT_SLIDING); - assertSymbolsShifted(); - // Slide out "=\<" key. - mSwitcher.onReleaseShift(SLIDING); - assertSymbolsShifted(); - - // Enter into symbol shifted letter key. - mSwitcher.onOtherKeyPressed(); - assertSymbolsShifted(); - // Release symbol shifted letter key, snap back to symbols. - mSwitcher.onCodeInput('~', SINGLE); - assertSymbolsNormal(); - } - - // Symbols shift sliding input from symbols shifted. - public void testSymbolsShiftSliding2() { - enterSymbolsMode(); - - // Press/release "=\<" key. - mSwitcher.onPressShift(NOT_SLIDING); - assertSymbolsShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertSymbolsShifted(); - - // Press "123?" key. - mSwitcher.onPressShift(NOT_SLIDING); - assertSymbolsNormal(); - // Slide out "123?" key. - mSwitcher.onReleaseShift(SLIDING); - assertSymbolsNormal(); - - // Enter into symbol letter key. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - // Release symbol letter key, snap back to symbols shift. - mSwitcher.onCodeInput('1', SINGLE); - assertSymbolsShifted(); - } - - // Automatic snap back to alphabet from symbols by space key. - public void testSnapBackBySpace() { - enterSymbolsMode(); - - // Enter a symbol letter. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.onCodeInput('1', SINGLE); - assertSymbolsNormal(); - // Enter space, snap back to alphabet. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.onCodeInput(Keyboard.CODE_SPACE, SINGLE); - assertAlphabetNormal(); - } - - // Automatic snap back to alphabet from symbols by registered letters. - public void testSnapBack() { - final String snapBackChars = "'"; - final int snapBackCode = snapBackChars.codePointAt(0); - final boolean hasDistinctMultitouch = true; - mSwitcher.loadKeyboard(snapBackChars, hasDistinctMultitouch); - - enterSymbolsMode(); - - // Enter a symbol letter. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.onCodeInput('1', SINGLE); - assertSymbolsNormal(); - // Enter snap back letter, snap back to alphabet. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - mSwitcher.onCodeInput(snapBackCode, SINGLE); - assertAlphabetNormal(); - } - - // Automatic upper case test - public void testAutomaticUpperCase() { - mSwitcher.setAutoCapsMode(AUTO_CAPS); - // Update shift state with auto caps enabled. - mSwitcher.updateShiftState(); - assertAlphabetAutomaticShifted(); - - // Press shift key. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Release shift key. - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - } - // Chording shift key in automatic upper case. public void testAutomaticUpperCaseChording() { mSwitcher.setAutoCapsMode(AUTO_CAPS); @@ -364,143 +107,5 @@ public class KeyboardStateTests extends AndroidTestCase { assertAlphabetNormal(); } - // Sliding from shift key in automatic upper case. - public void testAutomaticUpperCaseSliding() { - mSwitcher.setAutoCapsMode(AUTO_CAPS); - // Update shift state with auto caps enabled. - mSwitcher.updateShiftState(); - assertAlphabetAutomaticShifted(); - - // Press shift key. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Slide out shift key. - mSwitcher.onReleaseShift(SLIDING); - assertAlphabetManualShifted(); - // Enter into letter key. - mSwitcher.onOtherKeyPressed(); - assertAlphabetManualShifted(); - // Release letter key, snap back to alphabet. - mSwitcher.onCodeInput('Z', SINGLE); - assertAlphabetNormal(); - } - - // Sliding from symbol key in automatic upper case. - public void testAutomaticUpperCaseSliding2() { - mSwitcher.setAutoCapsMode(AUTO_CAPS); - // Update shift state with auto caps enabled. - mSwitcher.updateShiftState(); - assertAlphabetAutomaticShifted(); - - // Press "123?" key. - mSwitcher.onPressSymbol(); - assertSymbolsNormal(); - // Slide out "123?" key. - mSwitcher.onReleaseSymbol(); - assertSymbolsNormal(); - // Enter into symbol letter keys. - mSwitcher.onOtherKeyPressed(); - assertSymbolsNormal(); - // Release symbol letter key, snap back to alphabet. - mSwitcher.onCodeInput('1', SINGLE); - assertAlphabetNormal(); - } - - private void enterShiftLockWithLongPressShift() { - // Long press shift key - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Long press recognized in LatinKeyboardView.KeyTimerHandler. - mSwitcher.toggleCapsLock(); - assertAlphabetShiftLocked(); - mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE); - assertAlphabetShiftLocked(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetShiftLocked(); - } - - private void leaveShiftLockWithLongPressShift() { - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Long press recognized in LatinKeyboardView.KeyTimerHandler. - mSwitcher.toggleCapsLock(); - assertAlphabetNormal(); - mSwitcher.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE); - assertAlphabetNormal(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - } - - // Long press shift key. - // TODO: Move long press recognizing timer/logic into KeyboardState. - public void testLongPressShift() { - enterShiftLockWithLongPressShift(); - leaveShiftLockWithLongPressShift(); - } - - // Leave shift lock with single tap shift key. - public void testShiftInShiftLock() { - enterShiftLockWithLongPressShift(); - assertAlphabetShiftLocked(); - - // Tap shift key. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - } - - // Double tap shift key. - // TODO: Move double tap recognizing timer/logic into KeyboardState. - public void testDoubleTapShift() { - // First shift key tap. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetManualShifted(); - // Second shift key tap. - // Double tap recognized in LatinKeyboardView.KeyTimerHandler. - mSwitcher.toggleCapsLock(); - assertAlphabetShiftLocked(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); - assertAlphabetShiftLocked(); - - // First shift key tap. - mSwitcher.onPressShift(NOT_SLIDING); - assertAlphabetManualShifted(); - mSwitcher.onCodeInput(Keyboard.CODE_SHIFT, SINGLE); - assertAlphabetManualShifted(); - mSwitcher.onReleaseShift(NOT_SLIDING); - assertAlphabetNormal(); - // Second shift key tap. - // Second tap is ignored in LatinKeyboardView.KeyTimerHandler. - } - - // Update shift state. - public void testUpdateShiftState() { - mSwitcher.setAutoCapsMode(AUTO_CAPS); - // Update shift state. - mSwitcher.updateShiftState(); - assertAlphabetAutomaticShifted(); - } - - // Update shift state when shift locked. - public void testUpdateShiftStateInShiftLocked() { - mSwitcher.setAutoCapsMode(AUTO_CAPS); - enterShiftLockWithLongPressShift(); - assertAlphabetShiftLocked(); - // Update shift state when shift locked - mSwitcher.updateShiftState(); - assertAlphabetShiftLocked(); - } - // TODO: Multitouch test - - // TODO: Change focus test. - - // TODO: Change orientation test. } diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java index e4fa46fb1..d5c647cd2 100644 --- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java +++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java @@ -104,18 +104,10 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); } - public void toggleShift() { - mState.onToggleShift(); - } - public void toggleCapsLock() { mState.onToggleCapsLock(); } - public void toggleAlphabetAndSymbols() { - mState.onToggleAlphabetAndSymbols(); - } - public void updateShiftState() { mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); }