Merge "Close dictionary appropriately"
This commit is contained in:
commit
905a6cdcba
1 changed files with 21 additions and 28 deletions
|
@ -117,30 +117,31 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(Context context, Dictionary mainDict) {
|
private void init(Context context, Dictionary mainDict) {
|
||||||
if (mainDict != null) {
|
mMainDict = mainDict;
|
||||||
mMainDict = mainDict;
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_MAIN, mainDict);
|
||||||
mUnigramDictionaries.put(DICT_KEY_MAIN, mainDict);
|
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_MAIN, mainDict);
|
||||||
mBigramDictionaries.put(DICT_KEY_MAIN, mainDict);
|
|
||||||
}
|
|
||||||
mWhiteListDictionary = WhitelistDictionary.init(context);
|
mWhiteListDictionary = WhitelistDictionary.init(context);
|
||||||
if (mWhiteListDictionary != null) {
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_WHITELIST, mWhiteListDictionary);
|
||||||
mUnigramDictionaries.put(DICT_KEY_WHITELIST, mWhiteListDictionary);
|
|
||||||
}
|
|
||||||
mAutoCorrection = new AutoCorrection();
|
mAutoCorrection = new AutoCorrection();
|
||||||
initPool();
|
initPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addOrReplaceDictionary(Map<String, Dictionary> dictionaries, String key,
|
||||||
|
Dictionary dict) {
|
||||||
|
final Dictionary oldDict = (dict == null)
|
||||||
|
? dictionaries.remove(key)
|
||||||
|
: dictionaries.put(key, dict);
|
||||||
|
if (oldDict != null && dict != oldDict) {
|
||||||
|
oldDict.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void resetMainDict(Context context, int dictionaryResId, Locale locale) {
|
public void resetMainDict(Context context, int dictionaryResId, Locale locale) {
|
||||||
final Dictionary newMainDict = DictionaryFactory.createDictionaryFromManager(
|
final Dictionary newMainDict = DictionaryFactory.createDictionaryFromManager(
|
||||||
context, locale, dictionaryResId);
|
context, locale, dictionaryResId);
|
||||||
mMainDict = newMainDict;
|
mMainDict = newMainDict;
|
||||||
if (null == newMainDict) {
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_MAIN, newMainDict);
|
||||||
mUnigramDictionaries.remove(DICT_KEY_MAIN);
|
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_MAIN, newMainDict);
|
||||||
mBigramDictionaries.remove(DICT_KEY_MAIN);
|
|
||||||
} else {
|
|
||||||
mUnigramDictionaries.put(DICT_KEY_MAIN, newMainDict);
|
|
||||||
mBigramDictionaries.put(DICT_KEY_MAIN, newMainDict);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initPool() {
|
private void initPool() {
|
||||||
|
@ -179,8 +180,7 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
* before the main dictionary, if set.
|
* before the main dictionary, if set.
|
||||||
*/
|
*/
|
||||||
public void setUserDictionary(Dictionary userDictionary) {
|
public void setUserDictionary(Dictionary userDictionary) {
|
||||||
if (userDictionary != null)
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_USER, userDictionary);
|
||||||
mUnigramDictionaries.put(DICT_KEY_USER, userDictionary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,23 +189,16 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
* won't be used.
|
* won't be used.
|
||||||
*/
|
*/
|
||||||
public void setContactsDictionary(Dictionary contactsDictionary) {
|
public void setContactsDictionary(Dictionary contactsDictionary) {
|
||||||
if (contactsDictionary != null) {
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_CONTACTS, contactsDictionary);
|
||||||
mUnigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
|
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_CONTACTS, contactsDictionary);
|
||||||
mBigramDictionaries.put(DICT_KEY_CONTACTS, contactsDictionary);
|
|
||||||
} else {
|
|
||||||
mUnigramDictionaries.remove(DICT_KEY_CONTACTS);
|
|
||||||
mBigramDictionaries.remove(DICT_KEY_CONTACTS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoDictionary(Dictionary autoDictionary) {
|
public void setAutoDictionary(Dictionary autoDictionary) {
|
||||||
if (autoDictionary != null)
|
addOrReplaceDictionary(mUnigramDictionaries, DICT_KEY_AUTO, autoDictionary);
|
||||||
mUnigramDictionaries.put(DICT_KEY_AUTO, autoDictionary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserBigramDictionary(Dictionary userBigramDictionary) {
|
public void setUserBigramDictionary(Dictionary userBigramDictionary) {
|
||||||
if (userBigramDictionary != null)
|
addOrReplaceDictionary(mBigramDictionaries, DICT_KEY_USER_BIGRAM, userBigramDictionary);
|
||||||
mBigramDictionaries.put(DICT_KEY_USER_BIGRAM, userBigramDictionary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoCorrectionThreshold(double threshold) {
|
public void setAutoCorrectionThreshold(double threshold) {
|
||||||
|
|
Loading…
Reference in a new issue