diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 64a4c9fc6..208711504 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -106,6 +106,14 @@
+
+
+
+
+
+
+
+
@@ -132,14 +140,14 @@
-
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml
index cc513ae89..018a1f983 100644
--- a/java/res/values/strings.xml
+++ b/java/res/values/strings.xml
@@ -226,6 +226,12 @@
ABC
ALT
+
+ Backspace
+
+ Shift
+
+ Return
More
diff --git a/java/res/xml-xlarge/kbd_phone.xml b/java/res/xml-xlarge/kbd_phone.xml
index 8199b019b..013f005d4 100644
--- a/java/res/xml-xlarge/kbd_phone.xml
+++ b/java/res/xml-xlarge/kbd_phone.xml
@@ -30,6 +30,7 @@
@@ -61,8 +62,8 @@
latin:horizontalGap="4.0%p" />
diff --git a/java/res/xml-xlarge/kbd_phone_symbols.xml b/java/res/xml-xlarge/kbd_phone_symbols.xml
index 2e604d374..618d2c3bc 100644
--- a/java/res/xml-xlarge/kbd_phone_symbols.xml
+++ b/java/res/xml-xlarge/kbd_phone_symbols.xml
@@ -30,6 +30,7 @@
@@ -64,8 +65,8 @@
latin:horizontalGap="4.0%p" />
diff --git a/java/res/xml-xlarge/kbd_qwerty_row1.xml b/java/res/xml-xlarge/kbd_qwerty_row1.xml
index 51a792798..754207983 100644
--- a/java/res/xml-xlarge/kbd_qwerty_row1.xml
+++ b/java/res/xml-xlarge/kbd_qwerty_row1.xml
@@ -25,7 +25,8 @@
diff --git a/java/res/xml-xlarge/kbd_qwerty_row2.xml b/java/res/xml-xlarge/kbd_qwerty_row2.xml
index 71aa916c7..cf1a90867 100644
--- a/java/res/xml-xlarge/kbd_qwerty_row2.xml
+++ b/java/res/xml-xlarge/kbd_qwerty_row2.xml
@@ -25,6 +25,7 @@
@@ -75,8 +76,8 @@
diff --git a/java/res/xml-xlarge/kbd_qwerty_row3.xml b/java/res/xml-xlarge/kbd_qwerty_row3.xml
index 24d1b1db9..cc3476cc7 100644
--- a/java/res/xml-xlarge/kbd_qwerty_row3.xml
+++ b/java/res/xml-xlarge/kbd_qwerty_row3.xml
@@ -24,9 +24,9 @@
@@ -80,8 +80,8 @@
@@ -80,6 +81,7 @@
@@ -119,8 +121,8 @@
latin:popupCharacters="]}>" />
@@ -129,7 +131,7 @@
@@ -70,6 +71,7 @@
@@ -99,8 +101,8 @@
latin:keyLabel="]" />
@@ -109,7 +111,7 @@
mTextHeightCache = new HashMap();
- // Distance from horizontal center of the key, proportional to key label text height.
- private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR = 0.55f;
- private final String KEY_LABEL_HEIGHT_REFERENCE_CHAR = "H";
+ // This map caches key label text width in pixel as value and key label text size as map key.
+ private final HashMap mTextWidthCache = new HashMap();
+ // Distance from horizontal center of the key, proportional to key label text height and width.
+ private final float KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER = 0.55f;
+ private final float KEY_LABEL_VERTICAL_PADDING_FACTOR = 1.60f;
+ private final float KEY_LABEL_HORIZONTAL_PADDING_FACTOR = 0.80f;
+ private final String KEY_LABEL_REFERENCE_CHAR = "H";
+ private final int KEY_LABEL_OPTION_ALIGN_LEFT = 1;
+ private final int KEY_LABEL_OPTION_ALIGN_RIGHT = 2;
+ private final int KEY_LABEL_OPTION_ALIGN_BOTTOM = 8;
+ private final int KEY_LABEL_OPTION_FONT_ITALIC = 16;
+ // TODO: Currently we don't have san-serif italic type face. This is actually san-serif
+ // non-italic type face.
+ private final Typeface TYPEFACE_ITALIC = Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC);
private final UIHandler mHandler = new UIHandler();
@@ -808,12 +819,17 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
keyBackground.draw(canvas);
boolean drawHintIcon = true;
+ // Draw key label
if (label != null) {
// For characters, use large font. For labels like "Done", use small font.
final int labelSize;
if (label.length() > 1 && key.codes.length < 2) {
labelSize = mLabelTextSize;
- paint.setTypeface(Typeface.DEFAULT_BOLD);
+ if ((key.labelOption & KEY_LABEL_OPTION_FONT_ITALIC) != 0) {
+ paint.setTypeface(TYPEFACE_ITALIC);
+ } else {
+ paint.setTypeface(Typeface.DEFAULT_BOLD);
+ }
} else {
labelSize = mKeyTextSize;
paint.setTypeface(mKeyTextStyle);
@@ -821,26 +837,51 @@ public class BaseKeyboardView extends View implements PointerTracker.UIProxy {
paint.setTextSize(labelSize);
Integer labelHeightValue = mTextHeightCache.get(labelSize);
- final int labelHeight;
+ final int labelCharHeight;
+ final int labelCharWidth;
if (labelHeightValue != null) {
- labelHeight = labelHeightValue;
+ labelCharHeight = labelHeightValue;
+ labelCharWidth = mTextWidthCache.get(labelSize);
} else {
Rect textBounds = new Rect();
- paint.getTextBounds(KEY_LABEL_HEIGHT_REFERENCE_CHAR, 0, 1, textBounds);
- labelHeight = textBounds.height();
- mTextHeightCache.put(labelSize, labelHeight);
+ paint.getTextBounds(KEY_LABEL_REFERENCE_CHAR, 0, 1, textBounds);
+ labelCharHeight = textBounds.height();
+ labelCharWidth = textBounds.width();
+ mTextHeightCache.put(labelSize, labelCharHeight);
+ mTextWidthCache.put(labelSize, labelCharWidth);
}
- // Draw a drop shadow for the text
+ // Vertical label text alignment.
+ final float baseline;
+ if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_BOTTOM) != 0) {
+ baseline = key.height -
+ + labelCharHeight * KEY_LABEL_VERTICAL_PADDING_FACTOR;
+ } else { // Align center
+ final float centerY = (key.height + padding.top - padding.bottom) / 2;
+ baseline = centerY
+ + labelCharHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR_CENTER;
+ }
+ // Horizontal label text alignment
+ final int positionX;
+ if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_LEFT) != 0) {
+ positionX = (int)(
+ labelCharWidth * KEY_LABEL_HORIZONTAL_PADDING_FACTOR + padding.left);
+ paint.setTextAlign(Align.LEFT);
+ } else if ((key.labelOption & KEY_LABEL_OPTION_ALIGN_RIGHT) != 0) {
+ positionX = (int)(key.width
+ - labelCharWidth * KEY_LABEL_HORIZONTAL_PADDING_FACTOR - padding.right);
+ paint.setTextAlign(Align.RIGHT);
+ } else {
+ positionX = (key.width + padding.left - padding.right) / 2;
+ paint.setTextAlign(Align.CENTER);
+ }
+ // Set a drop shadow for the text
paint.setShadowLayer(mShadowRadius, 0, 0, mShadowColor);
- final int centerX = (key.width + padding.left - padding.right) / 2;
- final int centerY = (key.height + padding.top - padding.bottom) / 2;
- final float baseline = centerY
- + labelHeight * KEY_LABEL_VERTICAL_ADJUSTMENT_FACTOR;
- canvas.drawText(label, centerX, baseline, paint);
+ canvas.drawText(label, positionX, baseline, paint);
// Turn off drop shadow
paint.setShadowLayer(0, 0, 0, 0);
}
+ // Draw key icon
if (key.label == null && key.icon != null) {
int drawableWidth = key.icon.getIntrinsicWidth();
int drawableHeight = key.icon.getIntrinsicHeight();