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
main
Tadashi G. Takaoka 2010-08-19 18:20:09 +09:00
parent 103634dd8d
commit f95e947223
3 changed files with 56 additions and 31 deletions

View File

@ -24,6 +24,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.inputmethodservice.Keyboard;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.InflateException; import android.view.InflateException;
@ -343,6 +344,18 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false; return false;
} }
void setShifted(boolean shifted) {
if (mInputView != null) {
mInputView.setShifted(shifted);
}
}
void setShiftLocked(boolean shiftLocked) {
if (mInputView != null) {
mInputView.setShiftLocked(shiftLocked);
}
}
void toggleShift() { void toggleShift() {
if (mCurrentId.equals(mSymbolsId)) { if (mCurrentId.equals(mSymbolsId)) {
LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId); LatinKeyboard symbolsKeyboard = getKeyboard(mSymbolsId);

View File

@ -195,6 +195,7 @@ public class LatinIME extends InputMethodService
private boolean mAutoCorrectEnabled; private boolean mAutoCorrectEnabled;
private boolean mBigramSuggestionEnabled; private boolean mBigramSuggestionEnabled;
private boolean mAutoCorrectOn; private boolean mAutoCorrectOn;
// TODO move this state variable outside LatinIME
private boolean mCapsLock; private boolean mCapsLock;
private boolean mPasswordText; private boolean mPasswordText;
private boolean mVibrateOn; private boolean mVibrateOn;
@ -967,10 +968,8 @@ public class LatinIME extends InputMethodService
public void updateShiftKeyState(EditorInfo attr) { public void updateShiftKeyState(EditorInfo attr) {
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
if (attr != null && mKeyboardSwitcher.getInputView() != null if (attr != null && mKeyboardSwitcher.isAlphabetMode() && ic != null) {
&& mKeyboardSwitcher.isAlphabetMode() && ic != null) { mKeyboardSwitcher.setShifted(mCapsLock || getCursorCapsMode(ic, attr) != 0);
mKeyboardSwitcher.getInputView().setShifted(
mCapsLock || getCursorCapsMode(ic, attr) != 0);
} }
} }
@ -1106,11 +1105,7 @@ public class LatinIME extends InputMethodService
toggleLanguage(false, false); toggleLanguage(false, false);
break; break;
case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS: case LatinKeyboardView.KEYCODE_SHIFT_LONGPRESS:
if (mCapsLock) { handleCapsLock();
handleShift();
} else {
toggleCapsLock();
}
break; break;
case Keyboard.KEYCODE_MODE_CHANGE: case Keyboard.KEYCODE_MODE_CHANGE:
changeKeyboardMode(); changeKeyboardMode();
@ -1235,13 +1230,35 @@ public class LatinIME extends InputMethodService
private void handleShift() { private void handleShift() {
mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE); mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE);
if (mKeyboardSwitcher.isAlphabetMode()) { KeyboardSwitcher switcher = mKeyboardSwitcher;
// Alphabet keyboard LatinKeyboardView inputView = switcher.getInputView();
checkToggleCapsLock(); if (switcher.isAlphabetMode()) {
mKeyboardSwitcher.getInputView().setShifted(mCapsLock if (mCapsLock) {
|| !mKeyboardSwitcher.getInputView().isShifted()); mCapsLock = false;
switcher.setShifted(false);
} else if (inputView != null) {
if (inputView.isShifted()) {
mCapsLock = true;
switcher.setShiftLocked(true);
} else { } else {
mKeyboardSwitcher.toggleShift(); switcher.setShifted(true);
}
}
} else {
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); 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() { private void postUpdateSuggestions() {
mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS); mHandler.removeMessages(MSG_UPDATE_SUGGESTIONS);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100); mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_UPDATE_SUGGESTIONS), 100);
@ -2414,8 +2417,7 @@ public class LatinIME extends InputMethodService
private void changeKeyboardMode() { private void changeKeyboardMode() {
mKeyboardSwitcher.toggleSymbols(); mKeyboardSwitcher.toggleSymbols();
if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) { if (mCapsLock && mKeyboardSwitcher.isAlphabetMode()) {
((LatinKeyboard) mKeyboardSwitcher.getInputView().getKeyboard()).setShiftLocked( mKeyboardSwitcher.setShiftLocked(mCapsLock);
mCapsLock);
} }
updateShiftKeyState(getCurrentInputEditorInfo()); updateShiftKeyState(getCurrentInputEditorInfo());

View File

@ -124,6 +124,16 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
return label; 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 * 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. * that could be due to a multi-touch being treated as a move by the firmware or hardware.