Merge "Introduce maxMoreSuggestionsRow and minMoreSuggetionsWidth attributes to SuggestionsView"

This commit is contained in:
Tadashi G. Takaoka 2011-09-05 03:56:37 -07:00 committed by Android (Google) Code Review
commit 3f8351e186
10 changed files with 50 additions and 15 deletions

View file

@ -60,7 +60,10 @@
<dimen name="suggestions_strip_height">36dip</dimen> <dimen name="suggestions_strip_height">36dip</dimen>
<dimen name="more_suggestions_row_height">36dip</dimen> <dimen name="more_suggestions_row_height">36dip</dimen>
<dimen name="key_preview_backing_height">36dip</dimen> <integer name="max_more_suggestions_row">2</integer>
<fraction name="min_more_suggestions_width">60%</fraction>
<!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row -->
<dimen name="key_preview_backing_height">72dip</dimen>
<!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. --> <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
<!-- popup_key_height x 1.2 --> <!-- popup_key_height x 1.2 -->
<dimen name="mini_keyboard_slide_allowance">0.336in</dimen> <dimen name="mini_keyboard_slide_allowance">0.336in</dimen>

View file

@ -51,4 +51,8 @@
<fraction name="key_uppercase_letter_ratio">29%</fraction> <fraction name="key_uppercase_letter_ratio">29%</fraction>
<dimen name="suggestions_strip_padding">40.0mm</dimen> <dimen name="suggestions_strip_padding">40.0mm</dimen>
<integer name="max_more_suggestions_row">5</integer>
<fraction name="min_more_suggestions_width">50%</fraction>
<!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row -->
<dimen name="key_preview_backing_height">220dip</dimen>
</resources> </resources>

View file

@ -68,7 +68,10 @@
<dimen name="suggestions_strip_height">44dip</dimen> <dimen name="suggestions_strip_height">44dip</dimen>
<dimen name="more_suggestions_row_height">44dip</dimen> <dimen name="more_suggestions_row_height">44dip</dimen>
<dimen name="key_preview_backing_height">44dip</dimen> <integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction>
<!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row -->
<dimen name="key_preview_backing_height">264dip</dimen>
<dimen name="suggestions_strip_padding">15.0mm</dimen> <dimen name="suggestions_strip_padding">15.0mm</dimen>
<dimen name="suggestion_min_width">0.3in</dimen> <dimen name="suggestion_min_width">0.3in</dimen>
<dimen name="suggestion_padding">12dip</dimen> <dimen name="suggestion_padding">12dip</dimen>

View file

@ -59,4 +59,5 @@
<dimen name="key_preview_offset_ics">0.05in</dimen> <dimen name="key_preview_offset_ics">0.05in</dimen>
<dimen name="suggestions_strip_padding">40.0mm</dimen> <dimen name="suggestions_strip_padding">40.0mm</dimen>
<fraction name="min_more_suggestions_width">50%</fraction>
</resources> </resources>

View file

@ -71,7 +71,10 @@
<dimen name="suggestions_strip_height">44dip</dimen> <dimen name="suggestions_strip_height">44dip</dimen>
<dimen name="more_suggestions_row_height">44dip</dimen> <dimen name="more_suggestions_row_height">44dip</dimen>
<dimen name="key_preview_backing_height">44dip</dimen> <integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction>
<!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row -->
<dimen name="key_preview_backing_height">264dip</dimen>
<dimen name="suggestions_strip_padding">15.0mm</dimen> <dimen name="suggestions_strip_padding">15.0mm</dimen>
<dimen name="suggestion_min_width">46dip</dimen> <dimen name="suggestion_min_width">46dip</dimen>
<dimen name="suggestion_padding">8dip</dimen> <dimen name="suggestion_padding">8dip</dimen>

View file

@ -124,6 +124,8 @@
<attr name="colorSuggested" format="color" /> <attr name="colorSuggested" format="color" />
<attr name="suggestionsCountInStrip" format="integer" /> <attr name="suggestionsCountInStrip" format="integer" />
<attr name="centerSuggestionPercentile" format="integer" /> <attr name="centerSuggestionPercentile" format="integer" />
<attr name="maxMoreSuggestionsRow" format="integer" />
<attr name="minMoreSuggestionsWidth" format="float" />
</declare-styleable> </declare-styleable>
<declare-styleable name="Keyboard"> <declare-styleable name="Keyboard">

