aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/KeyboardSwitcher.java28
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java18
-rw-r--r--java/src/com/android/inputmethod/latin/ModifierKeyState.java30
-rw-r--r--java/src/com/android/inputmethod/latin/ShiftKeyState.java43
4 files changed, 83 insertions, 36 deletions
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index fdcf0ad4e..fce0e34fe 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -75,7 +75,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private final LatinIME mInputMethodService;
private final LanguageSwitcher mLanguageSwitcher;
+ private ShiftKeyState mShiftState = new ShiftKeyState();
private ModifierKeyState mSymbolKeyState = new ModifierKeyState();
+
private KeyboardId mSymbolsId;
private KeyboardId mSymbolsShiftedId;
@@ -383,6 +385,30 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
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() {
mSymbolKeyState.onPress();
}
@@ -396,7 +422,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
}
public void onOtherKeyPressed() {
- // TODO: shift key state will be handled too.
+ mShiftState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed();
}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index a432eaa02..156d0bcca 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -235,9 +235,6 @@ public class LatinIME extends InputMethodService
private int mDeleteCount;
private long mLastKeyTime;
- // Modifier keys state
- private final ModifierKeyState mShiftKeyState = new ModifierKeyState();
-
private Tutorial mTutorial;
private AudioManager mAudioManager;
@@ -1091,8 +1088,8 @@ public class LatinIME extends InputMethodService
if (!switcher.isKeyboardAvailable())
return;
if (ic != null && attr != null && switcher.isAlphabetMode()
- && !mShiftKeyState.isIgnoring()) {
- switcher.setShifted(mShiftKeyState.isMomentary()
+ && !switcher.isShiftIgnoring()) {
+ switcher.setShifted(switcher.isShiftMomentary()
|| 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
// method, onPress(), only when we are in the small letter mode.
if (switcher.isAlphabetMode() && switcher.isShifted()) {
- mShiftKeyState.onPressOnShifted();
+ switcher.onPressShiftOnShifted();
} else {
- mShiftKeyState.onPress();
+ switcher.onPressShift();
handleShift();
}
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
switcher.onPressSymbol();
changeKeyboardMode();
} else {
- mShiftKeyState.onOtherKeyPressed();
switcher.onOtherKeyPressed();
}
}
@@ -2364,18 +2360,18 @@ public class LatinIME extends InputMethodService
switcher.keyReleased();
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
- if (mShiftKeyState.isMomentary()) {
+ if (switcher.isShiftMomentary()) {
resetShift();
}
if (switcher.isAlphabetMode()) {
// 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
// mode or caps lock mode.
- if (switcher.isShifted() && mShiftKeyState.isPressingOnShifted()) {
+ if (switcher.isShifted() && switcher.isShiftPressingOnShifted()) {
handleShift();
}
}
- mShiftKeyState.onRelease();
+ switcher.onReleaseShift();
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
if (switcher.isSymbolMomentary()) {
changeKeyboardMode();
diff --git a/java/src/com/android/inputmethod/latin/ModifierKeyState.java b/java/src/com/android/inputmethod/latin/ModifierKeyState.java
index 75820e7d3..8139ec531 100644
--- a/java/src/com/android/inputmethod/latin/ModifierKeyState.java
+++ b/java/src/com/android/inputmethod/latin/ModifierKeyState.java
@@ -16,44 +16,26 @@
package com.android.inputmethod.latin;
-class ModifierKeyState {
- private static final int RELEASING = 0;
- private static final int PRESSING = 1;
- private static final int PRESSING_ON_SHIFTED = 2; // both temporary shifted & shift locked
- private static final int MOMENTARY = 3;
- private static final int IGNORING = 4;
+public class ModifierKeyState {
+ protected static final int RELEASING = 0;
+ protected static final int PRESSING = 1;
+ protected static final int MOMENTARY = 2;
- private int mState = RELEASING;
+ protected int mState = RELEASING;
public void onPress() {
mState = PRESSING;
}
- public void onPressOnShifted() {
- mState = PRESSING_ON_SHIFTED;
- }
-
public void onRelease() {
mState = RELEASING;
}
public void onOtherKeyPressed() {
- if (mState == PRESSING) {
- mState = MOMENTARY;
- } else if (mState == PRESSING_ON_SHIFTED) {
- mState = IGNORING;
- }
+ mState = MOMENTARY;
}
public boolean isMomentary() {
return mState == MOMENTARY;
}
-
- public boolean isPressingOnShifted() {
- return mState == PRESSING_ON_SHIFTED;
- }
-
- public boolean isIgnoring() {
- return mState == IGNORING;
- }
}
diff --git a/java/src/com/android/inputmethod/latin/ShiftKeyState.java b/java/src/com/android/inputmethod/latin/ShiftKeyState.java
new file mode 100644
index 000000000..5312ce2cc
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/ShiftKeyState.java
@@ -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;
+ }
+}