Move some key top visual attributes from KeyboardView to Key

Change-Id: I1e2d59bf8c438ca653e2e415ccf66fd4f15d5394
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 27bf329..a44f84b 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -41,45 +41,6 @@
              checkable+checked+pressed. -->
         <attr name="keyBackground" format="reference" />
 
-        <!-- Size of the text for one letter keys. If specified as fraction, the text size is
-             measured in the proportion of key height. -->
-        <attr name="keyLetterSize" format="dimension|fraction" />
-        <!-- Size of the text for keys with multiple letters. If specified as fraction, the text
-             size is measured in the proportion of key height. -->
-        <attr name="keyLabelSize" format="dimension|fraction" />
-        <!-- Large size of the text for one letter keys, in the proportion of key height. -->
-        <attr name="keyLargeLetterRatio" format="fraction" />
-        <!-- Large size of the text for keys with multiple letters, in the proportion of key height. -->
-        <attr name="keyLargeLabelRatio" format="fraction" />
-        <!-- Size of the text for hint letter (= one character hint label), in the proportion of
-             key height. -->
-        <attr name="keyHintLetterRatio" format="fraction" />
-        <!-- Size of the text for hint label, in the proportion of key height. -->
-        <attr name="keyHintLabelRatio" format="fraction" />
-        <!-- Size of the text for shifted letter hint, in the proportion of key height. -->
-        <attr name="keyShiftedLetterHintRatio" format="dimension|fraction" />
-
-        <!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
-        <attr name="keyLabelHorizontalPadding" format="dimension" />
-        <!-- Right padding of hint letter to the edge of the key.-->
-        <attr name="keyHintLetterPadding" format="dimension" />
-        <!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
-        <attr name="keyPopupHintLetterPadding" format="dimension" />
-        <!-- Right padding of shifted letter hint to the edge of the key.-->
-        <attr name="keyShiftedLetterHintPadding" format="dimension" />
-
-        <!-- Color to use for the label in a key. -->
-        <attr name="keyTextColor" format="color" />
-        <!-- Color to use for the label in a key when in inactivated state. -->
-        <attr name="keyTextInactivatedColor" format="color" />
-        <!-- Key hint letter (= one character hint label) color -->
-        <attr name="keyHintLetterColor" format="color" />
-        <!-- Key hint label color -->
-        <attr name="keyHintLabelColor" format="color" />
-        <!-- Shifted letter hint colors -->
-        <attr name="keyShiftedLetterHintInactivatedColor" format="color" />
-        <attr name="keyShiftedLetterHintActivatedColor" format="color" />
-
         <!-- Layout resource for key press feedback.-->
         <attr name="keyPreviewLayout" format="reference" />
         <!-- The background for key press feedback. -->
@@ -88,14 +49,10 @@
         <attr name="keyPreviewLeftBackground" format="reference" />
         <!-- The background for the right edge key press feedback. -->
         <attr name="keyPreviewRightBackground" format="reference" />
-        <!-- The text color for key press feedback. -->
-        <attr name="keyPreviewTextColor" format="color" />
         <!-- Vertical offset of the key press feedback from the key. -->
         <attr name="keyPreviewOffset" format="dimension" />
         <!-- Height of the key press feedback popup. -->
         <attr name="keyPreviewHeight" format="dimension" />
-        <!-- Size of the text for key press feedback popup, in the proportion of key height. -->
-        <attr name="keyPreviewTextRatio" format="fraction" />
         <!-- Delay after key releasing and key press feedback dismissing in millisecond -->
         <attr name="keyPreviewLingerTimeout" format="integer" />
 
@@ -105,18 +62,8 @@
         <!-- Layout resource for more keys panel -->
         <attr name="moreKeysLayout" format="reference" />
 
-        <attr name="shadowColor" format="color" />
-        <attr name="shadowRadius" format="float" />
         <attr name="backgroundDimAlpha" format="integer" />
 
