Revert "Add onGetSuggestedWordsCallback."

This reverts commit 820c290a61.

Change-Id: I5c50731ff9f330c05c5841b8c65f16e28e67422c
main
Ken Wakasa 2013-08-30 14:06:19 +00:00
parent 820c290a61
commit 78f707a142
2 changed files with 76 additions and 121 deletions

View File

@ -71,7 +71,6 @@ import com.android.inputmethod.keyboard.KeyboardActionListener;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.KeyboardSwitcher;
import com.android.inputmethod.keyboard.MainKeyboardView; import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.personalization.PersonalizationDictionary; import com.android.inputmethod.latin.personalization.PersonalizationDictionary;
@ -1742,13 +1741,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Batch input has ended or canceled while the message was being delivered. // Batch input has ended or canceled while the message was being delivered.
return; return;
} }
final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
getSuggestedWordsGestureLocked(batchPointers, new OnGetSuggestedWordsCallback() { mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
@Override suggestedWords, false /* dismissGestureFloatingPreviewText */);
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
suggestedWords, false /* dismissGestureFloatingPreviewText */);
}});
} }
} }
@ -1771,39 +1766,29 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
// Run in the UI thread. // Run in the UI thread.
public void onEndBatchInput(final InputPointers batchPointers) { public SuggestedWords onEndBatchInput(final InputPointers batchPointers) {
getSuggestedWordsGestureLocked(batchPointers, new OnGetSuggestedWordsCallback() { synchronized (mLock) {
@Override mInBatchInput = false;
public void onGetSuggestedWords(final SuggestedWords suggestedWords) { final SuggestedWords suggestedWords = getSuggestedWordsGestureLocked(batchPointers);
synchronized (mLock) { mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(
mInBatchInput = false; suggestedWords, true /* dismissGestureFloatingPreviewText */);
mLatinIme.mHandler.showGesturePreviewAndSuggestionStrip(suggestedWords, return suggestedWords;
true /* dismissGestureFloatingPreviewText */); }
}
mLatinIme.onEndBatchInputAsyncInternal(suggestedWords);
}
});
} }
// {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to // {@link LatinIME#getSuggestedWords(int)} method calls with same session id have to
// be synchronized. // be synchronized.
private void getSuggestedWordsGestureLocked(final InputPointers batchPointers, private SuggestedWords getSuggestedWordsGestureLocked(final InputPointers batchPointers) {
final OnGetSuggestedWordsCallback callback) {
mLatinIme.mWordComposer.setBatchInputPointers(batchPointers); mLatinIme.mWordComposer.setBatchInputPointers(batchPointers);
mLatinIme.getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_GESTURE, final SuggestedWords suggestedWords =
new OnGetSuggestedWordsCallback() { mLatinIme.getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_GESTURE);
@Override final int suggestionCount = suggestedWords.size();
public void onGetSuggestedWords(SuggestedWords suggestedWords) { if (suggestionCount <= 1) {
final int suggestionCount = suggestedWords.size(); final String mostProbableSuggestion = (suggestionCount == 0) ? null
if (suggestionCount <= 1) { : suggestedWords.getWord(0);
final String mostProbableSuggestion = (suggestionCount == 0) ? null return mLatinIme.getOlderSuggestions(mostProbableSuggestion);
: suggestedWords.getWord(0); }
callback.onGetSuggestedWords( return suggestedWords;
mLatinIme.getOlderSuggestions(mostProbableSuggestion));
}
callback.onGetSuggestedWords(suggestedWords);
}
});
} }
} }
@ -1828,7 +1813,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
BatchInputUpdater.getInstance().onUpdateBatchInput(batchPointers); BatchInputUpdater.getInstance().onUpdateBatchInput(batchPointers);
} }
public void onEndBatchInputAsyncInternal(final SuggestedWords suggestedWords) { @Override
public void onEndBatchInput(final InputPointers batchPointers) {
final SuggestedWords suggestedWords = BatchInputUpdater.getInstance().onEndBatchInput(
batchPointers);
final String batchInputText = suggestedWords.isEmpty() final String batchInputText = suggestedWords.isEmpty()
? null : suggestedWords.getWord(0); ? null : suggestedWords.getWord(0);
if (TextUtils.isEmpty(batchInputText)) { if (TextUtils.isEmpty(batchInputText)) {
@ -1850,11 +1838,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
} }
@Override
public void onEndBatchInput(final InputPointers batchPointers) {
BatchInputUpdater.getInstance().onEndBatchInput(batchPointers);
}
private String specificTldProcessingOnTextInput(final String text) { private String specificTldProcessingOnTextInput(final String text) {
if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD if (text.length() <= 1 || text.charAt(0) != Constants.CODE_PERIOD
|| !Character.isLetter(text.charAt(1))) { || !Character.isLetter(text.charAt(1))) {
@ -2325,23 +2308,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return; return;
} }
final SuggestedWords suggestedWords =
getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_TYPING);
final String typedWord = mWordComposer.getTypedWord(); final String typedWord = mWordComposer.getTypedWord();
getSuggestedWordsOrOlderSuggestions(Suggest.SESSION_TYPING, showSuggestionStrip(suggestedWords, typedWord);
new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(SuggestedWords suggestedWords) {
showSuggestionStrip(suggestedWords, typedWord);
}
});
} }
private void getSuggestedWords(final int sessionId, private SuggestedWords getSuggestedWords(final int sessionId) {
final OnGetSuggestedWordsCallback callback) {
final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); final Keyboard keyboard = mKeyboardSwitcher.getKeyboard();
final Suggest suggest = mSuggest; final Suggest suggest = mSuggest;
if (keyboard == null || suggest == null) { if (keyboard == null || suggest == null) {
callback.onGetSuggestedWords(SuggestedWords.EMPTY); return SuggestedWords.EMPTY;
return;
} }
// Get the word on which we should search the bigrams. If we are composing a word, it's // Get the word on which we should search the bigrams. If we are composing a word, it's
// whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we // whatever is *before* the half-committed word in the buffer, hence 2; if we aren't, we
@ -2358,20 +2335,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
prevWord = LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null prevWord = LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
: mLastComposedWord.mCommittedWord; : mLastComposedWord.mCommittedWord;
} }
suggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(), return suggest.getSuggestedWords(mWordComposer, prevWord, keyboard.getProximityInfo(),
currentSettings.mBlockPotentiallyOffensive, currentSettings.mCorrectionEnabled, currentSettings.mBlockPotentiallyOffensive,
additionalFeaturesOptions, sessionId, callback); currentSettings.mCorrectionEnabled, additionalFeaturesOptions, sessionId);
} }
private void getSuggestedWordsOrOlderSuggestions(final int sessionId, private SuggestedWords getSuggestedWordsOrOlderSuggestions(final int sessionId) {
final OnGetSuggestedWordsCallback callback) { return maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(),
getSuggestedWords(sessionId, new OnGetSuggestedWordsCallback() { getSuggestedWords(sessionId));
@Override
public void onGetSuggestedWords(SuggestedWords suggestedWords) {
callback.onGetSuggestedWords(maybeRetrieveOlderSuggestions(
mWordComposer.getTypedWord(), suggestedWords));
}
});
} }
private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
@ -2669,49 +2640,39 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mConnection.setComposingRegion( mConnection.setComposingRegion(
mLastSelectionStart - numberOfCharsInWordBeforeCursor, mLastSelectionStart - numberOfCharsInWordBeforeCursor,
mLastSelectionEnd + range.getNumberOfCharsInWordAfterCursor()); mLastSelectionEnd + range.getNumberOfCharsInWordAfterCursor());
final SuggestedWords suggestedWords;
if (suggestions.isEmpty()) { if (suggestions.isEmpty()) {
// We come here if there weren't any suggestion spans on this word. We will try to // We come here if there weren't any suggestion spans on this word. We will try to
// compute suggestions for it instead. // compute suggestions for it instead.
getSuggestedWords(Suggest.SESSION_TYPING, new OnGetSuggestedWordsCallback() { final SuggestedWords suggestedWordsIncludingTypedWord =
@Override getSuggestedWords(Suggest.SESSION_TYPING);
public void onGetSuggestedWords(SuggestedWords suggestedWordsIncludingTypedWord) { if (suggestedWordsIncludingTypedWord.size() > 1) {
final SuggestedWords suggestedWords; // We were able to compute new suggestions for this word.
if (suggestedWordsIncludingTypedWord.size() > 1) { // Remove the typed word, since we don't want to display it in this case.
// We were able to compute new suggestions for this word. // The #getSuggestedWordsExcludingTypedWord() method sets willAutoCorrect to false.
// Remove the typed word, since we don't want to display it in this case. suggestedWords =
// The #getSuggestedWordsExcludingTypedWord() method sets willAutoCorrect to suggestedWordsIncludingTypedWord.getSuggestedWordsExcludingTypedWord();
// false. } else {
suggestedWords = suggestedWordsIncludingTypedWord // No saved suggestions, and we were unable to compute any good one either.
.getSuggestedWordsExcludingTypedWord(); // Rather than displaying an empty suggestion strip, we'll display the original
} else { // word alone in the middle.
// No saved suggestions, and we were unable to compute any good one either. // Since there is only one word, willAutoCorrect is false.
// Rather than displaying an empty suggestion strip, we'll display the suggestedWords = suggestedWordsIncludingTypedWord;
// original word alone in the middle. }
// Since there is only one word, willAutoCorrect is false.
suggestedWords = suggestedWordsIncludingTypedWord;
}
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords,
typedWord);
}});
} else { } else {
// We found suggestion spans in the word. We'll create the SuggestedWords out of // We found suggestion spans in the word. We'll create the SuggestedWords out of
// them, and make willAutoCorrect false. // them, and make willAutoCorrect false.
final SuggestedWords suggestedWords = new SuggestedWords(suggestions, suggestedWords = new SuggestedWords(suggestions,
true /* typedWordValid */, false /* willAutoCorrect */, true /* typedWordValid */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
false /* isPrediction */); false /* isPrediction */);
unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords, typedWord);
} }
}
public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
final SuggestedWords suggestedWords, final String typedWord) {
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false. // Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
// We never want to auto-correct on a resumed suggestion. Please refer to the three places // We never want to auto-correct on a resumed suggestion. Please refer to the three
// above in restartSuggestionsOnWordTouchedByCursor() where suggestedWords is affected. // places above where suggestedWords is affected. We also need to reset
// We also need to unset mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching // mIsAutoCorrectionIndicatorOn to avoid showSuggestionStrip touching the text to adapt it.
// the text to adapt it. // TODO: remove mIsAutoCorrectionIndicator on (see comment on definition)
// TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
mIsAutoCorrectionIndicatorOn = false; mIsAutoCorrectionIndicatorOn = false;
showSuggestionStrip(suggestedWords, typedWord); showSuggestionStrip(suggestedWords, typedWord);
} }