View file

@ -80,8 +80,11 @@
<dimen name="more_suggestions_key_horizontal_padding">12dip</dimen> <dimen name="more_suggestions_key_horizontal_padding">12dip</dimen>
<dimen name="more_suggestions_row_height">40dip</dimen> <dimen name="more_suggestions_row_height">40dip</dimen>
<dimen name="more_suggestions_slide_allowance">0.2in</dimen> <dimen name="more_suggestions_slide_allowance">0.2in</dimen>
<integer name="max_more_suggestions_row">6</integer>
<fraction name="min_more_suggestions_width">90%</fraction>
<fraction name="more_suggestions_info_ratio">18%</fraction> <fraction name="more_suggestions_info_ratio">18%</fraction>
<dimen name="key_preview_backing_height">40dip</dimen> <!-- key_preview_backing_height = more_suggestions_row_height * max_more_suggestions_row -->
<dimen name="key_preview_backing_height">160dip</dimen>
<dimen name="suggestions_strip_padding">0dip</dimen> <dimen name="suggestions_strip_padding">0dip</dimen>
<dimen name="suggestion_min_width">44dip</dimen> <dimen name="suggestion_min_width">44dip</dimen>
<dimen name="suggestion_padding">6dip</dimen> <dimen name="suggestion_padding">6dip</dimen>

View file

@ -92,6 +92,8 @@
<item name="colorSuggested">#FFFCAE00</item> <item name="colorSuggested">#FFFCAE00</item>
<item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item> <item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item>
<item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item> <item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item>
<item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item>
<item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item>
</style> </style>
<style <style
name="MoreSuggestionsViewStyle" name="MoreSuggestionsViewStyle"
@ -242,6 +244,8 @@
<item name="colorSuggested">#FFA7A9AC</item> <item name="colorSuggested">#FFA7A9AC</item>
<item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item> <item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item>
<item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item> <item name="centerSuggestionPercentile">@integer/center_suggestion_percentile</item>
<item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item>
<item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item>
</style> </style>
<style <style
name="MoreSuggestionsViewStyle.IceCreamSandwich" name="MoreSuggestionsViewStyle.IceCreamSandwich"

View file

