Change variable names for readability

Change-Id: I9face4e90af4bcd6040eb7e303b596af7d643934
This commit is contained in:
Ken Wakasa 2011-07-12 10:29:29 +09:00
parent 1fa878339e
commit 9318d33b6e
2 changed files with 52 additions and 52 deletions

View file

@ -164,8 +164,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private boolean mIsSettingsSuggestionStripOn; private boolean mIsSettingsSuggestionStripOn;
private boolean mApplicationSpecifiedCompletionOn; private boolean mApplicationSpecifiedCompletionOn;
private final StringBuilder mComposing = new StringBuilder(); private final StringBuilder mComposingStringBuilder = new StringBuilder();
private WordComposer mWord = new WordComposer(); private WordComposer mWordComposer = new WordComposer();
private CharSequence mBestWord; private CharSequence mBestWord;
private boolean mHasUncommittedTypedChars; private boolean mHasUncommittedTypedChars;
private boolean mHasDictionary; private boolean mHasDictionary;
@ -233,7 +233,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_UPDATE_OLD_SUGGESTIONS: case MSG_UPDATE_OLD_SUGGESTIONS:
latinIme.mRecorrection.fetchAndDisplayRecorrectionSuggestions( latinIme.mRecorrection.fetchAndDisplayRecorrectionSuggestions(
latinIme.mVoiceProxy, latinIme.mCandidateView, latinIme.mVoiceProxy, latinIme.mCandidateView,
latinIme.mSuggest, latinIme.mKeyboardSwitcher, latinIme.mWord, latinIme.mSuggest, latinIme.mKeyboardSwitcher, latinIme.mWordComposer,
latinIme.mHasUncommittedTypedChars, latinIme.mLastSelectionStart, latinIme.mHasUncommittedTypedChars, latinIme.mLastSelectionStart,
latinIme.mLastSelectionEnd, latinIme.mSettingsValues.mWordSeparators); latinIme.mLastSelectionEnd, latinIme.mSettingsValues.mWordSeparators);
break; break;
@ -555,7 +555,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
inputView.closing(); inputView.closing();
mEnteredText = null; mEnteredText = null;
mComposing.setLength(0); mComposingStringBuilder.setLength(0);
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
mDeleteCount = 0; mDeleteCount = 0;
mJustAddedMagicSpace = false; mJustAddedMagicSpace = false;
@ -717,16 +717,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean selectionChanged = (newSelStart != candidatesEnd final boolean selectionChanged = (newSelStart != candidatesEnd
|| newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart; || newSelEnd != candidatesEnd) && mLastSelectionStart != newSelStart;
final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1; final boolean candidatesCleared = candidatesStart == -1 && candidatesEnd == -1;
if (((mComposing.length() > 0 && mHasUncommittedTypedChars) if (((mComposingStringBuilder.length() > 0 && mHasUncommittedTypedChars)
|| mVoiceProxy.isVoiceInputHighlighted()) || mVoiceProxy.isVoiceInputHighlighted())
&& (selectionChanged || candidatesCleared)) { && (selectionChanged || candidatesCleared)) {
if (candidatesCleared) { if (candidatesCleared) {
// If the composing span has been cleared, save the typed word in the history for // If the composing span has been cleared, save the typed word in the history for
// recorrection before we reset the candidate strip. Then, we'll be able to show // recorrection before we reset the candidate strip. Then, we'll be able to show
// suggestions for recorrection right away. // suggestions for recorrection right away.
mRecorrection.saveRecorrectionSuggestion(mWord, mComposing); mRecorrection.saveRecorrectionSuggestion(mWordComposer, mComposingStringBuilder);
} }
mComposing.setLength(0); mComposingStringBuilder.setLength(0);
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
if (isCursorTouchingWord()) { if (isCursorTouchingWord()) {
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();
@ -947,13 +947,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void commitTyped(InputConnection inputConnection) { public void commitTyped(InputConnection inputConnection) {
if (mHasUncommittedTypedChars) { if (mHasUncommittedTypedChars) {
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
if (mComposing.length() > 0) { if (mComposingStringBuilder.length() > 0) {
if (inputConnection != null) { if (inputConnection != null) {
inputConnection.commitText(mComposing, 1); inputConnection.commitText(mComposingStringBuilder, 1);
} }
mCommittedLength = mComposing.length(); mCommittedLength = mComposingStringBuilder.length();
TextEntryState.acceptedTyped(mComposing); TextEntryState.acceptedTyped(mComposingStringBuilder);
addToAutoAndUserBigramDictionaries(mComposing, AutoDictionary.FREQUENCY_FOR_TYPED); addToAutoAndUserBigramDictionaries(mComposingStringBuilder,
AutoDictionary.FREQUENCY_FOR_TYPED);
} }
updateSuggestions(); updateSuggestions();
} }
@ -1185,12 +1186,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final boolean deleteChar = !mHasUncommittedTypedChars; final boolean deleteChar = !mHasUncommittedTypedChars;
if (mHasUncommittedTypedChars) { if (mHasUncommittedTypedChars) {
final int length = mComposing.length(); final int length = mComposingStringBuilder.length();
if (length > 0) { if (length > 0) {
mComposing.delete(length - 1, length); mComposingStringBuilder.delete(length - 1, length);
mWord.deleteLast(); mWordComposer.deleteLast();
ic.setComposingText(mComposing, 1); ic.setComposingText(mComposingStringBuilder, 1);
if (mComposing.length() == 0) { if (mComposingStringBuilder.length() == 0) {
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
} }
if (1 == length) { if (1 == length) {
@ -1280,9 +1281,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (isAlphabet(code) && isSuggestionsRequested() && !isCursorTouchingWord()) { if (isAlphabet(code) && isSuggestionsRequested() && !isCursorTouchingWord()) {
if (!mHasUncommittedTypedChars) { if (!mHasUncommittedTypedChars) {
mHasUncommittedTypedChars = true; mHasUncommittedTypedChars = true;
mComposing.setLength(0); mComposingStringBuilder.setLength(0);
mRecorrection.saveRecorrectionSuggestion(mWord, mBestWord); mRecorrection.saveRecorrectionSuggestion(mWordComposer, mBestWord);
mWord.reset(); mWordComposer.reset();
clearSuggestions(); clearSuggestions();
} }
} }
@ -1308,19 +1309,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
} }
if (mHasUncommittedTypedChars) { if (mHasUncommittedTypedChars) {
if (mComposing.length() == 0 && switcher.isAlphabetMode() if (mComposingStringBuilder.length() == 0 && switcher.isAlphabetMode()
&& switcher.isShiftedOrShiftLocked()) { && switcher.isShiftedOrShiftLocked()) {
mWord.setFirstCharCapitalized(true); mWordComposer.setFirstCharCapitalized(true);
} }
mComposing.append((char) code); mComposingStringBuilder.append((char) code);
mWord.add(code, keyCodes, x, y); mWordComposer.add(code, keyCodes, x, y);
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
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 (mWordComposer.size() == 1) {
mWord.setAutoCapitalized(getCurrentAutoCapsState()); mWordComposer.setAutoCapitalized(getCurrentAutoCapsState());
} }
ic.setComposingText(mComposing, 1); ic.setComposingText(mComposingStringBuilder, 1);
} }
mHandler.postUpdateSuggestions(); mHandler.postUpdateSuggestions();
} else { } else {
@ -1388,7 +1389,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
TextEntryState.typedCharacter((char) primaryCode, true, x, y); TextEntryState.typedCharacter((char) primaryCode, true, x, y);
if (pickedDefault) { if (pickedDefault) {
CharSequence typedWord = mWord.getTypedWord(); CharSequence typedWord = mWordComposer.getTypedWord();
TextEntryState.backToAcceptedDefault(typedWord); TextEntryState.backToAcceptedDefault(typedWord);
if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) { if (!TextUtils.isEmpty(typedWord) && !typedWord.equals(mBestWord)) {
InputConnectionCompatUtils.commitCorrection( InputConnectionCompatUtils.commitCorrection(
@ -1491,18 +1492,16 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
setPunctuationSuggestions(); setPunctuationSuggestions();
return; return;
} }
showSuggestions(mWord);
}
private void showSuggestions(WordComposer word) { final WordComposer wordComposer = mWordComposer;
// TODO: May need a better way of retrieving previous word // TODO: May need a better way of retrieving previous word
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(), CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
mSettingsValues.mWordSeparators); mSettingsValues.mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getKeyboardView(), word, prevWord); mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord);
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection(); boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
final CharSequence typedWord = word.getTypedWord(); final CharSequence typedWord = wordComposer.getTypedWord();
// Here, we want to promote a whitelisted word if exists. // Here, we want to promote a whitelisted word if exists.
final boolean typedWordValid = AutoCorrection.isValidWordForAutoCorrection( final boolean typedWordValid = AutoCorrection.isValidWordForAutoCorrection(
mSuggest.getUnigramDictionaries(), typedWord, preferCapitalization()); mSuggest.getUnigramDictionaries(), typedWord, preferCapitalization());
@ -1511,7 +1510,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
correctionAvailable |= typedWordValid; correctionAvailable |= typedWordValid;
} }
// Don't auto-correct words with multiple capital letter // Don't auto-correct words with multiple capital letter
correctionAvailable &= !word.isMostlyCaps(); correctionAvailable &= !wordComposer.isMostlyCaps();
correctionAvailable &= !TextEntryState.isRecorrecting(); correctionAvailable &= !TextEntryState.isRecorrecting();
// Basically, we update the suggestion strip only when suggestion count > 1. However, // Basically, we update the suggestion strip only when suggestion count > 1. However,
@ -1558,7 +1557,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
updateSuggestions(); updateSuggestions();
} }
if (mBestWord != null && mBestWord.length() > 0) { if (mBestWord != null && mBestWord.length() > 0) {
TextEntryState.acceptedDefault(mWord.getTypedWord(), mBestWord, separatorCode); TextEntryState.acceptedDefault(mWordComposer.getTypedWord(), mBestWord, separatorCode);
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
commitBestWord(mBestWord); commitBestWord(mBestWord);
// Add the word to the auto dictionary if it's not a known word // Add the word to the auto dictionary if it's not a known word
@ -1625,7 +1624,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (!mHasUncommittedTypedChars) { if (!mHasUncommittedTypedChars) {
// If we are not composing a word, then it was a suggestion inferred from // If we are not composing a word, then it was a suggestion inferred from
// context - no user input. We should reset the word composer. // context - no user input. We should reset the word composer.
mWord.reset(); mWordComposer.reset();
} }
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
commitBestWord(suggestion); commitBestWord(suggestion);
@ -1635,9 +1634,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} else { } else {
addToOnlyBigramDictionary(suggestion, 1); addToOnlyBigramDictionary(suggestion, 1);
} }
LatinImeLogger.logOnManualSuggestion(mComposing.toString(), suggestion.toString(), LatinImeLogger.logOnManualSuggestion(mComposingStringBuilder.toString(),
index, suggestions.mWords); suggestion.toString(), index, suggestions.mWords);
TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion); TextEntryState.acceptedSuggestion(mComposingStringBuilder.toString(), suggestion);
// Follow it with a space // Follow it with a space
if (mShouldInsertMagicSpace && !recorrecting) { if (mShouldInsertMagicSpace && !recorrecting) {
sendMagicSpace(); sendMagicSpace();
@ -1696,7 +1695,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
this, bestWord, suggestedWords), 1); this, bestWord, suggestedWords), 1);
} }
mRecorrection.saveRecorrectionSuggestion(mWord, bestWord); mRecorrection.saveRecorrectionSuggestion(mWordComposer, bestWord);
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
mCommittedLength = bestWord.length(); mCommittedLength = bestWord.length();
} }
@ -1800,7 +1799,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
private void revertLastWord(boolean deleteChar) { private void revertLastWord(boolean deleteChar) {
final int length = mComposing.length(); final int length = mComposingStringBuilder.length();
if (!mHasUncommittedTypedChars && length > 0) { if (!mHasUncommittedTypedChars && length > 0) {
final InputConnection ic = getCurrentInputConnection(); final InputConnection ic = getCurrentInputConnection();
final CharSequence punctuation = ic.getTextBeforeCursor(1, 0); final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
@ -1817,17 +1816,17 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (deleteChar if (deleteChar
&& !TextUtils.isEmpty(punctuation) && !TextUtils.isEmpty(punctuation)
&& mSettingsValues.isWordSeparator(punctuation.charAt(0)) && mSettingsValues.isWordSeparator(punctuation.charAt(0))
&& !TextUtils.equals(mComposing, toTheLeft)) { && !TextUtils.equals(mComposingStringBuilder, toTheLeft)) {
ic.commitText(mComposing, 1); ic.commitText(mComposingStringBuilder, 1);
TextEntryState.acceptedTyped(mComposing); TextEntryState.acceptedTyped(mComposingStringBuilder);
ic.commitText(punctuation, 1); ic.commitText(punctuation, 1);
TextEntryState.typedCharacter(punctuation.charAt(0), true, TextEntryState.typedCharacter(punctuation.charAt(0), true,
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
// Clear composing text // Clear composing text
mComposing.setLength(0); mComposingStringBuilder.setLength(0);
} else { } else {
mHasUncommittedTypedChars = true; mHasUncommittedTypedChars = true;
ic.setComposingText(mComposing, 1); ic.setComposingText(mComposingStringBuilder, 1);
TextEntryState.backspace(); TextEntryState.backspace();
} }
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();
@ -1863,7 +1862,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
public boolean preferCapitalization() { public boolean preferCapitalization() {
return mWord.isFirstCharCapitalized(); return mWordComposer.isFirstCharCapitalized();
} }
// Notify that language or mode have been changed and toggleLanguage will update KeyboardID // Notify that language or mode have been changed and toggleLanguage will update KeyboardID
@ -1987,7 +1986,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
public WordComposer getCurrentWord() { public WordComposer getCurrentWord() {
return mWord; return mWordComposer;
} }
boolean isSoundOn() { boolean isSoundOn() {
@ -2123,7 +2122,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final Printer p = new PrintWriterPrinter(fout); final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :"); p.println("LatinIME state :");
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode()); p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode());
p.println(" mComposing=" + mComposing.toString()); 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);

View file

@ -16,6 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Utils.RingCharBuffer; import com.android.inputmethod.latin.Utils.RingCharBuffer;
import android.util.Log; import android.util.Log;
@ -100,7 +101,7 @@ public class TextEntryState {
} }
public static void typedCharacter(char c, boolean isSeparator, int x, int y) { public static void typedCharacter(char c, boolean isSeparator, int x, int y) {
final boolean isSpace = (c == ' '); final boolean isSpace = (c == Keyboard.CODE_SPACE);
switch (sState) { switch (sState) {
case IN_WORD: case IN_WORD:
if (isSpace || isSeparator) { if (isSpace || isSeparator) {