From 541fa7858d3eeee3a797da19ff3d14bc6c87953c Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Thu, 7 Nov 2013 18:11:19 +0900
Subject: [PATCH] Add keyLabelHintVerticalAdjustment attribute

Bug: 11546184
Change-Id: I1fbdbbdcf4d6a74888c48f2e4f0b7afce7913653
---
 java/res/values/attrs.xml                                   | 2 ++
 java/src/com/android/inputmethod/keyboard/KeyboardView.java | 5 ++++-
 .../inputmethod/keyboard/internal/KeyVisualAttributes.java  | 6 ++++++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 9a1e56a60a..a7425f1e7f 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -276,6 +276,8 @@
         <attr name="keyLabel" format="string" />
         <!-- The hint label to display on the key in conjunction with the label. -->
         <attr name="keyHintLabel" format="string" />
+        <!-- The vertical adjustment of key hint label in proportion to its height. -->
+        <attr name="keyHintLabelVerticalAdjustment" format="fraction" />
         <!-- The key label flags. -->
         <attr name="keyLabelFlags" format="integer">
             <!-- This should be aligned with Key.LABEL_FLAGS__* -->
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 5c4a11f432..dcd90070ef 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -454,6 +454,9 @@ public class KeyboardView extends View {
             blendAlpha(paint, params.mAnimAlpha);
             final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
             final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
+            final KeyVisualAttributes visualAttr = key.getVisualAttributes();
+            final float adjustmentY = (visualAttr == null) ? 0.0f
+                    : visualAttr.mHintLabelVerticalAdjustment * labelCharHeight;
             final float hintX, hintY;
             if (key.hasHintLabel()) {
                 // The hint label is placed just right of the key label. Used mainly on
@@ -477,7 +480,7 @@ public class KeyboardView extends View {
                 hintY = -paint.ascent();
                 paint.setTextAlign(Align.CENTER);
             }
-            canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY, paint);
+            canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintY + adjustmentY, paint);
 
             if (LatinImeLogger.sVISUALDEBUG) {
                 final Paint line = new Paint();
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java b/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java
index 8bdad364c8..c3e0aa685d 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyVisualAttributes.java
@@ -47,6 +47,8 @@ public final class KeyVisualAttributes {
     public final int mShiftedLetterHintActivatedColor;
     public final int mPreviewTextColor;
 
+    public final float mHintLabelVerticalAdjustment;
+
     private static final int[] VISUAL_ATTRIBUTE_IDS = {
         R.styleable.Keyboard_Key_keyTypeface,
         R.styleable.Keyboard_Key_keyLetterSize,
@@ -65,6 +67,7 @@ public final class KeyVisualAttributes {
         R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor,
         R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor,
         R.styleable.Keyboard_Key_keyPreviewTextColor,
+        R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment,
     };
     private static final SparseIntArray sVisualAttributeIds = new SparseIntArray();
     private static final int ATTR_DEFINED = 1;
@@ -127,5 +130,8 @@ public final class KeyVisualAttributes {
         mShiftedLetterHintActivatedColor = keyAttr.getColor(
                 R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, 0);
         mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
+
+        mHintLabelVerticalAdjustment = ResourceUtils.getFraction(keyAttr,
+                R.styleable.Keyboard_Key_keyHintLabelVerticalAdjustment, 0.0f);
     }
 }
-- 
GitLab