Merge "Pressing shift could turn off shift state while auto capitalize mode" into honeycomb

main
Tadashi G. Takaoka 2011-01-18 19:18:01 -08:00 committed by Android (Google) Code Review
commit 08ca36d038
3 changed files with 54 additions and 11 deletions

View File

@ -330,6 +330,10 @@ public class Keyboard {
return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCase(); return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCase();
} }
public boolean isManualTemporaryUpperCaseFromAuto() {
return isAlphaKeyboard() && mShiftState.isManualTemporaryUpperCaseFromAuto();
}
public KeyboardShiftState getKeyboardShiftState() { public KeyboardShiftState getKeyboardShiftState() {
return mShiftState; return mShiftState;
} }

View File

@ -24,25 +24,37 @@ public class KeyboardShiftState {
private static final int NORMAL = 0; private static final int NORMAL = 0;
private static final int MANUAL_SHIFTED = 1; private static final int MANUAL_SHIFTED = 1;
private static final int SHIFT_LOCKED = 2; private static final int MANUAL_SHIFTED_FROM_AUTO = 2;
private static final int AUTO_SHIFTED = 3; private static final int AUTO_SHIFTED = 3;
private static final int SHIFT_LOCK_SHIFTED = 4; private static final int SHIFT_LOCKED = 4;
private static final int SHIFT_LOCK_SHIFTED = 5;
private int mState = NORMAL; private int mState = NORMAL;
public boolean setShifted(boolean newShiftState) { public boolean setShifted(boolean newShiftState) {
final int oldState = mState; final int oldState = mState;
if (newShiftState) { if (newShiftState) {
if (oldState == NORMAL || oldState == AUTO_SHIFTED) { switch (oldState) {
case NORMAL:
mState = MANUAL_SHIFTED; mState = MANUAL_SHIFTED;
} else if (oldState == SHIFT_LOCKED) { break;
case AUTO_SHIFTED:
mState = MANUAL_SHIFTED_FROM_AUTO;
break;
case SHIFT_LOCKED:
mState = SHIFT_LOCK_SHIFTED; mState = SHIFT_LOCK_SHIFTED;
break;
} }
} else { } else {
if (oldState == MANUAL_SHIFTED || oldState == AUTO_SHIFTED) { switch (oldState) {
case MANUAL_SHIFTED:
case MANUAL_SHIFTED_FROM_AUTO:
case AUTO_SHIFTED:
mState = NORMAL; mState = NORMAL;
} else if (oldState == SHIFT_LOCK_SHIFTED) { break;
case SHIFT_LOCK_SHIFTED:
mState = SHIFT_LOCKED; mState = SHIFT_LOCKED;
break;
} }
} }
if (DEBUG) if (DEBUG)
@ -53,11 +65,21 @@ public class KeyboardShiftState {
public void setShiftLocked(boolean newShiftLockState) { public void setShiftLocked(boolean newShiftLockState) {
final int oldState = mState; final int oldState = mState;
if (newShiftLockState) { if (newShiftLockState) {
if (oldState == NORMAL || oldState == MANUAL_SHIFTED || oldState == AUTO_SHIFTED) switch (oldState) {
case NORMAL:
case MANUAL_SHIFTED:
case MANUAL_SHIFTED_FROM_AUTO:
case AUTO_SHIFTED:
mState = SHIFT_LOCKED; mState = SHIFT_LOCKED;
break;
}
} else { } else {
if (oldState == SHIFT_LOCKED || oldState == SHIFT_LOCK_SHIFTED) switch (oldState) {
case SHIFT_LOCKED:
case SHIFT_LOCK_SHIFTED:
mState = NORMAL; mState = NORMAL;
break;
}
} }
if (DEBUG) if (DEBUG)
Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState) Log.d(TAG, "setShiftLocked(" + newShiftLockState + "): " + toString(oldState)
@ -84,7 +106,12 @@ public class KeyboardShiftState {
} }
public boolean isManualTemporaryUpperCase() { public boolean isManualTemporaryUpperCase() {
return mState == MANUAL_SHIFTED || mState == SHIFT_LOCK_SHIFTED; return mState == MANUAL_SHIFTED || mState == MANUAL_SHIFTED_FROM_AUTO
|| mState == SHIFT_LOCK_SHIFTED;
}
public boolean isManualTemporaryUpperCaseFromAuto() {
return mState == MANUAL_SHIFTED_FROM_AUTO;
} }
@Override @Override
@ -96,8 +123,9 @@ public class KeyboardShiftState {
switch (state) { switch (state) {
case NORMAL: return "NORMAL"; case NORMAL: return "NORMAL";
case MANUAL_SHIFTED: return "MANUAL_SHIFTED"; case MANUAL_SHIFTED: return "MANUAL_SHIFTED";
case SHIFT_LOCKED: return "SHIFT_LOCKED"; case MANUAL_SHIFTED_FROM_AUTO: return "MANUAL_SHIFTED_FROM_AUTO";
case AUTO_SHIFTED: return "AUTO_SHIFTED"; case AUTO_SHIFTED: return "AUTO_SHIFTED";
case SHIFT_LOCKED: return "SHIFT_LOCKED";
case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED"; case SHIFT_LOCK_SHIFTED: return "SHIFT_LOCK_SHIFTED";
default: return "UKNOWN"; default: return "UKNOWN";
} }

View File

@ -327,6 +327,13 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return false; return false;
} }
private boolean isManualTemporaryUpperCaseFromAuto() {
LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null)
return latinKeyboard.isManualTemporaryUpperCaseFromAuto();
return false;
}
private void setManualTemporaryUpperCase(boolean shifted) { private void setManualTemporaryUpperCase(boolean shifted) {
LatinKeyboard latinKeyboard = getLatinKeyboard(); LatinKeyboard latinKeyboard = getLatinKeyboard();
if (latinKeyboard != null) { if (latinKeyboard != null) {
@ -482,6 +489,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
} else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()) { } else if (isShiftedOrShiftLocked() && shiftKeyState.isPressingOnShifted()) {
// Shift has been pressed without chording while shifted state. // Shift has been pressed without chording while shifted state.
toggleShift(); toggleShift();
} else if (isManualTemporaryUpperCaseFromAuto() && shiftKeyState.isPressing()) {
// Shift has been pressed without chording while manual temporary upper case
// transited from automatic temporary upper case.
toggleShift();
} }
} }
shiftKeyState.onRelease(); shiftKeyState.onRelease();