From ea0c567f86bd19015d53fc038c4579df776cfec3 Mon Sep 17 00:00:00 2001
From: "Tadashi G. Takaoka" <takaoka@google.com>
Date: Mon, 5 Sep 2011 18:58:30 +0900
Subject: [PATCH] Tune mini keyboard visual

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

Bug: 5248783
Change-Id: Idb95ac1467085c230fd60e4bc0f466fef5700bfb
---
 ...eyboard_popup_panel_background_holo.9.png} | Bin
 ...eyboard_popup_panel_background_holo.9.png} | Bin
 ...eyboard_popup_panel_background_holo.9.png} | Bin
 java/res/values/attrs.xml                     |   8 +++--
 java/res/values/dimens.xml                    |   2 +-
 java/res/values/styles.xml                    |  34 +++++++++++++++++-
 java/res/values/themes-basic-highcontrast.xml |   1 +
 java/res/values/themes-basic.xml              |   1 +
 java/res/values/themes-gingerbread.xml        |   1 +
 java/res/values/themes-ics.xml                |   1 +
 java/res/values/themes-stone-bold.xml         |   1 +
 java/res/values/themes-stone.xml              |   1 +
 java/res/xml/kbd_mini_keyboard_template.xml   |   1 +
 .../inputmethod/keyboard/MiniKeyboard.java    |  21 ++++-------
 14 files changed, 52 insertions(+), 20 deletions(-)
 rename java/res/drawable-hdpi/{btn_keyboard_key_popup_background_holo.9.png => keyboard_popup_panel_background_holo.9.png} (100%)
 rename java/res/drawable-mdpi/{btn_keyboard_key_popup_background_holo.9.png => keyboard_popup_panel_background_holo.9.png} (100%)
 rename java/res/drawable-xhdpi/{btn_keyboard_key_popup_background_holo.9.png => keyboard_popup_panel_background_holo.9.png} (100%)

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
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
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
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 20f1e32c86..e964889c48 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 e75347442f..a0ab695289 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 dc2021a44d..0e8216b480 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -67,6 +67,14 @@
         <item name="shadowRadius">2.75</item>
         <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"
@@ -145,6 +153,14 @@
         <item name="keyUppercaseLetterActivatedColor">#CC000000</item>
         <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"
@@ -176,6 +192,14 @@
         <item name="keyBackground">@drawable/btn_keyboard_key_gingerbread</item>
         <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"
@@ -219,6 +243,14 @@
         <item name="shadowColor">#00000000</item>
         <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 a45fa52391..ce05980424 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 4f754844f8..ff9fed55f2 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 f3a74f33e5..be853eb0f7 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 4b5ae6d20d..618aaed79e 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 3cff0f1236..fdf9c51f54 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 785f4107f2..cb3edc58f4 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 d25878b483..ad6cf51fe3 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 da91b62d9a..ad8056cc0a 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -123,7 +123,9 @@ public class MiniKeyboard extends Keyboard {
                 }
 
                 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 @@ public class MiniKeyboard extends Keyboard {
             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;
 
-- 
GitLab