2011-12-05 06:02:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
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()},
|
2012-05-17 03:55:01 +00:00
|
|
|
* {@link #onPressKey(int, boolean, int)}, {@link #onReleaseKey(int, boolean)},
|
2012-05-18 07:45:26 +00:00
|
|
|
* {@link #onCodeInput(int, boolean, int)}, {@link #onCancelInput(boolean)},
|
|
|
|
* {@link #onUpdateShiftState(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
|
|
|
|
|
|
|
/**
|
2012-05-18 07:45:26 +00:00
|
|
|
* Request to call back {@link KeyboardState#onUpdateShiftState(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();
|
2012-02-01 06:07:25 +00:00
|
|
|
public void hapticAndAudioFeedback(int code);
|
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;
|
|
|
|
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;
|
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;
|
2011-12-08 05:42:12 +00:00
|
|
|
public boolean mIsShifted;
|
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";
|
2012-01-23 04:14:02 +00:00
|
|
|
return mIsShifted ? "ALPHABET_SHIFTED" : "ALPHABET";
|
|
|
|
} else {
|
|
|
|
return mIsShifted ? "SYMBOLS_SHIFTED" : "SYMBOLS";
|
|
|
|
}
|
|
|
|
}
|
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;
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
state.mIsShifted = !state.mIsAlphabetShiftLocked
|
2012-01-19 09:42:11 +00:00
|
|
|
&& mAlphabetShiftState.isShiftedOrShiftLocked();
|
2011-12-08 05:42:12 +00:00
|
|
|
} else {
|
2012-01-31 08:29:40 +00:00
|
|
|
state.mIsAlphabetShiftLocked = mPrevMainKeyboardWasShiftLocked;
|
2011-12-09 07:09:16 +00:00
|
|
|
state.mIsShifted = mIsSymbolShifted;
|
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 {
|
|
|
|
if (state.mIsShifted) {
|
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) {
|
2012-01-24 03:06:49 +00:00
|
|
|
setShifted(state.mIsShifted ? MANUAL_SHIFT : UNSHIFT);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-24 03:06:49 +00:00
|
|
|
private static final int UNSHIFT = 0;
|
|
|
|
private static final int MANUAL_SHIFT = 1;
|
|
|
|
private static final int AUTOMATIC_SHIFT = 2;
|
2012-01-26 09:25:48 +00:00
|
|
|
private static final int SHIFT_LOCK_SHIFTED = 3;
|
2012-01-24 03:06:49 +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;
|
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
|
|
|
mSwitchActions.hapticAndAudioFeedback(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onUpdateShiftState(final int autoCaps) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
2011-12-09 11:18:39 +00:00
|
|
|
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
|
2011-12-08 13:10:27 +00:00
|
|
|
}
|
2012-01-24 07:01:59 +00:00
|
|
|
updateAlphabetShiftState(autoCaps);
|
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-01-18 09:04:24 +00:00
|
|
|
private void updateAlphabetShiftState(final int autoCaps) {
|
2012-01-24 07:01:59 +00:00
|
|
|
if (!mIsAlphabetMode) 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;
|
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) {
|
2011-12-09 07:09:16 +00:00
|
|
|
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);
|
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-01-18 09:04:24 +00:00
|
|
|
public void onCancelInput(final boolean isSinglePointer) {
|
2012-01-17 08:08:26 +00:00
|
|
|
if (DEBUG_EVENT) {
|
|
|
|
Log.d(TAG, "onCancelInput: single=" + isSinglePointer + " " + 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.
|
2011-12-07 10:31:11 +00:00
|
|
|
if (isSinglePointer) {
|
|
|
|
if (mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL) {
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleAlphabetAndSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
} else if (mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE) {
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleShiftInSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInMomentarySwitchState() {
|
|
|
|
return mSwitchState == SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL
|
|
|
|
|| mSwitchState == SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE;
|
|
|
|
}
|
|
|
|
|
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-01-18 09:04:24 +00:00
|
|
|
public void onCodeInput(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, "onCodeInput: code=" + Constants.printableCode(code)
|
2012-01-17 08:08:26 +00:00
|
|
|
+ " single=" + isSinglePointer
|
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;
|
|
|
|
}
|
|
|
|
} else if (isSinglePointer) {
|
2012-01-18 07:40:28 +00:00
|
|
|
// Switch back to the previous keyboard mode if the user pressed the mode change key
|
2011-12-07 10:31:11 +00:00
|
|
|
// and slid to other key, then released the finger.
|
2012-01-18 07:40:28 +00:00
|
|
|
// If the user cancels the sliding input, switching back to the previous keyboard
|
2011-12-07 10:31:11 +00:00
|
|
|
// mode is handled by {@link #onCancelInput}.
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleAlphabetAndSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
} else if (isSinglePointer) {
|
2012-01-18 07:40:28 +00:00
|
|
|
// Switch back to the previous keyboard mode if the user pressed the shift key on
|
2011-12-07 10:31:11 +00:00
|
|
|
// symbol mode and slid to other key, then released the finger.
|
2011-12-09 07:09:16 +00:00
|
|
|
toggleShiftInSymbols();
|
2011-12-07 10:31:11 +00:00
|
|
|
mSwitchState = SWITCH_STATE_SYMBOL;
|
|
|
|
}
|
|
|
|
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)) {
|
2012-01-24 07:01:59 +00:00
|
|
|
updateAlphabetShiftState(autoCaps);
|
2011-12-26 14:40:09 +00:00
|
|
|
}
|
2011-12-07 10:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
private 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";
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|