Tune mini keyboard visual

This change only gets rid of the surrounding paddings of the mini keyboard.

Bug: 5248783
Change-Id: Idb95ac1467085c230fd60e4bc0f466fef5700bfb
diff --git a/java/res/drawable-hdpi/btn_keyboard_key_popup_background_holo.9.png b/java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png
similarity index 100%
rename from java/res/drawable-hdpi/btn_keyboard_key_popup_background_holo.9.png
rename to java/res/drawable-hdpi/keyboard_popup_panel_background_holo.9.png
Binary files differ
diff --git a/java/res/drawable-mdpi/btn_keyboard_key_popup_background_holo.9.png b/java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png
similarity index 100%
rename from java/res/drawable-mdpi/btn_keyboard_key_popup_background_holo.9.png
rename to java/res/drawable-mdpi/keyboard_popup_panel_background_holo.9.png
Binary files differ
diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_popup_background_holo.9.png b/java/res/drawable-xhdpi/keyboard_popup_panel_background_holo.9.png
similarity index 100%
rename from java/res/drawable-xhdpi/btn_keyboard_key_popup_background_holo.9.png
rename to java/res/drawable-xhdpi/keyboard_popup_panel_background_holo.9.png
Binary files differ
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 20f1e32..e964889 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -22,6 +22,8 @@
         <attr name="latinKeyboardStyle" format="reference" />
         <!-- KeyboardView style -->
         <attr name="keyboardViewStyle" format="reference" />
+        <!-- MiniKeyboard style -->
+        <attr name="miniKeyboardStyle" format="reference" />
         <!-- MiniKeyboardView style -->
         <attr name="miniKeyboardViewStyle" format="reference" />
         <attr name="miniKeyboardPanelStyle" format="reference" />
@@ -130,15 +132,15 @@
 
     <declare-styleable name="Keyboard">
         <!-- Default keyboard height -->
-        <attr name="keyboardHeight" format="dimension" />
+        <attr name="keyboardHeight" format="dimension|fraction" />
         <!-- Maximum keyboard height, in pixels or percentage of display height -->
         <attr name="maxKeyboardHeight" format="dimension|fraction" />
         <!-- Minimum keyboard height represented in pixels, percentage of display height if fraction
              is positive, or percentage of display width if fraction is negative. -->
         <attr name="minKeyboardHeight" format="dimension|fraction" />
         <!-- Keyboard top and bottom paddings. -->
-        <attr name="keyboardTopPadding" format="dimension" />
-        <attr name="keyboardBottomPadding" format="dimension" />
+        <attr name="keyboardTopPadding" format="dimension|fraction" />
+        <attr name="keyboardBottomPadding" format="dimension|fraction" />
         <!-- Default width of a key, in pixels or percentage of display width.
              If the value is zero, the actual key width will be determined to fill out the area up
              to the right edge of the keyboard.
diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml
index e753474..a0ab695 100644
--- a/java/res/values/dimens.xml
+++ b/java/res/values/dimens.xml
@@ -48,7 +48,7 @@
     <fraction name="keyboard_bottom_padding_ics">4.669%p</fraction>
     <fraction name="key_bottom_gap_ics">6.127%p</fraction>
     <fraction name="key_horizontal_gap_ics">1.739%p</fraction>
-    <dimen name="mini_keyboard_horizontal_edges_padding_ics">6dp</dimen>
+    <dimen name="mini_keyboard_horizontal_edges_padding_ics">4dip</dimen>
 
     <!-- Amount of allowance for selecting keys in a mini popup keyboard by sliding finger. -->
     <!-- popup_key_height x 1.2 -->
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index dc2021a..0e8216b 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -68,6 +68,14 @@
         <item name="backgroundDimAmount">0.5</item>
     </style>
     <style
+        name="MiniKeyboard"
+        parent="Keyboard"
+    >
+        <item name="keyboardTopPadding">0dip</item>
+        <item name="keyboardBottomPadding">0dip</item>
+        <item name="horizontalGap">0dip</item>
+    </style>
+    <style
         name="MiniKeyboardView"
         parent="KeyboardView"
     >
@@ -146,6 +154,14 @@
         <item name="shadowColor">#FFFFFFFF</item>
     </style>
     <style
+        name="MiniKeyboard.Stone"
+        parent="Keyboard.Stone"
+    >
+        <item name="keyboardTopPadding">0dip</item>
+        <item name="keyboardBottomPadding">0dip</item>
+        <item name="horizontalGap">0dip</item>
+    </style>
+    <style
         name="MiniKeyboardView.Stone"
         parent="MiniKeyboardView"
     >
@@ -177,6 +193,14 @@
         <item name="keyTextStyle">bold</item>
     </style>
     <style
+        name="MiniKeyboard.Gingerbread"
+        parent="Keyboard.Gingerbread"
+    >
+        <item name="keyboardTopPadding">0dip</item>
+        <item name="keyboardBottomPadding">0dip</item>
+        <item name="horizontalGap">0dip</item>
+    </style>
+    <style
         name="MiniKeyboardView.Gingerbread"
         parent="MiniKeyboardView"
     >
@@ -220,6 +244,14 @@
         <item name="shadowRadius">0.0</item>
     </style>
     <style
+        name="MiniKeyboard.IceCreamSandwich"
+        parent="Keyboard.IceCreamSandwich"
+    >
+        <item name="keyboardTopPadding">0dip</item>
+        <item name="keyboardBottomPadding">0dip</item>
+        <item name="horizontalGap">0dip</item>
+    </style>
+    <style
         name="MiniKeyboardView.IceCreamSandwich"
         parent="MiniKeyboardView"
     >
@@ -227,7 +259,7 @@
         <item name="keyBackground">@drawable/btn_keyboard_key_popup_ics</item>
     </style>
     <style name="MiniKeyboardPanelStyle.IceCreamSandwich">
