Fix key letter size of 5-rows Thai keyboard

The key text size can be specified in each keyboard layout in addition
to by KeyboardView theme.

Bug: 6473915
Change-Id: Icd2d436fa1d8fc7bd1deb9e4b799d4f624376fb2
main
Tadashi G. Takaoka 2012-08-28 11:28:42 +09:00
parent 160dc0f98e
commit ac621d1527
13 changed files with 97 additions and 22 deletions

View File

@ -53,6 +53,8 @@
<fraction name="key_uppercase_letter_ratio">40%</fraction>
<fraction name="key_preview_text_ratio">90%</fraction>
<fraction name="spacebar_text_ratio">40.000%</fraction>
<fraction name="key_letter_ratio_5rows">78%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">48%</fraction>
<dimen name="key_preview_offset">0.0dp</dimen>
<dimen name="key_preview_offset_ics">1.6dp</dimen>

View File

@ -51,6 +51,8 @@
<fraction name="key_hint_label_ratio">34%</fraction>
<fraction name="key_uppercase_letter_ratio">29%</fraction>
<fraction name="spacebar_text_ratio">30.0%</fraction>
<fraction name="key_letter_ratio_5rows">62%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">36%</fraction>
<dimen name="key_uppercase_letter_padding">4dp</dimen>
<dimen name="suggestions_strip_padding">252.0dp</dimen>

View File

@ -63,6 +63,8 @@
<fraction name="key_uppercase_letter_ratio">22%</fraction>
<fraction name="key_preview_text_ratio">50%</fraction>
<fraction name="spacebar_text_ratio">28.0%</fraction>
<fraction name="key_letter_ratio_5rows">52%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">27%</fraction>
<dimen name="key_preview_height">94.5dp</dimen>
<dimen name="key_preview_offset">16.0dp</dimen>

View File

@ -53,6 +53,8 @@
<fraction name="key_hint_label_ratio">28%</fraction>
<fraction name="key_uppercase_letter_ratio">24%</fraction>
<fraction name="spacebar_text_ratio">24.00%</fraction>
<fraction name="key_letter_ratio_5rows">53%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">30%</fraction>
<dimen name="key_preview_height">107.1dp</dimen>
<dimen name="key_preview_offset_ics">8.0dp</dimen>

View File

@ -64,6 +64,8 @@
<fraction name="key_uppercase_letter_ratio">26%</fraction>
<fraction name="key_preview_text_ratio">50%</fraction>
<fraction name="spacebar_text_ratio">29.03%</fraction>
<fraction name="key_letter_ratio_5rows">51%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">33%</fraction>
<dimen name="key_preview_height">94.5dp</dimen>
<dimen name="key_preview_offset">16.0dp</dimen>

View File

@ -65,6 +65,8 @@
<fraction name="key_uppercase_letter_ratio">35%</fraction>
<fraction name="key_preview_text_ratio">82%</fraction>
<fraction name="spacebar_text_ratio">33.735%</fraction>
<fraction name="key_letter_ratio_5rows">64%</fraction>
<fraction name="key_uppercase_letter_ratio_5rows">41%</fraction>
<dimen name="key_preview_height">80dp</dimen>
<dimen name="key_preview_offset">-8.0dp</dimen>

View File

@ -23,6 +23,8 @@
latin:rowHeight="20%p"
latin:verticalGap="3.20%p"
latin:keyTypeface="normal"
latin:keyLetterSize="@fraction/key_letter_ratio_5rows"
latin:keyShiftedLetterHintRatio="@fraction/key_uppercase_letter_ratio_5rows"
latin:touchPositionCorrectionData="@null"
>
<include

View File

@ -23,6 +23,8 @@
latin:rowHeight="20%p"
latin:verticalGap="3.20%p"
latin:keyTypeface="normal"
latin:keyLetterSize="@fraction/key_letter_ratio_5rows"
latin:keyShiftedLetterHintRatio="@fraction/key_uppercase_letter_ratio_5rows"
latin:touchPositionCorrectionData="@null"
>
<include

View File

@ -23,6 +23,8 @@
latin:rowHeight="20%p"
latin:verticalGap="2.65%p"
latin:keyTypeface="normal"
latin:keyLetterSize="@fraction/key_letter_ratio_5rows"
latin:keyShiftedLetterHintRatio="@fraction/key_uppercase_letter_ratio_5rows"
latin:touchPositionCorrectionData="@null"
>
<include

View File

@ -23,6 +23,8 @@
latin:rowHeight="20%p"
latin:verticalGap="2.95%p"
latin:keyTypeface="normal"
latin:keyLetterSize="@fraction/key_letter_ratio_5rows"
latin:keyShiftedLetterHintRatio="@fraction/key_uppercase_letter_ratio_5rows"
latin:touchPositionCorrectionData="@null"
>
<include

