aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2010-08-19 18:20:09 +0900
committerTadashi G. Takaoka <takaoka@google.com>2010-08-20 11:42:28 +0900
commitf95e94722345ef291adc5833103c1e9210f67fc9 (patch)
tree014dc68350cd44de5d2b24c32401b2308008cad3 /java/src
parent103634dd8ddf8d6e893e94125e2108c61af2b7e5 (diff)
downloadlatinime-f95e94722345ef291adc5833103c1e9210f67fc9.tar.gz
latinime-f95e94722345ef291adc5833103c1e9210f67fc9.tar.xz
latinime-f95e94722345ef291adc5833103c1e9210f67fc9.zip
Refactor shift state and caps lock state handling code.
Move setShifted and setShifLocked methods to KeyboardSwitcher, then delegate to LatinKeyboardView. Bug: 2910379 Change-Id: I5dba70ec0dfc7a1ed67f1e05d54a2bd92252ed24
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/KeyboardSwitcher.java13
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java64
-rw-r--r--java/src/com/android/inputmethod/latin/LatinKeyboardView.java10
3 files changed, 56 insertions, 31 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index ed6adce9e..d04930303 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -24,6 +24,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.inputmethodservice.Keyboard;
import android.preference.PreferenceManager;
import android.view.InflateException;
@@ -343,6 +344,18 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false;
}
+ void setShifted(boolean shifted) {
+ if (mInputView != null) {
+ mInputView.setShifted(shifted);
+ }
+ }
+
+ void setShiftLocked(boolean shiftLocked) {
+ if (mInputView != null) {
+ mInputView.setShiftLocked(shiftLocked);
+ }
+ }
+
void toggleShift() {
if (mCurrentId.equals(mSymbolsId)) {
LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3df0a152e..9bd16adb2 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -195,6 +195,7 @@ public class LatinIME extends InputMethodService
private boolean mAutoCorrectEnabled;
private boolean mBigramSuggestionEnabled;
private boolean mAutoCorrectOn;
+ // TODO move this state variable outside LatinIME
private boolean mCapsLock;
private boolean mPasswordText;
private boolean mVibrateOn;
@@ -967,10 +968,8 @@ public class LatinIME extends InputMethodService
public void updateShiftKeyState(EditorInfo attr) {
InputConnection ic = getCurrentInputConnection();
- if (attr != null && mKeyboardSwitcher.getInputView() != null
- && mKeyboardSwitcher.isAlphabetMode() && ic != null) {
- mKeyboardSwitcher.getInputView().setShifted(
- mCapsLock || getCursorCapsMode(ic, attr) != 0);
+ if (attr != null && mKeyboardSwitcher.isAlphabetMode() && ic != null) {
+ mKeyboardSwitcher.setShifted(mCapsLock || getCursorCapsMode(ic, attr) != 0);
}
}
@@ -1106,11 +1105,7 @@ public class LatinIME extends InputMethodService
toggleLanguage(false, false);
break;
case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS:
- if (mCapsLock) {
- handleShift();
- } else {
- toggleCapsLock();
- }
+ handleCapsLock();
break;
case Keyboard.KEYCODE_MODE_CHANGE:
changeKeyboardMode();
@@ -1235,13 +1230,35 @@ public class LatinIME extends InputMethodService
private void handleShift() {
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
- if (mKeyboardSwitcher.isAlphabetMode()) {
- // Alphabet keyboard
- checkToggleCapsLock();
- mKeyboardSwitcher.getInputView().setShifted(mCapsLock
- || !mKeyboardSwitcher.getInputView().isShifted());
+ KeyboardSwitcher switcher = mKeyboardSwitcher;
+ LatinKeyboardView inputView = switcher.getInputView();
+ if (switcher.isAlphabetMode()) {
+ if (mCapsLock) {
+ mCapsLock = false;
+ switcher.setShifted(false);
+ } else if (inputView != null) {
+ if (inputView.isShifted()) {
+ mCapsLock = true;
+ switcher.setShiftLocked(true);
+ } else {
+ switcher.setShifted(true);
+ }
+ }
} else {
- mKeyboardSwitcher.toggleShift();
+ switcher.toggleShift();
+ }
+ }
+
+ private void handleCapsLock() {
+ mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
+ KeyboardSwitcher switcher = mKeyboardSwitcher;
+ if (switcher.isAlphabetMode()) {
+ mCapsLock = !mCapsLock;
+ if (mCapsLock) {
+ switcher.setShiftLocked(true);
+ } else {
+ switcher.setShifted(false);
+ }
}
}
@@ -1405,20 +1422,6 @@ public class LatinIME extends InputMethodService
mWordHistory.add(entry);
}
- private void checkToggleCapsLock() {
- if (mKeyboardSwitcher.getInputView().getKeyboard().isShifted()) {
- toggleCapsLock();
- }
- }
-
- private void toggleCapsLock() {
- mCapsLock = !mCapsLock;
- if (mKeyboardSwitcher.isAlphabetMode()) {
- ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setShiftLocked(
- mCapsLock);
- }
- }
-
private void postUpdateSuggestions() {
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
@@ -2414,8 +2417,7 @@ public class LatinIME extends InputMethodService
private void changeKeyboardMode() {
mKeyboardSwitcher.toggleSymbols();
if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) {
- ((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setShiftLocked(
- mCapsLock);
+ mKeyboardSwitcher.setShiftLocked(mCapsLock);
}
updateShiftKeyState(getCurrentInputEditorInfo());
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
index bce2cde25..38d9cefb1 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboardView.java
@@ -124,6 +124,16 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
return label;
}
+ public boolean setShiftLocked(boolean shiftLocked) {
+ Keyboard keyboard = getKeyboard();
+ if (keyboard != null && keyboard instanceof LatinKeyboard) {
+ ((LatinKeyboard)keyboard).setShiftLocked(shiftLocked);
+ invalidateAllKeys();
+ return true;
+ }
+ return false;
+ }
+
/**
* This function checks to see if we need to handle any sudden jumps in the pointer location
* that could be due to a multi-touch being treated as a move by the firmware or hardware.