-        <item name="android:background">@drawable/btn_keyboard_key_popup_background_holo</item>
+        <item name="android:background">@drawable/keyboard_popup_panel_background_holo</item>
         <item name="android:paddingLeft">@dimen/mini_keyboard_horizontal_edges_padding_ics</item>
         <item name="android:paddingRight">@dimen/mini_keyboard_horizontal_edges_padding_ics</item>
     </style>
diff --git a/java/res/values/themes-basic-highcontrast.xml b/java/res/values/themes-basic-highcontrast.xml
index a45fa52..ce05980 100644
--- a/java/res/values/themes-basic-highcontrast.xml
+++ b/java/res/values/themes-basic-highcontrast.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
         <item name="keyboardViewStyle">@style/KeyboardView.HighContrast</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
diff --git a/java/res/values/themes-basic.xml b/java/res/values/themes-basic.xml
index 4f75484..ff9fed5 100644
--- a/java/res/values/themes-basic.xml
+++ b/java/res/values/themes-basic.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
         <item name="keyboardViewStyle">@style/KeyboardView</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
diff --git a/java/res/values/themes-gingerbread.xml b/java/res/values/themes-gingerbread.xml
index f3a74f3..be853eb 100644
--- a/java/res/values/themes-gingerbread.xml
+++ b/java/res/values/themes-gingerbread.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard.Gingerbread</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard</item>
         <item name="keyboardViewStyle">@style/KeyboardView.Gingerbread</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard.Gingerbread</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Gingerbread</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
diff --git a/java/res/values/themes-ics.xml b/java/res/values/themes-ics.xml
index 4b5ae6d..618aaed 100644
--- a/java/res/values/themes-ics.xml
+++ b/java/res/values/themes-ics.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard.IceCreamSandwich</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard.IceCreamSandwich</item>
         <item name="keyboardViewStyle">@style/KeyboardView.IceCreamSandwich</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard.IceCreamSandwich</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.IceCreamSandwich</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle.IceCreamSandwich</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle.IceCreamSandwich</item>
diff --git a/java/res/values/themes-stone-bold.xml b/java/res/values/themes-stone-bold.xml
index 3cff0f1..fdf9c51 100644
--- a/java/res/values/themes-stone-bold.xml
+++ b/java/res/values/themes-stone-bold.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard.Stone</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item>
         <item name="keyboardViewStyle">@style/KeyboardView.Stone.Bold</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard.Stone</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Stone</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
diff --git a/java/res/values/themes-stone.xml b/java/res/values/themes-stone.xml
index 785f410..cb3edc5 100644
--- a/java/res/values/themes-stone.xml
+++ b/java/res/values/themes-stone.xml
@@ -19,6 +19,7 @@
         <item name="keyboardStyle">@style/Keyboard.Stone</item>
         <item name="latinKeyboardStyle">@style/LatinKeyboard.Stone</item>
         <item name="keyboardViewStyle">@style/KeyboardView.Stone</item>
+        <item name="miniKeyboardStyle">@style/MiniKeyboard.Stone</item>
         <item name="miniKeyboardViewStyle">@style/MiniKeyboardView.Stone</item>
         <item name="miniKeyboardPanelStyle">@style/MiniKeyboardPanelStyle</item>
         <item name="suggestionsStripBackgroundStyle">@style/SuggestionsStripBackgroundStyle</item>
diff --git a/java/res/xml/kbd_mini_keyboard_template.xml b/java/res/xml/kbd_mini_keyboard_template.xml
index d25878b..ad6cf51 100644
--- a/java/res/xml/kbd_mini_keyboard_template.xml
+++ b/java/res/xml/kbd_mini_keyboard_template.xml
@@ -21,5 +21,6 @@
 <Keyboard xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
     latin:keyWidth="10%p"
     latin:rowHeight="@dimen/popup_key_height"
+    style="?attr/miniKeyboardStyle"
     >
 </Keyboard>
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index da91b62..ad8056c 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -123,7 +123,9 @@
                 }
 
                 mWidth = mOccupiedWidth = mNumColumns * mDefaultKeyWidth;
-                mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight + mVerticalGap;
+                // Need to subtract the bottom row's gutter only.
+                mHeight = mOccupiedHeight = mNumRows * mDefaultRowHeight - mVerticalGap
+                        + mTopPadding + mBottomPadding;
             }
 
             // Return key position according to column count (0 is default).
@@ -209,20 +211,9 @@
             super(view.getContext(), new MiniKeyboardParams());
             load(parentKeyboard.mId.cloneWithNewXml(mResources.getResourceEntryName(xmlId), xmlId));
 
-            // HACK: Current mini keyboard design totally relies on the 9-patch
-            // padding about horizontal
-            // and vertical key spacing. To keep the visual of mini keyboard as
-            // is, these hacks are
-            // needed to keep having the same horizontal and vertical key
-            // spacing.
-            mParams.mHorizontalGap = 0;
-            mParams.mVerticalGap = mParams.mTopPadding = parentKeyboard.mVerticalGap / 2;
-            // TODO: When we have correctly padded key background 9-patch
-            // drawables for mini keyboard,
-            // revert the above hacks and uncomment the following lines.
-            // mParams.mHorizontalGap = parentKeyboard.mHorizontalGap;
-            // mParams.mVerticalGap = parentKeyboard.mVerticalGap;
-
+            // TODO: Mini keyboard's vertical gap is currently calculated heuristically.
+            // Should revise the algorithm.
+            mParams.mVerticalGap = parentKeyboard.mVerticalGap / 2;
             mParams.mIsRtlKeyboard = parentKeyboard.mIsRtlKeyboard;
             mMoreKeys = parentKey.mMoreKeys;