Search in sources :

Example 1 with AsyncResultHolder

use of com.android.inputmethod.latin.utils.AsyncResultHolder in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class InputLogic method performUpdateSuggestionStripSync.

public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, final int inputStyle) {
    long startTimeMillis = 0;
    if (DebugFlags.DEBUG_ENABLED) {
        startTimeMillis = System.currentTimeMillis();
        Log.d(TAG, "performUpdateSuggestionStripSync()");
    }
    // Check if we have a suggestion engine attached.
    if (!settingsValues.needsToLookupSuggestions()) {
        if (mWordComposer.isComposingWord()) {
            Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + "requested!");
        }
        // Clear the suggestions strip.
        mSuggestionStripViewAccessor.showSuggestionStrip(SuggestedWords.getEmptyInstance());
        return;
    }
    if (!mWordComposer.isComposingWord() && !settingsValues.mBigramPredictionEnabled) {
        mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
        return;
    }
    final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>("Suggest");
    mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {

        @Override
        public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
            final String typedWordString = mWordComposer.getTypedWord();
            final SuggestedWordInfo typedWordInfo = new SuggestedWordInfo(typedWordString, "", /* prevWordsContext */
            SuggestedWordInfo.MAX_SCORE, SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED, SuggestedWordInfo.NOT_AN_INDEX, /* indexOfTouchPointOfSecondWord */
            SuggestedWordInfo.NOT_A_CONFIDENCE);
            // typed word is <= 1 (after a deletion typically) we clear old suggestions.
            if (suggestedWords.size() > 1 || typedWordString.length() <= 1) {
                holder.set(suggestedWords);
            } else {
                holder.set(retrieveOlderSuggestions(typedWordInfo, mSuggestedWords));
            }
        }
    });
    // This line may cause the current thread to wait.
    final SuggestedWords suggestedWords = holder.get(null, Constants.GET_SUGGESTED_WORDS_TIMEOUT);
    if (suggestedWords != null) {
        mSuggestionStripViewAccessor.showSuggestionStrip(suggestedWords);
    }
    if (DebugFlags.DEBUG_ENABLED) {
        long runTimeMillis = System.currentTimeMillis() - startTimeMillis;
        Log.d(TAG, "performUpdateSuggestionStripSync() : " + runTimeMillis + " ms to finish");
    }
}
Also used : OnGetSuggestedWordsCallback(com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback) SuggestedWordInfo(com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo) SuggestedWords(com.android.inputmethod.latin.SuggestedWords) SpannableString(android.text.SpannableString) AsyncResultHolder(com.android.inputmethod.latin.utils.AsyncResultHolder)

Example 2 with AsyncResultHolder

use of com.android.inputmethod.latin.utils.AsyncResultHolder in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class ExpandableBinaryDictionary method getDictionaryStats.

public DictionaryStats getDictionaryStats() {
    reloadDictionaryIfRequired();
    final String dictName = mDictName;
    final File dictFile = mDictFile;
    final AsyncResultHolder<DictionaryStats> result = new AsyncResultHolder<>("DictionaryStats");
    asyncExecuteTaskWithLock(mLock.readLock(), new Runnable() {

        @Override
        public void run() {
            result.set(new DictionaryStats(mLocale, dictName, dictName, dictFile, 0));
        }
    });
    return result.get(null, /* defaultValue */
    TIMEOUT_FOR_READ_OPS_IN_MILLISECONDS);
}
Also used : File(java.io.File) AsyncResultHolder(com.android.inputmethod.latin.utils.AsyncResultHolder)

Aggregations

AsyncResultHolder (com.android.inputmethod.latin.utils.AsyncResultHolder)2 SpannableString (android.text.SpannableString)1 OnGetSuggestedWordsCallback (com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback)1 SuggestedWords (com.android.inputmethod.latin.SuggestedWords)1 SuggestedWordInfo (com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo)1 File (java.io.File)1