Refactor shift key state into KeyboardSwitcher
Change-Id: If484d3d7e7a0794ee7fc88f0771229d6f90db466
This commit is contained in:
parent
d7641636db
commit
889691eca1
4 changed files with 83 additions and 36 deletions
|
@ -75,7 +75,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
private final LatinIME mInputMethodService;
|
private final LatinIME mInputMethodService;
|
||||||
private final LanguageSwitcher mLanguageSwitcher;
|
private final LanguageSwitcher mLanguageSwitcher;
|
||||||
|
|
||||||
|
private ShiftKeyState mShiftState = new ShiftKeyState();
|
||||||
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
|
||||||
|
|
||||||
private KeyboardId mSymbolsId;
|
private KeyboardId mSymbolsId;
|
||||||
private KeyboardId mSymbolsShiftedId;
|
private KeyboardId mSymbolsShiftedId;
|
||||||
|
|
||||||
|
@ -383,6 +385,30 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
mInputView.setShiftLocked(shiftLocked);
|
mInputView.setShiftLocked(shiftLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onPressShift() {
|
||||||
|
mShiftState.onPress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPressShiftOnShifted() {
|
||||||
|
mShiftState.onPressOnShifted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onReleaseShift() {
|
||||||
|
mShiftState.onRelease();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShiftMomentary() {
|
||||||
|
return mShiftState.isMomentary();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShiftPressingOnShifted() {
|
||||||
|
return mShiftState.isPressingOnShifted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShiftIgnoring() {
|
||||||
|
return mShiftState.isIgnoring();
|
||||||
|
}
|
||||||
|
|
||||||
public void onPressSymbol() {
|
public void onPressSymbol() {
|
||||||
mSymbolKeyState.onPress();
|
mSymbolKeyState.onPress();
|
||||||
}
|
}
|
||||||
|
@ -396,7 +422,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onOtherKeyPressed() {
|
public void onOtherKeyPressed() {
|
||||||
// TODO: shift key state will be handled too.
|
mShiftState.onOtherKeyPressed();
|
||||||
mSymbolKeyState.onOtherKeyPressed();
|
mSymbolKeyState.onOtherKeyPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,9 +235,6 @@ public class LatinIME extends InputMethodService
|
||||||
private int mDeleteCount;
|
private int mDeleteCount;
|
||||||
private long mLastKeyTime;
|
private long mLastKeyTime;
|
||||||
|
|
||||||
// Modifier keys state
|
|
||||||
private final ModifierKeyState mShiftKeyState = new ModifierKeyState();
|
|
||||||
|
|
||||||
private Tutorial mTutorial;
|
private Tutorial mTutorial;
|
||||||
|
|
||||||
private AudioManager mAudioManager;
|
private AudioManager mAudioManager;
|
||||||
|
@ -1091,8 +1088,8 @@ public class LatinIME extends InputMethodService
|
||||||
if (!switcher.isKeyboardAvailable())
|
if (!switcher.isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
if (ic != null && attr != null && switcher.isAlphabetMode()
|
if (ic != null && attr != null && switcher.isAlphabetMode()
|
||||||
&& !mShiftKeyState.isIgnoring()) {
|
&& !switcher.isShiftIgnoring()) {
|
||||||
switcher.setShifted(mShiftKeyState.isMomentary()
|
switcher.setShifted(switcher.isShiftMomentary()
|
||||||
|| switcher.isShiftLocked() || getCursorCapsMode(ic, attr) != 0);
|
|| switcher.isShiftLocked() || getCursorCapsMode(ic, attr) != 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2342,16 +2339,15 @@ public class LatinIME extends InputMethodService
|
||||||
// In alphabet mode, we call handleShift() to go into the shifted mode in this
|
// In alphabet mode, we call handleShift() to go into the shifted mode in this
|
||||||
// method, onPress(), only when we are in the small letter mode.
|
// method, onPress(), only when we are in the small letter mode.
|
||||||
if (switcher.isAlphabetMode() && switcher.isShifted()) {
|
if (switcher.isAlphabetMode() && switcher.isShifted()) {
|
||||||
mShiftKeyState.onPressOnShifted();
|
switcher.onPressShiftOnShifted();
|
||||||
} else {
|
} else {
|
||||||
mShiftKeyState.onPress();
|
switcher.onPressShift();
|
||||||
handleShift();
|
handleShift();
|
||||||
}
|
}
|
||||||
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
||||||
switcher.onPressSymbol();
|
switcher.onPressSymbol();
|
||||||
changeKeyboardMode();
|
changeKeyboardMode();
|
||||||
} else {
|
} else {
|
||||||
mShiftKeyState.onOtherKeyPressed();
|
|
||||||
switcher.onOtherKeyPressed();
|
switcher.onOtherKeyPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2364,18 +2360,18 @@ public class LatinIME extends InputMethodService
|
||||||
switcher.keyReleased();
|
switcher.keyReleased();
|
||||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
|
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
|
||||||
if (mShiftKeyState.isMomentary()) {
|
if (switcher.isShiftMomentary()) {
|
||||||
resetShift();
|
resetShift();
|
||||||
}
|
}
|
||||||
if (switcher.isAlphabetMode()) {
|
if (switcher.isAlphabetMode()) {
|
||||||
// In alphabet mode, we call handleShift() to go into the small letter mode in this
|
// In alphabet mode, we call handleShift() to go into the small letter mode in this
|
||||||
// method, onRelease(), only when we are in the shifted modes -- temporary shifted
|
// method, onRelease(), only when we are in the shifted modes -- temporary shifted
|
||||||
// mode or caps lock mode.
|
// mode or caps lock mode.
|
||||||
if (switcher.isShifted() && mShiftKeyState.isPressingOnShifted()) {
|
if (switcher.isShifted() && switcher.isShiftPressingOnShifted()) {
|
||||||
handleShift();
|
handleShift();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mShiftKeyState.onRelease();
|
switcher.onReleaseShift();
|
||||||
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
||||||
if (switcher.isSymbolMomentary()) {
|
if (switcher.isSymbolMomentary()) {
|
||||||
changeKeyboardMode();
|
changeKeyboardMode();
|
||||||
|
|
|
@ -16,44 +16,26 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin;
|
package com.android.inputmethod.latin;
|
||||||
|
|
||||||
class ModifierKeyState {
|
public class ModifierKeyState {
|
||||||
private static final int RELEASING = 0;
|
protected static final int RELEASING = 0;
|
||||||
private static final int PRESSING = 1;
|
protected static final int PRESSING = 1;
|
||||||
private static final int PRESSING_ON_SHIFTED = 2; // both temporary shifted & shift locked
|
protected static final int MOMENTARY = 2;
|
||||||
private static final int MOMENTARY = 3;
|
|
||||||
private static final int IGNORING = 4;
|
|
||||||
|
|
||||||
private int mState = RELEASING;
|
protected int mState = RELEASING;
|
||||||
|
|
||||||
public void onPress() {
|
public void onPress() {
|
||||||
mState = PRESSING;
|
mState = PRESSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPressOnShifted() {
|
|
||||||
mState = PRESSING_ON_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onRelease() {
|
public void onRelease() {
|
||||||
mState = RELEASING;
|
mState = RELEASING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onOtherKeyPressed() {
|
public void onOtherKeyPressed() {
|
||||||
if (mState == PRESSING) {
|
mState = MOMENTARY;
|
||||||
mState = MOMENTARY;
|
|
||||||
} else if (mState == PRESSING_ON_SHIFTED) {
|
|
||||||
mState = IGNORING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMomentary() {
|
public boolean isMomentary() {
|
||||||
return mState == MOMENTARY;
|
return mState == MOMENTARY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPressingOnShifted() {
|
|
||||||
return mState == PRESSING_ON_SHIFTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIgnoring() {
|
|
||||||
return mState == IGNORING;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
43
java/src/com/android/inputmethod/latin/ShiftKeyState.java
Normal file
43
java/src/com/android/inputmethod/latin/ShiftKeyState.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 Google Inc.
|
||||||
|
*
|
||||||
|
* 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.latin;
|
||||||
|
|
||||||
|
public class ShiftKeyState extends ModifierKeyState {
|
||||||
|
private static final int PRESSING_ON_SHIFTED = 3; // both temporary shifted & shift locked
|
||||||
|
private static final int IGNORING = 4;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOtherKeyPressed() {
|
||||||
|
if (mState == PRESSING) {
|
||||||
|
mState = MOMENTARY;
|
||||||
|
} else if (mState == PRESSING_ON_SHIFTED) {
|
||||||
|
mState = IGNORING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPressOnShifted() {
|
||||||
|
mState = PRESSING_ON_SHIFTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPressingOnShifted() {
|
||||||
|
return mState == PRESSING_ON_SHIFTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIgnoring() {
|
||||||
|
return mState == IGNORING;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue