Auto-switch back from symbols keyboard on space.
Also fix bug 1904029: Rotating keyboard while texting causes words to be deleted.
This commit is contained in:
parent
34386e6988
commit
b19668cfc1
2 changed files with 44 additions and 4 deletions
|
@ -37,6 +37,10 @@ public class KeyboardSwitcher {
|
||||||
public static final int KEYBOARDMODE_EMAIL = R.id.mode_email;
|
public static final int KEYBOARDMODE_EMAIL = R.id.mode_email;
|
||||||
public static final int KEYBOARDMODE_IM = R.id.mode_im;
|
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;
|
LatinKeyboardView mInputView;
|
||||||
LatinIME mContext;
|
LatinIME mContext;
|
||||||
|
|
||||||
|
@ -50,6 +54,7 @@ public class KeyboardSwitcher {
|
||||||
private int mImeOptions;
|
private int mImeOptions;
|
||||||
private int mTextMode = MODE_TEXT_QWERTY;
|
private int mTextMode = MODE_TEXT_QWERTY;
|
||||||
private boolean mIsSymbols;
|
private boolean mIsSymbols;
|
||||||
|
private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE;
|
||||||
|
|
||||||
private int mLastDisplayWidth;
|
private int mLastDisplayWidth;
|
||||||
|
|
||||||
|
@ -228,5 +233,28 @@ public class KeyboardSwitcher {
|
||||||
|
|
||||||
void toggleSymbols() {
|
void toggleSymbols() {
|
||||||
setKeyboardMode(mMode, mImeOptions, !mIsSymbols);
|
setKeyboardMode(mMode, mImeOptions, !mIsSymbols);
|
||||||
|
if (mIsSymbols) {
|
||||||
|
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 characters followed by
|
||||||
|
// a space.
|
||||||
|
switch (mSymbolsModeState) {
|
||||||
|
case SYMBOLS_MODE_STATE_BEGIN:
|
||||||
|
if (key != ' ' && key > 0) mSymbolsModeState = SYMBOLS_MODE_STATE_SYMBOL;
|
||||||
|
break;
|
||||||
|
case SYMBOLS_MODE_STATE_SYMBOL:
|
||||||
|
if (key == ' ') return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,6 +115,8 @@ public class LatinIME extends InputMethodService
|
||||||
private boolean mQuickFixes;
|
private boolean mQuickFixes;
|
||||||
private boolean mShowSuggestions;
|
private boolean mShowSuggestions;
|
||||||
private int mCorrectionMode;
|
private int mCorrectionMode;
|
||||||
|
private int mOrientation;
|
||||||
|
|
||||||
// Indicates whether the suggestion strip is to be on in landscape
|
// Indicates whether the suggestion strip is to be on in landscape
|
||||||
private boolean mJustAccepted;
|
private boolean mJustAccepted;
|
||||||
private CharSequence mJustRevertedSeparator;
|
private CharSequence mJustRevertedSeparator;
|
||||||
|
@ -159,10 +161,12 @@ public class LatinIME extends InputMethodService
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
//setStatusIcon(R.drawable.ime_qwerty);
|
//setStatusIcon(R.drawable.ime_qwerty);
|
||||||
mKeyboardSwitcher = new KeyboardSwitcher(this);
|
mKeyboardSwitcher = new KeyboardSwitcher(this);
|
||||||
initSuggest(getResources().getConfiguration().locale.toString());
|
final Configuration conf = getResources().getConfiguration();
|
||||||
|
initSuggest(conf.locale.toString());
|
||||||
|
mOrientation = conf.orientation;
|
||||||
|
|
||||||
mVibrateDuration = getResources().getInteger(R.integer.vibrate_duration_ms);
|
mVibrateDuration = getResources().getInteger(R.integer.vibrate_duration_ms);
|
||||||
|
|
||||||
// register to receive ringer mode changes for silent mode
|
// register to receive ringer mode changes for silent mode
|
||||||
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
|
||||||
registerReceiver(mReceiver, filter);
|
registerReceiver(mReceiver, filter);
|
||||||
|
@ -191,9 +195,14 @@ public class LatinIME extends InputMethodService
|
||||||
if (!TextUtils.equals(conf.locale.toString(), mLocale)) {
|
if (!TextUtils.equals(conf.locale.toString(), mLocale)) {
|
||||||
initSuggest(conf.locale.toString());
|
initSuggest(conf.locale.toString());
|
||||||
}
|
}
|
||||||
|
// If orientation changed while predicting, commit the change
|
||||||
|
if (conf.orientation != mOrientation) {
|
||||||
|
commitTyped(getCurrentInputConnection());
|
||||||
|
mOrientation = conf.orientation;
|
||||||
|
}
|
||||||
super.onConfigurationChanged(conf);
|
super.onConfigurationChanged(conf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateInputView() {
|
public View onCreateInputView() {
|
||||||
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
|
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
|
||||||
|
@ -575,6 +584,9 @@ public class LatinIME extends InputMethodService
|
||||||
// Cancel the just reverted state
|
// Cancel the just reverted state
|
||||||
mJustRevertedSeparator = null;
|
mJustRevertedSeparator = null;
|
||||||
}
|
}
|
||||||
|
if (mKeyboardSwitcher.onKey(primaryCode)) {
|
||||||
|
changeKeyboardMode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onText(CharSequence text) {
|
public void onText(CharSequence text) {
|
||||||
|
|
Loading…
Reference in a new issue