aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/android/inputmethod/latin/KeyboardSwitcher.java
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2009-11-12 18:46:12 -0800
committerJean-Baptiste Queru <jbq@google.com>2009-11-12 18:46:12 -0800
commit68eb1b1932f77a34d13d0ec0ab2d76cd50fdda92 (patch)
tree01cc9bfa4fd4e2fbe8f74916cfa47257a1e4e1e8 /src/com/android/inputmethod/latin/KeyboardSwitcher.java
parent399d49b76d450fffc7e7e5e8ccc4111061dc9b87 (diff)
downloadlatinime-68eb1b1932f77a34d13d0ec0ab2d76cd50fdda92.tar.gz
latinime-68eb1b1932f77a34d13d0ec0ab2d76cd50fdda92.tar.xz
latinime-68eb1b1932f77a34d13d0ec0ab2d76cd50fdda92.zip
eclair snapshot
Diffstat (limited to 'src/com/android/inputmethod/latin/KeyboardSwitcher.java')
-rw-r--r--src/com/android/inputmethod/latin/KeyboardSwitcher.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index 92b7cd4a1..c82587b71 100644
--- a/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -37,6 +37,10 @@ public class KeyboardSwitcher {
public static final int KEYBOARDMODE_EMAIL = R.id.mode_email;
public static final int KEYBOARDMODE_IM = R.id.mode_im;
+ private static final int SYMBOLS_MODE_STATE_NONE = 0;
+ private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
+ private static final int SYMBOLS_MODE_STATE_SYMBOL = 2;
+
LatinKeyboardView mInputView;
LatinIME mContext;
@@ -50,6 +54,8 @@ public class KeyboardSwitcher {
private int mImeOptions;
private int mTextMode = MODE_TEXT_QWERTY;
private boolean mIsSymbols;
+ private boolean mPreferSymbols;
+ private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
private int mLastDisplayWidth;
@@ -64,14 +70,15 @@ public class KeyboardSwitcher {
mInputView = inputView;
}
- void makeKeyboards() {
+ void makeKeyboards(boolean forceCreate) {
+ if (forceCreate) mKeyboards.clear();
// Configuration change is coming after the keyboard gets recreated. So don't rely on that.
// If keyboards have already been made, check if we have a screen width change and
// create the keyboard layouts again at the correct orientation
int displayWidth = mContext.getMaxWidth();
if (displayWidth == mLastDisplayWidth) return;
mLastDisplayWidth = displayWidth;
- mKeyboards.clear();
+ if (!forceCreate) mKeyboards.clear();
mSymbolsId = new KeyboardId(R.xml.kbd_symbols);
mSymbolsShiftedId = new KeyboardId(R.xml.kbd_symbols_shift);
}
@@ -109,7 +116,10 @@ public class KeyboardSwitcher {
}
void setKeyboardMode(int mode, int imeOptions) {
- setKeyboardMode(mode, imeOptions, false);
+ mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
+ mPreferSymbols = mode == MODE_SYMBOLS;
+ setKeyboardMode(mode == MODE_SYMBOLS ? MODE_TEXT : mode, imeOptions,
+ mPreferSymbols);
}
void setKeyboardMode(int mode, int imeOptions, boolean isSymbols) {
@@ -228,5 +238,30 @@ public class KeyboardSwitcher {
void toggleSymbols() {
setKeyboardMode(mMode, mImeOptions, !mIsSymbols);
+ if (mIsSymbols && !mPreferSymbols) {
+ mSymbolsModeState = SYMBOLS_MODE_STATE_BEGIN;
+ } else {
+ mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
+ }
+ }
+
+ /**
+ * Updates state machine to figure out when to automatically switch back to alpha mode.
+ * Returns true if the keyboard needs to switch back
+ */
+ boolean onKey(int key) {
+ // Switch back to alpha mode if user types one or more non-space/enter characters
+ // followed by a space/enter
+ switch (mSymbolsModeState) {
+ case SYMBOLS_MODE_STATE_BEGIN:
+ if (key != LatinIME.KEYCODE_SPACE && key != LatinIME.KEYCODE_ENTER && key > 0) {
+ mSymbolsModeState = SYMBOLS_MODE_STATE_SYMBOL;
+ }
+ break;
+ case SYMBOLS_MODE_STATE_SYMBOL:
+ if (key == LatinIME.KEYCODE_ENTER || key == LatinIME.KEYCODE_SPACE) return true;
+ break;
+ }
+ return false;
}
}