diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml index 62597258c72cadb81302066cdf4c76752de67b10..fbfbb512cec2dfd6ffa28801b6b2ad96b04ff356 100644 --- a/java/res/values-land/dimens.xml +++ b/java/res/values-land/dimens.xml @@ -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> diff --git a/java/res/values-sw600dp-land/dimens.xml b/java/res/values-sw600dp-land/dimens.xml index a478df89a66f58ed1017d0a38dafbb8835a4b6be..8283cd9fbe8df7805dd9e50451d217608f0a2cd1 100644 --- a/java/res/values-sw600dp-land/dimens.xml +++ b/java/res/values-sw600dp-land/dimens.xml @@ -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> diff --git a/java/res/values-sw600dp/dimens.xml b/java/res/values-sw600dp/dimens.xml index 5596ba41ce1150513fb2fa7894ca207b27b18783..78aa60533a7f5c6de45fe77357e8bfbdf6737b74 100644 --- a/java/res/values-sw600dp/dimens.xml +++ b/java/res/values-sw600dp/dimens.xml @@ -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> diff --git a/java/res/values-sw768dp-land/dimens.xml b/java/res/values-sw768dp-land/dimens.xml index b95c858dc666d641304155edd1c6270fbe25fcfc..ac94c9293dc41b7f36d044d274a46ff03e3904f6 100644 --- a/java/res/values-sw768dp-land/dimens.xml +++ b/java/res/values-sw768dp-land/dimens.xml @@ -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> diff --git a/java/res/values-sw768dp/dimens.xml b/java/res/values-sw768dp/dimens.xml index ce33b73cb5b7e11bac735938a35c85862e4e67bf..0fd9cedcbc619018812adb2fbbd5e333414d10da 100644 --- a/java/res/values-sw768dp/dimens.xml +++ b/java/res/values-sw768dp/dimens.xml @@ -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> diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml index 4fd942b1446843f84c3fbec790c97131af32d128..e0fcd5e2d12be827dd5674e9fb480b34ea1a7cd4 100644 --- a/java/res/values/dimens.xml +++ b/java/res/values/dimens.xml @@ -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> diff --git a/java/res/xml-sw600dp-land/kbd_thai.xml b/java/res/xml-sw600dp-land/kbd_thai.xml index 3143061400bc22364112b93b78b4c3c20047dfe4..a7763f2c7a53a909916058e1e3790472422f6f4d 100644 --- a/java/res/xml-sw600dp-land/kbd_thai.xml +++ b/java/res/xml-sw600dp-land/kbd_thai.xml @@ -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 diff --git a/java/res/xml-sw600dp/kbd_thai.xml b/java/res/xml-sw600dp/kbd_thai.xml index 3143061400bc22364112b93b78b4c3c20047dfe4..a7763f2c7a53a909916058e1e3790472422f6f4d 100644 --- a/java/res/xml-sw600dp/kbd_thai.xml +++ b/java/res/xml-sw600dp/kbd_thai.xml @@ -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 diff --git a/java/res/xml-sw768dp-land/kbd_thai.xml b/java/res/xml-sw768dp-land/kbd_thai.xml index b7633df33ee547317bcf449eb8a52bb5bfa0a602..0f8516f5df915f9c11b9670d198a31f98d99cd74 100644 --- a/java/res/xml-sw768dp-land/kbd_thai.xml +++ b/java/res/xml-sw768dp-land/kbd_thai.xml @@ -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 diff --git a/java/res/xml-sw768dp/kbd_thai.xml b/java/res/xml-sw768dp/kbd_thai.xml index 2be6a254983a0a7e108e924c864b62a593075626..7e4451455fbf92484e5f91a6e515e17dcb87c499 100644 --- a/java/res/xml-sw768dp/kbd_thai.xml +++ b/java/res/xml-sw768dp/kbd_thai.xml @@ -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 diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index aa757f153c3311296aaf53c4d4141f0dc11dc84e..a32b3e7959b54c36ba96663860dd9f6bcb7fcdac 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -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); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index d4d4ce76b71b22900f7c4e00bbb42d219ba35c45..6a23c919b7046201dc0f74c691acaa31d5cba8ad 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -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, diff --git a/java/src/com/android/inputmethod/latin/ResourceUtils.java b/java/src/com/android/inputmethod/latin/ResourceUtils.java index b3d7ac5bf2cd66ac48555e51a38f28df66e4d14f..5021ad3842c1828af1194dec33a6343cf7995379 100644 --- a/java/src/com/android/inputmethod/latin/ResourceUtils.java +++ b/java/src/com/android/inputmethod/latin/ResourceUtils.java @@ -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)) {