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
|
|
|
import com.android.inputmethod.keyboard.internal.KeyboardState.SwitchActions;
|
|
|
|
|
|
|
|
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_CAPSLOCK = Keyboard.CODE_CAPSLOCK;
|
|
|
|
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;
|
|
|
|
public static final int SYMBOLS_UNSHIFTED = 4;
|
|
|
|
public static final int SYMBOLS_SHIFTED = 5;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutoCapsMode(boolean autoCaps) {
|
2012-01-16 07:03:06 +00:00
|
|
|
mAutoCapsMode = autoCaps;
|
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
|
|
|
|
public void setShifted(int shiftMode) {
|
|
|
|
if (shiftMode == SwitchActions.UNSHIFT) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_UNSHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
} else if (shiftMode == SwitchActions.MANUAL_SHIFT) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_MANUAL_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
} else if (shiftMode == SwitchActions.AUTOMATIC_SHIFT) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_AUTOMATIC_SHIFTED;
|
2012-01-16 06:07:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setShiftLocked(boolean shiftLocked) {
|
|
|
|
if (shiftLocked) {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_SHIFT_LOCKED;
|
2012-01-16 06:07:58 +00:00
|
|
|
} else {
|
2012-01-18 03:31:02 +00:00
|
|
|
mLayout = Constants.ALPHABET_UNSHIFTED;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-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);
|
|
|
|
}
|
|
|
|
}
|