Merge "Draw more suggestions hint using text font"

main
Tadashi G. Takaoka 2011-09-16 01:07:17 -07:00 committed by Android (Google) Code Review
commit dc7974d54c
12 changed files with 29 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 310 B

View File

@ -76,4 +76,5 @@
<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>
<dimen name="suggestion_text_size">22dip</dimen> <dimen name="suggestion_text_size">22dip</dimen>
<dimen name="more_suggestions_hint_text_size">33dip</dimen>
</resources> </resources>

View File

@ -79,4 +79,5 @@
<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>
<dimen name="suggestion_text_size">22dip</dimen> <dimen name="suggestion_text_size">22dip</dimen>
<dimen name="more_suggestions_hint_text_size">33dip</dimen>
</resources> </resources>

View File

@ -132,7 +132,6 @@
<attr name="alphaObsoleted" format="integer" /> <attr name="alphaObsoleted" format="integer" />
<attr name="suggestionsCountInStrip" format="integer" /> <attr name="suggestionsCountInStrip" format="integer" />
<attr name="centerSuggestionPercentile" format="integer" /> <attr name="centerSuggestionPercentile" format="integer" />
<attr name="moreSuggestionsHint" format="reference" />
<attr name="maxMoreSuggestionsRow" format="integer" /> <attr name="maxMoreSuggestionsRow" format="integer" />
<attr name="minMoreSuggestionsWidth" format="float" /> <attr name="minMoreSuggestionsWidth" format="float" />
</declare-styleable> </declare-styleable>

View File

@ -92,6 +92,7 @@
<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>
<dimen name="suggestion_text_size">18dip</dimen> <dimen name="suggestion_text_size">18dip</dimen>
<dimen name="more_suggestions_hint_text_size">27dip</dimen>
<integer name="suggestions_count_in_strip">3</integer> <integer name="suggestions_count_in_strip">3</integer>
<integer name="center_suggestion_percentile">36</integer> <integer name="center_suggestion_percentile">36</integer>

View File

@ -102,7 +102,6 @@
<item name="alphaObsoleted">50</item> <item name="alphaObsoleted">50</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="moreSuggestionsHint">@drawable/more_suggestions_hint</item>
<item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item> <item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item>
<item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item> <item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item>
</style> </style>
@ -284,7 +283,6 @@
<item name="alphaObsoleted">70</item> <item name="alphaObsoleted">70</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="moreSuggestionsHint">@drawable/more_suggestions_hint_holo</item>
<item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item> <item name="maxMoreSuggestionsRow">@integer/max_more_suggestions_row</item>
<item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item> <item name="minMoreSuggestionsWidth">@fraction/min_more_suggestions_width</item>
</style> </style>

View File

@ -19,8 +19,14 @@ package com.android.inputmethod.latin;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
@ -167,6 +173,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private final float mCenterSuggestionWeight; private final float mCenterSuggestionWeight;
private final int mCenterSuggestionIndex; private final int mCenterSuggestionIndex;
private final Drawable mMoreSuggestionsHint; private final Drawable mMoreSuggestionsHint;
private static final String MORE_SUGGESTIONS_HINT = "\u2026";
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD); private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan(); private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
@ -225,7 +232,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mCenterSuggestionWeight = getPercent(a, mCenterSuggestionWeight = getPercent(a,
R.styleable.SuggestionsView_centerSuggestionPercentile, R.styleable.SuggestionsView_centerSuggestionPercentile,
DEFAULT_CENTER_SUGGESTION_PERCENTILE); DEFAULT_CENTER_SUGGESTION_PERCENTILE);
mMoreSuggestionsHint = a.getDrawable(R.styleable.SuggestionsView_moreSuggestionsHint);
mMaxMoreSuggestionsRow = a.getInt( mMaxMoreSuggestionsRow = a.getInt(
R.styleable.SuggestionsView_maxMoreSuggestionsRow, R.styleable.SuggestionsView_maxMoreSuggestionsRow,
DEFAULT_MAX_MORE_SUGGESTIONS_ROW); DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
@ -233,6 +239,8 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
R.styleable.SuggestionsView_minMoreSuggestionsWidth); R.styleable.SuggestionsView_minMoreSuggestionsWidth);
a.recycle(); a.recycle();
mMoreSuggestionsHint = getMoreSuggestionsHint(res,
res.getDimension(R.dimen.more_suggestions_hint_text_size), mColorAutoCorrect);
mCenterSuggestionIndex = mSuggestionsCountInStrip / 2; mCenterSuggestionIndex = mSuggestionsCountInStrip / 2;
mMoreSuggestionsBottomGap = res.getDimensionPixelOffset( mMoreSuggestionsBottomGap = res.getDimensionPixelOffset(
R.dimen.more_suggestions_bottom_gap); R.dimen.more_suggestions_bottom_gap);
@ -246,6 +254,23 @@ 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);
} }
private static Drawable getMoreSuggestionsHint(Resources res, float textSize, int color) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextAlign(Align.CENTER);
paint.setTextSize(textSize);
paint.setColor(color);
final Rect bounds = new Rect();
paint.getTextBounds(MORE_SUGGESTIONS_HINT, 0, 1, bounds);
final int width = Math.round(bounds.width() + 0.5f);
final int height = Math.round(bounds.height() + 0.5f);
final Bitmap buffer = Bitmap.createBitmap(
width, (height * 3 / 2), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(buffer);
canvas.drawText(MORE_SUGGESTIONS_HINT, width / 2, height, paint);
return new BitmapDrawable(res, buffer);
}
// Read integer value in TypedArray as percent. // Read integer value in TypedArray as percent.
private static float getPercent(TypedArray a, int index, int defValue) { private static float getPercent(TypedArray a, int index, int defValue) {
return a.getInt(index, defValue) / 100.0f; return a.getInt(index, defValue) / 100.0f;