@ -50,8 +50,8 @@ public class MoreSuggestions extends Keyboard {
private static final int MAX_COLUMNS_IN_ROW = 3; private static final int MAX_COLUMNS_IN_ROW = 3;
private int mNumRows; private int mNumRows;
public int layout(SuggestedWords suggestions, int fromPos, int maxWidth, int maxHeight, public int layout(SuggestedWords suggestions, int fromPos, int maxWidth, int minWidth,
KeyboardView view) { int maxRow, KeyboardView view) {
clearKeys(); clearKeys();
final Paint paint = new Paint(); final Paint paint = new Paint();
paint.setAntiAlias(true); paint.setAntiAlias(true);
@ -68,7 +68,7 @@ public class MoreSuggestions extends Keyboard {
final int numColumn = pos - rowStartPos + 1; final int numColumn = pos - rowStartPos + 1;
if (numColumn > MAX_COLUMNS_IN_ROW if (numColumn > MAX_COLUMNS_IN_ROW
|| !fitInWidth(rowStartPos, pos + 1, maxWidth / numColumn)) { || !fitInWidth(rowStartPos, pos + 1, maxWidth / numColumn)) {
if ((row + 1) * mDefaultRowHeight > maxHeight) { if ((row + 1) >= maxRow) {
break; break;
} }
mNumColumnsInRow[row] = pos - rowStartPos; mNumColumnsInRow[row] = pos - rowStartPos;
@ -81,7 +81,7 @@ public class MoreSuggestions extends Keyboard {
} }
mNumColumnsInRow[row] = pos - rowStartPos; mNumColumnsInRow[row] = pos - rowStartPos;
mNumRows = row + 1; mNumRows = row + 1;
mWidth = mOccupiedWidth = calcurateMaxRowWidth(fromPos, pos); mWidth = mOccupiedWidth = Math.max(minWidth, calcurateMaxRowWidth(fromPos, pos));
mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight + mVerticalGap; mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight + mVerticalGap;
return pos - fromPos; return pos - fromPos;
} }
@ -163,13 +163,14 @@ public class MoreSuggestions extends Keyboard {
} }
public Builder layout(SuggestedWords suggestions, int fromPos, int maxWidth, public Builder layout(SuggestedWords suggestions, int fromPos, int maxWidth,
int maxHeight) { int minWidth, int maxRow) {
final Keyboard keyboard = KeyboardSwitcher.getInstance().getLatinKeyboard(); final Keyboard keyboard = KeyboardSwitcher.getInstance().getLatinKeyboard();
final int xmlId = R.xml.kbd_suggestions_pane_template; final int xmlId = R.xml.kbd_suggestions_pane_template;
load(keyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId)); load(keyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId));
mParams.mVerticalGap = mParams.mTopPadding = keyboard.mVerticalGap / 2; mParams.mVerticalGap = mParams.mTopPadding = keyboard.mVerticalGap / 2;
final int count = mParams.layout(suggestions, fromPos, maxWidth, maxHeight, mPaneView); final int count = mParams.layout(suggestions, fromPos, maxWidth, minWidth, maxRow,
mPaneView);
mFromPos = fromPos; mFromPos = fromPos;
mToPos = fromPos + count; mToPos = fromPos + count;
mSuggestions = suggestions; mSuggestions = suggestions;

View file

@ -35,7 +35,6 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -146,12 +145,15 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private static class SuggestionsViewParams { private static class SuggestionsViewParams {
private static final int DEFAULT_SUGGESTIONS_COUNT_IN_STRIP = 3; private static final int DEFAULT_SUGGESTIONS_COUNT_IN_STRIP = 3;
private static final int DEFAULT_CENTER_SUGGESTION_PERCENTILE = 40; private static final int DEFAULT_CENTER_SUGGESTION_PERCENTILE = 40;
private static final int DEFAULT_MAX_MORE_SUGGESTIONS_ROW = 2;
private static final int PUNCTUATIONS_IN_STRIP = 6; private static final int PUNCTUATIONS_IN_STRIP = 6;
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; public final int mSuggestionsCountInStrip;
public final int mMaxMoreSuggestionsRow;
public final float mMinMoreSuggestionsWidth;
private final List<TextView> mWords; private final List<TextView> mWords;
private final List<View> mDividers; private final List<View> mDividers;
@ -211,6 +213,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mCenterSuggestionWeight = a.getInt( mCenterSuggestionWeight = a.getInt(
R.styleable.SuggestionsView_centerSuggestionPercentile, R.styleable.SuggestionsView_centerSuggestionPercentile,
DEFAULT_CENTER_SUGGESTION_PERCENTILE) / 100.0f; DEFAULT_CENTER_SUGGESTION_PERCENTILE) / 100.0f;
mMaxMoreSuggestionsRow = a.getInt(
R.styleable.SuggestionsView_maxMoreSuggestionsRow,
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
mMinMoreSuggestionsWidth = getRatio(a,
R.styleable.SuggestionsView_minMoreSuggestionsWidth);
a.recycle(); a.recycle();
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2; mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
@ -225,6 +232,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mHintToSaveText = context.getText(R.string.hint_add_to_dictionary); mHintToSaveText = context.getText(R.string.hint_add_to_dictionary);
} }
// Read fraction value in TypedArray as float.
private static float getRatio(TypedArray a, int index) {
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
}
private CharSequence getStyledSuggestionWord(SuggestedWords suggestions, int pos) { private CharSequence getStyledSuggestionWord(SuggestedWords suggestions, int pos) {
final CharSequence word = suggestions.getWord(pos); final CharSequence word = suggestions.getWord(pos);
final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions); final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions);
@ -718,11 +730,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final View container = mMoreSuggestionsContainer; final View container = mMoreSuggestionsContainer;
final int maxWidth = stripWidth - container.getPaddingLeft() final int maxWidth = stripWidth - container.getPaddingLeft()
- container.getPaddingRight(); - container.getPaddingRight();
final DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
// TODO: Revise how we determine the height
final int maxHeight = dm.heightPixels - mKeyboardView.getHeight() - getHeight() * 3;
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth, maxHeight); builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * params.mMinMoreSuggestionsWidth),
params.mMaxMoreSuggestionsRow);
mMoreSuggestionsView.setKeyboard(builder.build()); mMoreSuggestionsView.setKeyboard(builder.build());
container.measure( container.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);