Fix a code path that looks ridiculous
Bug: 12295276 Change-Id: I187016b59213d351c943c6e0b9a2ad3708499646
This commit is contained in:
parent
be147f1fdc
commit
f294ed3308
2 changed files with 12 additions and 12 deletions
|
@ -274,10 +274,10 @@ public class DictionaryFacilitatorForSuggest {
|
||||||
mUserDictionary.addWordToUserDictionary(word);
|
mUserDictionary.addWordToUserDictionary(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String addToUserHistory(final WordComposer wordComposer, final String previousWord,
|
public void addToUserHistory(final WordComposer wordComposer, final String previousWord,
|
||||||
final String suggestion) {
|
final String suggestion) {
|
||||||
if (mUserHistoryDictionary == null) {
|
if (mUserHistoryDictionary == null) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
final String secondWord;
|
final String secondWord;
|
||||||
if (wordComposer.wasAutoCapitalized() && !wordComposer.isMostlyCaps()) {
|
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.).
|
// We don't add words with 0-frequency (assuming they would be profanity etc.).
|
||||||
final int maxFreq = getMaxFrequency(suggestion);
|
final int maxFreq = getMaxFrequency(suggestion);
|
||||||
if (maxFreq == 0) {
|
if (maxFreq == 0) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
final boolean isValid = maxFreq > 0;
|
final boolean isValid = maxFreq > 0;
|
||||||
final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis()));
|
final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis()));
|
||||||
mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp);
|
mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp);
|
||||||
return previousWord;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelAddingUserHistory(final String previousWord, final String committedWord) {
|
public void cancelAddingUserHistory(final String previousWord, final String committedWord) {
|
||||||
|
|
|
@ -974,19 +974,18 @@ public final class InputLogic {
|
||||||
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
|
private void performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
|
||||||
final String suggestion) {
|
final String suggestion, final String prevWord) {
|
||||||
// If correction is not enabled, we don't add words to the user history dictionary.
|
// 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
|
// That's to avoid unintended additions in some sensitive fields, or fields that
|
||||||
// expect to receive non-words.
|
// 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;
|
final Suggest suggest = mSuggest;
|
||||||
if (suggest == null) return null;
|
if (suggest == null) return;
|
||||||
|
|
||||||
final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
|
suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
|
||||||
return suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
|
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
|
||||||
|
@ -1605,8 +1604,10 @@ public final class InputLogic {
|
||||||
final SuggestedWords suggestedWords = mSuggestedWords;
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
||||||
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
|
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
|
||||||
suggestedWords), 1);
|
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
|
// 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
|
// 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
|
// what user typed. Note: currently this is done much later in
|
||||||
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
// LastComposedWord#didCommitTypedWord by string equality of the remembered
|
||||||
|
|
Loading…
Reference in a new issue