Merge "Add a kind to the suggestion for bookkeeping (A1)"
commit
0176faf6c0
|
@ -178,12 +178,11 @@ public class SettingsValues {
|
||||||
|
|
||||||
// Helper functions to create member values.
|
// Helper functions to create member values.
|
||||||
private static SuggestedWords createSuggestPuncList(final String[] puncs) {
|
private static SuggestedWords createSuggestPuncList(final String[] puncs) {
|
||||||
final ArrayList<SuggestedWords.SuggestedWordInfo> puncList =
|
final ArrayList<SuggestedWordInfo> puncList = new ArrayList<SuggestedWordInfo>();
|
||||||
new ArrayList<SuggestedWords.SuggestedWordInfo>();
|
|
||||||
if (puncs != null) {
|
if (puncs != null) {
|
||||||
for (final String puncSpec : puncs) {
|
for (final String puncSpec : puncs) {
|
||||||
puncList.add(new SuggestedWords.SuggestedWordInfo(
|
puncList.add(new SuggestedWordInfo(KeySpecParser.getLabel(puncSpec),
|
||||||
KeySpecParser.getLabel(puncSpec), SuggestedWordInfo.MAX_SCORE));
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_HARDCODED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new SuggestedWords(puncList,
|
return new SuggestedWords(puncList,
|
||||||
|
|
|
@ -339,15 +339,16 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
||||||
}
|
}
|
||||||
mSuggestions.add(0, new SuggestedWordInfo(
|
mSuggestions.add(0, new SuggestedWordInfo(sb.toString(),
|
||||||
sb.toString(), SuggestedWordInfo.MAX_SCORE));
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
|
||||||
} else {
|
} else {
|
||||||
mSuggestions.add(0, new SuggestedWordInfo(
|
mSuggestions.add(0, new SuggestedWordInfo(whitelistedWord,
|
||||||
whitelistedWord, SuggestedWordInfo.MAX_SCORE));
|
SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_WHITELIST));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE));
|
mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
||||||
|
SuggestedWordInfo.KIND_TYPED));
|
||||||
SuggestedWordInfo.removeDups(mSuggestions);
|
SuggestedWordInfo.removeDups(mSuggestions);
|
||||||
|
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsList;
|
final ArrayList<SuggestedWordInfo> suggestionsList;
|
||||||
|
@ -499,7 +500,8 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
for (int i = mTrailingSingleQuotesCount - 1; i >= 0; --i) {
|
||||||
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
sb.appendCodePoint(Keyboard.CODE_SINGLE_QUOTE);
|
||||||
}
|
}
|
||||||
suggestions.add(pos, new SuggestedWordInfo(sb, score));
|
// TODO: figure out what type of suggestion this is
|
||||||
|
suggestions.add(pos, new SuggestedWordInfo(sb, score, SuggestedWordInfo.KIND_CORRECTION));
|
||||||
if (suggestions.size() > prefMaxSuggestions) {
|
if (suggestions.size() > prefMaxSuggestions) {
|
||||||
suggestions.remove(prefMaxSuggestions);
|
suggestions.remove(prefMaxSuggestions);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -91,7 +91,8 @@ public class SuggestedWords {
|
||||||
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> result = new ArrayList<SuggestedWordInfo>();
|
||||||
for (CompletionInfo info : infos) {
|
for (CompletionInfo info : infos) {
|
||||||
if (null != info && info.getText() != null) {
|
if (null != info && info.getText() != null) {
|
||||||
result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE));
|
result.add(new SuggestedWordInfo(info.getText(), SuggestedWordInfo.MAX_SCORE,
|
||||||
|
SuggestedWordInfo.KIND_APP_DEFINED));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -103,7 +104,8 @@ public class SuggestedWords {
|
||||||
final CharSequence typedWord, final SuggestedWords previousSuggestions) {
|
final CharSequence typedWord, final SuggestedWords previousSuggestions) {
|
||||||
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>();
|
final ArrayList<SuggestedWordInfo> suggestionsList = new ArrayList<SuggestedWordInfo>();
|
||||||
final HashSet<String> alreadySeen = new HashSet<String>();
|
final HashSet<String> alreadySeen = new HashSet<String>();
|
||||||
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE));
|
suggestionsList.add(new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE,
|
||||||
|
SuggestedWordInfo.KIND_TYPED));
|
||||||
alreadySeen.add(typedWord.toString());
|
alreadySeen.add(typedWord.toString());
|
||||||
final int previousSize = previousSuggestions.size();
|
final int previousSize = previousSuggestions.size();
|
||||||
for (int pos = 1; pos < previousSize; pos++) {
|
for (int pos = 1; pos < previousSize; pos++) {
|
||||||
|
@ -120,16 +122,25 @@ public class SuggestedWords {
|
||||||
|
|
||||||
public static class SuggestedWordInfo {
|
public static class SuggestedWordInfo {
|
||||||
public static final int MAX_SCORE = Integer.MAX_VALUE;
|
public static final int MAX_SCORE = Integer.MAX_VALUE;
|
||||||
|
public static final int KIND_TYPED = 0; // What user typed
|
||||||
|
public static final int KIND_CORRECTION = 1; // Simple correction/suggestion
|
||||||
|
public static final int KIND_COMPLETION = 2; // Completion (suggestion with appended chars)
|
||||||
|
public static final int KIND_WHITELIST = 3; // Whitelisted word
|
||||||
|
public static final int KIND_BLACKLIST = 4; // Blacklisted word
|
||||||
|
public static final int KIND_HARDCODED = 5; // Hardcoded suggestion, e.g. punctuation
|
||||||
|
public static final int KIND_APP_DEFINED = 6; // Suggested by the application
|
||||||
private final String mWordStr;
|
private final String mWordStr;
|
||||||
public final CharSequence mWord;
|
public final CharSequence mWord;
|
||||||
public final int mScore;
|
public final int mScore;
|
||||||
|
public final int mKind;
|
||||||
public final int mCodePointCount;
|
public final int mCodePointCount;
|
||||||
private String mDebugString = "";
|
private String mDebugString = "";
|
||||||
|
|
||||||
public SuggestedWordInfo(final CharSequence word, final int score) {
|
public SuggestedWordInfo(final CharSequence word, final int score, final int kind) {
|
||||||
mWordStr = word.toString();
|
mWordStr = word.toString();
|
||||||
mWord = word;
|
mWord = word;
|
||||||
mScore = score;
|
mScore = score;
|
||||||
|
mKind = kind;
|
||||||
mCodePointCount = mWordStr.codePointCount(0, mWordStr.length());
|
mCodePointCount = mWordStr.codePointCount(0, mWordStr.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue