2011-12-05 06:02:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-12-05 06:02:06 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-05 06:02:06 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2011-12-05 06:02:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
import android.text.TextUtils;
|
2011-12-08 05:42:12 +00:00
|
|
|
import android.util.Log;
|
2011-12-07 10:31:11 +00:00
|
|
|
|
2012-05-18 07:45:26 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2013-04-15 13:00:29 +00:00
|
|
|
import com.android.inputmethod.latin.RecapitalizeStatus;
|
2011-12-07 10:31:11 +00:00
|
|
|
|
2011-12-08 12:27:57 +00:00
|
|
|
/**
|
|
|
|
* Keyboard state machine.
|
|
|
|
*
|
|
|
|
* This class contains all keyboard state transition logic.
|
2011-12-09 10:53:36 +00:00
|
|
|
*
|
2013-01-18 09:04:24 +00:00
|
|
|
* The input events are {@link #onLoadKeyboard()}, {@link #onSaveKeyboardState()},
|
2013-05-14 03:25:21 +00:00
|
|
|
* {@link #onPressKey(int,boolean,int)}, {@link #onReleaseKey(int,boolean)},
|
|
|
|
* {@link #onCodeInput(int,int)}, {@link #onFinishSlidingInput()}, {@link #onCancelInput()},
|
|
|
|
* {@link #onUpdateShiftState(int,int)}, {@link #onLongPressTimeout(int)}.
|
2011-12-09 10:53:36 +00:00
|
|
|
*
|
2011-12-09 07:09:16 +00:00
|
|
|
* The actions are {@link SwitchActions}'s methods.
|
2011-12-08 12:27:57 +00:00
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class KeyboardState {
|
2011-12-08 05:42:12 +00:00
|
|
|
private static final String TAG = KeyboardState.class.getSimpleName();
|
2012-01-17 08:08:26 +00:00
|
|
|
private static final boolean DEBUG_EVENT = false;
|
|
|
|
private static final boolean DEBUG_ACTION = false;
|
2011-12-08 05:42:12 +00:00
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
public interface SwitchActions {
|
|
|
|
public void setAlphabetKeyboard();
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetManualShiftedKeyboard();
|
|
|
|
public void setAlphabetAutomaticShiftedKeyboard();
|
|
|
|
public void setAlphabetShiftLockedKeyboard();
|
2012-01-26 09:25:48 +00:00
|
|
|
public void setAlphabetShiftLockShiftedKeyboard();
|
2011-12-07 10:31:11 +00:00
|
|
|
public void setSymbolsKeyboard();
|
|
|
|
public void setSymbolsShiftedKeyboard();
|
2012-01-13 11:15:14 +00:00
|
|
|
|
|
|
|
/**
|
2013-04-16 06:30:42 +00:00
|
|
|
* Request to call back {@link KeyboardState#onUpdateShiftState(int, int)}.
|
2012-01-13 11:15:14 +00:00
|
|
|
*/
|
|
|
|
public void requestUpdatingShiftState();
|
2012-01-31 06:54:48 +00:00
|
|
|
|
|
|
|
public void startDoubleTapTimer();
|
|
|
|
public boolean isInDoubleTapTimeout();
|
2012-02-16 19:45:35 +00:00
|
|
|
public void cancelDoubleTapTimer();
|
2012-02-01 06:07:25 +00:00
|
|
|
public void startLongPressTimer(int code);
|
2012-02-16 19:45:35 +00:00
|
|
|
public void cancelLongPressTimer();
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 09:42:11 +00:00
|
|
|
private final SwitchActions mSwitchActions;
|
2011-12-06 02:19:39 +00:00
|
|
|
|
2011-12-05 06:02:06 +00:00
|
|
|
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
|
|
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
// TODO: Merge {@link #mSwitchState}, {@link #mIsAlphabetMode}, {@link #mAlphabetShiftState},
|
|
|
|
// {@link #mIsSymbolShifted}, {@link #mPrevMainKeyboardWasShiftLocked}, and
|
|
|
|
// {@link #mPrevSymbolsKeyboardWasShifted} into single state variable.
|
2011-12-07 10:31:11 +00:00
|
|
|
private static final int SWITCH_STATE_ALPHA = 0;
|
|
|
|
private static final int SWITCH_STATE_SYMBOL_BEGIN = 1;
|
|
|
|
private static final int SWITCH_STATE_SYMBOL = 2;
|
|
|
|
private static final int SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL = 3;
|
|
|
|
private static final int SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE = 4;
|
2013-05-14 03:25:21 +00:00
|
|
|
private static final int SWITCH_STATE_MOMENTARY_ALPHA_SHIFT = 5;
|
2011-12-07 10:31:11 +00:00
|
|
|
private int mSwitchState = SWITCH_STATE_ALPHA;
|
|
|
|
|
2011-12-09 07:09:16 +00:00
|
|
|
private boolean mIsAlphabetMode;
|
2012-01-26 09:03:30 +00:00
|
|
|
private AlphabetShiftState mAlphabetShiftState = new AlphabetShiftState();
|
2011-12-09 07:09:16 +00:00
|
|
|
private boolean mIsSymbolShifted;
|
2012-01-19 09:42:11 +00:00
|
|
|
private boolean mPrevMainKeyboardWasShiftLocked;
|
2012-01-19 09:53:38 +00:00
|
|
|
private boolean mPrevSymbolsKeyboardWasShifted;
|
2013-04-15 13:00:29 +00:00
|
|
|
private int mRecapitalizeMode;
|
2011-12-09 07:09:16 +00:00
|
|
|
|
2012-05-29 06:47:57 +00:00
|
|
|
// For handling long press.
|
|
|
|
private boolean mLongPressShiftLockFired;
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
// For handling double tap.
|
|
|
|
private boolean mIsInAlphabetUnshiftedFromShifted;
|
|
|
|
private boolean mIsInDoubleTapShiftKey;
|
|
|
|
|
2011-12-08 05:42:12 +00:00
|
|
|
private final SavedKeyboardState mSavedKeyboardState = new SavedKeyboardState();
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
static final class SavedKeyboardState {
|
2011-12-08 05:42:12 +00:00
|
|
|
public boolean mIsValid;
|
|
|
|
public boolean mIsAlphabetMode;
|
2012-01-31 08:29:40 +00:00
|
|
|
public boolean mIsAlphabetShiftLocked;
|
2013-05-02 06:20:57 +00:00
|
|
|
public int mShiftMode;
|
2012-01-23 04:14:02 +00:00
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
@Override
|
2012-01-23 04:14:02 +00:00
|
|
|
public String toString() {
|
|
|
|
if (!mIsValid) return "INVALID";
|
|
|
|
if (mIsAlphabetMode) {
|
2012-01-31 08:29:40 +00:00
|
|
|
if (mIsAlphabetShiftLocked) return "ALPHABET_SHIFT_LOCKED";
|
2013-05-02 06:20:57 +00:00
|
|
|
return "ALPHABET_" + shiftModeToString(mShiftMode);
|
2012-01-23 04:14:02 +00:00
|
|
|
} else {
|
2013-05-02 06:20:57 +00:00
|
|
|
return "SYMBOLS_" + shiftModeToString(mShiftMode);
|
2012-01-23 04:14:02 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public KeyboardState(final SwitchActions switchActions) {
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchActions = switchActions;
|
2013-04-15 13:00:29 +00:00
|
|
|
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onLoadKeyboard() {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-01-23 04:14:02 +00:00
|
|
|
Log.d(TAG, "onLoadKeyboard: " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-19 09:42:11 +00:00
|
|
|
// Reset alphabet shift state.
|
|
|
|
mAlphabetShiftState.setShiftLocked(false);
|
|
|
|
mPrevMainKeyboardWasShiftLocked = false;
|
2012-01-19 09:53:38 +00:00
|
|
|
mPrevSymbolsKeyboardWasShifted = false;
|
2011-12-07 08:55:22 +00:00
|
|
|
mShiftKeyState.onRelease();
|
|
|
|
mSymbolKeyState.onRelease();
|
2011-12-08 07:30:13 +00:00
|
|
|
onRestoreKeyboardState();
|
2011-12-07 08:55:22 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 06:20:57 +00:00
|
|
|
private static final int UNSHIFT = 0;
|
|
|
|
private static final int MANUAL_SHIFT = 1;
|
|
|
|
private static final int AUTOMATIC_SHIFT = 2;
|
|
|
|
private static final int SHIFT_LOCK_SHIFTED = 3;
|
|
|
|
|
2011-12-09 07:09:16 +00:00
|
|
|
public void onSaveKeyboardState() {
|
2011-12-08 05:42:12 +00:00
|
|
|
final SavedKeyboardState state = mSavedKeyboardState;
|
2011-12-09 07:09:16 +00:00
|
|
|
state.mIsAlphabetMode = mIsAlphabetMode;
|
|
|
|
if (mIsAlphabetMode) {
|
2012-01-31 08:29:40 +00:00
|
|
|
state.mIsAlphabetShiftLocked = mAlphabetShiftState.isShiftLocked();
|
2013-05-02 06:20:57 +00:00
|
|
|
state.mShiftMode = mAlphabetShiftState.isAutomaticShifted() ? AUTOMATIC_SHIFT
|
|
|
|
: (mAlphabetShiftState.isShiftedOrShiftLocked() ? MANUAL_SHIFT : UNSHIFT);
|
2011-12-08 05:42:12 +00:00
|
|
|
} else {
|
2012-01-31 08:29:40 +00:00
|
|
|
state.mIsAlphabetShiftLocked = mPrevMainKeyboardWasShiftLocked;
|
2013-05-02 06:20:57 +00:00
|
|
|
state.mShiftMode = mIsSymbolShifted ? MANUAL_SHIFT : UNSHIFT;
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
state.mIsValid = true;
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-01-23 04:14:02 +00:00
|
|
|
Log.d(TAG, "onSaveKeyboardState: saved=" + state + " " + this);
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 07:30:13 +00:00
|
|
|
private void onRestoreKeyboardState() {
|
2011-12-08 05:42:12 +00:00
|
|
|
final SavedKeyboardState state = mSavedKeyboardState;
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-01-23 04:14:02 +00:00
|
|
|
Log.d(TAG, "onRestoreKeyboardState: saved=" + state + " " + this);
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
if (!state.mIsValid || state.mIsAlphabetMode) {
|
2011-12-08 12:03:25 +00:00
|
|
|
setAlphabetKeyboard();
|
2011-12-08 05:42:12 +00:00
|
|
|
} else {
|
2013-05-02 06:20:57 +00:00
|
|
|
if (state.mShiftMode == MANUAL_SHIFT) {
|
2011-12-08 12:03:25 +00:00
|
|
|
setSymbolsShiftedKeyboard();
|
2011-12-08 05:42:12 +00:00
|
|
|
} else {
|
2011-12-08 12:03:25 +00:00
|
|
|
setSymbolsKeyboard();
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.mIsValid) return;
|
|
|
|
state.mIsValid = false;
|
|
|
|
|
|
|
|
if (state.mIsAlphabetMode) {
|
2012-01-31 08:29:40 +00:00
|
|
|
setShiftLocked(state.mIsAlphabetShiftLocked);
|
|
|
|
if (!state.mIsAlphabetShiftLocked) {
|
2013-05-02 06:20:57 +00:00
|
|
|
setShifted(state.mShiftMode);
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
2012-01-31 08:29:40 +00:00
|
|
|
} else {
|
|
|
|
mPrevMainKeyboardWasShiftLocked = state.mIsAlphabetShiftLocked;
|
2011-12-08 05:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private void setShifted(final int shiftMode) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_ACTION) {
|
2012-01-24 03:06:49 +00:00
|
|
|
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this);
|
|
|
|
}
|
|
|
|
if (!mIsAlphabetMode) return;
|
|
|
|
final int prevShiftMode;
|
2012-01-26 09:03:30 +00:00
|
|
|
if (mAlphabetShiftState.isAutomaticShifted()) {
|
2012-01-24 03:06:49 +00:00
|
|
|
prevShiftMode = AUTOMATIC_SHIFT;
|
2012-01-26 09:03:30 +00:00
|
|
|
} else if (mAlphabetShiftState.isManualShifted()) {
|
2012-01-24 03:06:49 +00:00
|
|
|
prevShiftMode = MANUAL_SHIFT;
|
|
|
|
} else {
|
|
|
|
prevShiftMode = UNSHIFT;
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-18 09:01:53 +00:00
|
|
|
switch (shiftMode) {
|
2012-01-24 03:06:49 +00:00
|
|
|
case AUTOMATIC_SHIFT:
|
2012-01-26 09:03:30 +00:00
|
|
|
mAlphabetShiftState.setAutomaticShifted();
|
2012-01-24 03:06:49 +00:00
|
|
|
if (shiftMode != prevShiftMode) {
|
|
|
|
mSwitchActions.setAlphabetAutomaticShiftedKeyboard();
|
|
|
|
}
|
2012-01-18 09:01:53 +00:00
|
|
|
break;
|
2012-01-24 03:06:49 +00:00
|
|
|
case MANUAL_SHIFT:
|
2012-01-19 09:42:11 +00:00
|
|
|
mAlphabetShiftState.setShifted(true);
|
2012-01-24 03:06:49 +00:00
|
|
|
if (shiftMode != prevShiftMode) {
|
|
|
|
mSwitchActions.setAlphabetManualShiftedKeyboard();
|
|
|
|
}
|
2012-01-18 09:01:53 +00:00
|
|
|
break;
|
2012-01-24 03:06:49 +00:00
|
|
|
case UNSHIFT:
|
2012-01-19 09:42:11 +00:00
|
|
|
mAlphabetShiftState.setShifted(false);
|
2012-01-24 03:06:49 +00:00
|
|
|
if (shiftMode != prevShiftMode) {
|
|
|
|
mSwitchActions.setAlphabetKeyboard();
|
|
|
|
}
|
2012-01-18 09:01:53 +00:00
|
|
|
break;
|
2012-01-26 09:25:48 +00:00
|
|
|
case SHIFT_LOCK_SHIFTED:
|
|
|
|
mAlphabetShiftState.setShifted(true);
|
|
|
|
mSwitchActions.setAlphabetShiftLockShiftedKeyboard();
|
|
|
|
break;
|
2011-12-08 12:27:57 +00:00
|
|
|
}
|
2011-12-06 02:19:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private void setShiftLocked(final boolean shiftLocked) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_ACTION) {
|
2012-01-24 03:06:49 +00:00
|
|
|
Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked + " " + this);
|
|
|
|
}
|
|
|
|
if (!mIsAlphabetMode) return;
|
|
|
|
if (shiftLocked && (!mAlphabetShiftState.isShiftLocked()
|
|
|
|
|| mAlphabetShiftState.isShiftLockShifted())) {
|
|
|
|
mSwitchActions.setAlphabetShiftLockedKeyboard();
|
|
|
|
}
|
|
|
|
if (!shiftLocked && mAlphabetShiftState.isShiftLocked()) {
|
|
|
|
mSwitchActions.setAlphabetKeyboard();
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-19 09:42:11 +00:00
|
|
|
mAlphabetShiftState.setShiftLocked(shiftLocked);
|
2011-12-06 02:19:39 +00:00
|
|
|
}
|
|
|
|
|
2011-12-09 07:09:16 +00:00
|
|
|
private void toggleAlphabetAndSymbols() {
|
2012-01-26 12:43:50 +00:00
|
|
|
if (DEBUG_ACTION) {
|
|
|
|
Log.d(TAG, "toggleAlphabetAndSymbols: " + this);
|
|
|
|
}
|
2011-12-09 07:09:16 +00:00
|
|
|
if (mIsAlphabetMode) {
|
2012-01-26 12:43:50 +00:00
|
|
|
mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked();
|
|
|
|
if (mPrevSymbolsKeyboardWasShifted) {
|
|
|
|
setSymbolsShiftedKeyboard();
|
|
|
|
} else {
|
|
|
|
setSymbolsKeyboard();
|
|
|
|
}
|
|
|
|
mPrevSymbolsKeyboardWasShifted = false;
|
2011-12-07 10:31:11 +00:00
|
|
|
} else {
|
2012-01-26 12:43:50 +00:00
|
|
|
mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
|
2011-12-08 12:03:25 +00:00
|
|
|
setAlphabetKeyboard();
|
2012-01-26 12:43:50 +00:00
|
|
|
if (mPrevMainKeyboardWasShiftLocked) {
|
|
|
|
setShiftLocked(true);
|
|
|
|
}
|
|
|
|
mPrevMainKeyboardWasShiftLocked = false;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 07:45:44 +00:00
|
|
|
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
|
|
|
// when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal().
|
|
|
|
private void resetKeyboardStateToAlphabet() {
|
|
|
|
if (DEBUG_ACTION) {
|
|
|
|
Log.d(TAG, "resetKeyboardStateToAlphabet: " + this);
|
|
|
|
}
|
|
|
|
if (mIsAlphabetMode) return;
|
|
|
|
|
|
|
|
mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
|
|
|
|
setAlphabetKeyboard();
|
|
|
|
if (mPrevMainKeyboardWasShiftLocked) {
|
|
|
|
setShiftLocked(true);
|
|
|
|
}
|
|
|
|
mPrevMainKeyboardWasShiftLocked = false;
|
|
|
|
}
|
|
|
|
|
2011-12-09 07:09:16 +00:00
|
|
|
private void toggleShiftInSymbols() {
|
|
|
|
if (mIsSymbolShifted) {
|
2011-12-08 12:03:25 +00:00
|
|
|
setSymbolsKeyboard();
|
2011-12-07 10:31:11 +00:00
|
|
|
} else {
|
2011-12-08 12:03:25 +00:00
|
|
|
setSymbolsShiftedKeyboard();
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:03:25 +00:00
|
|
|
private void setAlphabetKeyboard() {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_ACTION) {
|
2011-12-08 13:10:27 +00:00
|
|
|
Log.d(TAG, "setAlphabetKeyboard");
|
|
|
|
}
|
2012-03-30 20:15:46 +00:00
|
|
|
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchActions.setAlphabetKeyboard();
|
2011-12-09 07:09:16 +00:00
|
|
|
mIsAlphabetMode = true;
|
|
|
|
mIsSymbolShifted = false;
|
2013-04-15 13:00:29 +00:00
|
|
|
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchState = SWITCH_STATE_ALPHA;
|
2012-01-13 11:15:14 +00:00
|
|
|
mSwitchActions.requestUpdatingShiftState();
|
2011-12-08 07:30:13 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
private void setSymbolsKeyboard() {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_ACTION) {
|
2011-12-08 13:10:27 +00:00
|
|
|
Log.d(TAG, "setSymbolsKeyboard");
|
|
|
|
}
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchActions.setSymbolsKeyboard();
|
2011-12-09 07:09:16 +00:00
|
|
|
mIsAlphabetMode = false;
|
|
|
|
mIsSymbolShifted = false;
|
2012-01-19 09:42:11 +00:00
|
|
|
// Reset alphabet shift state.
|
|
|
|
mAlphabetShiftState.setShiftLocked(false);
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
2011-12-08 07:30:13 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 12:03:25 +00:00
|
|
|
private void setSymbolsShiftedKeyboard() {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_ACTION) {
|
2011-12-08 13:10:27 +00:00
|
|
|
Log.d(TAG, "setSymbolsShiftedKeyboard");
|
|
|
|
}
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchActions.setSymbolsShiftedKeyboard();
|
2011-12-09 07:09:16 +00:00
|
|
|
mIsAlphabetMode = false;
|
|
|
|
mIsSymbolShifted = true;
|
2012-01-19 09:42:11 +00:00
|
|
|
// Reset alphabet shift state.
|
|
|
|
mAlphabetShiftState.setShiftLocked(false);
|
2011-12-08 12:03:25 +00:00
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onPressKey(final int code, final boolean isSinglePointer, final int autoCaps) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-10-29 05:46:34 +00:00
|
|
|
Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code)
|
2012-05-17 03:55:01 +00:00
|
|
|
+ " single=" + isSinglePointer + " autoCaps=" + autoCaps + " " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_SHIFT) {
|
2012-01-17 08:08:26 +00:00
|
|
|
onPressShift();
|
2012-10-29 05:46:34 +00:00
|
|
|
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
|
2012-01-17 08:08:26 +00:00
|
|
|
onPressSymbol();
|
|
|
|
} else {
|
2012-02-16 19:45:35 +00:00
|
|
|
mSwitchActions.cancelDoubleTapTimer();
|
|
|
|
mSwitchActions.cancelLongPressTimer();
|
2012-05-29 06:47:57 +00:00
|
|
|
mLongPressShiftLockFired = false;
|
2012-01-17 08:08:26 +00:00
|
|
|
mShiftKeyState.onOtherKeyPressed();
|
|
|
|
mSymbolKeyState.onOtherKeyPressed();
|
2012-05-17 03:55:01 +00:00
|
|
|
// It is required to reset the auto caps state when all of the following conditions
|
|
|
|
// are met:
|
|
|
|
// 1) two or more fingers are in action
|
|
|
|
// 2) in alphabet layout
|
|
|
|
// 3) not in all characters caps mode
|
|
|
|
// As for #3, please note that it's required to check even when the auto caps mode is
|
|
|
|
// off because, for example, we may be in the #1 state within the manual temporary
|
|
|
|
// shifted mode.
|
|
|
|
if (!isSinglePointer && mIsAlphabetMode && autoCaps != TextUtils.CAP_MODE_CHARACTERS) {
|
|
|
|
final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted()
|
|
|
|
|| (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing());
|
|
|
|
if (needsToResetAutoCaps) {
|
|
|
|
mSwitchActions.setAlphabetKeyboard();
|
|
|
|
}
|
|
|
|
}
|
2012-01-17 08:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onReleaseKey(final int code, final boolean withSliding) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-10-29 05:46:34 +00:00
|
|
|
Log.d(TAG, "onReleaseKey: code=" + Constants.printableCode(code)
|
2012-01-17 08:08:26 +00:00
|
|
|
+ " sliding=" + withSliding + " " + this);
|
|
|
|
}
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_SHIFT) {
|
2012-01-17 08:08:26 +00:00
|
|
|
onReleaseShift(withSliding);
|
2012-10-29 05:46:34 +00:00
|
|
|
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
|
2012-01-24 05:47:46 +00:00
|
|
|
onReleaseSymbol(withSliding);
|
2012-01-17 08:08:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onPressSymbol() {
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleAlphabetAndSymbols();
|
2011-12-05 06:02:06 +00:00
|
|
|
mSymbolKeyState.onPress();
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL;
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private void onReleaseSymbol(final boolean withSliding) {
|
2012-01-24 07:01:59 +00:00
|
|
|
if (mSymbolKeyState.isChording()) {
|
2012-01-24 05:47:46 +00:00
|
|
|
// Switch back to the previous keyboard mode if the user chords the mode change key and
|
|
|
|
// another key, then releases the mode change key.
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleAlphabetAndSymbols();
|
2012-01-24 05:47:46 +00:00
|
|
|
} else if (!withSliding) {
|
|
|
|
// If the mode change key is being released without sliding, we should forget the
|
|
|
|
// previous symbols keyboard shift state and simply switch back to symbols layout
|
|
|
|
// (never symbols shifted) next time the mode gets changed to symbols layout.
|
|
|
|
mPrevSymbolsKeyboardWasShifted = false;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
mSymbolKeyState.onRelease();
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onLongPressTimeout(final int code) {
|
2012-02-01 06:07:25 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-10-29 05:46:34 +00:00
|
|
|
Log.d(TAG, "onLongPressTimeout: code=" + Constants.printableCode(code) + " " + this);
|
2012-02-01 06:07:25 +00:00
|
|
|
}
|
2012-10-29 05:46:34 +00:00
|
|
|
if (mIsAlphabetMode && code == Constants.CODE_SHIFT) {
|
2012-05-29 06:47:57 +00:00
|
|
|
mLongPressShiftLockFired = true;
|
2012-02-01 06:07:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:29 +00:00
|
|
|
public void onUpdateShiftState(final int autoCaps, final int recapitalizeMode) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2013-04-15 13:00:29 +00:00
|
|
|
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + ", recapitalizeMode="
|
2013-04-16 06:30:42 +00:00
|
|
|
+ recapitalizeMode + " " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2013-04-15 13:00:29 +00:00
|
|
|
mRecapitalizeMode = recapitalizeMode;
|
|
|
|
updateAlphabetShiftState(autoCaps, recapitalizeMode);
|
2011-12-26 14:40:09 +00:00
|
|
|
}
|
|
|
|
|
2012-11-06 07:45:44 +00:00
|
|
|
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
|
|
|
|
// when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal().
|
|
|
|
public void onResetKeyboardStateToAlphabet() {
|
|
|
|
if (DEBUG_EVENT) {
|
|
|
|
Log.d(TAG, "onResetKeyboardStateToAlphabet: " + this);
|
|
|
|
}
|
|
|
|
resetKeyboardStateToAlphabet();
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:00:29 +00:00
|
|
|
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) {
|
2012-01-24 07:01:59 +00:00
|
|
|
if (!mIsAlphabetMode) return;
|
2013-04-15 13:00:29 +00:00
|
|
|
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != recapitalizeMode) {
|
|
|
|
// We are recapitalizing. Match the keyboard to the current recapitalize state.
|
|
|
|
updateShiftStateForRecapitalize(recapitalizeMode);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-16 19:45:35 +00:00
|
|
|
if (!mShiftKeyState.isReleasing()) {
|
|
|
|
// Ignore update shift state event while the shift key is being pressed (including
|
|
|
|
// chording).
|
|
|
|
return;
|
|
|
|
}
|
2012-01-24 07:01:59 +00:00
|
|
|
if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
|
2012-05-18 07:45:26 +00:00
|
|
|
if (mShiftKeyState.isReleasing() && autoCaps != Constants.TextUtils.CAP_MODE_OFF) {
|
2012-01-24 07:01:59 +00:00
|
|
|
// Only when shift key is releasing, automatic temporary upper case will be set.
|
|
|
|
setShifted(AUTOMATIC_SHIFT);
|
|
|
|
} else {
|
|
|
|
setShifted(mShiftKeyState.isChording() ? MANUAL_SHIFT : UNSHIFT);
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 08:08:26 +00:00
|
|
|
private void onPressShift() {
|
2012-05-29 06:47:57 +00:00
|
|
|
mLongPressShiftLockFired = false;
|
2013-04-15 13:00:29 +00:00
|
|
|
// 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;
|
2011-12-09 07:09:16 +00:00
|
|
|
if (mIsAlphabetMode) {
|
2012-01-31 06:54:48 +00:00
|
|
|
mIsInDoubleTapShiftKey = mSwitchActions.isInDoubleTapTimeout();
|
|
|
|
if (!mIsInDoubleTapShiftKey) {
|
|
|
|
// This is first tap.
|
|
|
|
mSwitchActions.startDoubleTapTimer();
|
|
|
|
}
|
|
|
|
if (mIsInDoubleTapShiftKey) {
|
|
|
|
if (mAlphabetShiftState.isManualShifted() || mIsInAlphabetUnshiftedFromShifted) {
|
|
|
|
// Shift key has been double tapped while in manual shifted or automatic
|
|
|
|
// shifted state.
|
|
|
|
setShiftLocked(true);
|
|
|
|
} else {
|
|
|
|
// Shift key has been double tapped while in normal state. This is the second
|
|
|
|
// tap to disable shift locked state, so just ignore this.
|
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
} else {
|
2012-02-01 06:07:25 +00:00
|
|
|
if (mAlphabetShiftState.isShiftLocked()) {
|
|
|
|
// Shift key is pressed while shift locked state, we will treat this state as
|
|
|
|
// shift lock shifted state and mark as if shift key pressed while normal state.
|
|
|
|
setShifted(SHIFT_LOCK_SHIFTED);
|
|
|
|
mShiftKeyState.onPress();
|
|
|
|
} else if (mAlphabetShiftState.isAutomaticShifted()) {
|
|
|
|
// Shift key is pressed while automatic shifted, we have to move to manual
|
|
|
|
// shifted.
|
|
|
|
setShifted(MANUAL_SHIFT);
|
|
|
|
mShiftKeyState.onPress();
|
|
|
|
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()) {
|
|
|
|
// In manual shifted state, we just record shift key has been pressing while
|
|
|
|
// shifted state.
|
|
|
|
mShiftKeyState.onPressOnShifted();
|
|
|
|
} else {
|
|
|
|
// In base layout, chording or manual shifted mode is started.
|
|
|
|
setShifted(MANUAL_SHIFT);
|
|
|
|
mShiftKeyState.onPress();
|
|
|
|
}
|
2012-10-29 05:46:34 +00:00
|
|
|
mSwitchActions.startLongPressTimer(Constants.CODE_SHIFT);
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// In symbol mode, just toggle symbol and symbol more keyboard.
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleShiftInSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchState = SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE;
|
2011-12-05 06:02:06 +00:00
|
|
|
mShiftKeyState.onPress();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private void onReleaseShift(final boolean withSliding) {
|
2013-04-15 13:00:29 +00:00
|
|
|
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) {
|
2012-01-19 09:42:11 +00:00
|
|
|
final boolean isShiftLocked = mAlphabetShiftState.isShiftLocked();
|
2012-01-31 06:54:48 +00:00
|
|
|
mIsInAlphabetUnshiftedFromShifted = false;
|
|
|
|
if (mIsInDoubleTapShiftKey) {
|
|
|
|
// Double tap shift key has been handled in {@link #onPressShift}, so that just
|
|
|
|
// ignore this release shift key here.
|
|
|
|
mIsInDoubleTapShiftKey = false;
|
2012-05-29 06:47:57 +00:00
|
|
|
} else if (mLongPressShiftLockFired) {
|
|
|
|
setShiftLocked(!mAlphabetShiftState.isShiftLocked());
|
2012-01-31 06:54:48 +00:00
|
|
|
} else if (mShiftKeyState.isChording()) {
|
2012-01-19 09:48:02 +00:00
|
|
|
if (mAlphabetShiftState.isShiftLockShifted()) {
|
2012-01-31 06:54:48 +00:00
|
|
|
// After chording input while shift locked state.
|
2012-01-19 09:48:02 +00:00
|
|
|
setShiftLocked(true);
|
|
|
|
} else {
|
2012-01-24 06:02:35 +00:00
|
|
|
// After chording input while normal state.
|
2012-01-24 03:06:49 +00:00
|
|
|
setShifted(UNSHIFT);
|
2012-01-19 09:48:02 +00:00
|
|
|
}
|
2012-11-21 03:51:36 +00:00
|
|
|
// After chording input, automatic shift state may have been changed depending on
|
|
|
|
// what characters were input.
|
|
|
|
mShiftKeyState.onRelease();
|
|
|
|
mSwitchActions.requestUpdatingShiftState();
|
|
|
|
return;
|
2012-01-24 06:02:35 +00:00
|
|
|
} else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) {
|
2012-01-31 06:54:48 +00:00
|
|
|
// In shift locked state, shift has been pressed and slid out to other key.
|
2012-01-24 06:02:35 +00:00
|
|
|
setShiftLocked(true);
|
2013-05-14 03:25:21 +00:00
|
|
|
} else if (mAlphabetShiftState.isManualShifted() && withSliding) {
|
|
|
|
// Shift has been pressed and slid out to other key.
|
|
|
|
mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_SHIFT;
|
2012-01-19 09:42:11 +00:00
|
|
|
} else if (isShiftLocked && !mAlphabetShiftState.isShiftLockShifted()
|
2011-12-09 10:53:36 +00:00
|
|
|
&& (mShiftKeyState.isPressing() || mShiftKeyState.isPressingOnShifted())
|
|
|
|
&& !withSliding) {
|
2011-12-07 10:31:11 +00:00
|
|
|
// Shift has been long pressed, ignore this release.
|
|
|
|
} else if (isShiftLocked && !mShiftKeyState.isIgnoring() && !withSliding) {
|
2012-01-31 06:54:48 +00:00
|
|
|
// Shift has been pressed without chording while shift locked state.
|
2011-12-08 12:27:57 +00:00
|
|
|
setShiftLocked(false);
|
2012-01-19 09:42:11 +00:00
|
|
|
} else if (mAlphabetShiftState.isShiftedOrShiftLocked()
|
2011-12-09 10:53:36 +00:00
|
|
|
&& mShiftKeyState.isPressingOnShifted() && !withSliding) {
|
2011-12-07 10:31:11 +00:00
|
|
|
// Shift has been pressed without chording while shifted state.
|
2012-01-24 03:06:49 +00:00
|
|
|
setShifted(UNSHIFT);
|
2012-01-31 06:54:48 +00:00
|
|
|
mIsInAlphabetUnshiftedFromShifted = true;
|
2012-01-26 09:03:30 +00:00
|
|
|
} else if (mAlphabetShiftState.isManualShiftedFromAutomaticShifted()
|
2011-12-09 10:53:36 +00:00
|
|
|
&& mShiftKeyState.isPressing() && !withSliding) {
|
2012-01-31 06:54:48 +00:00
|
|
|
// Shift has been pressed without chording while manual shifted transited from
|
|
|
|
// automatic shifted
|
2012-01-24 03:06:49 +00:00
|
|
|
setShifted(UNSHIFT);
|
2012-01-31 06:54:48 +00:00
|
|
|
mIsInAlphabetUnshiftedFromShifted = true;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-01-18 07:40:28 +00:00
|
|
|
// In symbol mode, switch back to the previous keyboard mode if the user chords the
|
|
|
|
// shift key and another key, then releases the shift key.
|
2012-01-24 07:01:59 +00:00
|
|
|
if (mShiftKeyState.isChording()) {
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleShiftInSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-05 06:02:06 +00:00
|
|
|
mShiftKeyState.onRelease();
|
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onFinishSlidingInput() {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2013-05-14 03:25:21 +00:00
|
|
|
Log.d(TAG, "onFinishSlidingInput: " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-18 07:40:28 +00:00
|
|
|
// Switch back to the previous keyboard mode if the user cancels sliding input.
|
2013-05-14 03:25:21 +00:00
|
|
|
switch (mSwitchState) {
|
|
|
|
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
|
|
|
|
toggleAlphabetAndSymbols();
|
|
|
|
break;
|
|
|
|
case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE:
|
|
|
|
toggleShiftInSymbols();
|
|
|
|
break;
|
|
|
|
case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT:
|
|
|
|
setAlphabetKeyboard();
|
|
|
|
break;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private static boolean isSpaceCharacter(final int c) {
|
2012-10-29 05:46:34 +00:00
|
|
|
return c == Constants.CODE_SPACE || c == Constants.CODE_ENTER;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onCodeInput(final int code, final int autoCaps) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2012-10-29 05:46:34 +00:00
|
|
|
Log.d(TAG, "onCodeInput: code=" + Constants.printableCode(code)
|
2011-12-26 14:40:09 +00:00
|
|
|
+ " autoCaps=" + autoCaps + " " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-17 09:45:04 +00:00
|
|
|
|
2011-12-07 10:31:11 +00:00
|
|
|
switch (mSwitchState) {
|
|
|
|
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
|
2011-12-07 10:31:11 +00:00
|
|
|
// Detected only the mode change key has been pressed, and then released.
|
2011-12-09 07:09:16 +00:00
|
|
|
if (mIsAlphabetMode) {
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchState = SWITCH_STATE_ALPHA;
|
|
|
|
} else {
|
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE:
|
2012-10-29 05:46:34 +00:00
|
|
|
if (code == Constants.CODE_SHIFT) {
|
2011-12-07 10:31:11 +00:00
|
|
|
// Detected only the shift key has been pressed on symbol layout, and then released.
|
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL_BEGIN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SWITCH_STATE_SYMBOL_BEGIN:
|
2012-10-29 05:46:34 +00:00
|
|
|
if (!isSpaceCharacter(code) && (Constants.isLetterCode(code)
|
|
|
|
|| code == Constants.CODE_OUTPUT_TEXT)) {
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SWITCH_STATE_SYMBOL:
|
2012-01-18 07:40:28 +00:00
|
|
|
// Switch back to alpha keyboard mode if user types one or more non-space/enter
|
2013-01-18 09:04:24 +00:00
|
|
|
// characters followed by a space/enter.
|
|
|
|
if (isSpaceCharacter(code)) {
|
2012-01-26 12:43:50 +00:00
|
|
|
toggleAlphabetAndSymbols();
|
2012-02-27 03:56:08 +00:00
|
|
|
mPrevSymbolsKeyboardWasShifted = false;
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2011-12-26 14:40:09 +00:00
|
|
|
|
|
|
|
// If the code is a letter, update keyboard shift state.
|
2012-10-29 05:46:34 +00:00
|
|
|
if (Constants.isLetterCode(code)) {
|
2013-04-15 13:00:29 +00:00
|
|
|
updateAlphabetShiftState(autoCaps, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
2011-12-26 14:40:09 +00:00
|
|
|
}
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-05-02 06:20:57 +00:00
|
|
|
static String shiftModeToString(final int shiftMode) {
|
2011-12-08 13:10:27 +00:00
|
|
|
switch (shiftMode) {
|
2012-01-24 03:06:49 +00:00
|
|
|
case UNSHIFT: return "UNSHIFT";
|
|
|
|
case MANUAL_SHIFT: return "MANUAL";
|
|
|
|
case AUTOMATIC_SHIFT: return "AUTOMATIC";
|
2011-12-08 13:10:27 +00:00
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
2011-12-09 10:53:36 +00:00
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private static String switchStateToString(final int switchState) {
|
2011-12-07 10:31:11 +00:00
|
|
|
switch (switchState) {
|
|
|
|
case SWITCH_STATE_ALPHA: return "ALPHA";
|
|
|
|
case SWITCH_STATE_SYMBOL_BEGIN: return "SYMBOL-BEGIN";
|
|
|
|
case SWITCH_STATE_SYMBOL: return "SYMBOL";
|
|
|
|
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL: return "MOMENTARY-ALPHA-SYMBOL";
|
|
|
|
case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE: return "MOMENTARY-SYMBOL-MORE";
|
2013-05-14 03:25:21 +00:00
|
|
|
case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT: return "MOMENTARY-ALPHA_SHIFT";
|
2011-12-07 10:31:11 +00:00
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 06:02:06 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-01-19 09:42:11 +00:00
|
|
|
return "[keyboard=" + (mIsAlphabetMode ? mAlphabetShiftState.toString()
|
2012-11-16 10:28:56 +00:00
|
|
|
: (mIsSymbolShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS"))
|
2011-12-06 02:19:39 +00:00
|
|
|
+ " shift=" + mShiftKeyState
|
2011-12-07 10:31:11 +00:00
|
|
|
+ " symbol=" + mSymbolKeyState
|
|
|
|
+ " switch=" + switchStateToString(mSwitchState) + "]";
|
2011-12-05 06:02:06 +00:00
|
|
|
}
|
|
|
|
}
|