Have the spell checker use the User dictionary.
Bug: 5175868 Change-Id: I165eee4c865caa5ee1daf3e0b1acde8788b996ef
This commit is contained in:
parent
f0025a50ac
commit
150bad6fd4
3 changed files with 23 additions and 8 deletions
|
@ -42,9 +42,9 @@ public class DictionaryFactory {
|
||||||
* @param context application context for reading resources
|
* @param context application context for reading resources
|
||||||
* @param locale the locale for which to create the dictionary
|
* @param locale the locale for which to create the dictionary
|
||||||
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
|
* @param fallbackResId the id of the resource to use as a fallback if no pack is found
|
||||||
* @return an initialized instance of Dictionary
|
* @return an initialized instance of DictionaryCollection
|
||||||
*/
|
*/
|
||||||
public static Dictionary createDictionaryFromManager(Context context, Locale locale,
|
public static DictionaryCollection createDictionaryFromManager(Context context, Locale locale,
|
||||||
int fallbackResId) {
|
int fallbackResId) {
|
||||||
if (null == locale) {
|
if (null == locale) {
|
||||||
Log.e(TAG, "No locale defined for dictionary");
|
Log.e(TAG, "No locale defined for dictionary");
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
if (!mUpdatingDictionary) {
|
if (!mUpdatingDictionary) {
|
||||||
mUpdatingDictionary = true;
|
mUpdatingDictionary = true;
|
||||||
mRequiresReload = false;
|
mRequiresReload = false;
|
||||||
new LoadDictionaryTask().execute();
|
new LoadDictionaryTask().start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,14 +541,13 @@ public class ExpandableDictionary extends Dictionary {
|
||||||
mRoots = new NodeArray();
|
mRoots = new NodeArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LoadDictionaryTask extends AsyncTask<Void, Void, Void> {
|
private class LoadDictionaryTask extends Thread {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... v) {
|
public void run() {
|
||||||
loadDictionaryAsync();
|
loadDictionaryAsync();
|
||||||
synchronized (mUpdatingLock) {
|
synchronized (mUpdatingLock) {
|
||||||
mUpdatingDictionary = false;
|
mUpdatingDictionary = false;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,9 @@ import com.android.inputmethod.keyboard.ProximityInfo;
|
||||||
import com.android.inputmethod.latin.Dictionary;
|
import com.android.inputmethod.latin.Dictionary;
|
||||||
import com.android.inputmethod.latin.Dictionary.DataType;
|
import com.android.inputmethod.latin.Dictionary.DataType;
|
||||||
import com.android.inputmethod.latin.Dictionary.WordCallback;
|
import com.android.inputmethod.latin.Dictionary.WordCallback;
|
||||||
|
import com.android.inputmethod.latin.DictionaryCollection;
|
||||||
import com.android.inputmethod.latin.DictionaryFactory;
|
import com.android.inputmethod.latin.DictionaryFactory;
|
||||||
|
import com.android.inputmethod.latin.UserDictionary;
|
||||||
import com.android.inputmethod.latin.Utils;
|
import com.android.inputmethod.latin.Utils;
|
||||||
import com.android.inputmethod.latin.WordComposer;
|
import com.android.inputmethod.latin.WordComposer;
|
||||||
|
|
||||||
|
@ -51,6 +53,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
private final static String[] emptyArray = new String[0];
|
private final static String[] emptyArray = new String[0];
|
||||||
private Map<String, DictionaryPool> mDictionaryPools =
|
private Map<String, DictionaryPool> mDictionaryPools =
|
||||||
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
||||||
|
private Map<String, Dictionary> mUserDictionaries =
|
||||||
|
Collections.synchronizedMap(new TreeMap<String, Dictionary>());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Session createSession() {
|
public Session createSession() {
|
||||||
|
@ -109,9 +113,14 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
public boolean onUnbind(final Intent intent) {
|
public boolean onUnbind(final Intent intent) {
|
||||||
final Map<String, DictionaryPool> oldPools = mDictionaryPools;
|
final Map<String, DictionaryPool> oldPools = mDictionaryPools;
|
||||||
mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
|
||||||
|
final Map<String, Dictionary> oldUserDictionaries = mUserDictionaries;
|
||||||
|
mUserDictionaries = Collections.synchronizedMap(new TreeMap<String, Dictionary>());
|
||||||
for (DictionaryPool pool : oldPools.values()) {
|
for (DictionaryPool pool : oldPools.values()) {
|
||||||
pool.close();
|
pool.close();
|
||||||
}
|
}
|
||||||
|
for (Dictionary dict : oldUserDictionaries.values()) {
|
||||||
|
dict.close();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +138,16 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
|
||||||
final ProximityInfo proximityInfo = ProximityInfo.createSpellCheckerProximityInfo();
|
final ProximityInfo proximityInfo = ProximityInfo.createSpellCheckerProximityInfo();
|
||||||
final Resources resources = getResources();
|
final Resources resources = getResources();
|
||||||
final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources);
|
final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources);
|
||||||
final Dictionary dictionary =
|
final DictionaryCollection dictionaryCollection =
|
||||||
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId);
|
DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId);
|
||||||
return new DictAndProximity(dictionary, proximityInfo);
|
final String localeStr = locale.toString();
|
||||||
|
Dictionary userDict = mUserDictionaries.get(localeStr);
|
||||||
|
if (null == userDict) {
|
||||||
|
userDict = new UserDictionary(this, localeStr);
|
||||||
|
mUserDictionaries.put(localeStr, userDict);
|
||||||
|
}
|
||||||
|
dictionaryCollection.addDictionary(userDict);
|
||||||
|
return new DictAndProximity(dictionaryCollection, proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class AndroidSpellCheckerSession extends Session {
|
private class AndroidSpellCheckerSession extends Session {
|
||||||
|
|
Loading…
Reference in a new issue