/** Sets an optional contacts dictionary resource to be loaded. */ public void setContactsDictionary(Context context, boolean enabled) { if (!enabled && mContactsDictionary != null) { // had one, but now config says it should be off Log.i(TAG, "Contacts dictionary has been disabled! Closing resources."); mContactsDictionary.close(); mContactsDictionary = null; } else if (enabled && mContactsDictionary == null) { // config says it should be on, but I have none. mContactsDictionary = mDictionaryFactory.createContactsDictionary(context); if (mContactsDictionary != null) { // not all devices has contacts-dictionary DictionaryASyncLoader loader = new DictionaryASyncLoader(null); loader.execute(mContactsDictionary); } } }
public void setMainDictionary( Context askContext, @Nullable DictionaryAddOnAndBuilder dictionaryBuilder) { Log.d( TAG, "Suggest: Got main dictionary! Type: " + ((dictionaryBuilder == null) ? "NULL" : dictionaryBuilder.getName())); if (mMainDict != null) { mMainDict.close(); mMainDict = null; } mLocale = CompatUtils.getLocaleForLanguageTag( dictionaryBuilder == null ? null : dictionaryBuilder.getLanguage()); if (mAbbreviationDictionary != null) { mAbbreviationDictionary.close(); mAbbreviationDictionary = null; } if (dictionaryBuilder == null) { mMainDict = null; mAutoText = null; mAbbreviationDictionary = null; mLocaleSpecificPunctuations = null; } else { try { System.gc(); mMainDict = dictionaryBuilder.createDictionary(); DictionaryASyncLoader loader = new DictionaryASyncLoader(null); loader.execute(mMainDict); } catch (Exception e) { e.printStackTrace(); } mAutoText = dictionaryBuilder.createAutoText(); mLocaleSpecificPunctuations = dictionaryBuilder.createInitialSuggestions(); mAbbreviationDictionary = new AbbreviationsDictionary(askContext, dictionaryBuilder.getLanguage()); DictionaryASyncLoader loader = new DictionaryASyncLoader(null); loader.execute(mAbbreviationDictionary); } }