aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java30
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java22
-rw-r--r--java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java6
-rw-r--r--java/src/com/android/inputmethod/latin/ContactsDictionary.java6
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java4
-rw-r--r--java/src/com/android/inputmethod/latin/UserDictionary.java6
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java130
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java11
-rw-r--r--tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java4
10 files changed, 191 insertions, 33 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index e50d922ea..37fa674c2 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -71,7 +71,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
private InputView mCurrentInputView;
private LatinKeyboardView mKeyboardView;
- private LatinIME mInputMethodService;
+ private LatinIME mLatinIME;
private Resources mResources;
private KeyboardState mState;
@@ -95,17 +95,17 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Intentional empty constructor for singleton.
}
- public static void init(LatinIME ims, SharedPreferences prefs) {
- sInstance.initInternal(ims, prefs);
+ public static void init(LatinIME latinIme, SharedPreferences prefs) {
+ sInstance.initInternal(latinIme, prefs);
}
- private void initInternal(LatinIME ims, SharedPreferences prefs) {
- mInputMethodService = ims;
- mResources = ims.getResources();
+ private void initInternal(LatinIME latinIme, SharedPreferences prefs) {
+ mLatinIME = latinIme;
+ mResources = latinIme.getResources();
mPrefs = prefs;
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mState = new KeyboardState(this);
- setContextThemeWrapper(ims, getKeyboardTheme(ims, prefs));
+ setContextThemeWrapper(latinIme, getKeyboardTheme(latinIme, prefs));
mForceNonDistinctMultitouch = prefs.getBoolean(
DebugSettings.FORCE_NON_DISTINCT_MULTITOUCH_KEY, false);
}
@@ -194,14 +194,14 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
* Update keyboard shift state triggered by connected EditText status change.
*/
public void updateShiftState() {
- mState.onUpdateShiftState(mInputMethodService.getCurrentAutoCapsState());
+ mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
}
public void onPressKey(int code) {
if (isVibrateAndSoundFeedbackRequired()) {
- mInputMethodService.hapticAndAudioFeedback(code);
+ mLatinIME.hapticAndAudioFeedback(code);
}
- mState.onPressKey(code);
+ mState.onPressKey(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
}
public void onReleaseKey(int code, boolean withSliding) {
@@ -257,7 +257,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void requestUpdatingShiftState() {
- mState.onUpdateShiftState(mInputMethodService.getCurrentAutoCapsState());
+ mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
}
// Implements {@link KeyboardState.SwitchActions}.
@@ -311,7 +311,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}.
@Override
public void hapticAndAudioFeedback(int code) {
- mInputMethodService.hapticAndAudioFeedback(code);
+ mLatinIME.hapticAndAudioFeedback(code);
}
public void onLongPressTimeout(int code) {
@@ -338,7 +338,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
* Updates state machine to figure out when to automatically switch back to the previous mode.
*/
public void onCodeInput(int code) {
- mState.onCodeInput(code, isSinglePointer(), mInputMethodService.getCurrentAutoCapsState());
+ mState.onCodeInput(code, isSinglePointer(), mLatinIME.getCurrentAutoCapsState());
}
public LatinKeyboardView getKeyboardView() {
@@ -354,7 +354,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
boolean tryGC = true;
for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) {
try {
- setContextThemeWrapper(mInputMethodService, mKeyboardTheme);
+ setContextThemeWrapper(mLatinIME, mKeyboardTheme);
mCurrentInputView = (InputView)LayoutInflater.from(mThemeContext).inflate(
R.layout.input_view, null);
tryGC = false;
@@ -368,7 +368,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
mKeyboardView = (LatinKeyboardView) mCurrentInputView.findViewById(R.id.keyboard_view);
- mKeyboardView.setKeyboardActionListener(mInputMethodService);
+ mKeyboardView.setKeyboardActionListener(mLatinIME);
if (mForceNonDistinctMultitouch) {
mKeyboardView.setDistinctMultitouch(false);
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 2045b0c82..51a0f537f 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -389,11 +389,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
* @param keyboard the keyboard to display in this view
*/
public void setKeyboard(Keyboard keyboard) {
- // Remove any pending messages.
- mDrawingHandler.cancelAllMessages();
- if (mKeyboard != null) {
- PointerTracker.dismissAllKeyPreviews();
- }
mKeyboard = keyboard;
LatinImeLogger.onSetKeyboard(keyboard);
requestLayout();
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index e3661a9f8..c85122ad3 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -30,7 +30,7 @@ import com.android.inputmethod.latin.define.ProductionFlag;
* This class contains all keyboard state transition logic.
*
* The input events are {@link #onLoadKeyboard(String)}, {@link #onSaveKeyboardState()},
- * {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)},
+ * {@link #onPressKey(int, boolean, int)}, {@link #onReleaseKey(int, boolean)},
* {@link #onCodeInput(int, boolean, int)}, {@link #onCancelInput(boolean)},
* {@link #onUpdateShiftState(int)}, {@link #onLongPressTimeout(int)}.
*
@@ -297,9 +297,10 @@ public class KeyboardState {
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
}
- public void onPressKey(int code) {
+ public void onPressKey(int code, boolean isSinglePointer, int autoCaps) {
if (DEBUG_EVENT) {
- Log.d(TAG, "onPressKey: code=" + Keyboard.printableCode(code) + " " + this);
+ Log.d(TAG, "onPressKey: code=" + Keyboard.printableCode(code)
+ + " single=" + isSinglePointer + " autoCaps=" + autoCaps + " " + this);
}
if (ProductionFlag.IS_EXPERIMENTAL) {
ResearchLogger.keyboardState_onPressKey(code, this);
@@ -313,6 +314,21 @@ public class KeyboardState {
mSwitchActions.cancelLongPressTimer();
mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
+ // It is required to reset the auto caps state when all of the following conditions
+ // are met:
+ // 1) two or more fingers are in action
+ // 2) in alphabet layout
+ // 3) not in all characters caps mode
+ // As for #3, please note that it's required to check even when the auto caps mode is
+ // off because, for example, we may be in the #1 state within the manual temporary
+ // shifted mode.
+ if (!isSinglePointer && mIsAlphabetMode && autoCaps != TextUtils.CAP_MODE_CHARACTERS) {
+ final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted()
+ || (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing());
+ if (needsToResetAutoCaps) {
+ mSwitchActions.setAlphabetKeyboard();
+ }
+ }
}
}
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
index 4b77473d9..0a09c845e 100644
--- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
@@ -149,7 +149,11 @@ public class ContactsBinaryDictionary extends ExpandableBinaryDictionary {
final Cursor cursor = mContext.getContentResolver().query(
Contacts.CONTENT_URI, PROJECTION_ID_ONLY, null, null, null);
if (cursor != null) {
- return cursor.getCount();
+ try {
+ return cursor.getCount();
+ } finally {
+ cursor.close();
+ }
}
return 0;
}
diff --git a/java/src/com/android/inputmethod/latin/ContactsDictionary.java b/java/src/com/android/inputmethod/latin/ContactsDictionary.java
index 83bc9046b..2f3395245 100644
--- a/java/src/com/android/inputmethod/latin/ContactsDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsDictionary.java
@@ -28,6 +28,12 @@ import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
+// TODO: This class is superseded by {@link ContactsBinaryDictionary}. Should be cleaned up.
+/**
+ * An expandable dictionary that stores the words from Contacts provider.
+ *
+ * @deprecated Use {@link ContactsBinaryDictionary}.
+ */
public class ContactsDictionary extends ExpandableDictionary {
private static final String[] PROJECTION = {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index e26b2dc25..b474a8558 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1056,6 +1056,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
| InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0;
if (noNeedToCheckCapsMode) return Constants.TextUtils.CAP_MODE_OFF;
+ // Avoid making heavy round-trip IPC calls of {@link InputConnection#getCursorCapsMode}
+ // unless needed.
+ if (mWordComposer.isComposingWord()) return Constants.TextUtils.CAP_MODE_OFF;
+
final InputConnection ic = getCurrentInputConnection();
if (ic == null) return Constants.TextUtils.CAP_MODE_OFF;
// TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls.
diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java
index ea57db57c..81e2fdce4 100644
--- a/java/src/com/android/inputmethod/latin/UserDictionary.java
+++ b/java/src/com/android/inputmethod/latin/UserDictionary.java
@@ -29,10 +29,12 @@ import com.android.inputmethod.keyboard.ProximityInfo;
import java.util.Arrays;
+// TODO: This class is superseded by {@link UserBinaryDictionary}. Should be cleaned up.
/**
* An expandable dictionary that stores the words in the user unigram dictionary.
- * To be deprecated: functionality being transferred to UserBinaryDictionary.
-*/
+ *
+ * @deprecated Use {@link UserBinaryDictionary}.
+ */
public class UserDictionary extends ExpandableDictionary {
// TODO: use Words.SHORTCUT when it's public in the SDK
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
index c2408c9c5..dc098db1e 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
@@ -34,6 +34,26 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED);
}
+ // Chording input in shifted.
+ public void testChordingShifted() {
+ // Press shift key, enter alphabet shifted.
+ pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
+
+ // Press shift key and hold, enter into choring shift state.
+ pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+ // Press/release letter key.
+ chordingPressAndReleaseKey('Z', ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
+ // Release shift key, switch back to alphabet shifted.
+ releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+
+ // Press "?123" key and hold, enter into choring symbols state.
+ pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED);
+ // Press/release symbol letter key.
+ chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
+ // Release "123?" key, switch back to alphabet shift unshifted.
+ releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED);
+ }
+
// Chording input in shift locked.
public void testChordingShiftLocked() {
// Long press shift key, enter alphabet shift locked.
@@ -240,4 +260,114 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Release shift key
releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
}
+
+ // Multi touch input in manual shifted.
+ public void testMultiTouchManualShifted() {
+ // Press/release shift key, enter into alphabet shifted.
+ pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
+
+ // Press 'X' key and hold
+ pressKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Press 'z' key and hold, switch back to alphabet unshifted.
+ chordingPressKey('z', ALPHABET_UNSHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_UNSHIFTED);
+ // Release 'z' key
+ releaseKey('z', ALPHABET_UNSHIFTED);
+ }
+
+ // Multi touch input in automatic upper case.
+ public void testMultiTouchAutomaticUpperCase() {
+ // Set auto word caps mode on.
+ setAutoCapsMode(CAP_MODE_WORDS);
+ // Update shift state with auto caps enabled.
+ pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
+
+ // Press 'X' key and hold
+ pressKey('X', ALPHABET_AUTOMATIC_SHIFTED);
+ // Press 'z' key and hold, switch back to alphabet unshifted.
+ chordingPressKey('z', ALPHABET_UNSHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_UNSHIFTED);
+ // Release 'z' key
+ releaseKey('z', ALPHABET_UNSHIFTED);
+ }
+
+ // Multi touch input in capitalize character mode.
+ public void testMultiTouchCapModeCharacter() {
+ // Set auto character caps mode on.
+ setAutoCapsMode(CAP_MODE_CHARACTERS);
+ // Update shift state with auto caps enabled.
+ pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
+
+ // Press 'X' key and hold
+ pressKey('X', ALPHABET_AUTOMATIC_SHIFTED);
+ // Press 'Z' key and hold, stay in automatic shifted mode.
+ chordingPressKey('Z', ALPHABET_AUTOMATIC_SHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_AUTOMATIC_SHIFTED);
+ // Release 'Z' key
+ releaseKey('Z', ALPHABET_AUTOMATIC_SHIFTED);
+ }
+
+ // Multi touch shift chording input in manual shifted.
+ public void testMultiTouchShiftChordingManualShifted() {
+ // Press/release shift key, enter into alphabet shifted.
+ pressAndReleaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED, ALPHABET_MANUAL_SHIFTED);
+
+ // Press shift key and hold, stays in alphabet shifted.
+ pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+ // Press 'X' key and hold
+ chordingPressKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Press 'Z' key and hold, stays in alphabet shifted.
+ chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Release 'Z' key
+ releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release shift key.
+ releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+ }
+
+ // Multi touch shift chording input in automatic upper case.
+ public void testMultiTouchShiftChordingAutomaticUpperCase() {
+ // Set auto word caps mode on.
+ setAutoCapsMode(CAP_MODE_WORDS);
+ // Update shift state with auto caps enabled.
+ pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
+
+ // Press shift key and hold, switch to alphabet shifted.
+ pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+ // Press 'X' key and hold
+ chordingPressKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Press 'Z' key and hold, stays in alphabet shifted.
+ chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Release 'Z' key
+ releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release shift key.
+ releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
+ }
+
+ // Multi touch shift chording input in capitalize character mode.
+ public void testMultiTouchShiftChordingCapModeCharacter() {
+ // Set auto character caps mode on.
+ setAutoCapsMode(CAP_MODE_CHARACTERS);
+ // Update shift state with auto caps enabled.
+ pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
+
+ // Press shift key and hold, switch to alphabet shifted.
+ pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+ // Press 'X' key and hold
+ chordingPressKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Press 'Z' key and hold, stay in automatic shifted mode.
+ chordingPressKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release 'X' key
+ releaseKey('X', ALPHABET_MANUAL_SHIFTED);
+ // Release 'Z' key
+ releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
+ // Release shift key.
+ releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
+ }
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
index bbe0dbde5..9472a1fe5 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateTestsBase.java
@@ -64,14 +64,14 @@ public class KeyboardStateTestsBase extends AndroidTestCase
assertLayout(afterRotate, mSwitcher.getLayoutId());
}
- private void pressKeyWithoutTimerExpire(int code, int afterPress) {
- mSwitcher.onPressKey(code);
+ private void pressKeyWithoutTimerExpire(int code, boolean isSinglePointer, int afterPress) {
+ mSwitcher.onPressKey(code, isSinglePointer);
assertLayout(afterPress, mSwitcher.getLayoutId());
}
public void pressKey(int code, int afterPress) {
mSwitcher.expireDoubleTapTimeout();
- pressKeyWithoutTimerExpire(code, afterPress);
+ pressKeyWithoutTimerExpire(code, true, afterPress);
}
public void releaseKey(int code, int afterRelease) {
@@ -86,7 +86,8 @@ public class KeyboardStateTestsBase extends AndroidTestCase
}
public void chordingPressKey(int code, int afterPress) {
- pressKey(code, afterPress);
+ mSwitcher.expireDoubleTapTimeout();
+ pressKeyWithoutTimerExpire(code, false, afterPress);
}
public void chordingReleaseKey(int code, int afterRelease) {
@@ -114,7 +115,7 @@ public class KeyboardStateTestsBase extends AndroidTestCase
}
public void secondPressAndReleaseKey(int code, int afterPress, int afterRelease) {
- pressKeyWithoutTimerExpire(code, afterPress);
+ pressKeyWithoutTimerExpire(code, true, afterPress);
releaseKey(code, afterRelease);
}
}
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
index 485ea61e7..dd4caadf1 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
@@ -174,8 +174,8 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
mState.onSaveKeyboardState();
}
- public void onPressKey(int code) {
- mState.onPressKey(code);
+ public void onPressKey(int code, boolean isSinglePointer) {
+ mState.onPressKey(code, isSinglePointer, mAutoCapsState);
}
public void onReleaseKey(int code, boolean withSliding) {