From 4486d7727038ca6be2dda16cc213549dc080ba8d Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 12 Sep 2011 16:29:24 +0900 Subject: [PATCH] Introduce autoXScale label option Bug: 5267649 Change-Id: I7fdcb98c209b7ccf73075ef3a4e758782fe161e3 --- java/res/values/attrs.xml | 1 + java/res/xml-sw600dp/kbd_phone_shift.xml | 2 ++ java/res/xml-sw768dp/kbd_phone_shift.xml | 2 ++ java/res/xml/kbd_key_styles.xml | 4 ++++ java/res/xml/kbd_phone_shift.xml | 4 ++-- java/src/com/android/inputmethod/keyboard/Key.java | 5 +++++ .../android/inputmethod/keyboard/KeyboardView.java | 14 +++++++++++--- 7 files changed, 27 insertions(+), 5 deletions(-) diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index a456b221b..a876e2889 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -217,6 +217,7 @@ + diff --git a/java/res/xml-sw600dp/kbd_phone_shift.xml b/java/res/xml-sw600dp/kbd_phone_shift.xml index 2b6936dce..4c4f8ad12 100644 --- a/java/res/xml-sw600dp/kbd_phone_shift.xml +++ b/java/res/xml-sw600dp/kbd_phone_shift.xml @@ -41,6 +41,7 @@ + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" /> @@ -65,7 +65,7 @@ + latin:keyLabelOption="followKeyHintLabelRatio|autoXScale" /> diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index 4ccb27e4c..06d248e3a 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 acb76cc78..5a44460a1 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();