View File

@ -211,31 +211,26 @@ public final class Suggest {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }
public interface OnGetSuggestedWordsCallback { public SuggestedWords getSuggestedWords(final WordComposer wordComposer,
public void onGetSuggestedWords(final SuggestedWords suggestedWords);
}
public void getSuggestedWords(final WordComposer wordComposer,
final String prevWordForBigram, final ProximityInfo proximityInfo, final String prevWordForBigram, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final boolean isCorrectionEnabled, final boolean blockOffensiveWords, final boolean isCorrectionEnabled,
final int[] additionalFeaturesOptions, final int sessionId, final int[] additionalFeaturesOptions, final int sessionId) {
final OnGetSuggestedWordsCallback callback) {
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
if (wordComposer.isBatchMode()) { if (wordComposer.isBatchMode()) {
getSuggestedWordsForBatchInput(wordComposer, prevWordForBigram, proximityInfo, return getSuggestedWordsForBatchInput(
blockOffensiveWords, additionalFeaturesOptions, sessionId, callback); wordComposer, prevWordForBigram, proximityInfo, blockOffensiveWords,
additionalFeaturesOptions, sessionId);
} else { } else {
getSuggestedWordsForTypingInput(wordComposer, prevWordForBigram, proximityInfo, return getSuggestedWordsForTypingInput(wordComposer, prevWordForBigram, proximityInfo,
blockOffensiveWords, isCorrectionEnabled, additionalFeaturesOptions, callback); blockOffensiveWords, isCorrectionEnabled, additionalFeaturesOptions);
} }
} }
// Retrieves suggestions for the typing input // Retrieves suggestions for the typing input.
// and calls the callback function with the suggestions. private SuggestedWords getSuggestedWordsForTypingInput(final WordComposer wordComposer,
private void getSuggestedWordsForTypingInput(final WordComposer wordComposer,
final String prevWordForBigram, final ProximityInfo proximityInfo, final String prevWordForBigram, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final boolean isCorrectionEnabled, final boolean blockOffensiveWords, final boolean isCorrectionEnabled,
final int[] additionalFeaturesOptions, final OnGetSuggestedWordsCallback callback) { final int[] additionalFeaturesOptions) {
final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount(); final int trailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount();
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator, final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
MAX_SUGGESTIONS); MAX_SUGGESTIONS);
@ -258,8 +253,8 @@ public final class Suggest {
for (final String key : mDictionaries.keySet()) { for (final String key : mDictionaries.keySet()) {
final Dictionary dictionary = mDictionaries.get(key); final Dictionary dictionary = mDictionaries.get(key);
suggestionsSet.addAll(dictionary.getSuggestions(wordComposerForLookup, suggestionsSet.addAll(dictionary.getSuggestions(
prevWordForBigram, proximityInfo, blockOffensiveWords, wordComposerForLookup, prevWordForBigram, proximityInfo, blockOffensiveWords,
additionalFeaturesOptions)); additionalFeaturesOptions));
} }
@ -337,7 +332,7 @@ public final class Suggest {
suggestionsList = suggestionsContainer; suggestionsList = suggestionsContainer;
} }
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList, return new SuggestedWords(suggestionsList,
// TODO: this first argument is lying. If this is a whitelisted word which is an // TODO: this first argument is lying. If this is a whitelisted word which is an
// actual word, it says typedWordValid = false, which looks wrong. We should either // actual word, it says typedWordValid = false, which looks wrong. We should either
// rename the attribute or change the value. // rename the attribute or change the value.
@ -345,15 +340,14 @@ public final class Suggest {
hasAutoCorrection, /* willAutoCorrect */ hasAutoCorrection, /* willAutoCorrect */
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */, false /* isObsoleteSuggestions */,
!wordComposer.isComposingWord() /* isPrediction */)); !wordComposer.isComposingWord() /* isPrediction */);
} }
// Retrieves suggestions for the batch input // Retrieves suggestions for the batch input.
// and calls the callback function with the suggestions. private SuggestedWords getSuggestedWordsForBatchInput(final WordComposer wordComposer,
private void getSuggestedWordsForBatchInput(final WordComposer wordComposer,
final String prevWordForBigram, final ProximityInfo proximityInfo, final String prevWordForBigram, final ProximityInfo proximityInfo,
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions, final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final int sessionId, final OnGetSuggestedWordsCallback callback) { final int sessionId) {
final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator, final BoundedTreeSet suggestionsSet = new BoundedTreeSet(sSuggestedWordInfoComparator,
MAX_SUGGESTIONS); MAX_SUGGESTIONS);
@ -407,12 +401,12 @@ public final class Suggest {
// In the batch input mode, the most relevant suggested word should act as a "typed word" // In the batch input mode, the most relevant suggested word should act as a "typed word"
// (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false). // (typedWordValid=true), not as an "auto correct word" (willAutoCorrect=false).
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer, return new SuggestedWords(suggestionsContainer,
true /* typedWordValid */, true /* typedWordValid */,
false /* willAutoCorrect */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */, false /* isObsoleteSuggestions */,
false /* isPrediction */)); false /* isPrediction */);
} }
private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo( private static ArrayList<SuggestedWordInfo> getSuggestionsInfoListWithDebugInfo(