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

Commit 8dda9e48 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Jean Chalard
Browse files

Show important notice strip

Bug: 10587358
Change-Id: I1af3faa59afb2fc4cb90176acff1c2b0b1ba369c
parent 6422f77e
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -1350,8 +1350,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
    public void setSuggestedWords(final SuggestedWords suggestedWords, final boolean shouldShow) {
        mInputLogic.setSuggestedWords(suggestedWords);
        if (mSuggestionStripView != null) {
            final boolean showSuggestions;
            if (SuggestedWords.EMPTY == suggestedWords
                    || suggestedWords.mIsPunctuationSuggestions) {
                showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle();
            } else {
                showSuggestions = true;
            }
            if (showSuggestions) {
                mSuggestionStripView.setSuggestions(suggestedWords,
                        SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
            }
            mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect);
            setSuggestionStripShownInternal(shouldShow, true /* needsInputViewShown */);
        }
+4 −10
Original line number Diff line number Diff line
@@ -504,16 +504,10 @@ final class SuggestionStripLayoutHelper {
                titleView, infoIcon, null, moreIcon, null);
        final CharSequence importantNoticeTitle = titleView.getText();
        titleView.setTextScaleX(1.0f); // Reset textScaleX.
        // When the suggestions strip is displayed first time, stripWidth may be zero.
        // Then importantNoticeTitle will be displayed as is without auto text scaleX.
        // TODO: Fix the logic to always have a correct value of stripWidth.
        if (width > 0) {
            // Auto text scaleX to show entire important notice title should be on the strip.
        final float titleScaleX = getTextScaleX(
                importantNoticeTitle, width, titleView.getPaint());
        titleView.setTextScaleX(titleScaleX);
    }
    }

    static void setLayoutWeight(final View v, final float weight, final int height) {
        final ViewGroup.LayoutParams lp = v.getLayoutParams();
@@ -529,7 +523,7 @@ final class SuggestionStripLayoutHelper {
            final TextPaint paint) {
        paint.setTextScaleX(1.0f);
        final int width = getTextWidth(text, paint);
        if (width <= maxWidth) {
        if (width <= maxWidth || maxWidth <= 0) {
            return 1.0f;
        }
        return maxWidth / (float)width;
+20 −3
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import com.android.inputmethod.research.ResearchLogger;

import java.util.ArrayList;
@@ -220,11 +221,20 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
        return false;
    }

    // TODO: This method should be called after this View has been attached and displayed.
    public void showImportantNoticeTitle() {
        mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, getWidth());
    // This method checks if we should show the important notice (checks on permanent storage if
    // it has been shown once already or not, and if in the setup wizard). If applicable, it shows
    // the notice. In all cases, it returns true if it was shown, false otherwise.
    public boolean maybeShowImportantNoticeTitle() {
        if (!ImportantNoticeUtils.hasNewImportantNotice(getContext())
                || ImportantNoticeUtils.isInSystemSetupWizard(getContext())) {
            return false;
        }
        final int width = getWidth();
        if (width <= 0) return false;
        mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width);
        mStripVisibilityGroup.showImportantNoticeStrip();
        mImportantNoticeStrip.setOnClickListener(this);
        return true;
    }

    public void clear() {
@@ -415,4 +425,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
        super.onDetachedFromWindow();
        dismissMoreSuggestionsPanel();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        // Called by the framework when the size is known. Show the important notice if applicable.
        // This may be overriden by showing suggestions later, if applicable.
        maybeShowImportantNoticeTitle();
    }
}