aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2012-08-15 16:09:38 +0900
committerJean Chalard <jchalard@google.com>2012-08-15 18:10:10 +0900
commit653dbfb8ed4dfa17b2d10865a04185b1e15f4e43 (patch)
tree0e3665ebe7de896e8404ee375b9bae3e990fa322 /java
parent05384933097c1e9c35e8be5c03757d072e5ffa46 (diff)
downloadlatinime-653dbfb8ed4dfa17b2d10865a04185b1e15f4e43.tar.gz
latinime-653dbfb8ed4dfa17b2d10865a04185b1e15f4e43.tar.xz
latinime-653dbfb8ed4dfa17b2d10865a04185b1e15f4e43.zip
Ensure #offer always actually offers something.
This will allow remaining requests after a call to terminate correctly. Bug: 6963142 Change-Id: Iff67058bb8a39f2f1b468d3894861e8125de6659
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java4
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java28
2 files changed, 29 insertions, 3 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
index 06f5db749..317fe7cd3 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
@@ -194,7 +194,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
DictAndProximity dictInfo = null;
try {
dictInfo = mDictionaryPool.pollWithDefaultTimeout();
- if (null == dictInfo) {
+ if (!DictionaryPool.isAValidDictionary(dictInfo)) {
return AndroidSpellCheckerService.getNotInDictEmptySuggestions();
}
return dictInfo.mDictionary.isValidWord(inText)
@@ -237,7 +237,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
DictAndProximity dictInfo = null;
try {
dictInfo = mDictionaryPool.pollWithDefaultTimeout();
- if (null == dictInfo) {
+ if (!DictionaryPool.isAValidDictionary(dictInfo)) {
return AndroidSpellCheckerService.getNotInDictEmptySuggestions();
}
final ArrayList<SuggestedWordInfo> suggestions =
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
index 83f82faeb..218eab7de 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java
@@ -18,6 +18,12 @@ package com.android.inputmethod.latin.spellcheck;
import android.util.Log;
+import com.android.inputmethod.keyboard.ProximityInfo;
+import com.android.inputmethod.latin.Dictionary;
+import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
+import com.android.inputmethod.latin.WordComposer;
+
+import java.util.ArrayList;
import java.util.Locale;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -39,6 +45,26 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> {
private final Locale mLocale;
private int mSize;
private volatile boolean mClosed;
+ final static ArrayList<SuggestedWordInfo> noSuggestions = new ArrayList<SuggestedWordInfo>();
+ private final static DictAndProximity dummyDict = new DictAndProximity(
+ new Dictionary(Dictionary.TYPE_MAIN) {
+ @Override
+ public ArrayList<SuggestedWordInfo> getSuggestions(final WordComposer composer,
+ final CharSequence prevWord, final ProximityInfo proximityInfo) {
+ return noSuggestions;
+ }
+ @Override
+ public boolean isValidWord(CharSequence word) {
+ // This is never called. However if for some strange reason it ever gets
+ // called, returning true is less destructive (it will not underline the
+ // word in red).
+ return true;
+ }
+ }, null);
+
+ static public boolean isAValidDictionary(final DictAndProximity dictInfo) {
+ return null != dictInfo && dummyDict != dictInfo;
+ }
public DictionaryPool(final int maxSize, final AndroidSpellCheckerService service,
final Locale locale) {
@@ -98,7 +124,7 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> {
public boolean offer(final DictAndProximity dict) {
if (mClosed) {
dict.mDictionary.close();
- return false;
+ return super.offer(dummyDict);
} else {
return super.offer(dict);
}