aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/spellcheck
diff options
context:
space:
mode:
authorDan Zivkovic <zivkovic@google.com>2015-02-19 19:49:07 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-02-19 19:49:07 +0000
commite3e7589f8570390184312d776d0b53a248d66e3d (patch)
treeec7297b53dee694b99674c0cbca1703ce7d3587d /java/src/com/android/inputmethod/latin/spellcheck
parentbaefd1c87ec46bccda76cdafc4b8b9eb534a5fd8 (diff)
parent0b03f13cabec84d2d841fde47ce9fec0d531b6a1 (diff)
downloadlatinime-e3e7589f8570390184312d776d0b53a248d66e3d.tar.gz
latinime-e3e7589f8570390184312d776d0b53a248d66e3d.tar.xz
latinime-e3e7589f8570390184312d776d0b53a248d66e3d.zip
am 0b03f13c: Sanitize the usage of executors.
* commit '0b03f13cabec84d2d841fde47ce9fec0d531b6a1': Sanitize the usage of executors.
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java23
1 files changed, 7 insertions, 16 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java b/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java
index baff8f066..19620511d 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/UserDictionaryLookup.java
@@ -26,14 +26,13 @@ import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.common.LocaleUtils;
+import com.android.inputmethod.latin.utils.ExecutorUtils;
import java.io.Closeable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@@ -83,12 +82,6 @@ public class UserDictionaryLookup implements Closeable {
private final ContentResolver mResolver;
/**
- * Executor on which to perform the initial load and subsequent reloads (after a delay).
- */
- private final ScheduledExecutorService mLoadExecutor =
- Executors.newSingleThreadScheduledExecutor();
-
- /**
* Runnable that calls loadUserDictionary().
*/
private class UserDictionaryLoader implements Runnable {
@@ -150,7 +143,8 @@ public class UserDictionaryLookup implements Closeable {
}
// Schedule a new reload after RELOAD_DELAY_MS.
- mReloadFuture = mLoadExecutor.schedule(mLoader, RELOAD_DELAY_MS, TimeUnit.MILLISECONDS);
+ mReloadFuture = ExecutorUtils.getExecutorForDynamicLanguageModelUpdate().schedule(
+ mLoader, RELOAD_DELAY_MS, TimeUnit.MILLISECONDS);
}
}
private final ContentObserver mObserver = new UserDictionaryContentObserver();
@@ -192,7 +186,8 @@ public class UserDictionaryLookup implements Closeable {
// Schedule the initial load to run immediately. It's possible that the first call to
// isValidWord occurs before the dictionary has actually loaded, so it should not
// assume that the dictionary has been loaded.
- mLoadExecutor.schedule(mLoader, 0, TimeUnit.MILLISECONDS);
+ ExecutorUtils.getExecutorForDynamicLanguageModelUpdate().schedule(
+ mLoader, 0, TimeUnit.MILLISECONDS);
// Register the observer to be notified on changes to the UserDictionary and all individual
// items.
@@ -236,9 +231,6 @@ public class UserDictionaryLookup implements Closeable {
Log.d(TAG, "Close called (no pun intended), cleaning up executor and observer");
}
if (mIsClosed.compareAndSet(false, true)) {
- // Shut down the load executor.
- mLoadExecutor.shutdown();
-
// Unregister the content observer.
mResolver.unregisterContentObserver(mObserver);
}
@@ -342,8 +334,7 @@ public class UserDictionaryLookup implements Closeable {
if (DEBUG) {
Log.d(TAG, "Loading UserDictionary");
}
- HashMap<String, ArrayList<Locale>> dictWords =
- new HashMap<String, ArrayList<Locale>>();
+ HashMap<String, ArrayList<Locale>> dictWords = new HashMap<>();
// Load the UserDictionary. Request that items be returned in the default sort order
// for UserDictionary, which is by frequency.
Cursor cursor = mResolver.query(UserDictionary.Words.CONTENT_URI,
@@ -413,7 +404,7 @@ public class UserDictionaryLookup implements Closeable {
Log.d(TAG, "Word [" + dictWord +
"] not seen for other locales, creating new entry");
}
- dictLocales = new ArrayList<Locale>();
+ dictLocales = new ArrayList<>();
dictWords.put(dictWord, dictLocales);
}
// Append the locale to the list of locales this word is in.