am ef2bfad5
: Use TypedArray.getFraction to read percentile values in resource
* commit 'ef2bfad5903fb55adca61dbea51984fbc7e4375f': Use TypedArray.getFraction to read percentile values in resource
This commit is contained in:
commit
585b610b95
6 changed files with 49 additions and 52 deletions
|
@ -187,13 +187,13 @@
|
||||||
<attr name="colorTypedWord" format="color" />
|
<attr name="colorTypedWord" format="color" />
|
||||||
<attr name="colorAutoCorrect" format="color" />
|
<attr name="colorAutoCorrect" format="color" />
|
||||||
<attr name="colorSuggested" format="color" />
|
<attr name="colorSuggested" format="color" />
|
||||||
<attr name="alphaValidTypedWord" format="integer" />
|
<attr name="alphaValidTypedWord" format="fraction" />
|
||||||
<attr name="alphaTypedWord" format="integer" />
|
<attr name="alphaTypedWord" format="fraction" />
|
||||||
<attr name="alphaAutoCorrect" format="integer" />
|
<attr name="alphaAutoCorrect" format="fraction" />
|
||||||
<attr name="alphaSuggested" format="integer" />
|
<attr name="alphaSuggested" format="fraction" />
|
||||||
<attr name="alphaObsoleted" format="integer" />
|
<attr name="alphaObsoleted" format="fraction" />
|
||||||
<attr name="suggestionsCountInStrip" format="integer" />
|
<attr name="suggestionsCountInStrip" format="integer" />
|
||||||
<attr name="centerSuggestionPercentile" format="integer" />
|
<attr name="centerSuggestionPercentile" format="fraction" />
|
||||||
<attr name="maxMoreSuggestionsRow" format="integer" />
|
<attr name="maxMoreSuggestionsRow" format="integer" />
|
||||||
<attr name="minMoreSuggestionsWidth" format="float" />
|
<attr name="minMoreSuggestionsWidth" format="float" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
|
@ -92,7 +92,7 @@
|
||||||
<dimen name="suggestion_text_size">18dp</dimen>
|
<dimen name="suggestion_text_size">18dp</dimen>
|
||||||
<dimen name="more_suggestions_hint_text_size">27dp</dimen>
|
<dimen name="more_suggestions_hint_text_size">27dp</dimen>
|
||||||
<integer name="suggestions_count_in_strip">3</integer>
|
<integer name="suggestions_count_in_strip">3</integer>
|
||||||
<integer name="center_suggestion_percentile">36</integer>
|
<fraction name="center_suggestion_percentile">36%</fraction>
|
||||||
|
|
||||||
<!-- Gesture preview parameters -->
|
<!-- Gesture preview parameters -->
|
||||||
<dimen name="gesture_preview_trail_width">2.5dp</dimen>
|
<dimen name="gesture_preview_trail_width">2.5dp</dimen>
|
||||||
|
|
|
@ -138,9 +138,9 @@
|
||||||
<item name="colorTypedWord">@android:color/white</item>
|
<item name="colorTypedWord">@android:color/white</item>
|
||||||
<item name="colorAutoCorrect">#FFFCAE00</item>
|
<item name="colorAutoCorrect">#FFFCAE00</item>
|
||||||
<item name="colorSuggested">#FFFCAE00</item>
|
<item name="colorSuggested">#FFFCAE00</item>
|
||||||
<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">@fraction/center_suggestion_percentile</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>
|
||||||
|
@ -373,12 +373,12 @@
|
||||||
<item name="colorTypedWord">@android:color/holo_blue_light</item>
|
<item name="colorTypedWord">@android:color/holo_blue_light</item>
|
||||||
<item name="colorAutoCorrect">@android:color/holo_blue_light</item>
|
<item name="colorAutoCorrect">@android:color/holo_blue_light</item>
|
||||||
<item name="colorSuggested">@android:color/holo_blue_light</item>
|
<item name="colorSuggested">@android:color/holo_blue_light</item>
|
||||||
<item name="alphaValidTypedWord">85</item>
|
<item name="alphaValidTypedWord">85%</item>
|
||||||
<item name="alphaTypedWord">85</item>
|
<item name="alphaTypedWord">85%</item>
|
||||||
<item name="alphaSuggested">70</item>
|
<item name="alphaSuggested">70%</item>
|
||||||
<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">@fraction/center_suggestion_percentile</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>
|
||||||
|
|
|
@ -84,6 +84,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
|
|
||||||
// Miscellaneous constants
|
// Miscellaneous constants
|
||||||
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
|
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
|
||||||
|
private static final float UNDEFINED_RATIO = -1.0f;
|
||||||
|
|
||||||
// XML attributes
|
// XML attributes
|
||||||
protected final float mVerticalCorrection;
|
protected final float mVerticalCorrection;
|
||||||
|
@ -202,7 +203,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
private final float mKeyHintLetterRatio;
|
private final float mKeyHintLetterRatio;
|
||||||
private final float mKeyShiftedLetterHintRatio;
|
private final float mKeyShiftedLetterHintRatio;
|
||||||
private final float mKeyHintLabelRatio;
|
private final float mKeyHintLabelRatio;
|
||||||
private static final float UNDEFINED_RATIO = -1.0f;
|
|
||||||
|
|
||||||
public final Rect mPadding = new Rect();
|
public final Rect mPadding = new Rect();
|
||||||
public int mKeyLetterSize;
|
public int mKeyLetterSize;
|
||||||
|
@ -220,20 +220,20 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mKeyLetterRatio = UNDEFINED_RATIO;
|
mKeyLetterRatio = UNDEFINED_RATIO;
|
||||||
mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0);
|
mKeyLetterSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLetterSize, 0);
|
||||||
} else {
|
} else {
|
||||||
mKeyLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLetterRatio);
|
mKeyLetterRatio = getFraction(a, R.styleable.KeyboardView_keyLetterRatio);
|
||||||
}
|
}
|
||||||
if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) {
|
if (a.hasValue(R.styleable.KeyboardView_keyLabelSize)) {
|
||||||
mKeyLabelRatio = UNDEFINED_RATIO;
|
mKeyLabelRatio = UNDEFINED_RATIO;
|
||||||
mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0);
|
mKeyLabelSize = a.getDimensionPixelSize(R.styleable.KeyboardView_keyLabelSize, 0);
|
||||||
} else {
|
} else {
|
||||||
mKeyLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLabelRatio);
|
mKeyLabelRatio = getFraction(a, R.styleable.KeyboardView_keyLabelRatio);
|
||||||
}
|
}
|
||||||
mKeyLargeLabelRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLabelRatio);
|
mKeyLargeLabelRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLabelRatio);
|
||||||
mKeyLargeLetterRatio = getRatio(a, R.styleable.KeyboardView_keyLargeLetterRatio);
|
mKeyLargeLetterRatio = getFraction(a, R.styleable.KeyboardView_keyLargeLetterRatio);
|
||||||
mKeyHintLetterRatio = getRatio(a, R.styleable.KeyboardView_keyHintLetterRatio);
|
mKeyHintLetterRatio = getFraction(a, R.styleable.KeyboardView_keyHintLetterRatio);
|
||||||
mKeyShiftedLetterHintRatio = getRatio(a,
|
mKeyShiftedLetterHintRatio = getFraction(a,
|
||||||
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
|
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
|
||||||
mKeyHintLabelRatio = getRatio(a, R.styleable.KeyboardView_keyHintLabelRatio);
|
mKeyHintLabelRatio = getFraction(a, R.styleable.KeyboardView_keyHintLabelRatio);
|
||||||
mKeyLabelHorizontalPadding = a.getDimension(
|
mKeyLabelHorizontalPadding = a.getDimension(
|
||||||
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
|
||||||
mKeyHintLetterPadding = a.getDimension(
|
mKeyHintLetterPadding = a.getDimension(
|
||||||
|
@ -260,10 +260,10 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateKeyHeight(int keyHeight) {
|
public void updateKeyHeight(int keyHeight) {
|
||||||
if (mKeyLetterRatio >= 0.0f) {
|
if (isValidFraction(mKeyLetterRatio)) {
|
||||||
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
|
||||||
}
|
}
|
||||||
if (mKeyLabelRatio >= 0.0f) {
|
if (isValidFraction(mKeyLabelRatio)) {
|
||||||
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
|
||||||
}
|
}
|
||||||
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
|
||||||
|
@ -338,7 +338,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
R.styleable.KeyboardView_keyPreviewOffset, 0);
|
||||||
mPreviewHeight = a.getDimensionPixelSize(
|
mPreviewHeight = a.getDimensionPixelSize(
|
||||||
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
R.styleable.KeyboardView_keyPreviewHeight, 80);
|
||||||
mPreviewTextRatio = getRatio(a, R.styleable.KeyboardView_keyPreviewTextRatio);
|
mPreviewTextRatio = getFraction(a, R.styleable.KeyboardView_keyPreviewTextRatio);
|
||||||
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
|
mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
|
||||||
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
|
||||||
|
|
||||||
|
@ -387,9 +387,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
|
||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read fraction value in TypedArray as float.
|
static boolean isValidFraction(final float fraction) {
|
||||||
/* package */ static float getRatio(TypedArray a, int index) {
|
return fraction >= 0.0f;
|
||||||
return a.getFraction(index, 1000, 1000, 1) / 1000.0f;
|
}
|
||||||
|
|
||||||
|
static float getFraction(final TypedArray a, final int index) {
|
||||||
|
return a.getFraction(index, 1, 1, UNDEFINED_RATIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -344,8 +344,8 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
|
||||||
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
|
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedEnabled, false);
|
||||||
mAutoCorrectionSpacebarLedIcon = a.getDrawable(
|
mAutoCorrectionSpacebarLedIcon = a.getDrawable(
|
||||||
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon);
|
R.styleable.MainKeyboardView_autoCorrectionSpacebarLedIcon);
|
||||||
mSpacebarTextRatio = a.getFraction(R.styleable.MainKeyboardView_spacebarTextRatio,
|
mSpacebarTextRatio = a.getFraction(
|
||||||
1000, 1000, 1) / 1000.0f;
|
R.styleable.MainKeyboardView_spacebarTextRatio, 1, 1, 1.0f);
|
||||||
mSpacebarTextColor = a.getColor(R.styleable.MainKeyboardView_spacebarTextColor, 0);
|
mSpacebarTextColor = a.getColor(R.styleable.MainKeyboardView_spacebarTextColor, 0);
|
||||||
mSpacebarTextShadowColor = a.getColor(
|
mSpacebarTextShadowColor = a.getColor(
|
||||||
R.styleable.MainKeyboardView_spacebarTextShadowColor, 0);
|
R.styleable.MainKeyboardView_spacebarTextShadowColor, 0);
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
|
|
||||||
private static class SuggestionStripViewParams {
|
private static class SuggestionStripViewParams {
|
||||||
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 float DEFAULT_CENTER_SUGGESTION_PERCENTILE = 0.40f;
|
||||||
private static final int DEFAULT_MAX_MORE_SUGGESTIONS_ROW = 2;
|
private static final int DEFAULT_MAX_MORE_SUGGESTIONS_ROW = 2;
|
||||||
private static final int PUNCTUATIONS_IN_STRIP = 5;
|
private static final int PUNCTUATIONS_IN_STRIP = 5;
|
||||||
|
|
||||||
|
@ -196,16 +196,16 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripViewStyle);
|
R.styleable.SuggestionStripView, defStyle, R.style.SuggestionStripViewStyle);
|
||||||
mSuggestionStripOption = a.getInt(
|
mSuggestionStripOption = a.getInt(
|
||||||
R.styleable.SuggestionStripView_suggestionStripOption, 0);
|
R.styleable.SuggestionStripView_suggestionStripOption, 0);
|
||||||
final float alphaValidTypedWord = getPercent(a,
|
final float alphaValidTypedWord = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaValidTypedWord, 100);
|
R.styleable.SuggestionStripView_alphaValidTypedWord, 1.0f);
|
||||||
final float alphaTypedWord = getPercent(a,
|
final float alphaTypedWord = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaTypedWord, 100);
|
R.styleable.SuggestionStripView_alphaTypedWord, 1.0f);
|
||||||
final float alphaAutoCorrect = getPercent(a,
|
final float alphaAutoCorrect = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaAutoCorrect, 100);
|
R.styleable.SuggestionStripView_alphaAutoCorrect, 1.0f);
|
||||||
final float alphaSuggested = getPercent(a,
|
final float alphaSuggested = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaSuggested, 100);
|
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
||||||
mAlphaObsoleted = getPercent(a,
|
mAlphaObsoleted = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_alphaSuggested, 100);
|
R.styleable.SuggestionStripView_alphaSuggested, 1.0f);
|
||||||
mColorValidTypedWord = applyAlpha(a.getColor(
|
mColorValidTypedWord = applyAlpha(a.getColor(
|
||||||
R.styleable.SuggestionStripView_colorValidTypedWord, 0), alphaValidTypedWord);
|
R.styleable.SuggestionStripView_colorValidTypedWord, 0), alphaValidTypedWord);
|
||||||
mColorTypedWord = applyAlpha(a.getColor(
|
mColorTypedWord = applyAlpha(a.getColor(
|
||||||
|
@ -217,14 +217,14 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
mSuggestionsCountInStrip = a.getInt(
|
mSuggestionsCountInStrip = a.getInt(
|
||||||
R.styleable.SuggestionStripView_suggestionsCountInStrip,
|
R.styleable.SuggestionStripView_suggestionsCountInStrip,
|
||||||
DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
|
DEFAULT_SUGGESTIONS_COUNT_IN_STRIP);
|
||||||
mCenterSuggestionWeight = getPercent(a,
|
mCenterSuggestionWeight = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_centerSuggestionPercentile,
|
R.styleable.SuggestionStripView_centerSuggestionPercentile,
|
||||||
DEFAULT_CENTER_SUGGESTION_PERCENTILE);
|
DEFAULT_CENTER_SUGGESTION_PERCENTILE);
|
||||||
mMaxMoreSuggestionsRow = a.getInt(
|
mMaxMoreSuggestionsRow = a.getInt(
|
||||||
R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
|
R.styleable.SuggestionStripView_maxMoreSuggestionsRow,
|
||||||
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
|
DEFAULT_MAX_MORE_SUGGESTIONS_ROW);
|
||||||
mMinMoreSuggestionsWidth = getRatio(a,
|
mMinMoreSuggestionsWidth = getFraction(a,
|
||||||
R.styleable.SuggestionStripView_minMoreSuggestionsWidth);
|
R.styleable.SuggestionStripView_minMoreSuggestionsWidth, 1.0f);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
mMoreSuggestionsHint = getMoreSuggestionsHint(res,
|
mMoreSuggestionsHint = getMoreSuggestionsHint(res,
|
||||||
|
@ -278,14 +278,8 @@ public class SuggestionStripView extends RelativeLayout implements OnClickListen
|
||||||
return new BitmapDrawable(res, buffer);
|
return new BitmapDrawable(res, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read integer value in TypedArray as percent.
|
static float getFraction(final TypedArray a, final int index, final float defValue) {
|
||||||
private static float getPercent(TypedArray a, int index, int defValue) {
|
return a.getFraction(index, 1, 1, defValue);
|
||||||
return a.getInt(index, defValue) / 100.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 suggestedWords, int pos) {
|
private CharSequence getStyledSuggestionWord(SuggestedWords suggestedWords, int pos) {
|
||||||
|
|
Loading…
Reference in a new issue