View File

@ -124,6 +124,10 @@ public class Keyboard {
/** Per keyboard key visual parameters */
public final Typeface mKeyTypeface;
public final float mKeyLetterRatio;
public final int mKeyLetterSize;
public final float mKeyHintLetterRatio;
public final float mKeyShiftedLetterHintRatio;
public final int mMostCommonKeyHeight;
public final int mMostCommonKeyWidth;
@ -156,6 +160,10 @@ public class Keyboard {
mMaxMoreKeysKeyboardColumn = params.mMaxMoreKeysKeyboardColumn;
mKeyTypeface = params.mKeyTypeface;
mKeyLetterRatio = params.mKeyLetterRatio;
mKeyLetterSize = params.mKeyLetterSize;
mKeyHintLetterRatio = params.mKeyHintLetterRatio;
mKeyShiftedLetterHintRatio = params.mKeyShiftedLetterHintRatio;
mTopPadding = params.mTopPadding;
mVerticalGap = params.mVerticalGap;
@ -253,6 +261,10 @@ public class Keyboard {
public int mHorizontalCenterPadding;
public Typeface mKeyTypeface = null;
public float mKeyLetterRatio = ResourceUtils.UNDEFINED_RATIO;
public int mKeyLetterSize = ResourceUtils.UNDEFINED_DIMENSION;
public float mKeyHintLetterRatio = ResourceUtils.UNDEFINED_RATIO;;
public float mKeyShiftedLetterHintRatio = ResourceUtils.UNDEFINED_RATIO;
public int mDefaultRowHeight;
public int mDefaultKeyWidth;
@ -813,6 +825,14 @@ public class Keyboard {
params.mKeyTypeface = Typeface.defaultFromStyle(keyboardViewAttr.getInt(
R.styleable.KeyboardView_keyTypeface, Typeface.NORMAL));
}
params.mKeyLetterRatio = ResourceUtils.getFraction(keyboardViewAttr,
R.styleable.KeyboardView_keyLetterSize);
params.mKeyLetterSize = ResourceUtils.getDimensionPixelSize(keyboardViewAttr,
R.styleable.KeyboardView_keyLetterSize);
params.mKeyHintLetterRatio = ResourceUtils.getFraction(keyboardViewAttr,
R.styleable.KeyboardView_keyHintLetterRatio);
params.mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyboardViewAttr,
R.styleable.KeyboardView_keyShiftedLetterHintRatio);
params.mMoreKeysTemplate = keyboardAttr.getResourceId(
R.styleable.Keyboard_moreKeysTemplate, 0);

View File

@ -85,6 +85,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
// Miscellaneous constants
private static final int[] LONG_PRESSABLE_STATE_SET = { android.R.attr.state_long_pressable };
// XML attributes
protected final float mVerticalCorrection;
protected final int mMoreKeysLayout;
@ -197,6 +198,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private final Typeface mKeyTypefaceFromKeyboardView;
private final float mKeyLetterRatio;
private final int mKeyLetterSizeFromKeyboardView;
private final float mKeyLargeLetterRatio;
private final float mKeyLabelRatio;
private final float mKeyLargeLabelRatio;
@ -217,16 +219,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
public KeyDrawParams(final TypedArray a) {
mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
if (!ResourceUtils.isValidFraction(mKeyLetterRatio = ResourceUtils.getFraction(a,
R.styleable.KeyboardView_keyLetterSize))) {
mKeyLetterSize = ResourceUtils.getDimensionPixelSize(a,
R.styleable.KeyboardView_keyLetterSize);
}
if (!ResourceUtils.isValidFraction(mKeyLabelRatio = ResourceUtils.getFraction(a,
R.styleable.KeyboardView_keyLabelSize))) {
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(a,
R.styleable.KeyboardView_keyLabelSize);
}
mKeyLetterRatio = ResourceUtils.getFraction(a, R.styleable.KeyboardView_keyLetterSize);
mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(a,
R.styleable.KeyboardView_keyLetterSize);
mKeyLabelRatio = ResourceUtils.getFraction(a, R.styleable.KeyboardView_keyLabelSize);
mKeyLabelSize = ResourceUtils.getDimensionPixelSize(a,
R.styleable.KeyboardView_keyLabelSize);
mKeyLargeLabelRatio = ResourceUtils.getFraction(a,
R.styleable.KeyboardView_keyLargeLabelRatio);
mKeyLargeLetterRatio = ResourceUtils.getFraction(a,
@ -245,19 +243,23 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
mKeyShiftedLetterHintPadding = a.getDimension(
R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor, 0xFF000000);
mKeyTextColor = a.getColor(
R.styleable.KeyboardView_keyTextColor, Color.WHITE);
mKeyTextInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyTextInactivatedColor, 0xFF000000);
mKeyHintLetterColor = a.getColor(R.styleable.KeyboardView_keyHintLetterColor, 0);
mKeyHintLabelColor = a.getColor(R.styleable.KeyboardView_keyHintLabelColor, 0);
R.styleable.KeyboardView_keyTextInactivatedColor, Color.WHITE);
mKeyHintLetterColor = a.getColor(
R.styleable.KeyboardView_keyHintLetterColor, Color.TRANSPARENT);
mKeyHintLabelColor = a.getColor(
R.styleable.KeyboardView_keyHintLabelColor, Color.TRANSPARENT);
mKeyShiftedLetterHintInactivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor, 0);
R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor,
Color.TRANSPARENT);
mKeyShiftedLetterHintActivatedColor = a.getColor(
R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, 0);
R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
a.getInt(R.styleable.KeyboardView_keyTypeface, Typeface.NORMAL));
mKeyTypeface = mKeyTypefaceFromKeyboardView;
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, 0);
mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, Color.TRANSPARENT);
mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
mKeyBackground.getPadding(mPadding);
@ -267,19 +269,42 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mKeyTypeface = (keyboard.mKeyTypeface != null)
? keyboard.mKeyTypeface : mKeyTypefaceFromKeyboardView;
final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap;
if (ResourceUtils.isValidFraction(mKeyLetterRatio)) {
mKeyLetterSize = (int)(keyHeight * mKeyLetterRatio);
}
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight,
mKeyLetterSizeFromKeyboardView, mKeyLetterRatio,
mKeyLetterSizeFromKeyboardView);
// Override if size/ratio is specified in Keyboard.
mKeyLetterSize = selectTextSizeFromDimensionOrRatio(keyHeight, keyboard.mKeyLetterSize,
keyboard.mKeyLetterRatio, mKeyLetterSize);
if (ResourceUtils.isValidFraction(mKeyLabelRatio)) {
mKeyLabelSize = (int)(keyHeight * mKeyLabelRatio);
}
mKeyLargeLabelSize = (int)(keyHeight * mKeyLargeLabelRatio);
mKeyLargeLetterSize = (int)(keyHeight * mKeyLargeLetterRatio);
mKeyHintLetterSize = (int)(keyHeight * mKeyHintLetterRatio);
mKeyShiftedLetterHintSize = (int)(keyHeight * mKeyShiftedLetterHintRatio);
mKeyHintLetterSize = selectTextSizeFromKeyboardOrView(keyHeight,
keyboard.mKeyHintLetterRatio, mKeyHintLetterRatio);
mKeyShiftedLetterHintSize = selectTextSizeFromKeyboardOrView(keyHeight,
keyboard.mKeyShiftedLetterHintRatio, mKeyShiftedLetterHintRatio);
mKeyHintLabelSize = (int)(keyHeight * mKeyHintLabelRatio);
}
private static final int selectTextSizeFromDimensionOrRatio(final int keyHeight,
final int dimens, final float ratio, final int defaultDimens) {
if (ResourceUtils.isValidDimensionPixelSize(dimens)) {
return dimens;
}
if (ResourceUtils.isValidFraction(ratio)) {
return (int)(keyHeight * ratio);
}
return defaultDimens;
}
private static final int selectTextSizeFromKeyboardOrView(final int keyHeight,
final float ratioFromKeyboard, final float ratioFromView) {
final float ratio = ResourceUtils.isValidFraction(ratioFromKeyboard)
? ratioFromKeyboard : ratioFromView;
return (int)(keyHeight * ratio);
}
public void blendAlpha(final Paint paint) {
final int color = paint.getColor();
paint.setARGB((paint.getAlpha() * mAnimAlpha) / Constants.Color.ALPHA_OPAQUE,

View File

@ -55,6 +55,16 @@ public final class ResourceUtils {
return fraction >= 0.0f;
}
// {@link Resources#getDimensionPixelSize(int)} returns at least one pixel size.
public static boolean isValidDimensionPixelSize(final int dimension) {
return dimension > 0;
}
// {@link Resources#getDimensionPixelOffset(int)} may return zero pixel offset.
public static boolean isValidDimensionPixelOffset(final int dimension) {
return dimension >= 0;
}
public static float getFraction(final TypedArray a, final int index, final float defValue) {
final TypedValue value = a.peekValue(index);
if (value == null || !isFractionValue(value)) {