diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/Key.java | 5 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/KeyboardView.java | 14 |
2 files changed, 16 insertions, 3 deletions
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(); |