Match the keyboard state to the recapitalize state.
Bug: 7657025 Change-Id: I2f8fe7fc4596a498322ba5ccabbd0c18a2bc36cfmain
parent
e259b9f57d
commit
8094bf45d7
|
@ -207,7 +207,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
* Update keyboard shift state triggered by connected EditText status change.
|
* Update keyboard shift state triggered by connected EditText status change.
|
||||||
*/
|
*/
|
||||||
public void updateShiftState() {
|
public void updateShiftState() {
|
||||||
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState(),
|
||||||
|
mLatinIME.getCurrentRecapitalizeState());
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
||||||
|
@ -276,7 +277,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
@Override
|
@Override
|
||||||
public void requestUpdatingShiftState() {
|
public void requestUpdatingShiftState() {
|
||||||
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState());
|
mState.onUpdateShiftState(mLatinIME.getCurrentAutoCapsState(),
|
||||||
|
mLatinIME.getCurrentRecapitalizeState());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements {@link KeyboardState.SwitchActions}.
|
// Implements {@link KeyboardState.SwitchActions}.
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
import com.android.inputmethod.latin.RecapitalizeStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keyboard state machine.
|
* Keyboard state machine.
|
||||||
|
@ -80,6 +81,7 @@ public final class KeyboardState {
|
||||||
private boolean mIsSymbolShifted;
|
private boolean mIsSymbolShifted;
|
||||||
private boolean mPrevMainKeyboardWasShiftLocked;
|
private boolean mPrevMainKeyboardWasShiftLocked;
|
||||||
private boolean mPrevSymbolsKeyboardWasShifted;
|
private boolean mPrevSymbolsKeyboardWasShifted;
|
||||||
|
private int mRecapitalizeMode;
|
||||||
|
|
||||||
// For handling long press.
|
// For handling long press.
|
||||||
private boolean mLongPressShiftLockFired;
|
private boolean mLongPressShiftLockFired;
|
||||||
|
@ -110,6 +112,7 @@ public final class KeyboardState {
|
||||||
|
|
||||||
public KeyboardState(final SwitchActions switchActions) {
|
public KeyboardState(final SwitchActions switchActions) {
|
||||||
mSwitchActions = switchActions;
|
mSwitchActions = switchActions;
|
||||||
|
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoadKeyboard() {
|
public void onLoadKeyboard() {
|
||||||
|
@ -283,6 +286,7 @@ public final class KeyboardState {
|
||||||
mSwitchActions.setAlphabetKeyboard();
|
mSwitchActions.setAlphabetKeyboard();
|
||||||
mIsAlphabetMode = true;
|
mIsAlphabetMode = true;
|
||||||
mIsSymbolShifted = false;
|
mIsSymbolShifted = false;
|
||||||
|
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
||||||
mSwitchState = SWITCH_STATE_ALPHA;
|
mSwitchState = SWITCH_STATE_ALPHA;
|
||||||
mSwitchActions.requestUpdatingShiftState();
|
mSwitchActions.requestUpdatingShiftState();
|
||||||
}
|
}
|
||||||
|
@ -386,11 +390,13 @@ public final class KeyboardState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpdateShiftState(final int autoCaps) {
|
public void onUpdateShiftState(final int autoCaps, final int recapitalizeMode) {
|
||||||
if (DEBUG_EVENT) {
|
if (DEBUG_EVENT) {
|
||||||
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
|
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + ", recapitalizeMode="
|
||||||
|
+ recapitalizeMode + this);
|
||||||
}
|
}
|
||||||
updateAlphabetShiftState(autoCaps);
|
mRecapitalizeMode = recapitalizeMode;
|
||||||
|
updateAlphabetShiftState(autoCaps, recapitalizeMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
||||||
|
@ -402,8 +408,28 @@ public final class KeyboardState {
|
||||||
resetKeyboardStateToAlphabet();
|
resetKeyboardStateToAlphabet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateAlphabetShiftState(final int autoCaps) {
|
private void updateShiftStateForRecapitalize(final int recapitalizeMode) {
|
||||||
|
switch (recapitalizeMode) {
|
||||||
|
case RecapitalizeStatus.CAPS_MODE_ALL_UPPER:
|
||||||
|
setShifted(SHIFT_LOCK_SHIFTED);
|
||||||
|
break;
|
||||||
|
case RecapitalizeStatus.CAPS_MODE_FIRST_WORD_UPPER:
|
||||||
|
setShifted(AUTOMATIC_SHIFT);
|
||||||
|
break;
|
||||||
|
case RecapitalizeStatus.CAPS_MODE_ALL_LOWER:
|
||||||
|
case RecapitalizeStatus.CAPS_MODE_ORIGINAL_MIXED_CASE:
|
||||||
|
default:
|
||||||
|
setShifted(UNSHIFT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAlphabetShiftState(final int autoCaps, final int recapitalizeMode) {
|
||||||
if (!mIsAlphabetMode) return;
|
if (!mIsAlphabetMode) return;
|
||||||
|
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != recapitalizeMode) {
|
||||||
|
// We are recapitalizing. Match the keyboard to the current recapitalize state.
|
||||||
|
updateShiftStateForRecapitalize(recapitalizeMode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!mShiftKeyState.isReleasing()) {
|
if (!mShiftKeyState.isReleasing()) {
|
||||||
// Ignore update shift state event while the shift key is being pressed (including
|
// Ignore update shift state event while the shift key is being pressed (including
|
||||||
// chording).
|
// chording).
|
||||||
|
@ -421,6 +447,9 @@ public final class KeyboardState {
|
||||||
|
|
||||||
private void onPressShift() {
|
private void onPressShift() {
|
||||||
mLongPressShiftLockFired = false;
|
mLongPressShiftLockFired = false;
|
||||||
|
// If we are recapitalizing, we don't do any of the normal processing, including
|
||||||
|
// importantly the double tap timer.
|
||||||
|
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) return;
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapTimeout();
|
mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapTimeout();
|
||||||
if (!mIsInDoubleTapShiftKey) {
|
if (!mIsInDoubleTapShiftKey) {
|
||||||
|
@ -467,7 +496,11 @@ public final class KeyboardState {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onReleaseShift(final boolean withSliding) {
|
private void onReleaseShift(final boolean withSliding) {
|
||||||
if (mIsAlphabetMode) {
|
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
|
||||||
|
// We are recapitalizing. We should match the keyboard state to the recapitalize
|
||||||
|
// state in priority.
|
||||||
|
updateShiftStateForRecapitalize(mRecapitalizeMode);
|
||||||
|
} else if (mIsAlphabetMode) {
|
||||||
final boolean isShiftLocked = mAlphabetShiftState.isShiftLocked();
|
final boolean isShiftLocked = mAlphabetShiftState.isShiftLocked();
|
||||||
mIsInAlphabetUnshiftedFromShifted = false;
|
mIsInAlphabetUnshiftedFromShifted = false;
|
||||||
if (mIsInDoubleTapShiftKey) {
|
if (mIsInDoubleTapShiftKey) {
|
||||||
|
@ -597,7 +630,7 @@ public final class KeyboardState {
|
||||||
|
|
||||||
// If the code is a letter, update keyboard shift state.
|
// If the code is a letter, update keyboard shift state.
|
||||||
if (Constants.isLetterCode(code)) {
|
if (Constants.isLetterCode(code)) {
|
||||||
updateAlphabetShiftState(autoCaps);
|
updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1180,6 +1180,15 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
SPACE_STATE_PHANTOM == mSpaceState);
|
SPACE_STATE_PHANTOM == mSpaceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentRecapitalizeState() {
|
||||||
|
if (!mRecapitalizeStatus.isActive()
|
||||||
|
|| !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) {
|
||||||
|
// Not recapitalizing at the moment
|
||||||
|
return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
||||||
|
}
|
||||||
|
return mRecapitalizeStatus.getCurrentMode();
|
||||||
|
}
|
||||||
|
|
||||||
// Factor in auto-caps and manual caps and compute the current caps mode.
|
// Factor in auto-caps and manual caps and compute the current caps mode.
|
||||||
private int getActualCapsMode() {
|
private int getActualCapsMode() {
|
||||||
final int keyboardShiftMode = mKeyboardSwitcher.getKeyboardShiftMode();
|
final int keyboardShiftMode = mKeyboardSwitcher.getKeyboardShiftMode();
|
||||||
|
@ -1979,6 +1988,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
|
mLastSelectionStart = mRecapitalizeStatus.getNewCursorStart();
|
||||||
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
|
mLastSelectionEnd = mRecapitalizeStatus.getNewCursorEnd();
|
||||||
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
||||||
|
// Match the keyboard to the new state.
|
||||||
|
mKeyboardSwitcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if we did an autocorrection, false otherwise.
|
// Returns true if we did an autocorrection, false otherwise.
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Locale;
|
||||||
* The status of the current recapitalize process.
|
* The status of the current recapitalize process.
|
||||||
*/
|
*/
|
||||||
public class RecapitalizeStatus {
|
public class RecapitalizeStatus {
|
||||||
|
public static final int NOT_A_RECAPITALIZE_MODE = -1;
|
||||||
public static final int CAPS_MODE_ORIGINAL_MIXED_CASE = 0;
|
public static final int CAPS_MODE_ORIGINAL_MIXED_CASE = 0;
|
||||||
public static final int CAPS_MODE_ALL_LOWER = 1;
|
public static final int CAPS_MODE_ALL_LOWER = 1;
|
||||||
public static final int CAPS_MODE_FIRST_WORD_UPPER = 2;
|
public static final int CAPS_MODE_FIRST_WORD_UPPER = 2;
|
||||||
|
@ -181,4 +182,8 @@ public class RecapitalizeStatus {
|
||||||
public int getNewCursorEnd() {
|
public int getNewCursorEnd() {
|
||||||
return mCursorEndAfter;
|
return mCursorEndAfter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentMode() {
|
||||||
|
return ROTATION_STYLE[mRotationStyleCurrentIndex];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard.internal;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
|
import com.android.inputmethod.latin.RecapitalizeStatus;
|
||||||
|
|
||||||
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
public interface MockConstants {
|
public interface MockConstants {
|
||||||
|
@ -120,7 +121,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void requestUpdatingShiftState() {
|
public void requestUpdatingShiftState() {
|
||||||
mState.onUpdateShiftState(mAutoCapsState);
|
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -162,7 +163,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateShiftState() {
|
public void updateShiftState() {
|
||||||
mState.onUpdateShiftState(mAutoCapsState);
|
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadKeyboard() {
|
public void loadKeyboard() {
|
||||||
|
|
Loading…
Reference in New Issue