Put some more code in common (A51)

Change-Id: If1589e29728df20713c75e08df7f47f0de9202d4
This commit is contained in:
Jean Chalard 2012-06-29 15:54:51 +09:00
parent cbfd2e1fdb
commit ea80794dd4

View file

@ -1709,16 +1709,27 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
final CharSequence typedWord; final CharSequence typedWord;
final SuggestedWords suggestions;
if (isPredictions || !mWordComposer.isComposingWord()) { if (isPredictions || !mWordComposer.isComposingWord()) {
if (!mCurrentSettings.mBigramPredictionEnabled) {
setPunctuationSuggestions();
return;
}
typedWord = ""; typedWord = "";
updateBigramPredictions(typedWord); suggestions = updateBigramPredictions(typedWord);
} else { } else {
typedWord = mWordComposer.getTypedWord(); typedWord = mWordComposer.getTypedWord();
updateSuggestions(typedWord); suggestions = updateSuggestions(typedWord);
}
if (null != suggestions && suggestions.size() > 0) {
showSuggestions(suggestions, typedWord);
} else {
clearSuggestions();
} }
} }
private void updateSuggestions(final CharSequence typedWord) { private SuggestedWords updateSuggestions(final CharSequence typedWord) {
// TODO: May need a better way of retrieving previous word // TODO: May need a better way of retrieving previous word
final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators);
// getSuggestedWords handles gracefully a null value of prevWord // getSuggestedWords handles gracefully a null value of prevWord
@ -1735,8 +1746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (suggestedWords.size() > 1 || typedWord.length() == 1 if (suggestedWords.size() > 1 || typedWord.length() == 1
|| !suggestedWords.mTypedWordValid || !suggestedWords.mTypedWordValid
|| mSuggestionsView.isShowingAddToDictionaryHint()) { || mSuggestionsView.isShowingAddToDictionaryHint()) {
// We know suggestedWords.size() > 1 return suggestedWords;
showSuggestions(suggestedWords, typedWord);
} else { } else {
SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions();
if (previousSuggestions == mCurrentSettings.mSuggestPuncList) { if (previousSuggestions == mCurrentSettings.mSuggestPuncList) {
@ -1745,16 +1755,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions = final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions( SuggestedWords.getTypedWordAndPreviousSuggestions(
typedWord, previousSuggestions); typedWord, previousSuggestions);
final SuggestedWords obsoleteSuggestedWords = return new SuggestedWords(typedWordAndPreviousSuggestions,
new SuggestedWords(typedWordAndPreviousSuggestions,
false /* typedWordValid */, false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */, false /* hasAutoCorrectionCandidate */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,
true /* isObsoleteSuggestions */, true /* isObsoleteSuggestions */,
false /* isPrediction */); false /* isPrediction */);
// getTypedWordAndPreviousSuggestions never returns an empty array, so we know we have
// at least one element here.
showSuggestions(obsoleteSuggestedWords, typedWord);
} }
} }
@ -1927,12 +1933,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
separatorCode, prevWord); separatorCode, prevWord);
} }
private void updateBigramPredictions(final CharSequence typedWord) { private SuggestedWords updateBigramPredictions(final CharSequence typedWord) {
if (!mCurrentSettings.mBigramPredictionEnabled) {
setPunctuationSuggestions();
return;
}
final SuggestedWords suggestedWords; final SuggestedWords suggestedWords;
if (mCurrentSettings.mCorrectionEnabled) { if (mCurrentSettings.mCorrectionEnabled) {
final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators);
@ -1947,13 +1948,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
suggestedWords = null; suggestedWords = null;
} }
if (null != suggestedWords && suggestedWords.size() > 0) { return suggestedWords;
// Typed word is always empty. We pass it because the no-second-arg version of
// showSuggestions will retrieve the word near the cursor, and we don't want that here
showSuggestions(suggestedWords, typedWord);
} else {
clearSuggestions();
}
} }
public void setPunctuationSuggestions() { public void setPunctuationSuggestions() {