diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index a456b221b89416b52ee6bb00911c67fec79d3b1d..a876e28890182a60e5dcf22b002dda5b21bcbbae 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -217,6 +217,7 @@ <flag name="hasHintLabel" value="0x800" /> <flag name="withIconLeft" value="0x1000" /> <flag name="withIconRight" value="0x2000" /> + <flag name="autoXScale" value="0x4000" /> </attr> <!-- The icon to display on the key instead of the label. --> <attr name="keyIcon" format="enum"> diff --git a/java/res/xml-sw600dp/kbd_phone_shift.xml b/java/res/xml-sw600dp/kbd_phone_shift.xml index 2b6936dce42d4727d76be8215eb25e9a08f16ebd..4c4f8ad12f6a57deb94610ab5faac3e024bdfa36 100644 --- a/java/res/xml-sw600dp/kbd_phone_shift.xml +++ b/java/res/xml-sw600dp/kbd_phone_shift.xml @@ -41,6 +41,7 @@ <Key latin:code="44" latin:keyLabel="@string/label_pause_key" + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" latin:keyWidth="9.25%p" /> <Key latin:keyStyle="num1KeyStyle" @@ -69,6 +70,7 @@ <Key latin:code="59" latin:keyLabel="@string/label_wait_key" + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" latin:keyWidth="9.25%p" /> <Key latin:keyStyle="num4KeyStyle" diff --git a/java/res/xml-sw768dp/kbd_phone_shift.xml b/java/res/xml-sw768dp/kbd_phone_shift.xml index 646f0b86719c692065bc2df1e8f52235213485a8..46f67d311639cb9c357531993da0de5339f2cee8 100644 --- a/java/res/xml-sw768dp/kbd_phone_shift.xml +++ b/java/res/xml-sw768dp/kbd_phone_shift.xml @@ -43,6 +43,7 @@ <Key latin:code="44" latin:keyLabel="@string/label_pause_key" + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" latin:keyWidth="8.047%p" /> <Key latin:keyStyle="num1KeyStyle" @@ -72,6 +73,7 @@ <Key latin:code="59" latin:keyLabel="@string/label_wait_key" + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" latin:keyWidth="8.047%p" /> <Key latin:keyStyle="num4KeyStyle" diff --git a/java/res/xml/kbd_key_styles.xml b/java/res/xml/kbd_key_styles.xml index 12eab22b9851162baa079fa6ed6973607fdc13fd..84b1900f015a2cd75703f6bf8340a616ca54b325 100644 --- a/java/res/xml/kbd_key_styles.xml +++ b/java/res/xml/kbd_key_styles.xml @@ -101,6 +101,7 @@ latin:styleName="returnKeyStyle" latin:code="@integer/key_return" latin:keyLabel="@string/label_go_key" + latin:keyLabelOption="autoXScale" latin:parentStyle="functionalKeyStyle" /> </case> <case @@ -110,6 +111,7 @@ latin:styleName="returnKeyStyle" latin:code="@integer/key_return" latin:keyLabel="@string/label_next_key" + latin:keyLabelOption="autoXScale" latin:parentStyle="functionalKeyStyle" /> </case> <case @@ -119,6 +121,7 @@ latin:styleName="returnKeyStyle" latin:code="@integer/key_return" latin:keyLabel="@string/label_done_key" + latin:keyLabelOption="autoXScale" latin:parentStyle="functionalKeyStyle" /> </case> <case @@ -128,6 +131,7 @@ latin:styleName="returnKeyStyle" latin:code="@integer/key_return" latin:keyLabel="@string/label_send_key" + latin:keyLabelOption="autoXScale" latin:parentStyle="functionalKeyStyle" /> </case> <case diff --git a/java/res/xml/kbd_phone_shift.xml b/java/res/xml/kbd_phone_shift.xml index 89a9bd058bb30746c2b92fb975f7c1cc7ae1e756..5be9bf9a9e6784c6a88943b922f3615d1d8ec07d 100644 --- a/java/res/xml/kbd_phone_shift.xml +++ b/java/res/xml/kbd_phone_shift.xml @@ -49,7 +49,7 @@ <Key latin:code="44" latin:keyLabel="@string/label_pause_key" - latin:keyLabelOption="followKeyHintLabelRatio" /> + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" /> <Key latin:keyLabel="," latin:keyStyle="numKeyStyle" /> @@ -65,7 +65,7 @@ <Key latin:code="59" latin:keyLabel="@string/label_wait_key" - latin:keyLabelOption="followKeyHintLabelRatio" /> + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" /> <Key latin:keyLabel="#" latin:keyStyle="numKeyStyle" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 4ccb27e4cb7525e5d12fb003e4a23306e21f509a..06d248e3a7c46742f921a8cd45de573e50042141 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -64,6 +64,7 @@ public class Key { private static final int LABEL_OPTION_HAS_HINT_LABEL = 0x800; private static final int LABEL_OPTION_WITH_ICON_LEFT = 0x1000; private static final int LABEL_OPTION_WITH_ICON_RIGHT = 0x2000; + private static final int LABEL_OPTION_AUTO_X_SCALE = 0x4000; /** Icon to display instead of a label. Icon takes precedence over a label */ private Drawable mIcon; @@ -439,6 +440,10 @@ public class Key { return (mLabelOption & LABEL_OPTION_WITH_ICON_RIGHT) != 0; } + public boolean needsXScale() { + return (mLabelOption & LABEL_OPTION_AUTO_X_SCALE) != 0; + } + public Drawable getIcon() { return mIcon; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index acb76cc78c6769d245af69e25c8a2e8196be078d..5a44460a1c806e6b8ab5940b7c1727038dc4da40 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -91,6 +91,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { // TODO: Use resource parameter for this value. private static final float LABEL_ICON_MARGIN = 0.05f; + // The maximum key label width in the proportion to the key width. + private static final float MAX_LABEL_RATIO = 0.90f; + // Main keyboard private Keyboard mKeyboard; private final KeyDrawParams mKeyDrawParams; @@ -572,18 +575,22 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { paint.setTextAlign(Align.LEFT); } else if (key.hasLabelWithIconLeft() && icon != null) { labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth() - + (int)(LABEL_ICON_MARGIN * keyWidth); + + LABEL_ICON_MARGIN * keyWidth; positionX = centerX + labelWidth / 2; paint.setTextAlign(Align.RIGHT); } else if (key.hasLabelWithIconRight() && icon != null) { labelWidth = getLabelWidth(label, paint) + icon.getIntrinsicWidth() - + (int)(LABEL_ICON_MARGIN * keyWidth); + + LABEL_ICON_MARGIN * keyWidth; positionX = centerX - labelWidth / 2; paint.setTextAlign(Align.LEFT); } else { positionX = centerX; paint.setTextAlign(Align.CENTER); } + if (key.needsXScale()) { + paint.setTextScaleX( + Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / getLabelWidth(label, paint))); + } if (key.hasUppercaseLetter() && isManualTemporaryUpperCase) { paint.setColor(params.mKeyTextInactivatedColor); @@ -598,8 +605,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { paint.setColor(Color.TRANSPARENT); } canvas.drawText(label, 0, label.length(), positionX, baseline, paint); - // Turn off drop shadow + // Turn off drop shadow and reset x-scale. paint.setShadowLayer(0, 0, 0, 0); + paint.setTextScaleX(1.0f); if (icon != null) { final int iconWidth = icon.getIntrinsicWidth();