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

Commit 70d353a5 authored by Jean Chalard's avatar Jean Chalard Committed by The Android Automerger
Browse files

Always show the typed word in recorrections.

Bug: 11330140
Bug: 17875601
Bug: 17623275
Change-Id: Ie4620f36f312c54c7b01b5f6cbdb0bc9171b6179
parent c7589353
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1630,7 +1630,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    }

    @Override
    public void showAddToDictionaryHint(final String word) {
    public void suggestAddingToDictionary(final String word, final boolean isFromSuggestionStrip) {
        if (!hasSuggestionStripView()) {
            return;
        }
@@ -1640,7 +1640,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
        } else {
            wordToShow = word;
        }
        mSuggestionStripView.showAddToDictionaryHint(wordToShow);
        mSuggestionStripView.showAddToDictionaryHint(wordToShow,
                isFromSuggestionStrip /* shouldShowWordToSave */);
    }

    // This will show either an empty suggestion strip (if prediction is enabled) or
+0 −22
Original line number Diff line number Diff line
@@ -413,28 +413,6 @@ public class SuggestedWords {
        return isPrediction(mInputStyle);
    }

    // SuggestedWords is an immutable object, as much as possible. We must not just remove
    // words from the member ArrayList as some other parties may expect the object to never change.
    // This is only ever called by recorrection at the moment, hence the ForRecorrection moniker.
    public SuggestedWords getSuggestedWordsExcludingTypedWordForRecorrection() {
        final ArrayList<SuggestedWordInfo> newSuggestions = new ArrayList<>();
        String typedWord = null;
        for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) {
            final SuggestedWordInfo info = mSuggestedWordInfoList.get(i);
            if (!info.isKindOf(SuggestedWordInfo.KIND_TYPED)) {
                newSuggestions.add(info);
            } else {
                assert(null == typedWord);
                typedWord = info.mWord;
            }
        }
        // We should never autocorrect, so we say the typed word is valid. Also, in this case,
        // no auto-correction should take place hence willAutoCorrect = false.
        return new SuggestedWords(newSuggestions, null /* rawSuggestions */, typedWord,
                true /* typedWordValid */, false /* willAutoCorrect */, mIsObsoleteSuggestions,
                SuggestedWords.INPUT_STYLE_RECORRECTION, NOT_A_SEQUENCE_NUMBER);
    }

    // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the
    // last word of all suggestions, separated by a space. This is necessary because when we commit
    // a multiple-word suggestion, the IME only retains the last word as the composing word, and
