aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/Suggest.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-06-19 15:07:17 +0900
committerJean Chalard <jchalard@google.com>2014-06-23 22:19:09 +0900
commite83e79cb055fbfe5171fb79a2224e7d9e2cda4d2 (patch)
tree1f75e10b0a6cd94babf5e4fae998584862867a26 /java/src/com/android/inputmethod/latin/Suggest.java
parentf7322b166b88f72b19509d8416700d4ec8ea7753 (diff)
downloadlatinime-e83e79cb055fbfe5171fb79a2224e7d9e2cda4d2.tar.gz
latinime-e83e79cb055fbfe5171fb79a2224e7d9e2cda4d2.tar.xz
latinime-e83e79cb055fbfe5171fb79a2224e7d9e2cda4d2.zip
[CS1] Some initial clean up
Bug: 13238601 Change-Id: I54ee9a85ecfee3c50c8db3eb4cd6f391a775a630
Diffstat (limited to 'java/src/com/android/inputmethod/latin/Suggest.java')
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java41
1 files changed, 17 insertions, 24 deletions
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 670d856e3..7364fc979 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -100,30 +100,28 @@ public final class Suggest {
? typedWord.substring(0, typedWord.length() - trailingSingleQuotesCount)
: typedWord;
- final ArrayList<SuggestedWordInfo> rawSuggestions;
- if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
- rawSuggestions = new ArrayList<>();
- } else {
- rawSuggestions = null;
- }
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
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 =
wordComposer.isOrWillBeOnlyFirstCharCapitalized();
+
// 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
// normal, non-capitalized suggestion.
- final boolean isAllUpperCase = wordComposer.isAllUpperCase() && !wordComposer.isResumed();
final String firstSuggestion;
final String whitelistedWord;
if (suggestionResults.isEmpty()) {
whitelistedWord = firstSuggestion = null;
} else {
final SuggestedWordInfo firstSuggestedWordInfo = getTransformedSuggestedWordInfo(
- suggestionResults.first(), suggestionResults.mLocale, isAllUpperCase,
- isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
+ suggestionResults.first(), suggestionResults.mLocale,
+ shouldMakeSuggestionsAllUpperCase, isOnlyFirstCharCapitalized,
+ trailingSingleQuotesCount);
firstSuggestion = firstSuggestedWordInfo.mWord;
if (!firstSuggestedWordInfo.isKindOf(SuggestedWordInfo.KIND_WHITELIST)) {
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
// 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
@@ -174,11 +170,12 @@ public final class Suggest {
final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<>(suggestionResults);
final int suggestionsCount = suggestionsContainer.size();
- if (isOnlyFirstCharCapitalized || isAllUpperCase || 0 != trailingSingleQuotesCount) {
+ if (isOnlyFirstCharCapitalized || shouldMakeSuggestionsAllUpperCase
+ || 0 != trailingSingleQuotesCount) {
for (int i = 0; i < suggestionsCount; ++i) {
final SuggestedWordInfo wordInfo = suggestionsContainer.get(i);
final SuggestedWordInfo transformedWordInfo = getTransformedSuggestedWordInfo(
- wordInfo, suggestionResults.mLocale, isAllUpperCase,
+ wordInfo, suggestionResults.mLocale, shouldMakeSuggestionsAllUpperCase,
isOnlyFirstCharCapitalized, trailingSingleQuotesCount);
suggestionsContainer.set(i, transformedWordInfo);
}
@@ -200,12 +197,13 @@ public final class Suggest {
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
// actual word, it says typedWordValid = false, which looks wrong. We should either
// rename the attribute or change the value.
!isPrediction && !allowsToBeAutoCorrected /* typedWordValid */,
- hasAutoCorrection, /* willAutoCorrect */
+ hasAutoCorrection /* willAutoCorrect */,
false /* isObsoleteSuggestions */, isPrediction, sequenceNumber));
}
@@ -216,15 +214,9 @@ public final class Suggest {
final boolean blockOffensiveWords, final int[] additionalFeaturesOptions,
final int sessionId, final int sequenceNumber,
final OnGetSuggestedWordsCallback callback) {
- final ArrayList<SuggestedWordInfo> rawSuggestions;
- if (ProductionFlag.INCLUDE_RAW_SUGGESTIONS) {
- rawSuggestions = new ArrayList<>();
- } else {
- rawSuggestions = null;
- }
final SuggestionResults suggestionResults = mDictionaryFacilitator.getSuggestionResults(
wordComposer, prevWordsInfo, proximityInfo, blockOffensiveWords,
- additionalFeaturesOptions, sessionId, rawSuggestions);
+ additionalFeaturesOptions, sessionId);
final ArrayList<SuggestedWordInfo> suggestionsContainer =
new ArrayList<>(suggestionResults);
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"
// (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 */,
false /* willAutoCorrect */,
false /* isObsoleteSuggestions */,