2012-01-16 06:07:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-02-12 07:15:47 +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
|
2012-01-16 06:07:58 +00:00
|
|
|
*
|
2013-02-12 07:15:47 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-01-16 06:07:58 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-02-12 07:15:47 +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.
|
2012-01-16 06:07:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard.internal;
|
|
|
|
|
2012-05-18 07:45:26 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
|
|
|
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
|
2012-10-29 05:46:34 +00:00
|
|
|
public interface MockConstants {
|
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;
|
2012-10-29 05:46:34 +00:00
|
|
|
public static final int CAP_MODE_OFF = Constants.TextUtils.CAP_MODE_OFF;
|
2012-05-18 07:45:26 +00:00
|
|
|
public static final int CAP_MODE_WORDS = TextUtils.CAP_MODE_WORDS;
|
|
|
|
public static final int CAP_MODE_CHARACTERS = TextUtils.CAP_MODE_CHARACTERS;
|
2012-01-17 08:08:26 +00:00
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
public static final int CODE_SHIFT = Constants.CODE_SHIFT;
|
|
|
|
public static final int CODE_SYMBOL = Constants.CODE_SWITCH_ALPHA_SYMBOL;
|
|
|
|
public static final int CODE_SPACE = Constants.CODE_SPACE;
|
|
|
|
public static final int CODE_AUTO_CAPS_TRIGGER = Constants.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;
|
2013-09-04 03:57:04 +00:00
|
|
|
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-10-29 05:46:34 +00:00
|
|
|
private int mLayout = MockConstants.ALPHABET_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
2012-10-29 05:46:34 +00:00
|
|
|
private int mAutoCapsMode = MockConstants.CAP_MODE_OFF;
|
2012-01-16 07:03:06 +00:00
|
|
|
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
|
2012-10-29 05:46:34 +00:00
|
|
|
private int mAutoCapsState = MockConstants.CAP_MODE_OFF;
|
2012-01-16 06:07:58 +00:00
|
|
|
|
2013-06-03 08:50:48 +00:00
|
|
|
private boolean mIsInDoubleTapShiftKeyTimeout;
|
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
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public static String getLayoutName(final int layoutId) {
|
2012-01-23 09:11:37 +00:00
|
|
|
switch (layoutId) {
|
2012-10-29 05:46:34 +00:00
|
|
|
case MockConstants.ALPHABET_UNSHIFTED: return "ALPHABET_UNSHIFTED";
|
|
|
|
case MockConstants.ALPHABET_MANUAL_SHIFTED: return "ALPHABET_MANUAL_SHIFTED";
|
|
|
|
case MockConstants.ALPHABET_AUTOMATIC_SHIFTED: return "ALPHABET_AUTOMATIC_SHIFTED";
|
|
|
|
case MockConstants.ALPHABET_SHIFT_LOCKED: return "ALPHABET_SHIFT_LOCKED";
|
|
|
|
case MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED: return "ALPHABET_SHIFT_LOCK_SHIFTED";
|
2013-09-04 03:57:04 +00:00
|
|
|
case MockConstants.SYMBOLS_UNSHIFTED: return "SYMBOLS_UNSHIFTED";
|
|
|
|
case MockConstants.SYMBOLS_SHIFTED: return "SYMBOLS_SHIFTED";
|
2012-01-23 09:11:37 +00:00
|
|
|
default: return "UNKNOWN<" + layoutId + ">";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void setAutoCapsMode(final int autoCaps) {
|
2012-01-16 07:03:06 +00:00
|
|
|
mAutoCapsMode = autoCaps;
|
2012-05-18 07:45:26 +00:00
|
|
|
mAutoCapsState = autoCaps;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
public void expireDoubleTapTimeout() {
|
2013-06-03 08:50:48 +00:00
|
|
|
mIsInDoubleTapShiftKeyTimeout = false;
|
2012-01-31 06:54:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
@Override
|
|
|
|
public void setAlphabetKeyboard() {
|
2012-10-29 05:46:34 +00:00
|
|
|
mLayout = MockConstants.ALPHABET_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetManualShiftedKeyboard() {
|
2012-10-29 05:46:34 +00:00
|
|
|
mLayout = MockConstants.ALPHABET_MANUAL_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-01-24 03:06:49 +00:00
|
|
|
public void setAlphabetAutomaticShiftedKeyboard() {
|
2012-10-29 05:46:34 +00:00
|
|
|
mLayout = MockConstants.ALPHABET_AUTOMATIC_SHIFTED;
|
2012-01-24 03:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setAlphabetShiftLockedKeyboard() {
|
2012-10-29 05:46:34 +00:00
|
|
|
mLayout = MockConstants.ALPHABET_SHIFT_LOCKED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 09:25:48 +00:00
|
|
|
@Override
|
|
|
|
public void setAlphabetShiftLockShiftedKeyboard() {
|
2012-10-29 05:46:34 +00:00
|
|
|
mLayout = MockConstants.ALPHABET_SHIFT_LOCK_SHIFTED;
|
2012-01-26 09:25:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
@Override
|
|
|
|
public void setSymbolsKeyboard() {
|
2013-09-04 03:57:04 +00:00
|
|
|
mLayout = MockConstants.SYMBOLS_UNSHIFTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSymbolsShiftedKeyboard() {
|
|
|
|
mLayout = MockConstants.SYMBOLS_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-30 10:28:01 +00:00
|
|
|
@Override
|
|
|
|
public void setEmojiKeyboard() {
|
|
|
|
// Just ignore.
|
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
@Override
|
|
|
|
public void requestUpdatingShiftState() {
|
2013-04-15 13:00:29 +00:00
|
|
|
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2014-04-14 06:33:30 +00:00
|
|
|
@Override
|
|
|
|
public void requestUpdatingShiftState(final int currentAutoCapsState,
|
|
|
|
final int currentRecapitalizeState) {
|
|
|
|
mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState);
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void startDoubleTapShiftKeyTimer() {
|
|
|
|
mIsInDoubleTapShiftKeyTimeout = true;
|
2012-01-31 06:54:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 19:45:35 +00:00
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public void cancelDoubleTapShiftKeyTimer() {
|
|
|
|
mIsInDoubleTapShiftKeyTimeout = false;
|
2012-02-16 19:45:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:54:48 +00:00
|
|
|
@Override
|
2013-06-03 08:50:48 +00:00
|
|
|
public boolean isInDoubleTapShiftKeyTimeout() {
|
|
|
|
return mIsInDoubleTapShiftKeyTimeout;
|
2012-01-31 06:54:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 06:07:58 +00:00
|
|
|
public void updateShiftState() {
|
2013-04-15 13:00:29 +00:00
|
|
|
mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void loadKeyboard() {
|
|
|
|
mState.onLoadKeyboard();
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 07:40:28 +00:00
|
|
|
public void saveKeyboardState() {
|
|
|
|
mState.onSaveKeyboardState();
|
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onPressKey(final int code, final boolean isSinglePointer) {
|
2012-05-17 03:55:01 +00:00
|
|
|
mState.onPressKey(code, isSinglePointer, mAutoCapsState);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 09:04:24 +00:00
|
|
|
public void onReleaseKey(final int code, final boolean withSliding) {
|
2014-04-14 06:33:30 +00:00
|
|
|
onReleaseKey(code, withSliding, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onReleaseKey(final int code, final boolean withSliding,
|
|
|
|
final int currentAutoCapsState, final int currentRecapitalizeState) {
|
|
|
|
mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState);
|
2012-02-01 06:07:25 +00:00
|
|
|
if (mLongPressTimeoutCode == code) {
|
|
|
|
mLongPressTimeoutCode = 0;
|
|
|
|
}
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onCodeInput(final int code) {
|
2012-10-29 05:46:34 +00:00
|
|
|
if (mAutoCapsMode == MockConstants.CAP_MODE_WORDS) {
|
|
|
|
if (Constants.isLetterCode(code)) {
|
|
|
|
mAutoCapsState = (code == MockConstants.CODE_AUTO_CAPS_TRIGGER)
|
|
|
|
? mAutoCapsMode : MockConstants.CAP_MODE_OFF;
|
2012-05-18 07:45:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mAutoCapsState = mAutoCapsMode;
|
2012-01-18 03:31:02 +00:00
|
|
|
}
|
2013-05-14 03:25:21 +00:00
|
|
|
mState.onCodeInput(code, mAutoCapsState);
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-14 03:25:21 +00:00
|
|
|
public void onFinishSlidingInput() {
|
|
|
|
mState.onFinishSlidingInput();
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
2013-05-14 03:25:21 +00:00
|
|
|
}
|