+11 −20
Original line number Diff line number Diff line
@@ -349,7 +349,8 @@ public final class InputLogic {
        inputTransaction.requireShiftUpdate(InputTransaction.SHIFT_UPDATE_NOW);

        if (shouldShowAddToDictionaryHint) {
            mSuggestionStripViewAccessor.showAddToDictionaryHint(suggestion);
            mSuggestionStripViewAccessor.suggestAddingToDictionary(suggestion,
                    true /* isFromSuggestionStrip */);
        } else {
            // If we're not showing the "Touch again to save", then update the suggestion strip.
            // That's going to be predictions (or punctuation suggestions), so INPUT_STYLE_NONE.
@@ -1485,6 +1486,11 @@ public final class InputLogic {
        if (numberOfCharsInWordBeforeCursor > expectedCursorPosition) return;
        final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<>();
        final String typedWord = range.mWord.toString();
        suggestions.add(new SuggestedWordInfo(typedWord,
                SuggestedWords.MAX_SUGGESTIONS + 1,
                SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
                SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
                SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */));
        if (!isResumableWord(settingsValues, typedWord)) {
            mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
            return;
@@ -1517,30 +1523,14 @@ public final class InputLogic {
        mConnection.maybeMoveTheCursorAroundAndRestoreToWorkaroundABug();
        mConnection.setComposingRegion(expectedCursorPosition - numberOfCharsInWordBeforeCursor,
                expectedCursorPosition + range.getNumberOfCharsInWordAfterCursor());
        if (suggestions.size() <= 0) {
        if (suggestions.size() <= 1) {
            // If there weren't any suggestion spans on this word, suggestions#size() will be 1
            // if shouldIncludeResumedWordInSuggestions is true, 0 otherwise. In this case, we
            // have no useful suggestions, so we will try to compute some for it instead.
            mInputLogicHandler.getSuggestedWords(Suggest.SESSION_ID_TYPING,
                    SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
                        @Override
                        public void onGetSuggestedWords(
                                final SuggestedWords suggestedWordsIncludingTypedWord) {
                            final SuggestedWords suggestedWords;
                            if (suggestedWordsIncludingTypedWord.size() > 1) {
                                // We were able to compute new suggestions for this word.
                                // Remove the typed word, since we don't want to display it in this
                                // case. The #getSuggestedWordsExcludingTypedWordForRecorrection()
                                // method sets willAutoCorrect to false.
                                suggestedWords = suggestedWordsIncludingTypedWord
                                        .getSuggestedWordsExcludingTypedWordForRecorrection();
                            } else {
                                // No saved suggestions, and we were unable to compute any good one
                                // either. Rather than displaying an empty suggestion strip, we'll
                                // display the original word alone in the middle.
                                // Since there is only one word, willAutoCorrect is false.
                                suggestedWords = suggestedWordsIncludingTypedWord;
                            }
                        public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
                            mIsAutoCorrectionIndicatorOn = false;
                            mLatinIME.mHandler.showSuggestionStrip(suggestedWords);
                        }});
@@ -1684,7 +1674,8 @@ public final class InputLogic {
                        mConnection.getExpectedSelectionStart(),
                        mConnection.getExpectedSelectionEnd());
            }
            mSuggestionStripViewAccessor.showAddToDictionaryHint(originallyTypedWordString);
            mSuggestionStripViewAccessor.suggestAddingToDictionary(originallyTypedWordString,
                    false /* isFromSuggestionStrip */);
        } else {
            // We have a separator between the word and the cursor: we should show predictions.
            inputTransaction.setRequiresUpdateSuggestions();
+12 −12
Original line number Diff line number Diff line
@@ -553,12 +553,12 @@ final class SuggestionStripLayoutHelper {
        return countInStrip;
    }

    public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
        final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance().getCurrent()
                .mShouldShowLxxSuggestionUi;
    public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip,
            final boolean shouldShowWordToSave) {
        final boolean showsHintWithWord = shouldShowWordToSave
                || !Settings.getInstance().getCurrent().mShouldShowLxxSuggestionUi;
        final int stripWidth = addToDictionaryStrip.getWidth();
        final int width = shouldShowUiToAcceptTypedWord ? stripWidth
                : stripWidth - mDividerWidth - mPadding * 2;
        final int width = stripWidth - (showsHintWithWord ? mDividerWidth + mPadding * 2 : 0);

        final TextView wordView = (TextView)addToDictionaryStrip.findViewById(R.id.word_to_save);
        wordView.setTextColor(mColorTypedWord);
@@ -569,7 +569,7 @@ final class SuggestionStripLayoutHelper {
        wordView.setText(wordToSave);
        wordView.setTextScaleX(wordScaleX);
        setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
        final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
        final int wordVisibility = showsHintWithWord ? View.VISIBLE : View.GONE;
        wordView.setVisibility(wordVisibility);
        addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);

@@ -579,12 +579,7 @@ final class SuggestionStripLayoutHelper {
        final float hintWeight;
        final TextView hintView = (TextView)addToDictionaryStrip.findViewById(
                R.id.hint_add_to_dictionary);
        if (shouldShowUiToAcceptTypedWord) {
            hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
            hintWidth = width;
            hintWeight = 1.0f;
            hintView.setGravity(Gravity.CENTER);
        } else {
        if (showsHintWithWord) {
            final boolean isRtlLanguage = (ViewCompat.getLayoutDirection(addToDictionaryStrip)
                    == ViewCompat.LAYOUT_DIRECTION_RTL);
            final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
@@ -595,6 +590,11 @@ final class SuggestionStripLayoutHelper {
            hintWidth = width - wordWidth;
            hintWeight = 1.0f - mCenterSuggestionWeight;
            hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
        } else {
            hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
            hintWidth = width;
            hintWeight = 1.0f;
            hintView.setGravity(Gravity.CENTER);
        }
        hintView.setTextColor(mColorAutoCorrect);
        final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
+3 −3
Original line number Diff line number Diff line
@@ -231,8 +231,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
        return mStripVisibilityGroup.isShowingAddToDictionaryStrip();
    }

    public void showAddToDictionaryHint(final String word) {
        mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip);
    public void showAddToDictionaryHint(final String word, final boolean shouldShowWordToSave) {
        mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, shouldShowWordToSave);
        // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word
        // will be extracted at {@link #onClick(View)}.
        mAddToDictionaryStrip.setTag(word);
@@ -501,7 +501,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
            return;
        }
        final Object tag = view.getTag();
        // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}.
        // {@link String} tag is set at {@link #suggestAddingToDictionary(String,CharSequence)}.
        if (tag instanceof String) {
            final String wordToSave = (String)tag;
            mListener.addWordToUserDictionary(wordToSave);
Loading