aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2012-03-05 00:56:06 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-03-05 00:56:06 -0800
commit749048f4e4f66a5f0e5ffa443803204356e3beed (patch)
tree068ee081aa2dc7fb475f49ce14e385cf02cfa20a /java/src
parent907371b54fcad3df609bb75f7ad38f430189578b (diff)
parentc208f4dfb7abe1b7a83c725d515edb3615d5d927 (diff)
downloadlatinime-749048f4e4f66a5f0e5ffa443803204356e3beed.tar.gz
latinime-749048f4e4f66a5f0e5ffa443803204356e3beed.tar.xz
latinime-749048f4e4f66a5f0e5ffa443803204356e3beed.zip
Merge "Make SuggestedWords immutable"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java12
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java4
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java69
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java4
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java4
5 files changed, 50 insertions, 43 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 59fa66ded..6c9a827d6 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1827,9 +1827,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
}
}
- final SuggestedWords suggestedWords = builder.build();
- if (Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest)) {
- suggestedWords.setShouldBlockAutoCorrectionBySatefyNet();
+ if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) {
+ builder.setShouldBlockAutoCorrectionBySafetyNet();
}
showSuggestions(builder.build(), typedWord);
}
@@ -1837,7 +1836,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) {
final CharSequence autoCorrection;
if (suggestedWords.size() > 0) {
- if (!suggestedWords.shouldBlockAutoCorrectionBySafetyNet()
+ if (!suggestedWords.mShouldBlockAutoCorrectionBySafetyNet
&& suggestedWords.hasAutoCorrectionWord()) {
autoCorrection = suggestedWords.getWord(1);
} else {
@@ -1911,8 +1910,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something.
// So, LatinImeLogger logs "" as a user's input.
- LatinImeLogger.logOnManualSuggestion(
- "", suggestion.toString(), index, suggestions.mWords);
+ LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestions);
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
final int primaryCode = suggestion.charAt(0);
onCodeInput(primaryCode, new int[] { primaryCode },
@@ -1923,7 +1921,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// We need to log before we commit, because the word composer will store away the user
// typed word.
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
- suggestion.toString(), index, suggestions.mWords);
+ suggestion.toString(), index, suggestions);
mExpectingUpdateSelection = true;
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
LastComposedWord.NOT_A_SEPARATOR);
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index e3dadf250..9d4307fa5 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -22,8 +22,6 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Keyboard;
-import java.util.List;
-
public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChangeListener {
public static boolean sDBG = false;
@@ -44,7 +42,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
}
public static void logOnManualSuggestion(
- String before, String after, int position, List<CharSequence> suggestions) {
+ String before, String after, int position, SuggestedWords suggestions) {
}
public static void logOnAutoCorrection(String before, String after, int separatorCode) {
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index ff8945f71..bc6c52787 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -20,22 +20,25 @@ import android.text.TextUtils;
import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class SuggestedWords {
- public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null);
+ public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, false,
+ null);
- public final List<CharSequence> mWords;
+ private final List<CharSequence> mWords;
public final boolean mTypedWordValid;
public final boolean mHasAutoCorrectionCandidate;
public final boolean mIsPunctuationSuggestions;
+ public final boolean mShouldBlockAutoCorrectionBySafetyNet;
private final List<SuggestedWordInfo> mSuggestedWordInfoList;
- private boolean mShouldBlockAutoCorrectionBySafetyNet;
- private SuggestedWords(List<CharSequence> words, boolean typedWordValid,
+ SuggestedWords(List<CharSequence> words, boolean typedWordValid,
boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions,
+ boolean shouldBlockAutoCorrectionBySafetyNet,
List<SuggestedWordInfo> suggestedWordInfoList) {
if (words != null) {
mWords = words;
@@ -45,8 +48,8 @@ public class SuggestedWords {
mTypedWordValid = typedWordValid;
mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate;
mIsPunctuationSuggestions = isPunctuationSuggestions;
+ mShouldBlockAutoCorrectionBySafetyNet = shouldBlockAutoCorrectionBySafetyNet;
mSuggestedWordInfoList = suggestedWordInfoList;
- mShouldBlockAutoCorrectionBySafetyNet = false;
}
public int size() {
@@ -62,24 +65,23 @@ public class SuggestedWords {
}
public boolean hasAutoCorrectionWord() {
- return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid;
- }
-
- public boolean isPunctuationSuggestions() {
- return mIsPunctuationSuggestions;
- }
-
- public void setShouldBlockAutoCorrectionBySatefyNet() {
- mShouldBlockAutoCorrectionBySafetyNet = true;
- }
-
- public boolean shouldBlockAutoCorrectionBySafetyNet() {
- return mShouldBlockAutoCorrectionBySafetyNet;
+ return mHasAutoCorrectionCandidate && size() > 1 && mTypedWordValid;
}
public boolean willAutoCorrect() {
return !mTypedWordValid && mHasAutoCorrectionCandidate
- && !shouldBlockAutoCorrectionBySafetyNet();
+ && !mShouldBlockAutoCorrectionBySafetyNet;
+ }
+
+ @Override
+ public String toString() {
+ // Pretty-print method to help debug
+ return "SuggestedWords.Builder:"
+ + " mTypedWordValid = " + mTypedWordValid
+ + " mHasAutoCorrectionCandidate = " + mHasAutoCorrectionCandidate
+ + " mIsPunctuationSuggestions = " + mIsPunctuationSuggestions
+ + " mShouldBlockAutoCorrectionBySafetyNet" + mShouldBlockAutoCorrectionBySafetyNet
+ + " mWords=" + Arrays.toString(mWords.toArray());
}
public static class Builder {
@@ -87,6 +89,7 @@ public class SuggestedWords {
private boolean mTypedWordValid;
private boolean mHasMinimalSuggestion;
private boolean mIsPunctuationSuggestions;
+ private boolean mShouldBlockAutoCorrectionBySafetyNet;
private List<SuggestedWordInfo> mSuggestedWordInfoList =
new ArrayList<SuggestedWordInfo>();
@@ -151,6 +154,11 @@ public class SuggestedWords {
return this;
}
+ public Builder setShouldBlockAutoCorrectionBySafetyNet() {
+ mShouldBlockAutoCorrectionBySafetyNet = true;
+ return this;
+ }
+
// Should get rid of the first one (what the user typed previously) from suggestions
// and replace it with what the user currently typed.
public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord,
@@ -176,7 +184,8 @@ public class SuggestedWords {
public SuggestedWords build() {
return new SuggestedWords(mWords, mTypedWordValid, mHasMinimalSuggestion,
- mIsPunctuationSuggestions, mSuggestedWordInfoList);
+ mIsPunctuationSuggestions, mShouldBlockAutoCorrectionBySafetyNet,
+ mSuggestedWordInfoList);
}
public int size() {
@@ -187,18 +196,20 @@ public class SuggestedWords {
return mWords.get(pos);
}
+ public boolean isTypedWordValid() {
+ return mTypedWordValid;
+ }
+
@Override
public String toString() {
// Pretty-print method to help debug
- final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = "
- + mTypedWordValid + " ; mHasMinimalSuggestion = " + mHasMinimalSuggestion
- + " ; mIsPunctuationSuggestions = " + mIsPunctuationSuggestions
- + " --- ");
- for (CharSequence s : mWords) {
- sb.append(s);
- sb.append(" ; ");
- }
- return sb.toString();
+ return "SuggestedWords.Builder:"
+ + " mTypedWordValid = " + mTypedWordValid
+ + " mHasMinimalSuggestion = " + mHasMinimalSuggestion
+ + " mIsPunctuationSuggestions = " + mIsPunctuationSuggestions
+ + " mShouldBlockAutoCorrectionBySafetyNet"
+ + mShouldBlockAutoCorrectionBySafetyNet
+ + " mWords=" + Arrays.toString(mWords.toArray());
}
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index f6bc85431..69b2902cc 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -190,11 +190,11 @@ public class Utils {
// TODO: Resolve the inconsistencies between the native auto correction algorithms and
// this safety net
- public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions,
+ public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords.Builder suggestions,
Suggest suggest) {
// Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug.
- if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false;
+ if (suggestions.size() <= 1 || suggestions.isTypedWordValid()) return false;
// If user selected aggressive auto correction mode, there is no need to use the safety
// net.
if (suggest.isAggressiveAutoCorrectionMode()) return false;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
index e5638ef21..20eb55ce8 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java
@@ -307,7 +307,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
}
if (LatinImeLogger.sDBG) {
if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate
- && suggestions.shouldBlockAutoCorrectionBySafetyNet()) {
+ && suggestions.mShouldBlockAutoCorrectionBySafetyNet) {
return 0xFFFF0000;
}
}
@@ -335,7 +335,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
int stripWidth) {
- if (suggestions.isPunctuationSuggestions()) {
+ if (suggestions.mIsPunctuationSuggestions) {
layoutPunctuationSuggestions(suggestions, stripView);
return;
}