aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-19 22:27:10 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-12-19 22:27:10 -0800
commite3e80aa10754bba91d9543ed492a7e542a38dc24 (patch)
treecde113cf286adfae83cd579dee52ade374776d05 /java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
parent91000283b5332c6d8818be3a65b653c262752882 (diff)
parenta905fcec00f78e828c1fe9109f27cc9f149941b5 (diff)
downloadlatinime-e3e80aa10754bba91d9543ed492a7e542a38dc24.tar.gz
latinime-e3e80aa10754bba91d9543ed492a7e542a38dc24.tar.xz
latinime-e3e80aa10754bba91d9543ed492a7e542a38dc24.zip
am a905fcec: [IL16] Improve getTextWithSuggestionSpan
* commit 'a905fcec00f78e828c1fe9109f27cc9f149941b5': [IL16] Improve getTextWithSuggestionSpan
Diffstat (limited to 'java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 55282c583..b8d1651dc 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -23,8 +23,10 @@ import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.SuggestionSpan;
+import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.SuggestedWords;
+import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver;
import com.android.inputmethod.latin.utils.CollectionUtils;
@@ -66,30 +68,42 @@ public final class SuggestionSpanUtils {
}
public static CharSequence getTextWithSuggestionSpan(final Context context,
- final String pickedWord, final SuggestedWords suggestedWords,
- final boolean dictionaryAvailable) {
- if (!dictionaryAvailable || TextUtils.isEmpty(pickedWord) || suggestedWords.isEmpty()
+ final String pickedWord, final SuggestedWords suggestedWords) {
+ if (TextUtils.isEmpty(pickedWord) || suggestedWords.isEmpty()
|| suggestedWords.mIsPrediction || suggestedWords.mIsPunctuationSuggestions) {
return pickedWord;
}
- final Spannable spannable = new SpannableString(pickedWord);
+ boolean hasSuggestionFromMainDictionary = false;
final ArrayList<String> suggestionsList = CollectionUtils.newArrayList();
for (int i = 0; i < suggestedWords.size(); ++i) {
if (suggestionsList.size() >= SuggestionSpan.SUGGESTIONS_MAX_SIZE) {
break;
}
+ final SuggestedWordInfo info = suggestedWords.getInfo(i);
+ if (info.mKind == SuggestedWordInfo.KIND_PREDICTION) {
+ continue;
+ }
+ if (info.mSourceDict.mDictType == Dictionary.TYPE_MAIN) {
+ hasSuggestionFromMainDictionary = true;
+ }
final String word = suggestedWords.getWord(i);
if (!TextUtils.equals(pickedWord, word)) {
suggestionsList.add(word.toString());
}
}
+ if (!hasSuggestionFromMainDictionary) {
+ // If we don't have any suggestions from the dictionary, it probably looks bad
+ // enough as it is already because suggestions come pretty much only from contacts.
+ // Let's not embed these bad suggestions in the text view so as to avoid using
+ // them with recorrection.
+ return pickedWord;
+ }
- // TODO: We should avoid adding suggestion span candidates that came from the bigram
- // prediction.
final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null /* locale */,
suggestionsList.toArray(new String[suggestionsList.size()]), 0 /* flags */,
SuggestionSpanPickedNotificationReceiver.class);
+ final Spannable spannable = new SpannableString(pickedWord);
spannable.setSpan(suggestionSpan, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}