Remove a duplicated variable.
This is awesome cleanup. Change-Id: I35ce8940a13f3084630dc26d6e7e397acfdaac36
This commit is contained in:
parent
646a06ce25
commit
3651220327
3 changed files with 27 additions and 37 deletions
|
@ -203,7 +203,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private boolean mIsSettingsSuggestionStripOn;
|
private boolean mIsSettingsSuggestionStripOn;
|
||||||
private boolean mApplicationSpecifiedCompletionOn;
|
private boolean mApplicationSpecifiedCompletionOn;
|
||||||
|
|
||||||
private final StringBuilder mComposingStringBuilder = new StringBuilder();
|
|
||||||
private WordComposer mWordComposer = new WordComposer();
|
private WordComposer mWordComposer = new WordComposer();
|
||||||
private CharSequence mBestWord;
|
private CharSequence mBestWord;
|
||||||
private boolean mHasUncommittedTypedChars;
|
private boolean mHasUncommittedTypedChars;
|
||||||
|
@ -756,7 +755,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
inputView.closing();
|
inputView.closing();
|
||||||
mEnteredText = null;
|
mEnteredText = null;
|
||||||
mComposingStringBuilder.setLength(0);
|
mWordComposer.reset();
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
mDeleteCount = 0;
|
mDeleteCount = 0;
|
||||||
mSpaceState = SPACE_STATE_NONE;
|
mSpaceState = SPACE_STATE_NONE;
|
||||||
|
@ -928,10 +927,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// newly inserted punctuation.
|
// newly inserted punctuation.
|
||||||
mSpaceState = SPACE_STATE_NONE;
|
mSpaceState = SPACE_STATE_NONE;
|
||||||
}
|
}
|
||||||
if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars)
|
if (((mWordComposer.size() > 0 && mHasUncommittedTypedChars)
|
||||||
|| mVoiceProxy.isVoiceInputHighlighted())
|
|| mVoiceProxy.isVoiceInputHighlighted())
|
||||||
&& (selectionChanged || candidatesCleared)) {
|
&& (selectionChanged || candidatesCleared)) {
|
||||||
mComposingStringBuilder.setLength(0);
|
mWordComposer.reset();
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
TextEntryState.reset();
|
TextEntryState.reset();
|
||||||
updateSuggestions();
|
updateSuggestions();
|
||||||
|
@ -1146,13 +1145,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
public void commitTyped(final InputConnection ic) {
|
public void commitTyped(final InputConnection ic) {
|
||||||
if (!mHasUncommittedTypedChars) return;
|
if (!mHasUncommittedTypedChars) return;
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
if (mComposingStringBuilder.length() > 0) {
|
final CharSequence typedWord = mWordComposer.getTypedWord();
|
||||||
|
if (typedWord.length() > 0) {
|
||||||
if (ic != null) {
|
if (ic != null) {
|
||||||
ic.commitText(mComposingStringBuilder, 1);
|
ic.commitText(typedWord, 1);
|
||||||
}
|
}
|
||||||
mCommittedLength = mComposingStringBuilder.length();
|
mCommittedLength = typedWord.length();
|
||||||
TextEntryState.acceptedTyped(mComposingStringBuilder);
|
TextEntryState.acceptedTyped(typedWord);
|
||||||
addToUserUnigramAndBigramDictionaries(mComposingStringBuilder,
|
addToUserUnigramAndBigramDictionaries(typedWord,
|
||||||
UserUnigramDictionary.FREQUENCY_FOR_TYPED);
|
UserUnigramDictionary.FREQUENCY_FOR_TYPED);
|
||||||
}
|
}
|
||||||
updateSuggestions();
|
updateSuggestions();
|
||||||
|
@ -1408,17 +1408,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
final boolean deleteChar = !mHasUncommittedTypedChars;
|
final boolean deleteChar = !mHasUncommittedTypedChars;
|
||||||
if (mHasUncommittedTypedChars) {
|
if (mHasUncommittedTypedChars) {
|
||||||
final int length = mComposingStringBuilder.length();
|
final int length = mWordComposer.size();
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
mComposingStringBuilder.delete(length - 1, length);
|
|
||||||
mWordComposer.deleteLast();
|
mWordComposer.deleteLast();
|
||||||
final CharSequence textWithUnderline =
|
final CharSequence textWithUnderline =
|
||||||
mComposingStateManager.isAutoCorrectionIndicatorOn()
|
mComposingStateManager.isAutoCorrectionIndicatorOn()
|
||||||
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
||||||
this, mComposingStringBuilder)
|
this, mWordComposer.getTypedWord())
|
||||||
: mComposingStringBuilder;
|
: mWordComposer.getTypedWord();
|
||||||
ic.setComposingText(textWithUnderline, 1);
|
ic.setComposingText(textWithUnderline, 1);
|
||||||
if (mComposingStringBuilder.length() == 0) {
|
if (mWordComposer.size() == 0) {
|
||||||
mHasUncommittedTypedChars = false;
|
mHasUncommittedTypedChars = false;
|
||||||
}
|
}
|
||||||
if (1 == length) {
|
if (1 == length) {
|
||||||
|
@ -1521,7 +1520,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// 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 character is a single quote.
|
||||||
mHasUncommittedTypedChars = (Keyboard.CODE_SINGLE_QUOTE != code);
|
mHasUncommittedTypedChars = (Keyboard.CODE_SINGLE_QUOTE != code);
|
||||||
mComposingStringBuilder.setLength(0);
|
|
||||||
mWordComposer.reset();
|
mWordComposer.reset();
|
||||||
clearSuggestions();
|
clearSuggestions();
|
||||||
mComposingStateManager.onFinishComposingText();
|
mComposingStateManager.onFinishComposingText();
|
||||||
|
@ -1551,7 +1549,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mHasUncommittedTypedChars) {
|
if (mHasUncommittedTypedChars) {
|
||||||
mComposingStringBuilder.append((char) code);
|
|
||||||
mWordComposer.add(code, keyCodes, x, y);
|
mWordComposer.add(code, 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
|
||||||
|
@ -1562,8 +1559,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
final CharSequence textWithUnderline =
|
final CharSequence textWithUnderline =
|
||||||
mComposingStateManager.isAutoCorrectionIndicatorOn()
|
mComposingStateManager.isAutoCorrectionIndicatorOn()
|
||||||
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
||||||
this, mComposingStringBuilder)
|
this, mWordComposer.getTypedWord())
|
||||||
: mComposingStringBuilder;
|
: mWordComposer.getTypedWord();
|
||||||
ic.setComposingText(textWithUnderline, 1);
|
ic.setComposingText(textWithUnderline, 1);
|
||||||
}
|
}
|
||||||
mHandler.postUpdateSuggestions();
|
mHandler.postUpdateSuggestions();
|
||||||
|
@ -1751,8 +1748,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
final CharSequence textWithUnderline = newAutoCorrectionIndicator
|
final CharSequence textWithUnderline = newAutoCorrectionIndicator
|
||||||
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline(
|
||||||
this, mComposingStringBuilder)
|
this, mWordComposer.getTypedWord())
|
||||||
: mComposingStringBuilder;
|
: mWordComposer.getTypedWord();
|
||||||
if (!TextUtils.isEmpty(textWithUnderline)) {
|
if (!TextUtils.isEmpty(textWithUnderline)) {
|
||||||
ic.setComposingText(textWithUnderline, 1);
|
ic.setComposingText(textWithUnderline, 1);
|
||||||
}
|
}
|
||||||
|
@ -1945,9 +1942,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
} else {
|
} else {
|
||||||
addToOnlyBigramDictionary(suggestion, 1);
|
addToOnlyBigramDictionary(suggestion, 1);
|
||||||
}
|
}
|
||||||
LatinImeLogger.logOnManualSuggestion(mComposingStringBuilder.toString(),
|
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
|
||||||
suggestion.toString(), index, suggestions.mWords);
|
suggestion.toString(), index, suggestions.mWords);
|
||||||
TextEntryState.acceptedSuggestion(mComposingStringBuilder.toString(), suggestion);
|
TextEntryState.acceptedSuggestion(mWordComposer.getTypedWord().toString(), suggestion);
|
||||||
// Follow it with a space
|
// Follow it with a space
|
||||||
if (mInsertSpaceOnPickSuggestionManually) {
|
if (mInsertSpaceOnPickSuggestionManually) {
|
||||||
sendMagicSpace();
|
sendMagicSpace();
|
||||||
|
@ -2157,8 +2154,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
|
private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic,
|
||||||
final CharSequence word) {
|
final CharSequence word) {
|
||||||
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard());
|
mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard());
|
||||||
mComposingStringBuilder.setLength(0);
|
|
||||||
mComposingStringBuilder.append(word);
|
|
||||||
// mBestWord will be set appropriately by updateSuggestions() called by the handler
|
// mBestWord will be set appropriately by updateSuggestions() called by the handler
|
||||||
mBestWord = null;
|
mBestWord = null;
|
||||||
mHasUncommittedTypedChars = true;
|
mHasUncommittedTypedChars = true;
|
||||||
|
@ -2171,7 +2166,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
|
|
||||||
// "ic" must not be null
|
// "ic" must not be null
|
||||||
private void revertLastWord(final InputConnection ic) {
|
private void revertLastWord(final InputConnection ic) {
|
||||||
if (mHasUncommittedTypedChars || mComposingStringBuilder.length() <= 0) {
|
if (mHasUncommittedTypedChars || mWordComposer.size() <= 0) {
|
||||||
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2186,21 +2181,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
// the cursor.
|
// the cursor.
|
||||||
if (!TextUtils.isEmpty(separator)
|
if (!TextUtils.isEmpty(separator)
|
||||||
&& mSettingsValues.isWordSeparator(separator.charAt(0))
|
&& mSettingsValues.isWordSeparator(separator.charAt(0))
|
||||||
&& !TextUtils.equals(mComposingStringBuilder, textToTheLeft)) {
|
&& !TextUtils.equals(mWordComposer.getTypedWord(), textToTheLeft)) {
|
||||||
ic.commitText(mComposingStringBuilder, 1);
|
ic.commitText(mWordComposer.getTypedWord(), 1);
|
||||||
TextEntryState.acceptedTyped(mComposingStringBuilder);
|
TextEntryState.acceptedTyped(mWordComposer.getTypedWord());
|
||||||
ic.commitText(separator, 1);
|
ic.commitText(separator, 1);
|
||||||
TextEntryState.typedCharacter(separator.charAt(0), true,
|
TextEntryState.typedCharacter(separator.charAt(0), true,
|
||||||
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
|
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
|
||||||
// Clear composing text
|
|
||||||
mComposingStringBuilder.setLength(0);
|
|
||||||
} else {
|
} else {
|
||||||
// Note: this relies on the last word still being held in the WordComposer
|
// Note: this relies on the last word still being held in the WordComposer
|
||||||
// Note: in the interest of code simplicity, we may want to just call
|
// Note: in the interest of code simplicity, we may want to just call
|
||||||
// restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving
|
// restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving
|
||||||
// the old WordComposer allows to reuse the actual typed coordinates.
|
// the old WordComposer allows to reuse the actual typed coordinates.
|
||||||
mHasUncommittedTypedChars = true;
|
mHasUncommittedTypedChars = true;
|
||||||
ic.setComposingText(mComposingStringBuilder, 1);
|
ic.setComposingText(mWordComposer.getTypedWord(), 1);
|
||||||
TextEntryState.backspace();
|
TextEntryState.backspace();
|
||||||
}
|
}
|
||||||
mHandler.cancelUpdateBigramPredictions();
|
mHandler.cancelUpdateBigramPredictions();
|
||||||
|
@ -2479,7 +2472,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
|
final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
|
||||||
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
|
||||||
p.println(" Keyboard mode = " + keyboardMode);
|
p.println(" Keyboard mode = " + keyboardMode);
|
||||||
p.println(" mComposingStringBuilder=" + mComposingStringBuilder.toString());
|
|
||||||
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
|
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
|
||||||
p.println(" mCorrectionMode=" + mCorrectionMode);
|
p.println(" mCorrectionMode=" + mCorrectionMode);
|
||||||
p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
|
p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars);
|
||||||
|
|
|
@ -19,6 +19,7 @@ package com.android.inputmethod.latin;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
import com.android.inputmethod.latin.Utils.RingCharBuffer;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class TextEntryState {
|
public class TextEntryState {
|
||||||
|
@ -45,7 +46,7 @@ public class TextEntryState {
|
||||||
|
|
||||||
public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord,
|
public static void acceptedDefault(CharSequence typedWord, CharSequence actualWord,
|
||||||
int separatorCode) {
|
int separatorCode) {
|
||||||
if (typedWord == null) return;
|
if (TextUtils.isEmpty(typedWord)) return;
|
||||||
setState(ACCEPTED_DEFAULT);
|
setState(ACCEPTED_DEFAULT);
|
||||||
LatinImeLogger.logOnAutoCorrection(
|
LatinImeLogger.logOnAutoCorrection(
|
||||||
typedWord.toString(), actualWord.toString(), separatorCode);
|
typedWord.toString(), actualWord.toString(), separatorCode);
|
||||||
|
@ -57,7 +58,7 @@ public class TextEntryState {
|
||||||
// (see "case ACCEPTED_DEFAULT" in typedCharacter() below),
|
// (see "case ACCEPTED_DEFAULT" in typedCharacter() below),
|
||||||
// and should be restored back to State.ACCEPTED_DEFAULT after processing for each sub-state.
|
// and should be restored back to State.ACCEPTED_DEFAULT after processing for each sub-state.
|
||||||
public static void backToAcceptedDefault(CharSequence typedWord) {
|
public static void backToAcceptedDefault(CharSequence typedWord) {
|
||||||
if (typedWord == null) return;
|
if (TextUtils.isEmpty(typedWord)) return;
|
||||||
switch (sState) {
|
switch (sState) {
|
||||||
case SPACE_AFTER_ACCEPTED:
|
case SPACE_AFTER_ACCEPTED:
|
||||||
case PUNCTUATION_AFTER_ACCEPTED:
|
case PUNCTUATION_AFTER_ACCEPTED:
|
||||||
|
|
|
@ -231,9 +231,6 @@ public class WordComposer {
|
||||||
* @return the word that was typed so far
|
* @return the word that was typed so far
|
||||||
*/
|
*/
|
||||||
public String getTypedWord() {
|
public String getTypedWord() {
|
||||||
if (size() == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return mTypedWord.toString();
|
return mTypedWord.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue