Merge "Have the spell checker use the User dictionary."

main
Jean Chalard 2011-08-19 01:27:54 -07:00 committed by Android (Google) Code Review
commit ff5a54c5af
3 changed files with 23 additions and 8 deletions

View File

@ -42,9 +42,9 @@ public class DictionaryFactory {
* @param context application context for reading resources
* @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
* @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) {
if (null == locale) {
Log.e(TAG, "No locale defined for dictionary");

View File

@ -127,7 +127,7 @@ public class ExpandableDictionary extends Dictionary {
if (!mUpdatingDictionary) {
mUpdatingDictionary = true;
mRequiresReload = false;
new LoadDictionaryTask().execute();
new LoadDictionaryTask().start();
}
}
@ -541,14 +541,13 @@ public class ExpandableDictionary extends Dictionary {
mRoots = new NodeArray();
}
private class LoadDictionaryTask extends AsyncTask<Void, Void, Void> {
private class LoadDictionaryTask extends Thread {
@Override
protected Void doInBackground(Void... v) {
public void run() {
loadDictionaryAsync();
synchronized (mUpdatingLock) {
mUpdatingDictionary = false;
}
return null;
}
}

View File

@ -30,7 +30,9 @@ import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.Dictionary.DataType;
import com.android.inputmethod.latin.Dictionary.WordCallback;
import com.android.inputmethod.latin.DictionaryCollection;
import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.UserDictionary;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.WordComposer;
@ -51,6 +53,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private final static String[] emptyArray = new String[0];
private Map<String, DictionaryPool> mDictionaryPools =
Collections.synchronizedMap(new TreeMap<String, DictionaryPool>());
private Map<String, Dictionary> mUserDictionaries =
Collections.synchronizedMap(new TreeMap<String, Dictionary>());
@Override
public Session createSession() {
@ -109,9 +113,14 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
public boolean onUnbind(final Intent intent) {
final Map<String, DictionaryPool> oldPools = mDictionaryPools;
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()) {
pool.close();
}
for (Dictionary dict : oldUserDictionaries.values()) {
dict.close();
}
return false;
}
@ -129,9 +138,16 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final ProximityInfo proximityInfo = ProximityInfo.createSpellCheckerProximityInfo();
final Resources resources = getResources();
final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources);
final Dictionary dictionary =
final DictionaryCollection dictionaryCollection =
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 {