Factorize some common code (A49)
Also add some comment to clarify what's happening inside those methods Change-Id: I5b9b1e105b3145f0b050f35d12c5b6ca6e4a4d8c
This commit is contained in:
parent
0726f466f7
commit
7ed22f1f72
1 changed files with 22 additions and 36 deletions
|
@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
// the composing word, reset the last composed word, tell the inputconnection about it.
|
||||
private void resetEntireInputState() {
|
||||
resetComposingState(true /* alsoResetLastComposedWord */);
|
||||
updateSuggestionsOrPredictions(false /* isPredictions */);
|
||||
clearSuggestions();
|
||||
mConnection.finishComposingText();
|
||||
}
|
||||
|
||||
|
@ -1695,7 +1695,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
|
||||
public void updateSuggestionsOrPredictions(final boolean isPredictions) {
|
||||
if (isPredictions) {
|
||||
mHandler.cancelUpdateSuggestions();
|
||||
mHandler.cancelUpdateBigramPredictions();
|
||||
|
||||
// Check if we have a suggestion engine attached.
|
||||
if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
||||
if (mWordComposer.isComposingWord()) {
|
||||
Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not "
|
||||
+ "requested!");
|
||||
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPredictions || !mWordComposer.isComposingWord()) {
|
||||
updateBigramPredictions();
|
||||
} else {
|
||||
updateSuggestions();
|
||||
|
@ -1703,27 +1716,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
}
|
||||
|
||||
private void updateSuggestions() {
|
||||
mHandler.cancelUpdateSuggestions();
|
||||
mHandler.cancelUpdateBigramPredictions();
|
||||
|
||||
// Check if we have a suggestion engine attached.
|
||||
if ((mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation))) {
|
||||
if (mWordComposer.isComposingWord()) {
|
||||
Log.w(TAG, "Called updateSuggestions but suggestions were not requested!");
|
||||
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mWordComposer.isComposingWord()) {
|
||||
// We are never called with an empty word composer, but if because of a bug
|
||||
// we are, what we should do here is just call updateBigramsPredictions. This will
|
||||
// update the predictions if the "predict next word" option is on, or display
|
||||
// punctuation signs if it's off.
|
||||
updateBigramPredictions();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: May need a better way of retrieving previous word
|
||||
final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators);
|
||||
final CharSequence typedWord = mWordComposer.getTypedWord();
|
||||
|
@ -1741,6 +1733,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
if (suggestedWords.size() > 1 || typedWord.length() == 1
|
||||
|| !suggestedWords.mTypedWordValid
|
||||
|| mSuggestionsView.isShowingAddToDictionaryHint()) {
|
||||
// We know suggestedWords.size() > 1
|
||||
showSuggestions(suggestedWords, typedWord);
|
||||
} else {
|
||||
SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions();
|
||||
|
@ -1757,11 +1750,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
false /* isPunctuationSuggestions */,
|
||||
true /* isObsoleteSuggestions */,
|
||||
false /* isPrediction */);
|
||||
// getTypedWordAndPreviousSuggestions never returns an empty array, so we know we have
|
||||
// at least one element here.
|
||||
showSuggestions(obsoleteSuggestedWords, typedWord);
|
||||
}
|
||||
}
|
||||
|
||||
public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) {
|
||||
private void showSuggestions(final SuggestedWords suggestedWords,
|
||||
final CharSequence typedWord) {
|
||||
// This method is only ever called by updateSuggestions or updateBigramPredictions.
|
||||
final CharSequence autoCorrection;
|
||||
if (suggestedWords.size() > 0) {
|
||||
if (suggestedWords.mWillAutoCorrect) {
|
||||
|
@ -1928,18 +1925,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
|||
separatorCode, prevWord);
|
||||
}
|
||||
|
||||
public void updateBigramPredictions() {
|
||||
mHandler.cancelUpdateSuggestions();
|
||||
mHandler.cancelUpdateBigramPredictions();
|
||||
|
||||
if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) {
|
||||
if (mWordComposer.isComposingWord()) {
|
||||
Log.w(TAG, "Called updateBigramPredictions but suggestions were not requested!");
|
||||
mWordComposer.setAutoCorrection(mWordComposer.getTypedWord());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private void updateBigramPredictions() {
|
||||
if (!mCurrentSettings.mBigramPredictionEnabled) {
|
||||
setPunctuationSuggestions();
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue