More simplification
A suggested punctuation is sure to be 1 character and a word separator, so the isSuggestedPunctuation() test is redundant. Change-Id: I3d31f0825f069f64d514682e46be62afdae25291
This commit is contained in:
parent
8174373a0e
commit
e771fc2f1a
1 changed files with 48 additions and 44 deletions
|
@ -1224,12 +1224,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
return mOptionsDialog != null && mOptionsDialog.isShowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertPunctuationFromSuggestionStrip(final int code) {
|
|
||||||
onCodeInput(code, new int[] { code },
|
|
||||||
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE,
|
|
||||||
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implementation of {@link KeyboardActionListener}.
|
// Implementation of {@link KeyboardActionListener}.
|
||||||
@Override
|
@Override
|
||||||
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
|
||||||
|
@ -1476,6 +1470,28 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ic may be null
|
||||||
|
private boolean maybeStripSpaceWhileInBatchEdit(final InputConnection ic, final int code,
|
||||||
|
final int spaceState, final boolean isFromSuggestionStrip) {
|
||||||
|
if (Keyboard.CODE_ENTER == code && SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
|
||||||
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
||||||
|
return false;
|
||||||
|
} else if ((SPACE_STATE_WEAK == spaceState
|
||||||
|
|| SPACE_STATE_SWAP_PUNCTUATION == spaceState)
|
||||||
|
&& isFromSuggestionStrip) {
|
||||||
|
if (mSettingsValues.isMagicSpaceSwapper(code)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
if (mSettingsValues.isMagicSpaceStripper(code)) {
|
||||||
|
removeTrailingSpaceWhileInBatchEdit(ic);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleCharacter(final int primaryCode, final int[] keyCodes, final int x,
|
private void handleCharacter(final int primaryCode, final int[] keyCodes, final int x,
|
||||||
final int y, final int spaceState) {
|
final int y, final int spaceState) {
|
||||||
mVoiceProxy.handleCharacter();
|
mVoiceProxy.handleCharacter();
|
||||||
|
@ -1490,7 +1506,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private void handleCharacterWhileInBatchEdit(final int primaryCode, final int[] keyCodes,
|
private void handleCharacterWhileInBatchEdit(final int primaryCode, final int[] keyCodes,
|
||||||
final int x, final int y, final int spaceState, final InputConnection ic) {
|
final int x, final int y, final int spaceState, final InputConnection ic) {
|
||||||
boolean isComposingWord = mWordComposer.isComposingWord();
|
boolean isComposingWord = mWordComposer.isComposingWord();
|
||||||
int code = primaryCode;
|
|
||||||
|
|
||||||
if (SPACE_STATE_PHANTOM == spaceState &&
|
if (SPACE_STATE_PHANTOM == spaceState &&
|
||||||
!mSettingsValues.isSymbolExcludedFromWordSeparators(primaryCode)) {
|
!mSettingsValues.isSymbolExcludedFromWordSeparators(primaryCode)) {
|
||||||
|
@ -1501,14 +1516,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
sendKeyChar((char)Keyboard.CODE_SPACE);
|
sendKeyChar((char)Keyboard.CODE_SPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code))
|
if ((isAlphabet(primaryCode)
|
||||||
|
|| mSettingsValues.isSymbolExcludedFromWordSeparators(primaryCode))
|
||||||
&& isSuggestionsRequested() && !isCursorTouchingWord()) {
|
&& isSuggestionsRequested() && !isCursorTouchingWord()) {
|
||||||
if (!isComposingWord) {
|
if (!isComposingWord) {
|
||||||
// Reset entirely the composing state anyway, then start composing a new word unless
|
// Reset entirely the composing state anyway, then start composing a new word unless
|
||||||
// the character is a single quote. The idea here is, single quote is not a
|
// the character is a single quote. The idea here is, single quote is not a
|
||||||
// separator and it should be treated as a normal character, except in the first
|
// separator and it should be treated as a normal character, except in the first
|
||||||
// position where it should not start composing a word.
|
// position where it should not start composing a word.
|
||||||
isComposingWord = (Keyboard.CODE_SINGLE_QUOTE != code);
|
isComposingWord = (Keyboard.CODE_SINGLE_QUOTE != primaryCode);
|
||||||
// Here we don't need to reset the last composed word. It will be reset
|
// Here we don't need to reset the last composed word. It will be reset
|
||||||
// when we commit this one, if we ever do; if on the other hand we backspace
|
// when we commit this one, if we ever do; if on the other hand we backspace
|
||||||
// it entirely and resume suggestions on the previous word, we'd like to still
|
// it entirely and resume suggestions on the previous word, we'd like to still
|
||||||
|
@ -1519,7 +1535,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isComposingWord) {
|
if (isComposingWord) {
|
||||||
mWordComposer.add(code, keyCodes, x, y);
|
mWordComposer.add(primaryCode, keyCodes, x, y);
|
||||||
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 (mWordComposer.size() == 1) {
|
if (mWordComposer.size() == 1) {
|
||||||
|
@ -1530,10 +1546,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
mHandler.postUpdateSuggestions();
|
mHandler.postUpdateSuggestions();
|
||||||
} else {
|
} else {
|
||||||
sendKeyChar((char)code);
|
final boolean swapWeakSpace = maybeStripSpaceWhileInBatchEdit(ic, primaryCode,
|
||||||
}
|
spaceState, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
|
||||||
|
|
||||||
Utils.Stats.onNonSeparator((char)code, x, y);
|
sendKeyChar((char)primaryCode);
|
||||||
|
|
||||||
|
if (swapWeakSpace) {
|
||||||
|
swapSwapperAndSpaceWhileInBatchEdit(ic);
|
||||||
|
mSpaceState = SPACE_STATE_WEAK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Utils.Stats.onNonSeparator((char)primaryCode, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if we did an autocorrection, false otherwise.
|
// Returns true if we did an autocorrection, false otherwise.
|
||||||
|
@ -1569,23 +1592,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean swapWeakSpace;
|
final boolean swapWeakSpace = maybeStripSpaceWhileInBatchEdit(ic, primaryCode, spaceState,
|
||||||
if (Keyboard.CODE_ENTER == primaryCode && SPACE_STATE_SWAP_PUNCTUATION == spaceState) {
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x);
|
||||||
removeTrailingSpaceWhileInBatchEdit(ic);
|
|
||||||
swapWeakSpace = false;
|
|
||||||
} else if ((SPACE_STATE_WEAK == spaceState || SPACE_STATE_SWAP_PUNCTUATION == spaceState)
|
|
||||||
&& KeyboardActionListener.SUGGESTION_STRIP_COORDINATE == x) {
|
|
||||||
if (mSettingsValues.isMagicSpaceSwapper(primaryCode)) {
|
|
||||||
swapWeakSpace = true;
|
|
||||||
} else {
|
|
||||||
swapWeakSpace = false;
|
|
||||||
if (mSettingsValues.isMagicSpaceStripper(primaryCode)) {
|
|
||||||
removeTrailingSpaceWhileInBatchEdit(ic);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
swapWeakSpace = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: rethink interactions of sendKeyChar, commitText("\n") and actions. sendKeyChar
|
// TODO: rethink interactions of sendKeyChar, commitText("\n") and actions. sendKeyChar
|
||||||
// with a CODE_ENTER parameter will have the default InputMethodService implementation
|
// with a CODE_ENTER parameter will have the default InputMethodService implementation
|
||||||
|
@ -1875,35 +1883,31 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
if (mInputAttributes.mApplicationSpecifiedCompletionOn
|
if (mInputAttributes.mApplicationSpecifiedCompletionOn
|
||||||
&& mApplicationSpecifiedCompletions != null
|
&& mApplicationSpecifiedCompletions != null
|
||||||
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
||||||
|
if (mSuggestionsView != null) {
|
||||||
|
mSuggestionsView.clear();
|
||||||
|
}
|
||||||
|
mKeyboardSwitcher.updateShiftState();
|
||||||
final InputConnection ic = getCurrentInputConnection();
|
final InputConnection ic = getCurrentInputConnection();
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.beginBatchEdit();
|
ic.beginBatchEdit();
|
||||||
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index];
|
||||||
ic.commitCompletion(completionInfo);
|
ic.commitCompletion(completionInfo);
|
||||||
}
|
|
||||||
if (mSuggestionsView != null) {
|
|
||||||
mSuggestionsView.clear();
|
|
||||||
}
|
|
||||||
mKeyboardSwitcher.updateShiftState();
|
|
||||||
if (ic != null) {
|
|
||||||
ic.endBatchEdit();
|
ic.endBatchEdit();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a punctuation, apply it through the normal key press
|
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
||||||
if (suggestion.length() == 1 && (mSettingsValues.isWordSeparator(suggestion.charAt(0))
|
if (suggestion.length() == 1 && isShowingPunctuationList()) {
|
||||||
|| mSettingsValues.isSuggestedPunctuation(suggestion.charAt(0)))) {
|
|
||||||
// Word separators are suggested before the user inputs something.
|
// Word separators are suggested before the user inputs something.
|
||||||
// So, LatinImeLogger logs "" as a user's input.
|
// So, LatinImeLogger logs "" as a user's input.
|
||||||
LatinImeLogger.logOnManualSuggestion(
|
LatinImeLogger.logOnManualSuggestion(
|
||||||
"", suggestion.toString(), index, suggestions.mWords);
|
"", suggestion.toString(), index, suggestions.mWords);
|
||||||
|
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
|
||||||
final int primaryCode = suggestion.charAt(0);
|
final int primaryCode = suggestion.charAt(0);
|
||||||
// Find out whether the previous character is a space. If it is, as a special case
|
onCodeInput(primaryCode, new int[] { primaryCode },
|
||||||
// for punctuation entered through the suggestion strip, it should be swapped
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE,
|
||||||
// if it was a magic or a weak space. This is meant to help in case the user
|
KeyboardActionListener.SUGGESTION_STRIP_COORDINATE);
|
||||||
// pressed space on purpose of displaying the suggestion strip punctuation.
|
|
||||||
insertPunctuationFromSuggestionStrip(primaryCode);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We need to log before we commit, because the word composer will store away the user
|
// We need to log before we commit, because the word composer will store away the user
|
||||||
|
|
Loading…
Reference in a new issue