public final void getNextWords( String currentWord, int maxSuggestions, List<CharSequence> suggestionsHolder, @Nullable Iterable<String> localeSpecificPunctuations) { if (mNextWordDictionary != null) { for (String nextWordSuggestion : mNextWordDictionary.getNextWords( currentWord, mMaxNextWordSuggestionsCount, mMinWordUsage)) { suggestionsHolder.add(nextWordSuggestion); maxSuggestions--; if (maxSuggestions == 0) return; } if (Utils.NEXT_WORD_SUGGESTION_WORDS_AND_PUNCTUATIONS.equals(mNextWordSuggestionType)) { if (localeSpecificPunctuations == null) localeSpecificPunctuations = mFallbackInitialSuggestions; for (String evenMoreSuggestions : localeSpecificPunctuations) { suggestionsHolder.add(evenMoreSuggestions); maxSuggestions--; if (maxSuggestions == 0) return; } } } }
@Override protected final void loadAllResources() { mNextWordDictionary = new NextWordDictionary(mContext, mLocale); mNextWordDictionary.load(); BTreeDictionary androidBuiltIn = null; try { // The only reason I see someone uses this, is for development or debugging. if (AnyApplication.getConfig().alwaysUseFallBackUserDictionary()) throw new RuntimeException("User requested to always use fall-back user-dictionary."); androidBuiltIn = createAndroidUserDictionary(mContext, mLocale); androidBuiltIn.loadDictionary(); mActualDictionary = androidBuiltIn; } catch (Exception e) { Logger.w( TAG, "Can not load Android's built-in user dictionary (since '%s'). FallbackUserDictionary to the rescue!", e.getMessage()); if (androidBuiltIn != null) { try { androidBuiltIn.close(); } catch (Exception buildInCloseException) { // it's an half-baked object, no need to worry about it buildInCloseException.printStackTrace(); Logger.w( TAG, "Failed to close the build-in user dictionary properly, but it should be fine."); } } BTreeDictionary fallback = createFallbackUserDictionary(mContext, mLocale); fallback.loadDictionary(); mActualDictionary = fallback; } }
public final void resetNextWordMemory() { if (mNextWordDictionary != null) mNextWordDictionary.resetSentence(); }
@Override protected final void closeAllResources() { if (mActualDictionary != null) mActualDictionary.close(); if (mNextWordDictionary != null) mNextWordDictionary.close(); }