aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
diff options
context:
space:
mode:
authorMario Tanev <radix@google.com>2015-02-10 23:32:09 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-02-10 23:32:09 +0000
commit1c7d6283fcefb37d1f7ac35a1ded0b705225ccdd (patch)
tree0f8b22baef7f1579a41d80189d8f3f42b8b6a321 /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
parent5bfe1c56977912f02686af111813088c3dec8057 (diff)
parent2979fad21384bb595ba2baca8f5bbbfc053be921 (diff)
downloadlatinime-1c7d6283fcefb37d1f7ac35a1ded0b705225ccdd.tar.gz
latinime-1c7d6283fcefb37d1f7ac35a1ded0b705225ccdd.tar.xz
latinime-1c7d6283fcefb37d1f7ac35a1ded0b705225ccdd.zip
am 2979fad2: Merge "Add new class spellcheck.UserDictionaryLookup that can look up the system "Personal dictionary" in the event that the DictionaryFacilitator doesn\'t."
* commit '2979fad21384bb595ba2baca8f5bbbfc053be921': Add new class spellcheck.UserDictionaryLookup that can look up the system "Personal dictionary" in the event that the DictionaryFacilitator doesn't.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 02151522d..95293bf2f 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -24,6 +24,7 @@ import android.text.InputType;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import android.view.textservice.SuggestionsInfo;
+import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
@@ -52,6 +53,9 @@ import java.util.concurrent.Semaphore;
*/
public final class AndroidSpellCheckerService extends SpellCheckerService
implements SharedPreferences.OnSharedPreferenceChangeListener {
+ private static final String TAG = AndroidSpellCheckerService.class.getSimpleName();
+ private static final boolean DEBUG = false;
+
public static final String PREF_USE_CONTACTS_KEY = "pref_spellcheck_use_contacts";
private static final int SPELLCHECKER_DUMMY_KEYBOARD_WIDTH = 480;
@@ -80,6 +84,7 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public static final String SINGLE_QUOTE = "\u0027";
public static final String APOSTROPHE = "\u2019";
+ private UserDictionaryLookup mUserDictionaryLookup;
public AndroidSpellCheckerService() {
super();
@@ -95,6 +100,24 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, PREF_USE_CONTACTS_KEY);
+ // Create a UserDictionaryLookup. It needs to be close()d and set to null in onDestroy.
+ if (mUserDictionaryLookup == null) {
+ if (DEBUG) {
+ Log.d(TAG, "Creating mUserDictionaryLookup in onCreate");
+ }
+ mUserDictionaryLookup = new UserDictionaryLookup(this);
+ } else if (DEBUG) {
+ Log.d(TAG, "mUserDictionaryLookup already created before onCreate");
+ }
+ }
+
+ @Override public void onDestroy() {
+ if (DEBUG) {
+ Log.d(TAG, "Closing and dereferencing mUserDictionaryLookup in onDestroy");
+ }
+ mUserDictionaryLookup.close();
+ mUserDictionaryLookup = null;
+ super.onDestroy();
}
public float getRecommendedThreshold() {
@@ -150,6 +173,16 @@ public final class AndroidSpellCheckerService extends SpellCheckerService
public boolean isValidWord(final Locale locale, final String word) {
mSemaphore.acquireUninterruptibly();
try {
+ if (mUserDictionaryLookup.isValidWord(word, locale)) {
+ if (DEBUG) {
+ Log.d(TAG, "mUserDictionaryLookup.isValidWord(" + word + ")=true");
+ }
+ return true;
+ } else {
+ if (DEBUG) {
+ Log.d(TAG, "mUserDictionaryLookup.isValidWord(" + word + ")=false");
+ }
+ }
DictionaryFacilitator dictionaryFacilitatorForLocale =
mDictionaryFacilitatorCache.get(locale);
return dictionaryFacilitatorForLocale.isValidSpellingWord(word);