Call KeyboardState.onUpdateShiftState from onCodeInput if code is a normal letter
This will be helpful to write unit test code. Change-Id: Ib61cc46ac547084e0dc9ecd3a50814fecf08ace2main
parent
8edd306718
commit
ee4be6e3c6
|
@ -67,7 +67,9 @@ import java.util.Set;
|
||||||
public class Keyboard {
|
public class Keyboard {
|
||||||
private static final String TAG = Keyboard.class.getSimpleName();
|
private static final String TAG = Keyboard.class.getSimpleName();
|
||||||
|
|
||||||
/** Some common keys code. These should be aligned with values/keycodes.xml */
|
/** Some common keys code. Must be positive.
|
||||||
|
* These should be aligned with values/keycodes.xml
|
||||||
|
*/
|
||||||
public static final int CODE_ENTER = '\n';
|
public static final int CODE_ENTER = '\n';
|
||||||
public static final int CODE_TAB = '\t';
|
public static final int CODE_TAB = '\t';
|
||||||
public static final int CODE_SPACE = ' ';
|
public static final int CODE_SPACE = ' ';
|
||||||
|
@ -85,7 +87,9 @@ public class Keyboard {
|
||||||
public static final int CODE_DIGIT0 = '0';
|
public static final int CODE_DIGIT0 = '0';
|
||||||
public static final int CODE_PLUS = '+';
|
public static final int CODE_PLUS = '+';
|
||||||
|
|
||||||
/** Special keys code. These should be aligned with values/keycodes.xml */
|
/** Special keys code. Must be non-positive.
|
||||||
|
* These should be aligned with values/keycodes.xml
|
||||||
|
*/
|
||||||
public static final int CODE_DUMMY = 0;
|
public static final int CODE_DUMMY = 0;
|
||||||
public static final int CODE_SHIFT = -1;
|
public static final int CODE_SHIFT = -1;
|
||||||
public static final int CODE_SWITCH_ALPHA_SYMBOL = -2;
|
public static final int CODE_SWITCH_ALPHA_SYMBOL = -2;
|
||||||
|
@ -248,6 +252,10 @@ public class Keyboard {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isLetterCode(int code) {
|
||||||
|
return code > CODE_DUMMY;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Params {
|
public static class Params {
|
||||||
public KeyboardId mId;
|
public KeyboardId mId;
|
||||||
public int mThemeId;
|
public int mThemeId;
|
||||||
|
|
|
@ -332,7 +332,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
|
||||||
* Updates state machine to figure out when to automatically snap back to the previous mode.
|
* Updates state machine to figure out when to automatically snap back to the previous mode.
|
||||||
*/
|
*/
|
||||||
public void onCodeInput(int code) {
|
public void onCodeInput(int code) {
|
||||||
mState.onCodeInput(code, isSinglePointer());
|
mState.onCodeInput(code, isSinglePointer(), mInputMethodService.getCurrentAutoCapsState());
|
||||||
}
|
}
|
||||||
|
|
||||||
public LatinKeyboardView getKeyboardView() {
|
public LatinKeyboardView getKeyboardView() {
|
||||||
|
|
|
@ -29,9 +29,10 @@ import com.android.inputmethod.keyboard.Keyboard;
|
||||||
*
|
*
|
||||||
* The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()},
|
* The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()},
|
||||||
* {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()},
|
* {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()},
|
||||||
* {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()}, {@link #onCodeInput(int, boolean)},
|
* {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()},
|
||||||
* {@link #onCancelInput(boolean)}, {@link #onUpdateShiftState(boolean)}, {@link #onToggleShift()},
|
* {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)},
|
||||||
* {@link #onToggleCapsLock()}, and {@link #onToggleAlphabetAndSymbols()}.
|
* {@link #onUpdateShiftState(boolean)}, {@link #onToggleShift()}, {@link #onToggleCapsLock()},
|
||||||
|
* and {@link #onToggleAlphabetAndSymbols()}.
|
||||||
*
|
*
|
||||||
* The actions are {@link SwitchActions}'s methods.
|
* The actions are {@link SwitchActions}'s methods.
|
||||||
*/
|
*/
|
||||||
|
@ -267,6 +268,10 @@ public class KeyboardState {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
|
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
|
||||||
}
|
}
|
||||||
|
onUpdateShiftStateInternal(autoCaps);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onUpdateShiftStateInternal(boolean autoCaps) {
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
if (!mKeyboardShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
|
if (!mKeyboardShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
|
||||||
if (mShiftKeyState.isReleasing() && autoCaps) {
|
if (mShiftKeyState.isReleasing() && autoCaps) {
|
||||||
|
@ -381,10 +386,10 @@ public class KeyboardState {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCodeInput(int code, boolean isSinglePointer) {
|
public void onCodeInput(int code, boolean isSinglePointer, boolean autoCaps) {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onCodeInput: code=" + code + " isSinglePointer=" + isSinglePointer
|
Log.d(TAG, "onCodeInput: code=" + code + " isSinglePointer=" + isSinglePointer
|
||||||
+ " " + this);
|
+ " autoCaps=" + autoCaps + " " + this);
|
||||||
}
|
}
|
||||||
switch (mSwitchState) {
|
switch (mSwitchState) {
|
||||||
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
|
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
|
||||||
|
@ -446,6 +451,11 @@ public class KeyboardState {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the code is a letter, update keyboard shift state.
|
||||||
|
if (Keyboard.isLetterCode(code)) {
|
||||||
|
onUpdateShiftStateInternal(autoCaps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onToggleShift() {
|
public void onToggleShift() {
|
||||||
|
|
|
@ -1496,7 +1496,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
if (null != ic) swapSwapperAndSpaceWhileInBatchEdit(ic);
|
if (null != ic) swapSwapperAndSpaceWhileInBatchEdit(ic);
|
||||||
}
|
}
|
||||||
|
|
||||||
switcher.updateShiftState();
|
|
||||||
if (mSettingsValues.isWordSeparator(code)) {
|
if (mSettingsValues.isWordSeparator(code)) {
|
||||||
Utils.Stats.onSeparator((char)code, x, y);
|
Utils.Stats.onSeparator((char)code, x, y);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1581,7 +1580,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
Utils.Stats.onSeparator((char)primaryCode, x, y);
|
Utils.Stats.onSeparator((char)primaryCode, x, y);
|
||||||
|
|
||||||
mKeyboardSwitcher.updateShiftState();
|
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,8 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Argument for KeyboardState.onCodeInput.
|
// Argument for KeyboardState.onCodeInput.
|
||||||
private static final boolean SINGLE = true;
|
private static final boolean SINGLE = true;
|
||||||
private static final boolean MULTI = false;
|
private static final boolean MULTI = false;
|
||||||
|
private static final boolean NO_AUTO_CAPS = false;
|
||||||
|
private static final boolean AUTO_CAPS = true;
|
||||||
|
|
||||||
private void assertAlphabetNormal() {
|
private void assertAlphabetNormal() {
|
||||||
assertEquals(ALPHABET_UNSHIFTED, mSwitcher.mLayout);
|
assertEquals(ALPHABET_UNSHIFTED, mSwitcher.mLayout);
|
||||||
|
@ -213,7 +214,7 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mState.onToggleCapsLock();
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mState.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
|
@ -224,7 +225,7 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
// Long press recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mState.onToggleCapsLock();
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE);
|
mState.onCodeInput(Keyboard.CODE_CAPSLOCK, SINGLE, NO_AUTO_CAPS);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mState.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
@ -236,7 +237,7 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// First shift key tap.
|
// First shift key tap.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mState.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mState.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
|
@ -244,13 +245,13 @@ public class KeyboardStateTests extends AndroidTestCase {
|
||||||
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
|
// Double tap recognized in LatinKeyboardView.KeyTimerHandler.
|
||||||
mState.onToggleCapsLock();
|
mState.onToggleCapsLock();
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
||||||
assertAlphabetShiftLocked();
|
assertAlphabetShiftLocked();
|
||||||
|
|
||||||
// First shift key tap.
|
// First shift key tap.
|
||||||
mState.onPressShift(NOT_SLIDING);
|
mState.onPressShift(NOT_SLIDING);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE);
|
mState.onCodeInput(Keyboard.CODE_SHIFT, SINGLE, NO_AUTO_CAPS);
|
||||||
assertAlphabetManualShifted();
|
assertAlphabetManualShifted();
|
||||||
mState.onReleaseShift(NOT_SLIDING);
|
mState.onReleaseShift(NOT_SLIDING);
|
||||||
assertAlphabetNormal();
|
assertAlphabetNormal();
|
||||||
|
|
Loading…
Reference in New Issue