From 8dda9e480b6519ca57565c8aa507e14bff739b60 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 3 Feb 2014 11:49:34 +0900 Subject: [PATCH] Show important notice strip Bug: 10587358 Change-Id: I1af3faa59afb2fc4cb90176acff1c2b0b1ba369c --- .../android/inputmethod/latin/LatinIME.java | 13 +++++++++-- .../SuggestionStripLayoutHelper.java | 14 ++++------- .../suggestions/SuggestionStripView.java | 23 ++++++++++++++++--- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 3b427720a..432b8a5a9 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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) { - mSuggestionStripView.setSuggestions(suggestedWords, - SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype())); + 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 */); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index a89f70e1f..4063edccc 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -504,15 +504,9 @@ 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); - } + final float titleScaleX = getTextScaleX( + importantNoticeTitle, width, titleView.getPaint()); + titleView.setTextScaleX(titleScaleX); } static void setLayoutWeight(final View v, final float weight, final int height) { @@ -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; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index b04a2cb5b..68c891bf3 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -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(); + } }