Show important notice strip
Bug: 10587358 Change-Id: I1af3faa59afb2fc4cb90176acff1c2b0b1ba369c
This commit is contained in:
parent
6422f77e94
commit
8dda9e480b
3 changed files with 35 additions and 15 deletions
|
@ -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 */);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue