Merge "[CS1] Some initial clean up"
This commit is contained in:
commit
7d6bc4d063
4 changed files with 31 additions and 37 deletions
|
@ -485,7 +485,7 @@ public class DictionaryFacilitator {
|
||||||
public SuggestionResults getSuggestionResults(final WordComposer composer,
|
public SuggestionResults getSuggestionResults(final WordComposer composer,
|
||||||
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
final PrevWordsInfo prevWordsInfo, final ProximityInfo proximityInfo,
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId, final ArrayList<SuggestedWordInfo> rawSuggestions) {
|
final int sessionId) {
|
||||||
final Dictionaries dictionaries = mDictionaries;
|
final Dictionaries dictionaries = mDictionaries;
|
||||||
final SuggestionResults suggestionResults =
|
final SuggestionResults suggestionResults =
|
||||||
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS);
|
new SuggestionResults(dictionaries.mLocale, SuggestedWords.MAX_SUGGESTIONS);
|
||||||
|
@ -499,21 +499,13 @@ public class DictionaryFacilitator {
|
||||||
languageWeight);
|
languageWeight);
|
||||||
if (null == dictionarySuggestions) continue;
|
if (null == dictionarySuggestions) continue;
|
||||||
suggestionResults.addAll(dictionarySuggestions);
|
suggestionResults.addAll(dictionarySuggestions);
|
||||||
if (null != rawSuggestions) {
|
if (null != suggestionResults.mRawSuggestions) {
|
||||||
rawSuggestions.addAll(dictionarySuggestions);
|
suggestionResults.mRawSuggestions.addAll(dictionarySuggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return suggestionResults;
|
return suggestionResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValidMainDictWord(final String word) {
|
|
||||||
final Dictionary mainDict = mDictionaries.getDict(Dictionary.TYPE_MAIN);
|
|
||||||
if (TextUtils.isEmpty(word) || mainDict == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return mainDict.isValidWord(word);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isValidWord(final String word, final boolean ignoreCase) {
|
public boolean isValidWord(final String word, final boolean ignoreCase) {
|
||||||
if (TextUtils.isEmpty(word)) {
|
if (TextUtils.isEmpty(word)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -100,30 +100,28 @@ public final class Suggest {
|
||||||
? typedWord.substring(0, typedWord.length() - trailingSingleQuotesCount)
|
? typedWord.substring(0, typedWord.length() - trailingSingleQuotesCount)
|
||||||
: typedWord;
|
: typedWord;
|
||||||
|
|
||||||
final ArrayList<SuggestedWordInfo> rawSuggestions;
|
|
||||||
if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
|
|
||||||
rawSuggestions = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
rawSuggestions = null;
|
|
||||||
}
|
|
||||||
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
||||||
wordComposer, prevWordsInfo, proximityInfo, blockOffensiveWords,
|
wordComposer, prevWordsInfo, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions, SESSION_TYPING, rawSuggestions);
|
additionalFeaturesOptions, SESSION_TYPING);
|
||||||
|
|
||||||
|
final boolean isPrediction = !wordComposer.isComposingWord();
|
||||||
|
final boolean shouldMakeSuggestionsAllUpperCase = wordComposer.isAllUpperCase()
|
||||||
|
&& !wordComposer.isResumed();
|
||||||
final boolean isOnlyFirstCharCapitalized =
|
final boolean isOnlyFirstCharCapitalized =
|
||||||
wordComposer.isOrWillBeOnlyFirstCharCapitalized();
|
wordComposer.isOrWillBeOnlyFirstCharCapitalized();
|
||||||
|
|
||||||
// If resumed, then we don't want to upcase everything: resuming on a fully-capitalized
|
// If resumed, then we don't want to upcase everything: resuming on a fully-capitalized
|
||||||
// words is rarely done to switch to another fully-capitalized word, but usually to a
|
// words is rarely done to switch to another fully-capitalized word, but usually to a
|
||||||
// normal, non-capitalized suggestion.
|
// normal, non-capitalized suggestion.
|
||||||
final boolean isAllUpperCase = wordComposer.isAllUpperCase() && !wordComposer.isResumed();
|
|
||||||
final String firstSuggestion;
|
final String firstSuggestion;
|
||||||
final String whitelistedWord;
|
final String whitelistedWord;
|
||||||
if (suggestionResults.isEmpty()) {
|
if (suggestionResults.isEmpty()) {
|
||||||
whitelistedWord = firstSuggestion = null;
|
whitelistedWord = firstSuggestion = null;
|
||||||
} else {
|
} else {
|
||||||
final SuggestedWordInfo firstSuggestedWordInfo = getTransformedSuggestedWordInfo(
|
final SuggestedWordInfo firstSuggestedWordInfo = getTransformedSuggestedWordInfo(
|
||||||
suggestionResults.first(), suggestionResults.mLocale, isAllUpperCase,
|
suggestionResults.first(), suggestionResults.mLocale,
|
||||||
isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
|
shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized,
|
||||||
|
trailingSingleQuotesCount);
|
||||||
firstSuggestion = firstSuggestedWordInfo.mWord;
|
firstSuggestion = firstSuggestedWordInfo.mWord;
|
||||||
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
|
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
|
||||||
whitelistedWord = null;
|
whitelistedWord = null;
|
||||||
|
@ -132,8 +130,6 @@ public final class Suggest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isPrediction = !wordComposer.isComposingWord();
|
|
||||||
|
|
||||||
// We allow auto-correction if we have a whitelisted word, or if the word is not a valid
|
// We allow auto-correction if we have a whitelisted word, or if the word is not a valid
|
||||||
// word of more than 1 char, except if the first suggestion is the same as the typed string
|
// word of more than 1 char, except if the first suggestion is the same as the typed string
|
||||||
// because in this case if it's strong enough to auto-correct that will mistakenly designate
|
// because in this case if it's strong enough to auto-correct that will mistakenly designate
|
||||||
|
@ -174,11 +170,12 @@ public final class Suggest {
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
||||||
new ArrayList<>(suggestionResults);
|
new ArrayList<>(suggestionResults);
|
||||||
final int suggestionsCount = suggestionsContainer.size();
|
final int suggestionsCount = suggestionsContainer.size();
|
||||||
if (isOnlyFirstCharCapitalized || isAllUpperCase || 0 != trailingSingleQuotesCount) {
|
if (isOnlyFirstCharCapitalized || shouldMakeSuggestionsAllUpperCase
|
||||||
|
|| 0 != trailingSingleQuotesCount) {
|
||||||
for (int i = 0; i < suggestionsCount; ++i) {
|
for (int i = 0; i < suggestionsCount; ++i) {
|
||||||
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
|
||||||
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
|
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
|
||||||
wordInfo, suggestionResults.mLocale, isAllUpperCase,
|
wordInfo, suggestionResults.mLocale, shouldMakeSuggestionsAllUpperCase,
|
||||||
isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
|
isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
|
||||||
suggestionsContainer.set(i, transformedWordInfo);
|
suggestionsContainer.set(i, transformedWordInfo);
|
||||||
}
|
}
|
||||||
|
@ -200,12 +197,13 @@ public final class Suggest {
|
||||||
suggestionsList = suggestionsContainer;
|
suggestionsList = suggestionsContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList, rawSuggestions,
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsList,
|
||||||
|
suggestionResults.mRawSuggestions,
|
||||||
// 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.
|
||||||
!isPrediction && !allowsToBeAutoCorrected /* typedWordValid */,
|
!isPrediction && !allowsToBeAutoCorrected /* typedWordValid */,
|
||||||
hasAutoCorrection, /* willAutoCorrect */
|
hasAutoCorrection /* willAutoCorrect */,
|
||||||
false /* isObsoleteSuggestions */, isPrediction, sequenceNumber));
|
false /* isObsoleteSuggestions */, isPrediction, sequenceNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,15 +214,9 @@ public final class Suggest {
|
||||||
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
|
||||||
final int sessionId, final int sequenceNumber,
|
final int sessionId, final int sequenceNumber,
|
||||||
final OnGetSuggestedWordsCallback callback) {
|
final OnGetSuggestedWordsCallback callback) {
|
||||||
final ArrayList<SuggestedWordInfo> rawSuggestions;
|
|
||||||
if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
|
|
||||||
rawSuggestions = new ArrayList<>();
|
|
||||||
} else {
|
|
||||||
rawSuggestions = null;
|
|
||||||
}
|
|
||||||
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
|
||||||
wordComposer, prevWordsInfo, proximityInfo, blockOffensiveWords,
|
wordComposer, prevWordsInfo, proximityInfo, blockOffensiveWords,
|
||||||
additionalFeaturesOptions, sessionId, rawSuggestions);
|
additionalFeaturesOptions, sessionId);
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
final ArrayList<SuggestedWordInfo> suggestionsContainer =
|
||||||
new ArrayList<>(suggestionResults);
|
new ArrayList<>(suggestionResults);
|
||||||
final int suggestionsCount = suggestionsContainer.size();
|
final int suggestionsCount = suggestionsContainer.size();
|
||||||
|
@ -257,7 +249,8 @@ 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, rawSuggestions,
|
callback.onGetSuggestedWords(new SuggestedWords(suggestionsContainer,
|
||||||
|
suggestionResults.mRawSuggestions,
|
||||||
true /* typedWordValid */,
|
true /* typedWordValid */,
|
||||||
false /* willAutoCorrect */,
|
false /* willAutoCorrect */,
|
||||||
false /* isObsoleteSuggestions */,
|
false /* isObsoleteSuggestions */,
|
||||||
|
|
|
@ -49,6 +49,7 @@ import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.PunctuationSuggestions;
|
import com.android.inputmethod.latin.PunctuationSuggestions;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
import com.android.inputmethod.latin.SuggestedWords;
|
import com.android.inputmethod.latin.SuggestedWords;
|
||||||
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.ResourceUtils;
|
import com.android.inputmethod.latin.utils.ResourceUtils;
|
||||||
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
|
||||||
|
@ -250,8 +251,8 @@ final class SuggestionStripLayoutHelper {
|
||||||
final int positionInStrip =
|
final int positionInStrip =
|
||||||
getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords);
|
getPositionInSuggestionStrip(indexInSuggestedWords, suggestedWords);
|
||||||
// Use identity for strings, not #equals : it's the typed word if it's the same object
|
// Use identity for strings, not #equals : it's the typed word if it's the same object
|
||||||
final boolean isTypedWord =
|
final boolean isTypedWord = suggestedWords.getInfo(indexInSuggestedWords).isKindOf(
|
||||||
suggestedWords.getWord(indexInSuggestedWords) == suggestedWords.mTypedWord;
|
SuggestedWordInfo.KIND_TYPED);
|
||||||
|
|
||||||
final int color;
|
final int color;
|
||||||
if (positionInStrip == mCenterPositionInStrip && suggestedWords.mWillAutoCorrect) {
|
if (positionInStrip == mCenterPositionInStrip && suggestedWords.mWillAutoCorrect) {
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
package com.android.inputmethod.latin.utils;
|
package com.android.inputmethod.latin.utils;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
||||||
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
@ -29,6 +31,7 @@ import java.util.TreeSet;
|
||||||
*/
|
*/
|
||||||
public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
||||||
public final Locale mLocale;
|
public final Locale mLocale;
|
||||||
|
public final ArrayList<SuggestedWordInfo> mRawSuggestions;
|
||||||
private final int mCapacity;
|
private final int mCapacity;
|
||||||
|
|
||||||
public SuggestionResults(final Locale locale, final int capacity) {
|
public SuggestionResults(final Locale locale, final int capacity) {
|
||||||
|
@ -40,6 +43,11 @@ public final class SuggestionResults extends TreeSet<SuggestedWordInfo> {
|
||||||
super(comparator);
|
super(comparator);
|
||||||
mLocale = locale;
|
mLocale = locale;
|
||||||
mCapacity = capacity;
|
mCapacity = capacity;
|
||||||
|
if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
|
||||||
|
mRawSuggestions = new ArrayList<>();
|
||||||
|
} else {
|
||||||
|
mRawSuggestions = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue