Code cleanup

Change-Id: Ie43181721ba18e0c04048eaa9e3016dcea9f5a49
main
Ken Wakasa 2011-07-12 16:47:08 +09:00
parent 9318d33b6e
commit 8558cfb42a
1 changed files with 52 additions and 56 deletions

View File

@ -740,11 +740,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
ic.finishComposingText(); ic.finishComposingText();
} }
mVoiceProxy.setVoiceInputHighlighted(false); mVoiceProxy.setVoiceInputHighlighted(false);
} else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection) { } else if (!mHasUncommittedTypedChars && !mExpectingUpdateSelection
if (TextEntryState.isAcceptedDefault() || TextEntryState.isSpaceAfterPicked()) { && TextEntryState.isAcceptedDefault()) {
if (TextEntryState.isAcceptedDefault()) TextEntryState.reset();
TextEntryState.reset();
}
} }
if (!mExpectingUpdateSelection) { if (!mExpectingUpdateSelection) {
mJustAddedMagicSpace = false; // The user moved the cursor. mJustAddedMagicSpace = false; // The user moved the cursor.
@ -945,19 +943,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
public void commitTyped(InputConnection inputConnection) { public void commitTyped(InputConnection inputConnection) {
if (mHasUncommittedTypedChars) { if (!mHasUncommittedTypedChars) return;
mHasUncommittedTypedChars = false; mHasUncommittedTypedChars = false;
if (mComposingStringBuilder.length() > 0) { if (mComposingStringBuilder.length() > 0) {
if (inputConnection != null) { if (inputConnection != null) {
inputConnection.commitText(mComposingStringBuilder, 1); inputConnection.commitText(mComposingStringBuilder, 1);
}
mCommittedLength = mComposingStringBuilder.length();
TextEntryState.acceptedTyped(mComposingStringBuilder);
addToAutoAndUserBigramDictionaries(mComposingStringBuilder,
AutoDictionary.FREQUENCY_FOR_TYPED);
} }
updateSuggestions(); mCommittedLength = mComposingStringBuilder.length();
TextEntryState.acceptedTyped(mComposingStringBuilder);
addToAutoAndUserBigramDictionaries(mComposingStringBuilder,
AutoDictionary.FREQUENCY_FOR_TYPED);
} }
updateSuggestions();
} }
public boolean getCurrentAutoCapsState() { public boolean getCurrentAutoCapsState() {
@ -1500,18 +1497,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(
mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord); mKeyboardSwitcher.getKeyboardView(), wordComposer, prevWord);
boolean correctionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection(); boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
final CharSequence typedWord = wordComposer.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());
if (mCorrectionMode == Suggest.CORRECTION_FULL if (mCorrectionMode == Suggest.CORRECTION_FULL
|| mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) { || mCorrectionMode == Suggest.CORRECTION_FULL_BIGRAM) {
correctionAvailable |= typedWordValid; autoCorrectionAvailable |= typedWordValid;
} }
// Don't auto-correct words with multiple capital letter // Don't auto-correct words with multiple capital letter
correctionAvailable &= !wordComposer.isMostlyCaps(); autoCorrectionAvailable &= !wordComposer.isMostlyCaps();
correctionAvailable &= !TextEntryState.isRecorrecting(); autoCorrectionAvailable &= !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,
// there is an exception: We update the suggestion strip whenever typed word's length // there is an exception: We update the suggestion strip whenever typed word's length
@ -1523,7 +1520,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (builder.size() > 1 || typedWord.length() == 1 || typedWordValid if (builder.size() > 1 || typedWord.length() == 1 || typedWordValid
|| mCandidateView.isShowingAddToDictionaryHint()) { || mCandidateView.isShowingAddToDictionaryHint()) {
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion( builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(
correctionAvailable); autoCorrectionAvailable);
} else { } else {
final SuggestedWords previousSuggestions = mCandidateView.getSuggestions(); final SuggestedWords previousSuggestions = mCandidateView.getSuggestions();
if (previousSuggestions == mSettingsValues.mSuggestPuncList) if (previousSuggestions == mSettingsValues.mSuggestPuncList)
@ -1681,8 +1678,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
/** /**
* Commits the chosen word to the text field and saves it for later * Commits the chosen word to the text field and saves it for later retrieval.
* retrieval.
*/ */
private void commitBestWord(CharSequence bestWord) { private void commitBestWord(CharSequence bestWord) {
KeyboardSwitcher switcher = mKeyboardSwitcher; KeyboardSwitcher switcher = mKeyboardSwitcher;
@ -1799,41 +1795,41 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
private void revertLastWord(boolean deleteChar) { private void revertLastWord(boolean deleteChar) {
final int length = mComposingStringBuilder.length(); if (mHasUncommittedTypedChars || mComposingStringBuilder.length() <= 0) {
if (!mHasUncommittedTypedChars && length > 0) {
final InputConnection ic = getCurrentInputConnection();
final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
if (deleteChar) ic.deleteSurroundingText(1, 0);
int toDelete = mCommittedLength;
final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
if (!TextUtils.isEmpty(toTheLeft)
&& mSettingsValues.isWordSeparator(toTheLeft.charAt(0))) {
toDelete--;
}
ic.deleteSurroundingText(toDelete, 0);
// Re-insert punctuation only when the deleted character was word separator and the
// composing text wasn't equal to the auto-corrected text.
if (deleteChar
&& !TextUtils.isEmpty(punctuation)
&& mSettingsValues.isWordSeparator(punctuation.charAt(0))
&& !TextUtils.equals(mComposingStringBuilder, toTheLeft)) {
ic.commitText(mComposingStringBuilder, 1);
TextEntryState.acceptedTyped(mComposingStringBuilder);
ic.commitText(punctuation, 1);
TextEntryState.typedCharacter(punctuation.charAt(0), true,
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
// Clear composing text
mComposingStringBuilder.setLength(0);
} else {
mHasUncommittedTypedChars = true;
ic.setComposingText(mComposingStringBuilder, 1);
TextEntryState.backspace();
}
mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
} else {
sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL); sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
return;
} }
final InputConnection ic = getCurrentInputConnection();
final CharSequence punctuation = ic.getTextBeforeCursor(1, 0);
if (deleteChar) ic.deleteSurroundingText(1, 0);
int toDelete = mCommittedLength;
final CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
if (!TextUtils.isEmpty(toTheLeft)
&& mSettingsValues.isWordSeparator(toTheLeft.charAt(0))) {
toDelete--;
}
ic.deleteSurroundingText(toDelete, 0);
// Re-insert punctuation only when the deleted character was word separator and the
// composing text wasn't equal to the auto-corrected text.
if (deleteChar
&& !TextUtils.isEmpty(punctuation)
&& mSettingsValues.isWordSeparator(punctuation.charAt(0))
&& !TextUtils.equals(mComposingStringBuilder, toTheLeft)) {
ic.commitText(mComposingStringBuilder, 1);
TextEntryState.acceptedTyped(mComposingStringBuilder);
ic.commitText(punctuation, 1);
TextEntryState.typedCharacter(punctuation.charAt(0), true,
WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
// Clear composing text
mComposingStringBuilder.setLength(0);
} else {
mHasUncommittedTypedChars = true;
ic.setComposingText(mComposingStringBuilder, 1);
TextEntryState.backspace();
}
mHandler.cancelUpdateBigramPredictions();
mHandler.postUpdateSuggestions();
} }
private boolean revertDoubleSpace() { private boolean revertDoubleSpace() {