Fix showing all suggestions when the top suggestion is long

This change also fixes Bug#12982404; displays the suggestion word
using entire suggestions strip if there is only one suggestion.

Bug: 12564279
Bug: 12982404
Change-Id: I51806b90c3ee34a2072880245d4e33f7be273c8f
This commit is contained in:
Tadashi G. Takaoka 2014-02-12 15:22:13 +09:00
parent 8dd47029f1
commit 4f8a8f125e
2 changed files with 49 additions and 35 deletions

View File

@ -65,7 +65,7 @@ final class SuggestionStripLayoutHelper {
public final int mPadding; public final int mPadding;
public final int mDividerWidth; public final int mDividerWidth;
public final int mSuggestionsStripHeight; public final int mSuggestionsStripHeight;
public final int mSuggestionsCountInStrip; private final int mSuggestionsCountInStrip;
public final int mMoreSuggestionsRowHeight; public final int mMoreSuggestionsRowHeight;
private int mMaxMoreSuggestionsRow; private int mMaxMoreSuggestionsRow;
public final float mMinMoreSuggestionsWidth; public final float mMinMoreSuggestionsWidth;
@ -288,54 +288,65 @@ final class SuggestionStripLayoutHelper {
params.gravity = Gravity.CENTER; params.gravity = Gravity.CENTER;
} }
public void layout(final SuggestedWords suggestedWords, final ViewGroup stripView, /**
final ViewGroup placerView) { * Layout suggestions to the suggestions strip. And returns the number of suggestions displayed
* in the suggestions strip.
*
* @param suggestedWords suggestions to be shown in the suggestions strip.
* @param stripView the suggestions strip view.
* @param placerView the view where the debug info will be placed.
* @return the number of suggestions displayed in the suggestions strip
*/
public int layoutAndReturnSuggestionCountInStrip(final SuggestedWords suggestedWords,
final ViewGroup stripView, final ViewGroup placerView) {
if (suggestedWords.mIsPunctuationSuggestions) { if (suggestedWords.mIsPunctuationSuggestions) {
layoutPunctuationSuggestions(suggestedWords, stripView); return layoutPunctuationSuggestionsAndReturnSuggestionCountInStrip(
return; suggestedWords, stripView);
} }
final int countInStrip = mSuggestionsCountInStrip; setupWordViewsTextAndColor(suggestedWords, mSuggestionsCountInStrip);
setupWordViewsTextAndColor(suggestedWords, countInStrip);
final TextView centerWordView = mWordViews.get(mCenterPositionInStrip); final TextView centerWordView = mWordViews.get(mCenterPositionInStrip);
final int availableStripWidth = placerView.getWidth() final int availableStripWidth = placerView.getWidth()
- placerView.getPaddingRight() - placerView.getPaddingLeft(); - placerView.getPaddingRight() - placerView.getPaddingLeft();
final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, availableStripWidth); final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, availableStripWidth);
if (getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint()) final int countInStrip;
< MIN_TEXT_XSCALE) { if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth,
centerWordView.getPaint()) < MIN_TEXT_XSCALE) {
// Layout only the most relevant suggested word at the center of the suggestion strip // Layout only the most relevant suggested word at the center of the suggestion strip
// by consolidating all slots in the strip. // by consolidating all slots in the strip.
mMoreSuggestionsAvailable = (suggestedWords.size() > 1); countInStrip = 1;
mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
layoutWord(mCenterPositionInStrip, availableStripWidth - mPadding); layoutWord(mCenterPositionInStrip, availableStripWidth - mPadding);
stripView.addView(centerWordView); stripView.addView(centerWordView);
setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT); setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
if (SuggestionStripView.DBG) { if (SuggestionStripView.DBG) {
layoutDebugInfo(mCenterPositionInStrip, placerView, availableStripWidth); layoutDebugInfo(mCenterPositionInStrip, placerView, availableStripWidth);
} }
return; } else {
} countInStrip = mSuggestionsCountInStrip;
mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
int x = 0;
for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
if (positionInStrip != 0) {
final View divider = mDividerViews.get(positionInStrip);
// Add divider if this isn't the left most suggestion in suggestions strip.
addDivider(stripView, divider);
x += divider.getMeasuredWidth();
}
mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); final int width = getSuggestionWidth(positionInStrip, availableStripWidth);
int x = 0; final TextView wordView = layoutWord(positionInStrip, width);
for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) { stripView.addView(wordView);
if (positionInStrip != 0) { setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
final View divider = mDividerViews.get(positionInStrip); ViewGroup.LayoutParams.MATCH_PARENT);
// Add divider if this isn't the left most suggestion in suggestions strip. x += wordView.getMeasuredWidth();
addDivider(stripView, divider);
x += divider.getMeasuredWidth();
}
final int width = getSuggestionWidth(positionInStrip, availableStripWidth); if (SuggestionStripView.DBG) {
final TextView wordView = layoutWord(positionInStrip, width); layoutDebugInfo(positionInStrip, placerView, x);
stripView.addView(wordView); }
setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
ViewGroup.LayoutParams.MATCH_PARENT);
x += wordView.getMeasuredWidth();
if (SuggestionStripView.DBG) {
layoutDebugInfo(positionInStrip, placerView, x);
} }
} }
return countInStrip;
} }
/** /**
@ -435,8 +446,8 @@ final class SuggestionStripLayoutHelper {
} }
} }
private void layoutPunctuationSuggestions(final SuggestedWords suggestedWords, private int layoutPunctuationSuggestionsAndReturnSuggestionCountInStrip(
final ViewGroup stripView) { final SuggestedWords suggestedWords, final ViewGroup stripView) {
final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP); final int countInStrip = Math.min(suggestedWords.size(), PUNCTUATIONS_IN_STRIP);
for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) { for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
if (positionInStrip != 0) { if (positionInStrip != 0) {
@ -457,6 +468,7 @@ final class SuggestionStripLayoutHelper {
setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight); setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
} }
mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip);
return countInStrip;
} }
public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip, public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip,

View File

@ -77,6 +77,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
Listener mListener; Listener mListener;
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
private int mSuggestionsCountInStrip;
private final SuggestionStripLayoutHelper mLayoutHelper; private final SuggestionStripLayoutHelper mLayoutHelper;
private final StripVisibilityGroup mStripVisibilityGroup; private final StripVisibilityGroup mStripVisibilityGroup;
@ -189,7 +190,8 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
clear(); clear();
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
mSuggestedWords = suggestedWords; mSuggestedWords = suggestedWords;
mLayoutHelper.layout(mSuggestedWords, mSuggestionsStrip, this); mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip(
mSuggestedWords, mSuggestionsStrip, this);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords); ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords);
} }
@ -313,7 +315,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
final View container = mMoreSuggestionsContainer; final View container = mMoreSuggestionsContainer;
final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight(); final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight();
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
builder.layout(mSuggestedWords, layoutHelper.mSuggestionsCountInStrip, maxWidth, builder.layout(mSuggestedWords, mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth), (int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth),
layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard); layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard);
mMoreSuggestionsView.setKeyboard(builder.build()); mMoreSuggestionsView.setKeyboard(builder.build());
@ -327,7 +329,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING; mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
mOriginX = mLastX; mOriginX = mLastX;
mOriginY = mLastY; mOriginY = mLastY;
for (int i = 0; i < layoutHelper.mSuggestionsCountInStrip; i++) { for (int i = 0; i < mSuggestionsCountInStrip; i++) {
mWordViews.get(i).setPressed(false); mWordViews.get(i).setPressed(false);
} }
return true; return true;