Refactor KeyboardSwitcher and LatinIME
Bug: 3193390 Change-Id: Id894c9bc574a53966d9efc419ab398bae89c34c1main
parent
10227a71a0
commit
b643dab73a
|
@ -344,89 +344,155 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isKeyboardAvailable() {
|
public boolean isKeyboardAvailable() {
|
||||||
return mInputView != null && mInputView.getLatinKeyboard() != null;
|
if (mInputView != null)
|
||||||
|
return mInputView.getLatinKeyboard() != null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LatinKeyboard getLatinKeyboard() {
|
||||||
|
if (mInputView != null)
|
||||||
|
return mInputView.getLatinKeyboard();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferredLetters(int[] frequencies) {
|
public void setPreferredLetters(int[] frequencies) {
|
||||||
LatinKeyboard latinKeyboard;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
if (mInputView != null && (latinKeyboard = mInputView.getLatinKeyboard()) != null)
|
if (latinKeyboard != null)
|
||||||
latinKeyboard.setPreferredLetters(frequencies);
|
latinKeyboard.setPreferredLetters(frequencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void keyReleased() {
|
public void keyReleased() {
|
||||||
LatinKeyboard latinKeyboard;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
if (mInputView != null && (latinKeyboard = mInputView.getLatinKeyboard()) != null)
|
if (latinKeyboard != null)
|
||||||
latinKeyboard.keyReleased();
|
latinKeyboard.keyReleased();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShifted() {
|
public boolean isShifted() {
|
||||||
LatinKeyboard latinKeyboard;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
return mInputView != null && (latinKeyboard = mInputView.getLatinKeyboard()) != null
|
if (latinKeyboard != null)
|
||||||
&& latinKeyboard.isShifted();
|
return latinKeyboard.isShifted();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShiftLocked() {
|
public boolean isShiftLocked() {
|
||||||
LatinKeyboard latinKeyboard;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
return mInputView != null && (latinKeyboard = mInputView.getLatinKeyboard()) != null
|
if (latinKeyboard != null)
|
||||||
&& latinKeyboard.isShiftLocked();
|
return latinKeyboard.isShiftLocked();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShifted(boolean shifted) {
|
private void setShifted(boolean shifted) {
|
||||||
if (mInputView == null) return;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
LatinKeyboard latinKeyboard = mInputView.getLatinKeyboard();
|
if (latinKeyboard != null && latinKeyboard.setShifted(shifted)) {
|
||||||
if (latinKeyboard == null) return;
|
|
||||||
if (latinKeyboard.setShifted(shifted)) {
|
|
||||||
mInputView.invalidateAllKeys();
|
mInputView.invalidateAllKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShiftLocked(boolean shiftLocked) {
|
private void setShiftLocked(boolean shiftLocked) {
|
||||||
if (mInputView == null) return;
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
mInputView.setShiftLocked(shiftLocked);
|
if (latinKeyboard != null && latinKeyboard.setShiftLocked(shiftLocked)) {
|
||||||
|
mInputView.invalidateAllKeys();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleShift() {
|
||||||
|
handleShiftInternal(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetShift() {
|
||||||
|
handleShiftInternal(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleShiftInternal(boolean forceNormal) {
|
||||||
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
||||||
|
if (isAlphabetMode()) {
|
||||||
|
if (forceNormal) {
|
||||||
|
setShifted(false);
|
||||||
|
} else {
|
||||||
|
setShifted(!isShifted());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toggleShiftInSymbol();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void toggleCapsLock() {
|
||||||
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
||||||
|
if (isAlphabetMode()) {
|
||||||
|
if (isShiftLocked()) {
|
||||||
|
// setShifted(false) also disable shift locked state.
|
||||||
|
// Note: Caps lock LED is off when Key.on is false.
|
||||||
|
setShifted(false);
|
||||||
|
} else {
|
||||||
|
// setShiftLocked(true) enable shift state too.
|
||||||
|
// Note: Caps lock LED is on when Key.on is true.
|
||||||
|
setShiftLocked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateShiftState() {
|
||||||
|
if (isAlphabetMode() && !mShiftState.isIgnoring()) {
|
||||||
|
final boolean autoCapsMode = mInputMethodService.getCurrentAutoCapsState();
|
||||||
|
setShifted(mShiftState.isMomentary() || isShiftLocked() || autoCapsMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changeKeyboardMode() {
|
||||||
|
toggleKeyboardMode();
|
||||||
|
if (isShiftLocked() && isAlphabetMode())
|
||||||
|
setShiftLocked(true);
|
||||||
|
updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPressShift() {
|
public void onPressShift() {
|
||||||
mShiftState.onPress();
|
if (!isKeyboardAvailable())
|
||||||
}
|
return;
|
||||||
|
if (isAlphabetMode() && isShifted()) {
|
||||||
public void onPressShiftOnShifted() {
|
// In alphabet mode, we don't call toggleShift() when we are already in the shifted
|
||||||
|
// state.
|
||||||
mShiftState.onPressOnShifted();
|
mShiftState.onPressOnShifted();
|
||||||
|
} else {
|
||||||
|
// In alphabet mode, we call toggleShift() to go into the shifted mode only when we are
|
||||||
|
// not in the shifted state.
|
||||||
|
// This else clause also handles shift key pressing in symbol mode.
|
||||||
|
mShiftState.onPress();
|
||||||
|
toggleShift();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReleaseShift() {
|
public void onReleaseShift() {
|
||||||
|
if (!isKeyboardAvailable())
|
||||||
|
return;
|
||||||
|
if (isAlphabetMode()) {
|
||||||
|
if (mShiftState.isMomentary()) {
|
||||||
|
resetShift();
|
||||||
|
} else if (isShifted() && mShiftState.isPressingOnShifted()) {
|
||||||
|
// In alphabet mode, we call toggleShift() to go into the non shifted state only
|
||||||
|
// when we are in the shifted state -- temporary shifted mode or caps lock mode.
|
||||||
|
toggleShift();
|
||||||
|
}
|
||||||
|
}
|
||||||
mShiftState.onRelease();
|
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() {
|
||||||
|
changeKeyboardMode();
|
||||||
mSymbolKeyState.onPress();
|
mSymbolKeyState.onPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onReleaseSymbol() {
|
public void onReleaseSymbol() {
|
||||||
|
if (mSymbolKeyState.isMomentary())
|
||||||
|
changeKeyboardMode();
|
||||||
mSymbolKeyState.onRelease();
|
mSymbolKeyState.onRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSymbolMomentary() {
|
|
||||||
return mSymbolKeyState.isMomentary();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onOtherKeyPressed() {
|
public void onOtherKeyPressed() {
|
||||||
mShiftState.onOtherKeyPressed();
|
mShiftState.onOtherKeyPressed();
|
||||||
mSymbolKeyState.onOtherKeyPressed();
|
mSymbolKeyState.onOtherKeyPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleShift() {
|
private void toggleShiftInSymbol() {
|
||||||
if (isAlphabetMode())
|
if (isAlphabetMode())
|
||||||
return;
|
return;
|
||||||
final LatinKeyboard keyboard;
|
final LatinKeyboard keyboard;
|
||||||
|
@ -448,7 +514,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
mInputView.setKeyboard(keyboard);
|
mInputView.setKeyboard(keyboard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void toggleSymbols() {
|
public void toggleKeyboardMode() {
|
||||||
loadKeyboardInternal(mMode, mImeOptions, mVoiceButtonEnabled, mVoiceButtonOnPrimary,
|
loadKeyboardInternal(mMode, mImeOptions, mVoiceButtonEnabled, mVoiceButtonOnPrimary,
|
||||||
!mIsSymbols);
|
!mIsSymbols);
|
||||||
if (mIsSymbols) {
|
if (mIsSymbols) {
|
||||||
|
@ -464,11 +530,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates state machine to figure out when to automatically switch back to alpha mode.
|
* Updates state machine to figure out when to automatically switch back to alpha mode.
|
||||||
* Returns true if the keyboard needs to switch back
|
|
||||||
*/
|
*/
|
||||||
public boolean onKey(int key) {
|
public void onKey(int key) {
|
||||||
// Switch back to alpha mode if user types one or more non-space/enter characters
|
// Switch back to alpha mode if user types one or more non-space/enter
|
||||||
// followed by a space/enter
|
// characters followed by a space/enter
|
||||||
switch (mSymbolsModeState) {
|
switch (mSymbolsModeState) {
|
||||||
case SYMBOLS_MODE_STATE_BEGIN:
|
case SYMBOLS_MODE_STATE_BEGIN:
|
||||||
if (key != LatinIME.KEYCODE_SPACE && key != LatinIME.KEYCODE_ENTER && key > 0) {
|
if (key != LatinIME.KEYCODE_SPACE && key != LatinIME.KEYCODE_ENTER && key > 0) {
|
||||||
|
@ -476,10 +541,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SYMBOLS_MODE_STATE_SYMBOL:
|
case SYMBOLS_MODE_STATE_SYMBOL:
|
||||||
if (key == LatinIME.KEYCODE_ENTER || key == LatinIME.KEYCODE_SPACE) return true;
|
if (key == LatinIME.KEYCODE_ENTER || key == LatinIME.KEYCODE_SPACE) {
|
||||||
|
changeKeyboardMode();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LatinKeyboardView getInputView() {
|
public LatinKeyboardView getInputView() {
|
||||||
|
|
|
@ -331,7 +331,7 @@ public class LatinIME extends InputMethodService
|
||||||
setOldSuggestions();
|
setOldSuggestions();
|
||||||
break;
|
break;
|
||||||
case MSG_UPDATE_SHIFT_STATE:
|
case MSG_UPDATE_SHIFT_STATE:
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
break;
|
break;
|
||||||
case MSG_VOICE_RESULTS:
|
case MSG_VOICE_RESULTS:
|
||||||
handleVoiceResults();
|
handleVoiceResults();
|
||||||
|
@ -714,7 +714,7 @@ public class LatinIME extends InputMethodService
|
||||||
loadSettings(attribute);
|
loadSettings(attribute);
|
||||||
mKeyboardSwitcher.loadKeyboard(mode, attribute.imeOptions, mVoiceButtonEnabled,
|
mKeyboardSwitcher.loadKeyboard(mode, attribute.imeOptions, mVoiceButtonEnabled,
|
||||||
mVoiceButtonOnPrimary);
|
mVoiceButtonOnPrimary);
|
||||||
updateShiftKeyState(attribute);
|
mKeyboardSwitcher.updateShiftState();
|
||||||
|
|
||||||
setCandidatesViewShownInternal(isCandidateStripVisible(),
|
setCandidatesViewShownInternal(isCandidateStripVisible(),
|
||||||
false /* needsInputViewShown */ );
|
false /* needsInputViewShown */ );
|
||||||
|
@ -1081,25 +1081,13 @@ public class LatinIME extends InputMethodService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateShiftKeyState(EditorInfo attr) {
|
public boolean getCurrentAutoCapsState() {
|
||||||
InputConnection ic = getCurrentInputConnection();
|
InputConnection ic = getCurrentInputConnection();
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
if (ic != null && attr != null && switcher.isAlphabetMode()
|
|
||||||
&& !switcher.isShiftIgnoring()) {
|
|
||||||
switcher.setShifted(switcher.isShiftMomentary()
|
|
||||||
|| switcher.isShiftLocked() || getCursorCapsMode(ic, attr) != 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getCursorCapsMode(InputConnection ic, EditorInfo attr) {
|
|
||||||
int caps = 0;
|
|
||||||
EditorInfo ei = getCurrentInputEditorInfo();
|
EditorInfo ei = getCurrentInputEditorInfo();
|
||||||
if (mAutoCap && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
|
if (mAutoCap && ic != null && ei != null && ei.inputType != EditorInfo.TYPE_NULL) {
|
||||||
caps = ic.getCursorCapsMode(attr.inputType);
|
return ic.getCursorCapsMode(ei.inputType) != 0;
|
||||||
}
|
}
|
||||||
return caps;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void swapPunctuationAndSpace() {
|
private void swapPunctuationAndSpace() {
|
||||||
|
@ -1112,7 +1100,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.deleteSurroundingText(2, 0);
|
ic.deleteSurroundingText(2, 0);
|
||||||
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
ic.commitText(lastTwo.charAt(1) + " ", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
mJustAddedAutoSpace = true;
|
mJustAddedAutoSpace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1117,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.deleteSurroundingText(3, 0);
|
ic.deleteSurroundingText(3, 0);
|
||||||
ic.commitText(" ..", 1);
|
ic.commitText(" ..", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1146,7 +1134,7 @@ public class LatinIME extends InputMethodService
|
||||||
ic.deleteSurroundingText(2, 0);
|
ic.deleteSurroundingText(2, 0);
|
||||||
ic.commitText(". ", 1);
|
ic.commitText(". ", 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
mJustAddedAutoSpace = true;
|
mJustAddedAutoSpace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1229,7 +1217,8 @@ public class LatinIME extends InputMethodService
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
}
|
}
|
||||||
mLastKeyTime = when;
|
mLastKeyTime = when;
|
||||||
final boolean distinctMultiTouch = mKeyboardSwitcher.hasDistinctMultitouch();
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
switch (primaryCode) {
|
switch (primaryCode) {
|
||||||
case BaseKeyboard.KEYCODE_DELETE:
|
case BaseKeyboard.KEYCODE_DELETE:
|
||||||
handleBackspace();
|
handleBackspace();
|
||||||
|
@ -1239,12 +1228,12 @@ public class LatinIME extends InputMethodService
|
||||||
case BaseKeyboard.KEYCODE_SHIFT:
|
case BaseKeyboard.KEYCODE_SHIFT:
|
||||||
// Shift key is handled in onPress() when device has distinct multi-touch panel.
|
// Shift key is handled in onPress() when device has distinct multi-touch panel.
|
||||||
if (!distinctMultiTouch)
|
if (!distinctMultiTouch)
|
||||||
handleShift();
|
switcher.toggleShift();
|
||||||
break;
|
break;
|
||||||
case BaseKeyboard.KEYCODE_MODE_CHANGE:
|
case BaseKeyboard.KEYCODE_MODE_CHANGE:
|
||||||
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
// Symbol key is handled in onPress() when device has distinct multi-touch panel.
|
||||||
if (!distinctMultiTouch)
|
if (!distinctMultiTouch)
|
||||||
changeKeyboardMode();
|
switcher.changeKeyboardMode();
|
||||||
break;
|
break;
|
||||||
case BaseKeyboard.KEYCODE_CANCEL:
|
case BaseKeyboard.KEYCODE_CANCEL:
|
||||||
if (!isShowingOptionDialog()) {
|
if (!isShowingOptionDialog()) {
|
||||||
|
@ -1264,7 +1253,7 @@ public class LatinIME extends InputMethodService
|
||||||
toggleLanguage(false, false);
|
toggleLanguage(false, false);
|
||||||
break;
|
break;
|
||||||
case LatinKeyboardView.KEYCODE_CAPSLOCK:
|
case LatinKeyboardView.KEYCODE_CAPSLOCK:
|
||||||
handleCapsLock();
|
switcher.toggleCapsLock();
|
||||||
break;
|
break;
|
||||||
case LatinKeyboardView.KEYCODE_VOICE:
|
case LatinKeyboardView.KEYCODE_VOICE:
|
||||||
if (VOICE_INSTALLED) {
|
if (VOICE_INSTALLED) {
|
||||||
|
@ -1288,9 +1277,7 @@ public class LatinIME extends InputMethodService
|
||||||
// Cancel the just reverted state
|
// Cancel the just reverted state
|
||||||
mJustReverted = false;
|
mJustReverted = false;
|
||||||
}
|
}
|
||||||
if (mKeyboardSwitcher.onKey(primaryCode)) {
|
switcher.onKey(primaryCode);
|
||||||
changeKeyboardMode();
|
|
||||||
}
|
|
||||||
// Reset after any single keystroke
|
// Reset after any single keystroke
|
||||||
mEnteredText = null;
|
mEnteredText = null;
|
||||||
}
|
}
|
||||||
|
@ -1309,7 +1296,7 @@ public class LatinIME extends InputMethodService
|
||||||
maybeRemovePreviousPeriod(text);
|
maybeRemovePreviousPeriod(text);
|
||||||
ic.commitText(text, 1);
|
ic.commitText(text, 1);
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
mJustReverted = false;
|
mJustReverted = false;
|
||||||
mJustAddedAutoSpace = false;
|
mJustAddedAutoSpace = false;
|
||||||
mEnteredText = text;
|
mEnteredText = text;
|
||||||
|
@ -1389,48 +1376,6 @@ public class LatinIME extends InputMethodService
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetShift() {
|
|
||||||
handleShiftInternal(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleShift() {
|
|
||||||
handleShiftInternal(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleShiftInternal(boolean forceNormal) {
|
|
||||||
mHandler.cancelUpdateShiftState();
|
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
||||||
if (switcher.isAlphabetMode()) {
|
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
if (switcher.isShiftLocked() || forceNormal) {
|
|
||||||
switcher.setShifted(false);
|
|
||||||
} else {
|
|
||||||
switcher.setShifted(!switcher.isShifted());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
switcher.toggleShift();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleCapsLock() {
|
|
||||||
mHandler.cancelUpdateShiftState();
|
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
||||||
if (switcher.isAlphabetMode()) {
|
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
if (switcher.isShiftLocked()) {
|
|
||||||
// KeyboardSwitcher.setShifted(false) also disable shift locked state.
|
|
||||||
// Note: Caps lock LED is off when Key.on is false.
|
|
||||||
switcher.setShifted(false);
|
|
||||||
} else {
|
|
||||||
// KeyboardSwitcher.setShiftLocked(true) enable shift state too.
|
|
||||||
// Note: Caps lock LED is on when Key.on is true.
|
|
||||||
switcher.setShiftLocked(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void abortCorrection(boolean force) {
|
private void abortCorrection(boolean force) {
|
||||||
if (force || TextEntryState.isCorrecting()) {
|
if (force || TextEntryState.isCorrecting()) {
|
||||||
TextEntryState.onAbortCorrection();
|
TextEntryState.onAbortCorrection();
|
||||||
|
@ -1490,8 +1435,7 @@ public class LatinIME extends InputMethodService
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
// If it's the first letter, make note of auto-caps state
|
// If it's the first letter, make note of auto-caps state
|
||||||
if (mWord.size() == 1) {
|
if (mWord.size() == 1) {
|
||||||
mWord.setAutoCapitalized(
|
mWord.setAutoCapitalized(getCurrentAutoCapsState());
|
||||||
getCursorCapsMode(ic, getCurrentInputEditorInfo()) != 0);
|
|
||||||
}
|
}
|
||||||
ic.setComposingText(mComposing, 1);
|
ic.setComposingText(mComposing, 1);
|
||||||
}
|
}
|
||||||
|
@ -1499,7 +1443,7 @@ public class LatinIME extends InputMethodService
|
||||||
} else {
|
} else {
|
||||||
sendKeyChar((char)primaryCode);
|
sendKeyChar((char)primaryCode);
|
||||||
}
|
}
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
switcher.updateShiftState();
|
||||||
if (LatinIME.PERF_DEBUG) measureCps();
|
if (LatinIME.PERF_DEBUG) measureCps();
|
||||||
TextEntryState.typedCharacter((char) primaryCode, isWordSeparator(primaryCode));
|
TextEntryState.typedCharacter((char) primaryCode, isWordSeparator(primaryCode));
|
||||||
}
|
}
|
||||||
|
@ -1565,7 +1509,7 @@ public class LatinIME extends InputMethodService
|
||||||
if (pickedDefault) {
|
if (pickedDefault) {
|
||||||
TextEntryState.backToAcceptedDefault(mWord.getTypedWord());
|
TextEntryState.backToAcceptedDefault(mWord.getTypedWord());
|
||||||
}
|
}
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
|
@ -1937,7 +1881,7 @@ public class LatinIME extends InputMethodService
|
||||||
if (mCandidateView != null) {
|
if (mCandidateView != null) {
|
||||||
mCandidateView.clear();
|
mCandidateView.clear();
|
||||||
}
|
}
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
|
@ -2030,7 +1974,8 @@ public class LatinIME extends InputMethodService
|
||||||
* word.
|
* word.
|
||||||
*/
|
*/
|
||||||
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
|
private void pickSuggestion(CharSequence suggestion, boolean correcting) {
|
||||||
if (!mKeyboardSwitcher.isKeyboardAvailable())
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
|
if (!switcher.isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
InputConnection ic = getCurrentInputConnection();
|
InputConnection ic = getCurrentInputConnection();
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
|
@ -2040,12 +1985,12 @@ public class LatinIME extends InputMethodService
|
||||||
saveWordInHistory(suggestion);
|
saveWordInHistory(suggestion);
|
||||||
mPredicting = false;
|
mPredicting = false;
|
||||||
mCommittedLength = suggestion.length();
|
mCommittedLength = suggestion.length();
|
||||||
mKeyboardSwitcher.setPreferredLetters(null);
|
switcher.setPreferredLetters(null);
|
||||||
// If we just corrected a word, then don't show punctuations
|
// If we just corrected a word, then don't show punctuations
|
||||||
if (!correcting) {
|
if (!correcting) {
|
||||||
setPunctuationSuggestions();
|
setPunctuationSuggestions();
|
||||||
}
|
}
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
switcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2264,7 +2209,7 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
private void sendSpace() {
|
private void sendSpace() {
|
||||||
sendKeyChar((char)KEYCODE_SPACE);
|
sendKeyChar((char)KEYCODE_SPACE);
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
mKeyboardSwitcher.updateShiftState();
|
||||||
//onKey(KEY_SPACE[0], KEY_SPACE);
|
//onKey(KEY_SPACE[0], KEY_SPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2282,14 +2227,15 @@ public class LatinIME extends InputMethodService
|
||||||
mLanguageSwitcher.prev();
|
mLanguageSwitcher.prev();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final int mode = mKeyboardSwitcher.getKeyboardMode();
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
|
final int mode = switcher.getKeyboardMode();
|
||||||
final EditorInfo attribute = getCurrentInputEditorInfo();
|
final EditorInfo attribute = getCurrentInputEditorInfo();
|
||||||
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0;
|
||||||
mKeyboardSwitcher.loadKeyboard(mode, imeOptions, mVoiceButtonEnabled,
|
switcher.loadKeyboard(mode, imeOptions, mVoiceButtonEnabled,
|
||||||
mVoiceButtonOnPrimary);
|
mVoiceButtonOnPrimary);
|
||||||
initSuggest(mLanguageSwitcher.getInputLanguage());
|
initSuggest(mLanguageSwitcher.getInputLanguage());
|
||||||
mLanguageSwitcher.persist();
|
mLanguageSwitcher.persist();
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
switcher.updateShiftState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||||
|
@ -2328,21 +2274,11 @@ public class LatinIME extends InputMethodService
|
||||||
vibrate();
|
vibrate();
|
||||||
playKeyClick(primaryCode);
|
playKeyClick(primaryCode);
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
final boolean distinctMultiTouch = switcher.hasDistinctMultitouch();
|
||||||
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
|
if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_SHIFT) {
|
||||||
// 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()) {
|
|
||||||
switcher.onPressShiftOnShifted();
|
|
||||||
} else {
|
|
||||||
switcher.onPressShift();
|
switcher.onPressShift();
|
||||||
handleShift();
|
|
||||||
}
|
|
||||||
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
||||||
switcher.onPressSymbol();
|
switcher.onPressSymbol();
|
||||||
changeKeyboardMode();
|
|
||||||
} else {
|
} else {
|
||||||
switcher.onOtherKeyPressed();
|
switcher.onOtherKeyPressed();
|
||||||
}
|
}
|
||||||
|
@ -2350,28 +2286,12 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
public void onRelease(int primaryCode) {
|
public void onRelease(int primaryCode) {
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
// Reset any drag flags in the keyboard
|
// Reset any drag flags in the keyboard
|
||||||
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 (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() && switcher.isShiftPressingOnShifted()) {
|
|
||||||
handleShift();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switcher.onReleaseShift();
|
switcher.onReleaseShift();
|
||||||
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
} else if (distinctMultiTouch && primaryCode == BaseKeyboard.KEYCODE_MODE_CHANGE) {
|
||||||
if (switcher.isSymbolMomentary()) {
|
|
||||||
changeKeyboardMode();
|
|
||||||
}
|
|
||||||
switcher.onReleaseSymbol();
|
switcher.onReleaseSymbol();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2679,18 +2599,6 @@ public class LatinIME extends InputMethodService
|
||||||
mOptionsDialog.show();
|
mOptionsDialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeKeyboardMode() {
|
|
||||||
KeyboardSwitcher switcher = mKeyboardSwitcher;
|
|
||||||
switcher.toggleSymbols();
|
|
||||||
if (!switcher.isKeyboardAvailable())
|
|
||||||
return;
|
|
||||||
if (switcher.isShiftLocked() && switcher.isAlphabetMode()) {
|
|
||||||
switcher.setShiftLocked(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateShiftKeyState(getCurrentInputEditorInfo());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <E> ArrayList<E> newArrayList(E... elements) {
|
public static <E> ArrayList<E> newArrayList(E... elements) {
|
||||||
int capacity = (elements.length * 110) / 100 + 5;
|
int capacity = (elements.length * 110) / 100 + 5;
|
||||||
ArrayList<E> list = new ArrayList<E>(capacity);
|
ArrayList<E> list = new ArrayList<E>(capacity);
|
||||||
|
|
|
@ -232,13 +232,14 @@ public class LatinKeyboard extends BaseKeyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShiftLocked(boolean shiftLocked) {
|
public boolean setShiftLocked(boolean shiftLocked) {
|
||||||
// TODO: cleanup this method with BaseKeyboard.Key
|
// TODO: cleanup this method with BaseKeyboard.Key
|
||||||
for (final Key key : getShiftKeys()) {
|
for (final Key key : getShiftKeys()) {
|
||||||
key.on = shiftLocked;
|
key.on = shiftLocked;
|
||||||
key.icon = mShiftLockIcon;
|
key.icon = mShiftLockIcon;
|
||||||
}
|
}
|
||||||
mShiftState = shiftLocked ? SHIFT_LOCKED : SHIFT_ON;
|
mShiftState = shiftLocked ? SHIFT_LOCKED : SHIFT_ON;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShiftLocked() {
|
public boolean isShiftLocked() {
|
||||||
|
|
|
@ -127,13 +127,6 @@ public class LatinKeyboardView extends BaseKeyboardView {
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setShiftLocked(boolean shiftLocked) {
|
|
||||||
LatinKeyboard keyboard = getLatinKeyboard();
|
|
||||||
keyboard.setShiftLocked(shiftLocked);
|
|
||||||
invalidateAllKeys();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function checks to see if we need to handle any sudden jumps in the pointer location
|
* This function checks to see if we need to handle any sudden jumps in the pointer location
|
||||||
* that could be due to a multi-touch being treated as a move by the firmware or hardware.
|
* that could be due to a multi-touch being treated as a move by the firmware or hardware.
|
||||||
|
|
|
@ -217,7 +217,7 @@ public class Tutorial implements OnTouchListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mBubbleIndex == 3 || mBubbleIndex == 4) {
|
if (mBubbleIndex == 3 || mBubbleIndex == 4) {
|
||||||
mKeyboardSwitcher.toggleSymbols();
|
mKeyboardSwitcher.toggleKeyboardMode();
|
||||||
}
|
}
|
||||||
mHandler.sendMessageDelayed(
|
mHandler.sendMessageDelayed(
|
||||||
mHandler.obtainMessage(MSG_SHOW_BUBBLE, mBubbles.get(mBubbleIndex)), 500);
|
mHandler.obtainMessage(MSG_SHOW_BUBBLE, mBubbles.get(mBubbleIndex)), 500);
|
||||||
|
|
Loading…
Reference in New Issue