Move up the static methods of the Builder
Change-Id: Ic3e07b745b7b24cae0f772ea49e0de615b44caf9main
parent
8e19b1183e
commit
88bf1ba526
|
@ -924,7 +924,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
final List<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
|
||||||
SuggestedWords.Builder.getFromApplicationSpecifiedCompletions(
|
SuggestedWords.getFromApplicationSpecifiedCompletions(
|
||||||
applicationSpecifiedCompletions);
|
applicationSpecifiedCompletions);
|
||||||
SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords,
|
SuggestedWords.Builder builder = new SuggestedWords.Builder(applicationSuggestedWords,
|
||||||
false /* typedWordValid */,
|
false /* typedWordValid */,
|
||||||
|
@ -1788,7 +1788,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
|
||||||
previousSuggestions = SuggestedWords.EMPTY;
|
previousSuggestions = SuggestedWords.EMPTY;
|
||||||
}
|
}
|
||||||
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
||||||
SuggestedWords.Builder.getTypedWordAndPreviousSuggestions(
|
SuggestedWords.getTypedWordAndPreviousSuggestions(
|
||||||
typedWord, previousSuggestions);
|
typedWord, previousSuggestions);
|
||||||
final SuggestedWords.Builder obsoleteSuggestionsBuilder =
|
final SuggestedWords.Builder obsoleteSuggestionsBuilder =
|
||||||
new SuggestedWords.Builder(typedWordAndPreviousSuggestions,
|
new SuggestedWords.Builder(typedWordAndPreviousSuggestions,
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
StringUtils.removeDupes(mSuggestions);
|
StringUtils.removeDupes(mSuggestions);
|
||||||
|
|
||||||
return new SuggestedWords.Builder(
|
return new SuggestedWords.Builder(
|
||||||
SuggestedWords.Builder.getFromCharSequenceList(mSuggestions),
|
SuggestedWords.getFromCharSequenceList(mSuggestions),
|
||||||
false /* typedWordValid */,
|
false /* typedWordValid */,
|
||||||
false /* hasMinimalSuggestion */,
|
false /* hasMinimalSuggestion */,
|
||||||
false /* allowsToBeAutoCorrected */,
|
false /* allowsToBeAutoCorrected */,
|
||||||
|
@ -428,7 +428,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
"--", false));
|
"--", false));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scoreInfoList = SuggestedWords.Builder.getFromCharSequenceList(mSuggestions);
|
scoreInfoList = SuggestedWords.getFromCharSequenceList(mSuggestions);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean autoCorrectionAvailable = hasAutoCorrection;
|
boolean autoCorrectionAvailable = hasAutoCorrection;
|
||||||
|
|
|
@ -98,44 +98,6 @@ public class SuggestedWords {
|
||||||
mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet;
|
mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<SuggestedWordInfo> getFromCharSequenceList(
|
|
||||||
final List<CharSequence> wordList) {
|
|
||||||
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
|
||||||
for (CharSequence word : wordList) {
|
|
||||||
if (null != word) result.add(new SuggestedWordInfo(word, null, false));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
|
||||||
final CompletionInfo[] infos) {
|
|
||||||
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
|
||||||
for (CompletionInfo info : infos) {
|
|
||||||
if (null != info) result.add(new SuggestedWordInfo(info.getText(), null, false));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Should get rid of the first one (what the user typed previously) from suggestions
|
|
||||||
// and replace it with what the user currently typed.
|
|
||||||
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
|
|
||||||
final CharSequence typedWord, final SuggestedWords previousSuggestions) {
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>();
|
|
||||||
final HashSet<String> alreadySeen = new HashSet<String>();
|
|
||||||
suggestionsList.add(new SuggestedWordInfo(typedWord, null, false));
|
|
||||||
alreadySeen.add(typedWord.toString());
|
|
||||||
final int previousSize = previousSuggestions.size();
|
|
||||||
for (int pos = 1; pos < previousSize; pos++) {
|
|
||||||
final String prevWord = previousSuggestions.getWord(pos).toString();
|
|
||||||
// Filter out duplicate suggestion.
|
|
||||||
if (!alreadySeen.contains(prevWord)) {
|
|
||||||
suggestionsList.add(new SuggestedWordInfo(prevWord, null, true));
|
|
||||||
alreadySeen.add(prevWord);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return suggestionsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuggestedWords build() {
|
public SuggestedWords build() {
|
||||||
return new SuggestedWords(mTypedWordValid, mHasMinimalSuggestion,
|
return new SuggestedWords(mTypedWordValid, mHasMinimalSuggestion,
|
||||||
mIsPunctuationSuggestions, mShouldBlockAutoCorrectionBySafetyNet,
|
mIsPunctuationSuggestions, mShouldBlockAutoCorrectionBySafetyNet,
|
||||||
|
@ -143,6 +105,44 @@ public class SuggestedWords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<SuggestedWordInfo> getFromCharSequenceList(
|
||||||
|
final List<CharSequence> wordList) {
|
||||||
|
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
||||||
|
for (CharSequence word : wordList) {
|
||||||
|
if (null != word) result.add(new SuggestedWordInfo(word, null, false));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SuggestedWordInfo> getFromApplicationSpecifiedCompletions(
|
||||||
|
final CompletionInfo[] infos) {
|
||||||
|
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
||||||
|
for (CompletionInfo info : infos) {
|
||||||
|
if (null != info) result.add(new SuggestedWordInfo(info.getText(), null, false));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Should get rid of the first one (what the user typed previously) from suggestions
|
||||||
|
// and replace it with what the user currently typed.
|
||||||
|
public static ArrayList<SuggestedWordInfo> getTypedWordAndPreviousSuggestions(
|
||||||
|
final CharSequence typedWord, final SuggestedWords previousSuggestions) {
|
||||||
|
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>();
|
||||||
|
final HashSet<String> alreadySeen = new HashSet<String>();
|
||||||
|
suggestionsList.add(new SuggestedWordInfo(typedWord, null, false));
|
||||||
|
alreadySeen.add(typedWord.toString());
|
||||||
|
final int previousSize = previousSuggestions.size();
|
||||||
|
for (int pos = 1; pos < previousSize; pos++) {
|
||||||
|
final String prevWord = previousSuggestions.getWord(pos).toString();
|
||||||
|
// Filter out duplicate suggestion.
|
||||||
|
if (!alreadySeen.contains(prevWord)) {
|
||||||
|
suggestionsList.add(new SuggestedWordInfo(prevWord, null, true));
|
||||||
|
alreadySeen.add(prevWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return suggestionsList;
|
||||||
|
}
|
||||||
|
|
||||||
public static class SuggestedWordInfo {
|
public static class SuggestedWordInfo {
|
||||||
public final CharSequence mWord;
|
public final CharSequence mWord;
|
||||||
private final CharSequence mDebugString;
|
private final CharSequence mDebugString;
|
||||||
|
|
Loading…
Reference in New Issue