-        <attr name="keyTypeface" format="enum">
-            <!-- This should be aligned with Typeface.NORMAL etc. -->
-            <enum name="normal" value="0" />
-            <enum name="bold" value="1" />
-            <enum name="italic" value="2" />
-            <enum name="boldItalic" value="3" />
-        </attr>
-
         <!-- Attributes for PreviewPlacerView -->
         <attr name="gestureFloatingPreviewTextSize" format="dimension" />
         <attr name="gestureFloatingPreviewTextColor" format="color" />
@@ -335,6 +282,59 @@
         <!-- The X-coordinate of upper right corner of this key including horizontal gap.
              If the value is negative, the origin is the right edge of the keyboard. -->
         <attr name="keyXPos" format="dimension|fraction" />
+
+        <!-- Key top visual attributes -->
+        <attr name="keyTypeface" format="enum">
+            <!-- This should be aligned with Typeface.NORMAL etc. -->
+            <enum name="normal" value="0" />
+            <enum name="bold" value="1" />
+            <enum name="italic" value="2" />
+            <enum name="boldItalic" value="3" />
+        </attr>
+        <!-- Size of the text for one letter keys. If specified as fraction, the text size is
+             measured in the proportion of key height. -->
+        <attr name="keyLetterSize" format="dimension|fraction" />
+        <!-- Size of the text for keys with multiple letters. If specified as fraction, the text
+             size is measured in the proportion of key height. -->
+        <attr name="keyLabelSize" format="dimension|fraction" />
+        <!-- Large size of the text for one letter keys, in the proportion of key height. -->
+        <attr name="keyLargeLetterRatio" format="fraction" />
+        <!-- Large size of the text for keys with multiple letters, in the proportion of key height. -->
+        <attr name="keyLargeLabelRatio" format="fraction" />
+        <!-- Size of the text for hint letter (= one character hint label), in the proportion of
+             key height. -->
+        <attr name="keyHintLetterRatio" format="fraction" />
+        <!-- Size of the text for hint label, in the proportion of key height. -->
+        <attr name="keyHintLabelRatio" format="fraction" />
+        <!-- Size of the text for shifted letter hint, in the proportion of key height. -->
+        <attr name="keyShiftedLetterHintRatio" format="dimension|fraction" />
+        <!-- Horizontal padding of left/right aligned key label to the edge of the key. -->
+        <attr name="keyLabelHorizontalPadding" format="dimension" />
+        <!-- Right padding of hint letter to the edge of the key.-->
+        <attr name="keyHintLetterPadding" format="dimension" />
+        <!-- Bottom padding of popup hint letter "..." to the edge of the key.-->
+        <attr name="keyPopupHintLetterPadding" format="dimension" />
+        <!-- Right padding of shifted letter hint to the edge of the key.-->
+        <attr name="keyShiftedLetterHintPadding" format="dimension" />
+        <!-- Color to use for the label in a key. -->
+        <attr name="keyTextColor" format="color" />
+        <attr name="keyTextShadowColor" format="color" />
+        <attr name="keyTextShadowRadius" format="float" />
+        <!-- Color to use for the label in a key when in inactivated state. -->
+        <attr name="keyTextInactivatedColor" format="color" />
+        <!-- Key hint letter (= one character hint label) color -->
+        <attr name="keyHintLetterColor" format="color" />
+        <!-- Key hint label color -->
+        <attr name="keyHintLabelColor" format="color" />
+        <!-- Shifted letter hint colors -->
+        <attr name="keyShiftedLetterHintInactivatedColor" format="color" />
+        <attr name="keyShiftedLetterHintActivatedColor" format="color" />
+
+        <!-- Key preview visual parameters -->
+        <!-- The text color for key press feedback. -->
+        <attr name="keyPreviewTextColor" format="color" />
+        <!-- Size of the text for key press feedback popup, in the proportion of key height. -->
+        <attr name="keyPreviewTextRatio" format="fraction" />
     </declare-styleable>
 
     <declare-styleable name="Keyboard_Include">
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index a52ee06..634b32a 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -64,8 +64,8 @@
         <item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
         <item name="moreKeysLayout">@layout/more_keys_keyboard</item>
         <item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
