Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc2751ba authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Make commitCurrentAutoCorrection asynchronous.

Change-Id: Ida230ca4243347fb3ab9fda7de3a9a18f886cd1c
parent 37e0fd2f
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -2532,11 +2532,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                false /* isPrediction */);
    }

    private void showSuggestionStrip(final SuggestedWords suggestedWords) {
        if (suggestedWords.isEmpty()) {
            clearSuggestionStrip();
            return;
        }
    private void setAutoCorrection(final SuggestedWords suggestedWords) {
        if (suggestedWords.isEmpty()) return;
        final String autoCorrection;
        if (suggestedWords.mWillAutoCorrect) {
            autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
@@ -2544,17 +2541,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD);
        }
        mWordComposer.setAutoCorrection(autoCorrection);
    }

    private void showSuggestionStrip(final SuggestedWords suggestedWords) {
        if (suggestedWords.isEmpty()) {
            clearSuggestionStrip();
            return;
        }
        setAutoCorrection(suggestedWords);
        final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
        setSuggestedWords(suggestedWords, isAutoCorrection);
        setAutoCorrectionIndicator(isAutoCorrection);
        setSuggestionStripShown(isSuggestionsStripVisible());
    }

    private void commitCurrentAutoCorrection(final String separator, final Runnable callback) {
        // Complete any pending suggestions query first
        if (mHandler.hasPendingUpdateSuggestions()) {
            updateSuggestionStrip();
        }
    private void completeCommitCurrentAutoCorrection(final String separator) {
        final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
        final String typedWord = mWordComposer.getTypedWord();
        final String autoCorrection = (typedAutoCorrection != null)
@@ -2588,10 +2589,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
                        typedWord, autoCorrection));
            }
        }
    }

    private void commitCurrentAutoCorrection(final String separator, final Runnable callback) {
        getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_TYPING,
                new OnGetSuggestedWordsCallback() {
                    @Override
                    public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
                        if (suggestedWords != null) {
                            setAutoCorrection(suggestedWords);
                        }
                        completeCommitCurrentAutoCorrection(separator);
                        if (callback != null) {
                            callback.run();
                        }
                    }
                });
    }

    // Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
    // interface
+5 −2
Original line number Diff line number Diff line
@@ -44,10 +44,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {

    private static final String PREF_DEBUG_MODE = "debug_mode";

    // The message that sets the underline is posted with a 100 ms delay
    // The message that sets the underline is posted with a 200 ms delay
    protected static final int DELAY_TO_WAIT_FOR_UNDERLINE = 200;
    // The message that sets predictions is posted with a 100 ms delay
    // The message that sets predictions is posted with a 200 ms delay
    protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200;
    // The message that sets auto-corrections is posted within a 100 ms delay.
    protected static final int DELAY_TO_WAIT_FOR_AUTOCORRECTION = 100;

    protected LatinIME mLatinIME;
    protected Keyboard mKeyboard;
@@ -221,6 +223,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
    protected void type(final String stringToType) {
        for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) {
            type(stringToType.codePointAt(i));
            sleep(DELAY_TO_WAIT_FOR_AUTOCORRECTION);
        }
    }