Merge setManualTemporaryUpperCase and setAutomaticTemporaryUpperCase

Bug: 5708602
Change-Id: I6a0b5f0dcccbb6331a271cd61a48c474a7800289
main
Tadashi G. Takaoka 2011-12-05 18:16:40 +09:00
parent 46831d5a4b
commit 6ddb07433f
1 changed files with 19 additions and 18 deletions

View File

@ -69,6 +69,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private Resources mResources; private Resources mResources;
private KeyboardState mState; private KeyboardState mState;
private static final int UNSHIFT = 0;
private static final int MANUAL_SHIFT = 1;
private static final int AUTOMATIC_SHIFT = 2;
private KeyboardId mMainKeyboardId; private KeyboardId mMainKeyboardId;
private KeyboardId mSymbolsKeyboardId; private KeyboardId mSymbolsKeyboardId;
@ -391,7 +394,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false; return false;
} }
public boolean isAutomaticTemporaryUpperCase() { private boolean isAutomaticTemporaryUpperCase() {
LatinKeyboard latinKeyboard = getLatinKeyboard(); LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null) if (latinKeyboard != null)
return latinKeyboard.isAutomaticTemporaryUpperCase(); return latinKeyboard.isAutomaticTemporaryUpperCase();
@ -412,13 +415,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false; return false;
} }
private void setManualTemporaryUpperCase(boolean shifted) { private void setShift(int shiftMode) {
LatinKeyboard latinKeyboard = getLatinKeyboard(); LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null) { if (latinKeyboard == null)
return;
if (shiftMode == AUTOMATIC_SHIFT) {
latinKeyboard.setAutomaticTemporaryUpperCase();
mKeyboardView.invalidateAllKeys();
} else {
final boolean shifted = (shiftMode == MANUAL_SHIFT);
// On non-distinct multi touch panel device, we should also turn off the shift locked // On non-distinct multi touch panel device, we should also turn off the shift locked
// state when shift key is pressed to go to normal mode. // state when shift key is pressed to go to normal mode.
// On the other hand, on distinct multi touch panel device, turning off the shift locked // On the other hand, on distinct multi touch panel device, turning off the shift
// state with shift key pressing is handled by onReleaseShift(). // locked state with shift key pressing is handled by onReleaseShift().
if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) { if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) {
latinKeyboard.setShiftLocked(false); latinKeyboard.setShiftLocked(false);
} }
@ -428,14 +437,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} }
} }
private void setAutomaticTemporaryUpperCase() {
LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null) {
latinKeyboard.setAutomaticTemporaryUpperCase();
mKeyboardView.invalidateAllKeys();
}
}
private void setShiftLocked(boolean shiftLocked) { private void setShiftLocked(boolean shiftLocked) {
LatinKeyboard latinKeyboard = getLatinKeyboard(); LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) { if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) {
@ -454,7 +455,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
+ " state=" + mState); + " state=" + mState);
} }
if (isAlphabetMode()) { if (isAlphabetMode()) {
setManualTemporaryUpperCase(!isShiftedOrShiftLocked()); setShift(isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
} else { } else {
toggleShiftInSymbol(); toggleShiftInSymbol();
} }
@ -516,9 +517,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
if (!isShiftLocked && !mState.isShiftKeyIgnoring()) { if (!isShiftLocked && !mState.isShiftKeyIgnoring()) {
if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) { if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) {
// Only when shift key is releasing, automatic temporary upper case will be set. // Only when shift key is releasing, automatic temporary upper case will be set.
setAutomaticTemporaryUpperCase(); setShift(AUTOMATIC_SHIFT);
} else { } else {
setManualTemporaryUpperCase(mState.isShiftKeyMomentary()); setShift(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT);
} }
} }
} }
@ -541,11 +542,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
if (isShiftLocked) { if (isShiftLocked) {
// Shift key is pressed while caps lock state, we will treat this state as shifted // Shift key is pressed while caps lock state, we will treat this state as shifted
// caps lock state and mark as if shift key pressed while normal state. // caps lock state and mark as if shift key pressed while normal state.
setManualTemporaryUpperCase(true); setShift(MANUAL_SHIFT);
} else if (isAutomaticTemporaryUpperCase) { } else if (isAutomaticTemporaryUpperCase) {
// Shift key is pressed while automatic temporary upper case, we have to move to // Shift key is pressed while automatic temporary upper case, we have to move to
// manual temporary upper case. // manual temporary upper case.
setManualTemporaryUpperCase(true); setShift(MANUAL_SHIFT);
} else if (isShiftedOrShiftLocked) { } else if (isShiftedOrShiftLocked) {
// In manual upper case state, we just record shift key has been pressing while // In manual upper case state, we just record shift key has been pressing while
// shifted state. // shifted state.