-        <item name="shadowColor">#BB000000</item>
-        <item name="shadowRadius">2.75</item>
+        <item name="keyTextShadowColor">#BB000000</item>
+        <item name="keyTextShadowRadius">2.75</item>
         <item name="backgroundDimAlpha">128</item>
         <!-- android:color/holo_blue_light=#FF33B5E5 -->
         <item name="gestureFloatingPreviewTextSize">@dimen/gesture_floating_preview_text_size</item>
@@ -203,7 +203,7 @@
         <item name="keyHintLabelColor">#E0000000</item>
         <item name="keyShiftedLetterHintInactivatedColor">#66000000</item>
         <item name="keyShiftedLetterHintActivatedColor">#CC000000</item>
-        <item name="shadowColor">#FFFFFFFF</item>
+        <item name="keyTextShadowColor">#FFFFFFFF</item>
     </style>
     <style
         name="MainKeyboardView.Stone"
@@ -229,7 +229,7 @@
     >
         <item name="keyBackground">@drawable/btn_keyboard_key_stone</item>
         <item name="keyTextColor">#FF000000</item>
-        <item name="shadowColor">#FFFFFFFF</item>
+        <item name="keyTextShadowColor">#FFFFFFFF</item>
     </style>
     <!-- Theme "Stone bold" -->
     <style
@@ -328,8 +328,8 @@
         <item name="keyPreviewRightBackground">@drawable/keyboard_key_feedback_right_ics</item>
         <item name="keyPreviewTextColor">#FFFFFFFF</item>
         <item name="keyPreviewOffset">@dimen/key_preview_offset_ics</item>
-        <item name="shadowColor">#00000000</item>
-        <item name="shadowRadius">0.0</item>
+        <item name="keyTextShadowColor">#00000000</item>
+        <item name="keyTextShadowRadius">0.0</item>
     </style>
     <style
         name="MainKeyboardView.IceCreamSandwich"
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index b909a3a..c37285c 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -188,8 +188,8 @@
         public final float mKeyHintLetterPadding;
         public final float mKeyPopupHintLetterPadding;
         public final float mKeyShiftedLetterHintPadding;
-        public final int mShadowColor;
-        public final float mShadowRadius;
+        public final int mKeyTextShadowColor;
+        public final float mKeyTextShadowRadius;
         public final Drawable mKeyBackground;
         public final int mKeyHintLetterColor;
         public final int mKeyHintLabelColor;
@@ -217,52 +217,55 @@
         public int mKeyHintLabelSize;
         public int mAnimAlpha;
 
