2012-01-16 06:07:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 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;
|
|
|
|
|
2012-01-17 08:08:26 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
|
|
|
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
2012-01-17 08:08:26 +00:00
|
|
|
public interface Constants {
|
2012-01-18 03:31:02 +00:00
|
|
|
// Argument for {@link KeyboardState#onPressKey} and {@link KeyboardState#onReleaseKey}.
|
2012-01-17 08:08:26 +00:00
|
|
|
public static final boolean NOT_SLIDING = false;
|
|
|
|
public static final boolean SLIDING = true;
|
2012-01-18 03:31:02 +00:00
|
|
|
// Argument for {@link KeyboardState#onCodeInput}.
|
2012-01-17 08:08:26 +00:00
|
|
|
public static final boolean SINGLE = true;
|
|
|
|
public static final boolean MULTI = false;
|
|
|
|
public static final boolean NO_AUTO_CAPS = false;
|
|
|
|
public static final boolean AUTO_CAPS = true;
|
|
|
|
|
|
|
|
public static final int CODE_SHIFT = Keyboard.CODE_SHIFT;
|
|
|
|
public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
|
|
|
|
public static final int CODE_SPACE = Keyboard.CODE_SPACE;
|
2012-01-18 03:31:02 +00:00
|
|
|
public static final int CODE_AUTO_CAPS_TRIGGER = Keyboard.CODE_SPACE;
|
2012-01-16 07:03:06 +00:00
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
public static final int ALPHABET_UNSHIFTED = 0;
|
|
|
|
public static final int ALPHABET_MANUAL_SHIFTED = 1;
|
|
|
|
public static final int ALPHABET_AUTOMATIC_SHIFTED = 2;
|
|
|
|
public static final int ALPHABET_SHIFT_LOCKED = 3;
|
2012-01-26 09:25:48 +00:00
|
|
|
public static final int ALPHABET_SHIFT_LOCK_SHIFTED = 4;
|
|
|
|
public static final int SYMBOLS_UNSHIFTED = 5;
|
|
|
|
public static final int SYMBOLS_SHIFTED = 6;
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
2012-01-16 06:07:58 +00:00
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
private int mLayout = Constants.ALPHABET_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
2012-01-17 08:08:26 +00:00
|
|
|
private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS;
|
2012-01-16 07:03:06 +00:00
|
|
|
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
|
|
|
|
private boolean mAutoCapsState = true;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
private boolean mIsInDoubleTapTimeout;
|
2012-02-01 06:07:25 +00:00
|
|
|
private int mLongPressTimeoutCode;
|
2012-01-31 06:54:48 +00:00
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
private final KeyboardState mState = new KeyboardState(this);
|
|
|
|
|
2012-01-18 03:31:02 +00:00
|
|
|
public int getLayoutId() {
|
|
|
|
return mLayout;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 09:11:37 +00:00
|
|
|
public static String getLayoutName(int layoutId) {
|
|
|
|
switch (layoutId) {
|
|
|
|
case Constants.ALPHABET_UNSHIFTED: return "ALPHABET_UNSHIFTED";
|
|
|
|
case Constants.ALPHABET_MANUAL_SHIFTED: return "ALPHABET_MANUAL_SHIFTED";
|
|
|
|
case Constants.ALPHABET_AUTOMATIC_SHIFTED: return "ALPHABET_AUTOMATIC_SHIFTED";
|
|
|
|
case Constants.ALPHABET_SHIFT_LOCKED: return "ALPHABET_SHIFT_LOCKED";
|
2012-01-26 09:25:48 +00:00
|
|
|
case Constants.ALPHABET_SHIFT_LOCK_SHIFTED: return "ALPHABET_SHIFT_LOCK_SHIFTED";
|
2012-01-23 09:11:37 +00:00
|
|
|
case Constants.SYMBOLS_UNSHIFTED: return "SYMBOLS_UNSHIFTED";
|
|
|
|
case Constants.SYMBOLS_SHIFTED: return "SYMBOLS_SHIFTED";
|
|
|
|
default: return "UNKNOWN<" + layoutId + ">";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
public void setAutoCapsMode(boolean autoCaps) {
|
2012-01-16 07:03:06 +00:00
|
|
|
mAutoCapsMode = autoCaps;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
public void expireDoubleTapTimeout() {
|
|
|
|
mIsInDoubleTapTimeout = false;
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
@Override
|
|
|
|
public void setAlphabetKeyboard() {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetManualShiftedKeyboard() {
|
|
|
|
mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetAutomaticShiftedKeyboard() {
|
|
|
|
mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAlphabetShiftLockedKeyboard() {
|
|
|
|
mLayout = Constants.ALPHABET_SHIFT_LOCKED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:25:48 +00:00
|
|
|
@Override
|
|
|
|
public void setAlphabetShiftLockShiftedKeyboard() {
|
|
|
|
mLayout = Constants.ALPHABET_SHIFT_LOCK_SHIFTED;
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
@Override
|
|
|
|
public void setSymbolsKeyboard() {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.SYMBOLS_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSymbolsShiftedKeyboard() {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.SYMBOLS_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void requestUpdatingShiftState() {
|
2012-01-16 07:03:06 +00:00
|
|
|
mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
|
|
|
public void startDoubleTapTimer() {
|
|
|
|
mIsInDoubleTapTimeout = true;
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
@Override
|
|
|
|
public void cancelDoubleTapTimer() {
|
|
|
|
mIsInDoubleTapTimeout = false;
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean isInDoubleTapTimeout() {
|
|
|
|
return mIsInDoubleTapTimeout;
|
|
|
|
}
|
|
|
|
|
2012-02-01 06:07:25 +00:00
|
|
|
@Override
|
|
|
|
public void startLongPressTimer(int code) {
|
|
|
|
mLongPressTimeoutCode = code;
|
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
@Override
|
|
|
|
public void cancelLongPressTimer() {
|
|
|
|
mLongPressTimeoutCode = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-01 06:07:25 +00:00
|
|
|
@Override
|
|
|
|
public void hapticAndAudioFeedback(int code) {
|
|
|
|
// Nothing to do.
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onLongPressTimeout(int code) {
|
|
|
|
// TODO: Handle simultaneous long presses.
|
|
|
|
if (mLongPressTimeoutCode == code) {
|
|
|
|
mLongPressTimeoutCode = 0;
|
|
|
|
mState.onLongPressTimeout(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
public void updateShiftState() {
|
2012-01-16 07:03:06 +00:00
|
|
|
mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 09:01:53 +00:00
|
|
|
public void loadKeyboard(String layoutSwitchBackSymbols) {
|
|
|
|
mState.onLoadKeyboard(layoutSwitchBackSymbols);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public void saveKeyboardState() {
|
|
|
|
mState.onSaveKeyboardState();
|
|
|
|
}
|
|
|
|
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onPressKey(int code) {
|
|
|
|
mState.onPressKey(code);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 08:08:26 +00:00
|
|
|
public void onReleaseKey(int code, boolean withSliding) {
|
|
|
|
mState.onReleaseKey(code, withSliding);
|
2012-02-01 06:07:25 +00:00
|
|
|
if (mLongPressTimeoutCode == code) {
|
|
|
|
mLongPressTimeoutCode = 0;
|
|
|
|
}
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onCodeInput(int code, boolean isSinglePointer) {
|
2012-01-18 03:31:02 +00:00
|
|
|
if (Keyboard.isLetterCode(code)) {
|
|
|
|
mAutoCapsState = (code == Constants.CODE_AUTO_CAPS_TRIGGER);
|
|
|
|
}
|
2012-01-16 07:03:06 +00:00
|
|
|
mState.onCodeInput(code, isSinglePointer, mAutoCapsMode && mAutoCapsState);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onCancelInput(boolean isSinglePointer) {
|
|
|
|
mState.onCancelInput(isSinglePointer);
|
|
|
|
}
|
|
|
|
}
|