diff options
author | 2015-02-10 23:25:49 +0000 | |
---|---|---|
committer | 2015-02-10 23:25:50 +0000 | |
commit | 2979fad21384bb595ba2baca8f5bbbfc053be921 (patch) | |
tree | abce86b8667db57b1daa0a1db9922d510e542481 /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java | |
parent | a7805e9870430eac3049129d47bebb312d457477 (diff) | |
parent | 8aa310aa5a1b8e726e78c57361d496a82c569bf6 (diff) | |
download | latinime-2979fad21384bb595ba2baca8f5bbbfc053be921.tar.gz latinime-2979fad21384bb595ba2baca8f5bbbfc053be921.tar.xz latinime-2979fad21384bb595ba2baca8f5bbbfc053be921.zip |
Merge "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.java | 33 |
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); |