-        public KeyDrawParams(final TypedArray a) {
-            mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
-            mKeyLetterRatio = ResourceUtils.getFraction(a, R.styleable.KeyboardView_keyLetterSize);
-            mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(a,
-                    R.styleable.KeyboardView_keyLetterSize);
-            mKeyLabelRatio = ResourceUtils.getFraction(a, R.styleable.KeyboardView_keyLabelSize);
-            mKeyLabelSize = ResourceUtils.getDimensionPixelSize(a,
-                    R.styleable.KeyboardView_keyLabelSize);
-            mKeyLargeLabelRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyLargeLabelRatio);
-            mKeyLargeLetterRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyLargeLetterRatio);
-            mKeyHintLetterRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyHintLetterRatio);
-            mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyShiftedLetterHintRatio);
-            mKeyHintLabelRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyHintLabelRatio);
-            mKeyLabelHorizontalPadding = a.getDimension(
-                    R.styleable.KeyboardView_keyLabelHorizontalPadding, 0);
-            mKeyHintLetterPadding = a.getDimension(
-                    R.styleable.KeyboardView_keyHintLetterPadding, 0);
-            mKeyPopupHintLetterPadding = a.getDimension(
-                    R.styleable.KeyboardView_keyPopupHintLetterPadding, 0);
-            mKeyShiftedLetterHintPadding = a.getDimension(
-                    R.styleable.KeyboardView_keyShiftedLetterHintPadding, 0);
-            mKeyTextColor = a.getColor(
-                    R.styleable.KeyboardView_keyTextColor, Color.WHITE);
-            mKeyTextInactivatedColor = a.getColor(
-                    R.styleable.KeyboardView_keyTextInactivatedColor, Color.WHITE);
-            mKeyHintLetterColor = a.getColor(
-                    R.styleable.KeyboardView_keyHintLetterColor, Color.TRANSPARENT);
-            mKeyHintLabelColor = a.getColor(
-                    R.styleable.KeyboardView_keyHintLabelColor, Color.TRANSPARENT);
-            mKeyShiftedLetterHintInactivatedColor = a.getColor(
-                    R.styleable.KeyboardView_keyShiftedLetterHintInactivatedColor,
-                    Color.TRANSPARENT);
-            mKeyShiftedLetterHintActivatedColor = a.getColor(
-                    R.styleable.KeyboardView_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
-            mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
-                    a.getInt(R.styleable.KeyboardView_keyTypeface, Typeface.NORMAL));
-            mKeyTypeface = mKeyTypefaceFromKeyboardView;
-            mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor, Color.TRANSPARENT);
-            mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
-
+        public KeyDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
+            mKeyBackground = keyboardViewAttr.getDrawable(R.styleable.KeyboardView_keyBackground);
             mKeyBackground.getPadding(mPadding);
