aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/SuggestedWords.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-02-26 14:39:51 +0900
committerJean Chalard <jchalard@google.com>2014-03-04 14:31:47 +0900
commit32c6d4caea8e1391804f405d78e33e5c0fe89b4b (patch)
tree2c396147bb5d759c52767c922e7d1a50596d02f9 /java/src/com/android/inputmethod/latin/SuggestedWords.java
parentf2b0829aa1b05bae43ddde11407c7d8b29355f8f (diff)
downloadlatinime-32c6d4caea8e1391804f405d78e33e5c0fe89b4b.tar.gz
latinime-32c6d4caea8e1391804f405d78e33e5c0fe89b4b.tar.xz
latinime-32c6d4caea8e1391804f405d78e33e5c0fe89b4b.zip
[IL111] Remove a member.
...and improve encapsulation and readability. Bug: 8636060 Change-Id: I36407630b307df0721ea7fdb7e7a22cdf2b018b3
Diffstat (limited to 'java/src/com/android/inputmethod/latin/SuggestedWords.java')
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index 06bc90c97..dc2c9fd0e 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -167,15 +167,10 @@ public class SuggestedWords {
final CompletionInfo[] infos) {
final ArrayList<SuggestedWordInfo> result = CollectionUtils.newArrayList();
for (final CompletionInfo info : infos) {
- if (info == null) continue;
- final CharSequence text = info.getText();
- if (null == text) continue;
- final SuggestedWordInfo suggestedWordInfo = new SuggestedWordInfo(text.toString(),
- SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_APP_DEFINED,
- Dictionary.DICTIONARY_APPLICATION_DEFINED,
- SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
- SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
- result.add(suggestedWordInfo);
+ if (null == info || null == info.getText()) {
+ continue;
+ }
+ result.add(new SuggestedWordInfo(info));
}
return result;
}
@@ -234,6 +229,9 @@ public class SuggestedWords {
public static final int KIND_FLAG_EXACT_MATCH = 0x40000000;
public final String mWord;
+ // The completion info from the application. Null for suggestions that don't come from
+ // the application (including keyboard-computed ones, so this is almost always null)
+ public final CompletionInfo mApplicationSpecifiedCompletionInfo;
public final int mScore;
public final int mKind; // one of the KIND_* constants above
public final int mCodePointCount;
@@ -260,6 +258,7 @@ public class SuggestedWords {
final Dictionary sourceDict, final int indexOfTouchPointOfSecondWord,
final int autoCommitFirstWordConfidence) {
mWord = word;
+ mApplicationSpecifiedCompletionInfo = null;
mScore = score;
mKind = kind;
mSourceDict = sourceDict;
@@ -268,6 +267,22 @@ public class SuggestedWords {
mAutoCommitFirstWordConfidence = autoCommitFirstWordConfidence;
}
+ /**
+ * Create a new suggested word info from an application-specified completion.
+ * If the passed argument or its contained text is null, this throws a NPE.
+ * @param applicationSpecifiedCompletion The application-specified completion info.
+ */
+ public SuggestedWordInfo(final CompletionInfo applicationSpecifiedCompletion) {
+ mWord = applicationSpecifiedCompletion.getText().toString();
+ mApplicationSpecifiedCompletionInfo = applicationSpecifiedCompletion;
+ mScore = SuggestedWordInfo.MAX_SCORE;
+ mKind = SuggestedWordInfo.KIND_APP_DEFINED;
+ mSourceDict = Dictionary.DICTIONARY_APPLICATION_DEFINED;
+ mCodePointCount = StringUtils.codePointCount(mWord);
+ mIndexOfTouchPointOfSecondWord = SuggestedWordInfo.NOT_AN_INDEX;
+ mAutoCommitFirstWordConfidence = SuggestedWordInfo.NOT_A_CONFIDENCE;
+ }
+
public boolean isEligibleForAutoCommit() {
return (KIND_CORRECTION == mKind && NOT_AN_INDEX != mIndexOfTouchPointOfSecondWord);
}