am 33b2aaaf: Merge "Fix a code path that looks ridiculous"

* commit '33b2aaafc25acbfae1a670435ceb7cd7fe624a1c':
  Fix a code path that looks ridiculous
main
Jean Chalard 2013-12-26 05:43:23 -08:00 committed by Android Git Automerger
commit b9c96ca75a
2 changed files with 12 additions and 12 deletions

View File

@ -274,10 +274,10 @@ public class DictionaryFacilitatorForSuggest {
mUserDictionary.addWordToUserDictionary(word);
}
public String addToUserHistory(final WordComposer wordComposer, final String previousWord,
public void addToUserHistory(final WordComposer wordComposer, final String previousWord,
final String suggestion) {
if (mUserHistoryDictionary == null) {
return null;
return;
}
final String secondWord;
if (wordComposer.wasAutoCapitalized() && !wordComposer.isMostlyCaps()) {
@ -289,12 +289,11 @@ public class DictionaryFacilitatorForSuggest {
// We don't add words with 0-frequency (assuming they would be profanity etc.).
final int maxFreq = getMaxFrequency(suggestion);
if (maxFreq == 0) {
return null;
return;
}
final boolean isValid = maxFreq > 0;
final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis()));
mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp);
return previousWord;
}
public void cancelAddingUserHistory(final String previousWord, final String committedWord) {

View File

@ -976,19 +976,18 @@ public final class InputLogic {
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
}
private String performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
final String suggestion) {
private void performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
final String suggestion, final String prevWord) {
// If correction is not enabled, we don't add words to the user history dictionary.
// That's to avoid unintended additions in some sensitive fields, or fields that
// expect to receive non-words.
if (!settingsValues.mCorrectionEnabled) return null;
if (!settingsValues.mCorrectionEnabled) return;
if (TextUtils.isEmpty(suggestion)) return null;
if (TextUtils.isEmpty(suggestion)) return;
final Suggest suggest = mSuggest;
if (suggest == null) return null;
if (suggest == null) return;
final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
return suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
}
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
@ -1610,8 +1609,10 @@ public final class InputLogic {
final SuggestedWords suggestedWords = mSuggestedWords;
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
suggestedWords), 1);
// TODO: we pass 2 here, but would it be better to move this above and pass 1 instead?
final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
// Add the word to the user history dictionary
final String prevWord = performAdditionToUserHistoryDictionary(settingsValues, chosenWord);
performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord);
// TODO: figure out here if this is an auto-correct or if the best word is actually
// what user typed. Note: currently this is done much later in
// LastComposedWord#didCommitTypedWord by string equality of the remembered