+
+            mKeyLetterRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyLetterSize);
+            mKeyLetterSizeFromKeyboardView = ResourceUtils.getDimensionPixelSize(keyAttr,
+                    R.styleable.Keyboard_Key_keyLetterSize);
+            mKeyLabelRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyLabelSize);
+            mKeyLabelSize = ResourceUtils.getDimensionPixelSize(keyAttr,
+                    R.styleable.Keyboard_Key_keyLabelSize);
+            mKeyLargeLabelRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyLargeLabelRatio);
+            mKeyLargeLetterRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyLargeLetterRatio);
+            mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyHintLetterRatio);
+            mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
+            mKeyHintLabelRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyHintLabelRatio);
+            mKeyLabelHorizontalPadding = keyAttr.getDimension(
+                    R.styleable.Keyboard_Key_keyLabelHorizontalPadding, 0);
+            mKeyHintLetterPadding = keyAttr.getDimension(
+                    R.styleable.Keyboard_Key_keyHintLetterPadding, 0);
+            mKeyPopupHintLetterPadding = keyAttr.getDimension(
+                    R.styleable.Keyboard_Key_keyPopupHintLetterPadding, 0);
+            mKeyShiftedLetterHintPadding = keyAttr.getDimension(
+                    R.styleable.Keyboard_Key_keyShiftedLetterHintPadding, 0);
+            mKeyTextColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyTextColor, Color.WHITE);
+            mKeyTextInactivatedColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyTextInactivatedColor, Color.WHITE);
+            mKeyHintLetterColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyHintLetterColor, Color.TRANSPARENT);
+            mKeyHintLabelColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyHintLabelColor, Color.TRANSPARENT);
+            mKeyShiftedLetterHintInactivatedColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyShiftedLetterHintInactivatedColor,
+                    Color.TRANSPARENT);
+            mKeyShiftedLetterHintActivatedColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyShiftedLetterHintActivatedColor, Color.TRANSPARENT);
+            mKeyTypefaceFromKeyboardView = Typeface.defaultFromStyle(
+                    keyAttr.getInt(R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
+            mKeyTextShadowColor = keyAttr.getColor(
+                    R.styleable.Keyboard_Key_keyTextShadowColor, Color.TRANSPARENT);
+            mKeyTextShadowRadius = keyAttr.getFloat(
+                    R.styleable.Keyboard_Key_keyTextShadowRadius, 0f);
         }
 
         public void updateParams(final Keyboard keyboard) {
@@ -357,23 +360,26 @@
 
         private static final int PREVIEW_ALPHA = 240;
 
-        public KeyPreviewDrawParams(final TypedArray a) {
-            mPreviewBackground = a.getDrawable(R.styleable.KeyboardView_keyPreviewBackground);
-            mPreviewLeftBackground = a.getDrawable(
+        public KeyPreviewDrawParams(final TypedArray keyboardViewAttr, final TypedArray keyAttr) {
+            mPreviewBackground = keyboardViewAttr.getDrawable(
+                    R.styleable.KeyboardView_keyPreviewBackground);
+            mPreviewLeftBackground = keyboardViewAttr.getDrawable(
                     R.styleable.KeyboardView_keyPreviewLeftBackground);
-            mPreviewRightBackground = a.getDrawable(
+            mPreviewRightBackground = keyboardViewAttr.getDrawable(
                     R.styleable.KeyboardView_keyPreviewRightBackground);
             setAlpha(mPreviewBackground, PREVIEW_ALPHA);
             setAlpha(mPreviewLeftBackground, PREVIEW_ALPHA);
             setAlpha(mPreviewRightBackground, PREVIEW_ALPHA);
-            mPreviewOffset = a.getDimensionPixelOffset(
+            mPreviewOffset = keyboardViewAttr.getDimensionPixelOffset(
                     R.styleable.KeyboardView_keyPreviewOffset, 0);
-            mPreviewHeight = a.getDimensionPixelSize(
+            mPreviewHeight = keyboardViewAttr.getDimensionPixelSize(
                     R.styleable.KeyboardView_keyPreviewHeight, 80);
-            mPreviewTextRatio = ResourceUtils.getFraction(a,
-                    R.styleable.KeyboardView_keyPreviewTextRatio);
-            mPreviewTextColor = a.getColor(R.styleable.KeyboardView_keyPreviewTextColor, 0);
-            mLingerTimeout = a.getInt(R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
+            mLingerTimeout = keyboardViewAttr.getInt(
+                    R.styleable.KeyboardView_keyPreviewLingerTimeout, 0);
+
+            mPreviewTextRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyPreviewTextRatio);
+            mPreviewTextColor = keyAttr.getColor(R.styleable.Keyboard_Key_keyPreviewTextColor, 0);
         }
 
         public void updateParams(final Keyboard keyboard, final KeyDrawParams keyDrawParams) {
@@ -398,20 +404,26 @@
     public KeyboardView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
 
-        final TypedArray a = context.obtainStyledAttributes(
-                attrs, R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
-        mKeyDrawParams = new KeyDrawParams(a);
-        mKeyPreviewDrawParams = new KeyPreviewDrawParams(a);
+        final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs,
+                R.styleable.KeyboardView, defStyle, R.style.KeyboardView);
+        final TypedArray keyAttr = context.obtainStyledAttributes(attrs,
+                R.styleable.Keyboard_Key, defStyle, R.style.KeyboardView);
+        mKeyDrawParams = new KeyDrawParams(keyboardViewAttr, keyAttr);
+        mKeyPreviewDrawParams = new KeyPreviewDrawParams(keyboardViewAttr, keyAttr);
         mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout;
-        mKeyPreviewLayoutId = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
+        mKeyPreviewLayoutId = keyboardViewAttr.getResourceId(
+                R.styleable.KeyboardView_keyPreviewLayout, 0);
         if (mKeyPreviewLayoutId == 0) {
             mShowKeyPreviewPopup = false;
         }
-        mVerticalCorrection = a.getDimensionPixelOffset(
+        mVerticalCorrection = keyboardViewAttr.getDimensionPixelOffset(
                 R.styleable.KeyboardView_verticalCorrection, 0);
-        mMoreKeysLayout = a.getResourceId(R.styleable.KeyboardView_moreKeysLayout, 0);
-        mBackgroundDimAlpha = a.getInt(R.styleable.KeyboardView_backgroundDimAlpha, 0);
-        a.recycle();
+        mMoreKeysLayout = keyboardViewAttr.getResourceId(
+                R.styleable.KeyboardView_moreKeysLayout, 0);
+        mBackgroundDimAlpha = keyboardViewAttr.getInt(
+                R.styleable.KeyboardView_backgroundDimAlpha, 0);
+        keyboardViewAttr.recycle();
+        keyAttr.recycle();
 
         mPreviewPlacerView = new PreviewPlacerView(context, attrs);
         mPaint.setAntiAlias(true);
@@ -705,7 +717,7 @@
                     ? params.mKeyTextInactivatedColor : params.mKeyTextColor);
             if (key.isEnabled()) {
                 // Set a drop shadow for the text
-                paint.setShadowLayer(params.mShadowRadius, 0, 0, params.mShadowColor);
+                paint.setShadowLayer(params.mKeyTextShadowRadius, 0, 0, params.mKeyTextShadowColor);
             } else {
                 // Make label invisible
                 paint.setColor(Color.TRANSPARENT);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index c20b455..3d1045f 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -237,8 +237,6 @@
                 R.style.Keyboard);
         final TypedArray keyAttr = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                 R.styleable.Keyboard_Key);
-        final TypedArray keyboardViewAttr = mResources.obtainAttributes(
-                Xml.asAttributeSet(parser), R.styleable.KeyboardView);
         try {
             final int displayHeight = mDisplayMetrics.heightPixels;
             final String keyboardHeightString = ResourceUtils.getDeviceOverrideValue(
@@ -291,18 +289,18 @@
                     R.styleable.Keyboard_rowHeight, params.mBaseHeight,
                     params.mBaseHeight / DEFAULT_KEYBOARD_ROWS);
 
-            if (keyboardViewAttr.hasValue(R.styleable.KeyboardView_keyTypeface)) {
-                params.mKeyTypeface = Typeface.defaultFromStyle(keyboardViewAttr.getInt(
-                        R.styleable.KeyboardView_keyTypeface, Typeface.NORMAL));
+            if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyTypeface)) {
+                params.mKeyTypeface = Typeface.defaultFromStyle(keyAttr.getInt(
+                        R.styleable.Keyboard_Key_keyTypeface, Typeface.NORMAL));
             }
-            params.mKeyLetterRatio = ResourceUtils.getFraction(keyboardViewAttr,
-                    R.styleable.KeyboardView_keyLetterSize);
-            params.mKeyLetterSize = ResourceUtils.getDimensionPixelSize(keyboardViewAttr,
-                    R.styleable.KeyboardView_keyLetterSize);
-            params.mKeyHintLetterRatio = ResourceUtils.getFraction(keyboardViewAttr,
-                    R.styleable.KeyboardView_keyHintLetterRatio);
-            params.mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyboardViewAttr,
-                    R.styleable.KeyboardView_keyShiftedLetterHintRatio);
+            params.mKeyLetterRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyLetterSize);
+            params.mKeyLetterSize = ResourceUtils.getDimensionPixelSize(keyAttr,
+                    R.styleable.Keyboard_Key_keyLetterSize);
+            params.mKeyHintLetterRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyHintLetterRatio);
+            params.mKeyShiftedLetterHintRatio = ResourceUtils.getFraction(keyAttr,
+                    R.styleable.Keyboard_Key_keyShiftedLetterHintRatio);
 
             params.mMoreKeysTemplate = keyboardAttr.getResourceId(
                     R.styleable.Keyboard_moreKeysTemplate, 0);
@@ -334,7 +332,6 @@
                 params.mTouchPositionCorrection.load(data);
             }
         } finally {
-            keyboardViewAttr.recycle();
             keyAttr.recycle();
             keyboardAttr.recycle();
         }