Introduce maxMoreSuggestionsRow and minMoreSuggetionsWidth attributes to SuggestionsView

Bug: 5257594
Change-Id: Id52c841b72e38eb9034a1a7f26bcf3d4d81ad216
main
Tadashi G. Takaoka 2011-09-05 17:22:34 +09:00
parent 1d8ec1cb9f
commit 9676038b6e
10 changed files with 50 additions and 15 deletions

View File

@ -60,7 +60,10 @@
<dimen name="suggestions_strip_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. -->
<!-- popup_key_height x 1.2 -->
<dimen name="mini_keyboard_slide_allowance">0.336in</dimen>

View File

@ -51,4 +51,8 @@
<fraction name="key_uppercase_letter_ratio">29%</fraction>
<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>

View File

@ -68,7 +68,10 @@
<dimen name="suggestions_strip_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="suggestion_min_width">0.3in</dimen>
<dimen name="suggestion_padding">12dip</dimen>

View File

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

View File

@ -71,7 +71,10 @@
<dimen name="suggestions_strip_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="suggestion_min_width">46dip</dimen>
<dimen name="suggestion_padding">8dip</dimen>

View File

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

View File

@ -80,8 +80,11 @@
<dimen name="more_suggestions_key_horizontal_padding">12dip</dimen>
<dimen name="more_suggestions_row_height">40dip</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>
<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="suggestion_min_width">44dip</dimen>
<dimen name="suggestion_padding">6dip</dimen>

View File

@ -92,6 +92,8 @@
<item name="colorSuggested">#FFFCAE00</item>
<item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</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
name="MoreSuggestionsViewStyle"
@ -242,6 +244,8 @@
<item name="colorSuggested">#FFA7A9AC</item>
<item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</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
name="MoreSuggestionsViewStyle.IceCreamSandwich"

View File

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

View File

@ -35,7 +35,6 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -146,12 +145,15 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private static class SuggestionsViewParams {
private static final int DEFAULT_SUGGESTIONS_COUNT_IN_STRIP = 3;
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;
public final int mPadding;
public final int mDividerWidth;
public final int mSuggestionsStripHeight;
public final int mSuggestionsCountInStrip;
public final int mMaxMoreSuggestionsRow;
public final float mMinMoreSuggestionsWidth;
private final List<TextView> mWords;
private final List<View> mDividers;
@ -211,6 +213,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mCenterSuggestionWeight = a.getInt(
R.styleable.SuggestionsView_centerSuggestionPercentile,
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();
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
@ -225,6 +232,11 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
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) {
final CharSequence word = suggestions.getWord(pos);
final boolean isAutoCorrect = pos == 1 && willAutoCorrect(suggestions);
@ -718,11 +730,10 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
final View container = mMoreSuggestionsContainer;
final int maxWidth = stripWidth - container.getPaddingLeft()
- 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;
builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth, maxHeight);
builder.layout(mSuggestions, params.mSuggestionsCountInStrip, maxWidth,
(int)(maxWidth * params.mMinMoreSuggestionsWidth),
params.mMaxMoreSuggestionsRow);
mMoreSuggestionsView.setKeyboard(builder.build());
container.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);