From 42e8c64a042476f555da5015558d51f96aaeb7fd Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 16 Nov 2011 16:00:02 -0800 Subject: [PATCH] Fix long press caps lock handling Bug: 5627467 Change-Id: I3850f283d44da81ecb22fc4e6d8aa574f5fcf65f --- .../inputmethod/keyboard/Keyboard.java | 4 ++++ .../keyboard/KeyboardSwitcher.java | 10 ++++++++ .../keyboard/LatinKeyboardView.java | 23 ++++++++++++++----- .../keyboard/internal/KeyboardShiftState.java | 4 ++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index 8d40e7aa5..a8bc74551 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -169,6 +169,10 @@ public class Keyboard { return mShiftState.isShiftLocked(); } + public boolean isShiftLockShifted() { + return mShiftState.isShiftLockShifted(); + } + public boolean setShifted(boolean newShiftState) { for (final Key key : mShiftKeys) { if (!newShiftState && !mShiftState.isShiftLocked()) { diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 139e5eddf..4d30077e3 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -386,6 +386,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha return false; } + private boolean isShiftLockShifted() { + LatinKeyboard latinKeyboard = getLatinKeyboard(); + if (latinKeyboard != null) + return latinKeyboard.isShiftLockShifted(); + return false; + } + public boolean isAutomaticTemporaryUpperCase() { LatinKeyboard latinKeyboard = getLatinKeyboard(); if (latinKeyboard != null) @@ -559,6 +566,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha if (shiftKeyState.isMomentary()) { // After chording input while normal state. toggleShift(); + } else if (isShiftLocked() && !isShiftLockShifted() && shiftKeyState.isPressing() + && !withSliding) { + // Shift has been long pressed, ignore this release. } else if (isShiftLocked() && !shiftKeyState.isIgnoring() && !withSliding) { // Shift has been pressed without chording while caps lock state. toggleCapsLock(); diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 9d97cbf6c..b09628b3d 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -400,18 +400,22 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke if (primaryCode == Keyboard.CODE_DIGIT0 && latinKeyboard.isPhoneKeyboard()) { tracker.onLongPressed(); // Long pressing on 0 in phone number keypad gives you a '+'. - return invokeOnKey(Keyboard.CODE_PLUS); + invokeCodeInput(Keyboard.CODE_PLUS); + invokeReleaseKey(primaryCode); + return true; } if (primaryCode == Keyboard.CODE_SHIFT && latinKeyboard.isAlphaKeyboard()) { tracker.onLongPressed(); - return invokeOnKey(Keyboard.CODE_CAPSLOCK); + invokeCodeInput(Keyboard.CODE_CAPSLOCK); + invokeReleaseKey(primaryCode); + return true; } } if (primaryCode == Keyboard.CODE_SETTINGS || primaryCode == Keyboard.CODE_SPACE) { // Both long pressing settings key and space key invoke IME switcher dialog. - if (getKeyboardActionListener().onCustomRequest( - LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { + if (invokeCustomRequest(LatinIME.CODE_SHOW_INPUT_METHOD_PICKER)) { tracker.onLongPressed(); + invokeReleaseKey(primaryCode); return true; } else { return openMoreKeysPanel(parentKey, tracker); @@ -421,11 +425,18 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } } - private boolean invokeOnKey(int primaryCode) { + private boolean invokeCustomRequest(int code) { + return getKeyboardActionListener().onCustomRequest(code); + } + + private void invokeCodeInput(int primaryCode) { getKeyboardActionListener().onCodeInput(primaryCode, null, KeyboardActionListener.NOT_A_TOUCH_COORDINATE, KeyboardActionListener.NOT_A_TOUCH_COORDINATE); - return true; + } + + private void invokeReleaseKey(int primaryCode) { + getKeyboardActionListener().onRelease(primaryCode, false); } private boolean openMoreKeysPanel(Key parentKey, PointerTracker tracker) { diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java index fd98456a8..28a53cedc 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardShiftState.java @@ -103,6 +103,10 @@ public class KeyboardShiftState { return mState == SHIFT_LOCKED || mState == SHIFT_LOCK_SHIFTED; } + public boolean isShiftLockShifted() { + return mState == SHIFT_LOCK_SHIFTED; + } + public boolean isAutomaticTemporaryUpperCase() { return mState == AUTO_SHIFTED; }