diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 0be4cec717983dff8f4ef916782b6202ec72bee6..72e3f0dd09c45568c89df9da43d7a686566fe848 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -112,9 +112,6 @@
         <attr name="keyIcon" format="reference" />
         <!-- The hint icon to display on the key in conjunction with the label -->
         <attr name="keyHintIcon" format="reference" />
-        <!-- Mode of the keyboard. If the mode doesn't match the
-             requested keyboard mode, the key will be skipped. -->
-        <attr name="keyboardMode" />
     </declare-styleable>
 
     <declare-styleable name="BaseKeyboard_Row">
@@ -125,12 +122,15 @@
             <!-- Row is anchored to the bottom of the keyboard. -->
             <flag name="bottom" value="8" />
         </attr>
-        <!-- Mode of the keyboard. If the mode doesn't match the
-             requested keyboard mode, the row will be skipped. -->
-        <attr name="keyboardMode" format="reference" />
     </declare-styleable>
 
     <declare-styleable name="BaseKeyboard_Include">
         <attr name="keyboardLayout" format="reference" />
     </declare-styleable>
+
+    <declare-styleable name="BaseKeyboard_Case">
+        <attr name="mode" format="string" />
+        <attr name="settingsKey" format="string" />
+        <attr name="voiceKey" format="string" />
+    </declare-styleable>
 </resources>
diff --git a/java/res/xml-xlarge/kbd_qwerty.xml b/java/res/xml-xlarge/kbd_qwerty.xml
index b4b880ed795ff566fd8ebd5650b7fc73542daf80..6000911f6fa599a1f9931dc4dbfa5300dba0e027 100644
--- a/java/res/xml-xlarge/kbd_qwerty.xml
+++ b/java/res/xml-xlarge/kbd_qwerty.xml
@@ -25,85 +25,8 @@
     latin:verticalGap="@dimen/key_bottom_gap"
     latin:keyHeight="@dimen/key_height"
 >
-    <!-- This row is intentionally not marked as a top row -->
-    <Row>
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row1_common" />
-    </Row>
-    <!-- TODO: We should have new attributes for <Key> to eliminate these excess duplications -->
-    <Row
-        latin:keyboardMode="@+id/mode_normal"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row2_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row2_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row2_email" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row2_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row2_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_normal"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row3_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row3_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row3_email" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row3_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row3_common" />
-    </Row>
-    <!-- This row is intentionally not marked as a bottom row -->
-    <Row
-        latin:keyboardMode="@+id/mode_normal"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row4_url" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row4_email" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry"
-    >
-        <include latin:keyboardLayout="@xml/kbd_qwerty_row4_common" />
-    </Row>
+    <include latin:keyboardLayout="@xml/kbd_qwerty_row1" />
+    <include latin:keyboardLayout="@xml/kbd_qwerty_row2" />
+    <include latin:keyboardLayout="@xml/kbd_qwerty_row3" />
+    <include latin:keyboardLayout="@xml/kbd_qwerty_row4" />
 </Keyboard>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row1.xml b/java/res/xml-xlarge/kbd_qwerty_row1.xml
new file mode 100644
index 0000000000000000000000000000000000000000..51a792798f7fe0e476e5af5bbb4862517f05266e
--- /dev/null
+++ b/java/res/xml-xlarge/kbd_qwerty_row1.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <!-- This row is intentionally not marked as a top row -->
+    <Row>
+        <Key
+            latin:codes="@integer/key_tab"
+            latin:keyLabel="Tab"
+            latin:keyWidth="7.0%p"
+            latin:isModifier="true"
+            latin:keyEdgeFlags="left" />
+        <Key
+            latin:keyLabel="q"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_q" />
+        <Key
+            latin:keyLabel="w"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_w" />
+        <Key
+            latin:keyLabel="e"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_e" />
+        <Key
+            latin:keyLabel="r"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_r" />
+        <Key
+            latin:keyLabel="t"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_t" />
+        <Key
+            latin:keyLabel="y"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_y" />
+        <Key
+            latin:keyLabel="u"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_u" />
+        <Key
+            latin:keyLabel="i"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_i" />
+        <Key
+            latin:keyLabel="o"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_o" />
+        <Key
+            latin:keyLabel="p"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_p" />
+        <Key
+            latin:codes="@integer/key_delete"
+            latin:keyIcon="@drawable/sym_keyboard_delete"
+            latin:iconPreview="@drawable/sym_keyboard_feedback_delete"
+            latin:keyWidth="11.0%p"
+            latin:isModifier="true"
+            latin:isRepeatable="true"
+            latin:keyEdgeFlags="right" />
+    </Row>
+</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row1_common.xml b/java/res/xml-xlarge/kbd_qwerty_row1_common.xml
deleted file mode 100644
index 95bed0d2271b26b14e3ca72cae8a96c7a0d4acd0..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row1_common.xml
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_tab"
-        latin:keyLabel="Tab"
-        latin:keyWidth="7.0%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="q"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_q" />
-    <Key
-        latin:keyLabel="w"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_w" />
-    <Key
-        latin:keyLabel="e"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_e" />
-    <Key
-        latin:keyLabel="r"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_r" />
-    <Key
-        latin:keyLabel="t"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_t" />
-    <Key
-        latin:keyLabel="y"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_y" />
-    <Key
-        latin:keyLabel="u"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_u" />
-    <Key
-        latin:keyLabel="i"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_i" />
-    <Key
-        latin:keyLabel="o"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_o" />
-    <Key
-        latin:keyLabel="p"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_p" />
-    <Key
-        latin:codes="@integer/key_delete"
-        latin:keyIcon="@drawable/sym_keyboard_delete"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_delete"
-        latin:keyWidth="11.0%p"
-        latin:isModifier="true"
-        latin:isRepeatable="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row2.xml b/java/res/xml-xlarge/kbd_qwerty_row2.xml
new file mode 100644
index 0000000000000000000000000000000000000000..96077306fa79ca842ec04d66dafeb83f5361aee7
--- /dev/null
+++ b/java/res/xml-xlarge/kbd_qwerty_row2.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row>
+        <Key
+            latin:codes="@integer/key_symbol"
+            latin:keyLabel="@string/label_symbol_key"
+            latin:keyWidth="9.7%p"
+            latin:isModifier="true"
+            latin:keyEdgeFlags="left" />
+        <Key
+            latin:keyLabel="a"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_a" />
+        <Key
+            latin:keyLabel="s"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_s" />
+        <Key
+            latin:keyLabel="d"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_d" />
+        <Key
+            latin:keyLabel="f" />
+        <Key
+            latin:keyLabel="g"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_g" />
+        <Key
+            latin:keyLabel="h" />
+        <Key
+            latin:keyLabel="j" />
+        <Key
+            latin:keyLabel="k" />
+        <Key
+            latin:keyLabel="l"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_l" />
+        <switch>
+            <case
+                latin:mode="email"
+            >
+                <Key
+                    latin:keyLabel="\@" />
+            </case>
+            <default>
+                <Key
+                    latin:keyLabel="\'"
+                    latin:temporaryShiftKeyLabel="&quot;"
+                    latin:keyHintIcon="@drawable/key_hint_quote_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="&quot;" />
+            </default>
+        </switch>
+        <Key
+            latin:codes="@integer/key_return"
+            latin:keyIcon="@drawable/sym_keyboard_return"
+            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+            latin:keyWidth="8.3%p"
+            latin:isModifier="true"
+            latin:keyEdgeFlags="right" />
+    </Row>
+</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row2_common.xml b/java/res/xml-xlarge/kbd_qwerty_row2_common.xml
deleted file mode 100644
index 54befcabe254862f84851a2a6d20900bb5ade239..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row2_common.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_symbol_key"
-        latin:keyWidth="9.7%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="a"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_a" />
-    <Key
-        latin:keyLabel="s"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_s" />
-    <Key
-        latin:keyLabel="d"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_d" />
-    <Key
-        latin:keyLabel="f" />
-    <Key
-        latin:keyLabel="g"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_g" />
-    <Key
-        latin:keyLabel="h" />
-    <Key
-        latin:keyLabel="j" />
-    <Key
-        latin:keyLabel="k" />
-    <Key
-        latin:keyLabel="l"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_l" />
-    <Key
-        latin:keyLabel="\'"
-        latin:temporaryShiftKeyLabel="&quot;"
-        latin:keyHintIcon="@drawable/key_hint_quote_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="&quot;" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="8.3%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row2_email.xml b/java/res/xml-xlarge/kbd_qwerty_row2_email.xml
deleted file mode 100644
index 7fd43ce687c5348144fa81100adbd6b04181e4c1..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row2_email.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_symbol_key"
-        latin:keyWidth="9.7%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="a"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_a" />
-    <Key
-        latin:keyLabel="s"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_s" />
-    <Key
-        latin:keyLabel="d"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_d" />
-    <Key
-        latin:keyLabel="f" />
-    <Key
-        latin:keyLabel="g"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_g" />
-    <Key
-        latin:keyLabel="h" />
-    <Key
-        latin:keyLabel="j" />
-    <Key
-        latin:keyLabel="k" />
-    <Key
-        latin:keyLabel="l"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_l" />
-    <Key
-        latin:keyLabel="\@" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="8.3%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row3.xml b/java/res/xml-xlarge/kbd_qwerty_row3.xml
new file mode 100644
index 0000000000000000000000000000000000000000..77a4d4815caf474b7639e2bb963b3ef1e653031d
--- /dev/null
+++ b/java/res/xml-xlarge/kbd_qwerty_row3.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row>
+        <Key
+            latin:codes="@integer/key_shift"
+            latin:keyIcon="@drawable/sym_keyboard_shift"
+            latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
+            latin:keyWidth="13.1%p"
+            latin:isModifier="true"
+            latin:isSticky="true"
+            latin:keyEdgeFlags="left" />
+        <Key
+            latin:keyLabel="z"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_z" />
+        <Key
+            latin:keyLabel="x" />
+        <Key
+            latin:keyLabel="c"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_c" />
+        <Key
+            latin:keyLabel="v"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_v" />
+        <Key
+            latin:keyLabel="b" />
+        <Key
+            latin:keyLabel="n"
+            latin:popupKeyboard="@xml/kbd_popup_template"
+            latin:popupCharacters="@string/alternates_for_n" />
+        <Key
+            latin:keyLabel="m" />
+        <switch>
+            <case
+                latin:mode="email"
+            >
+                <Key
+                    latin:keyLabel="," />
+                <Key
+                    latin:keyLabel="." />
+            </case>
+            <default>
+                <Key
+                    latin:keyLabel=","
+                    latin:temporaryShiftKeyLabel="!"
+                    latin:keyHintIcon="@drawable/key_hint_exclamation_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="!" />
+                <Key
+                    latin:keyLabel="."
+                    latin:temporaryShiftKeyLabel="\?"
+                    latin:keyHintIcon="@drawable/key_hint_question_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="\?" />
+            </default>
+        </switch>
+        <Key
+            latin:codes="@integer/key_shift"
+            latin:keyIcon="@drawable/sym_keyboard_shift"
+            latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
+            latin:keyWidth="13.1%p"
+            latin:isModifier="true"
+            latin:isSticky="true"
+            latin:keyEdgeFlags="right" />
+    </Row>
+</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row3_common.xml b/java/res/xml-xlarge/kbd_qwerty_row3_common.xml
deleted file mode 100644
index eb1e18376a0c6abe2179b7dcf41bccbe640ac927..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row3_common.xml
+++ /dev/null
@@ -1,74 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_shift"
-        latin:keyIcon="@drawable/sym_keyboard_shift"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
-        latin:keyWidth="13.1%p"
-        latin:isModifier="true"
-        latin:isSticky="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="z"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_z" />
-    <Key
-        latin:keyLabel="x" />
-    <Key
-        latin:keyLabel="c"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_c" />
-    <Key
-        latin:keyLabel="v"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_v" />
-    <Key
-        latin:keyLabel="b" />
-    <Key
-        latin:keyLabel="n"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_n" />
-    <Key
-        latin:keyLabel="m" />
-    <Key
-        latin:keyLabel=","
-        latin:temporaryShiftKeyLabel="!"
-        latin:keyHintIcon="@drawable/key_hint_exclamation_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="!" />
-    <Key
-        latin:keyLabel="."
-        latin:temporaryShiftKeyLabel="\?"
-        latin:keyHintIcon="@drawable/key_hint_question_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="\?" />
-    <Key
-        latin:codes="@integer/key_shift"
-        latin:keyIcon="@drawable/sym_keyboard_shift"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
-        latin:keyWidth="13.1%p"
-        latin:isModifier="true"
-        latin:isSticky="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row3_email.xml b/java/res/xml-xlarge/kbd_qwerty_row3_email.xml
deleted file mode 100644
index d9e35421086d31955b50bab0080e08046eb285fd..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row3_email.xml
+++ /dev/null
@@ -1,66 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_shift"
-        latin:keyIcon="@drawable/sym_keyboard_shift"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
-        latin:keyWidth="13.1%p"
-        latin:isModifier="true"
-        latin:isSticky="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="z"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_z" />
-    <Key
-        latin:keyLabel="x" />
-    <Key
-        latin:keyLabel="c"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_c" />
-    <Key
-        latin:keyLabel="v"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_v" />
-    <Key
-        latin:keyLabel="b" />
-    <Key
-        latin:keyLabel="n"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="@string/alternates_for_n" />
-    <Key
-        latin:keyLabel="m" />
-    <Key
-        latin:keyLabel="," />
-    <Key
-        latin:keyLabel="." />
-    <Key
-        latin:codes="@integer/key_shift"
-        latin:keyIcon="@drawable/sym_keyboard_shift"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_shift"
-        latin:keyWidth="13.1%p"
-        latin:isModifier="true"
-        latin:isSticky="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row4.xml b/java/res/xml-xlarge/kbd_qwerty_row4.xml
new file mode 100644
index 0000000000000000000000000000000000000000..2392381a2792020e18ccf5940164ef18e5ed9c23
--- /dev/null
+++ b/java/res/xml-xlarge/kbd_qwerty_row4.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <!-- This row is intentionally not marked as a bottom row -->
+    <Row>
+        <Spacer
+            latin:horizontalGap="15.1%p" />
+        <switch>
+            <case
+                latin:mode="email"
+            >
+                <Key
+                    latin:keyLabel=".com"
+                    latin:keyOutputText=".com"
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_domains"
+                    latin:keyWidth="16.4%p" />
+            </case>
+            <!-- TODO: implement logical OR for <case> attribute -->
+            <case
+                latin:mode="url"
+            >
+                <Key
+                    latin:keyLabel=".com"
+                    latin:keyOutputText=".com"
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_domains"
+                    latin:keyWidth="16.4%p" />
+            </case>
+            <default>
+                <Key
+                    latin:keyLabel=":-)"
+                    latin:keyOutputText=":-)"
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_smileys" />
+                <Key
+                    latin:keyLabel="="
+                    latin:temporaryShiftKeyLabel="+"
+                    latin:keyHintIcon="@drawable/key_hint_plus_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="&gt;" />
+            </default>
+        </switch>
+        <Key
+            latin:codes="@integer/key_space"
+            latin:keyIcon="@drawable/sym_keyboard_space"
+            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+            latin:keyWidth="37.0%p"
+            latin:isModifier="true" />
+        <switch>
+            <case
+                latin:mode="email"
+            >
+                <Key
+                    latin:keyLabel="_" />
+                <Key
+                    latin:keyLabel="-" />
+            </case>
+            <default>
+                <Key
+                    latin:keyLabel="-"
+                    latin:temporaryShiftKeyLabel="/"
+                    latin:keyHintIcon="@drawable/key_hint_slash_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="/" />
+                <Key
+                    latin:keyLabel="_"
+                    latin:temporaryShiftKeyLabel="\@"
+                    latin:keyHintIcon="@drawable/key_hint_at_holo"
+                    latin:popupKeyboard="@xml/kbd_popup_template"
+                    latin:popupCharacters="\@" />
+            </default>
+        </switch>
+    </Row>
+</merge>
\ No newline at end of file
diff --git a/java/res/xml-xlarge/kbd_qwerty_row4_common.xml b/java/res/xml-xlarge/kbd_qwerty_row4_common.xml
deleted file mode 100644
index 2bcd71d7ffe804a05ab9d6c10910e0ca79ed9adc..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row4_common.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Spacer
-        latin:horizontalGap="15.1%p" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-)"
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys" />
-    <Key
-        latin:keyLabel="="
-        latin:temporaryShiftKeyLabel="+"
-        latin:keyHintIcon="@drawable/key_hint_plus_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="&gt;" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="37.0%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="-"
-        latin:temporaryShiftKeyLabel="/"
-        latin:keyHintIcon="@drawable/key_hint_slash_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="/" />
-    <Key
-        latin:keyLabel="_"
-        latin:temporaryShiftKeyLabel="\@"
-        latin:keyHintIcon="@drawable/key_hint_at_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="\@" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row4_email.xml b/java/res/xml-xlarge/kbd_qwerty_row4_email.xml
deleted file mode 100644
index f10cf4bf802b3b1de5c19e7239911dbdc0ee3309..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row4_email.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Spacer
-        latin:horizontalGap="15.1%p" />
-    <Key
-        latin:keyLabel=".com"
-        latin:keyOutputText=".com"
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_domains"
-        latin:keyWidth="16.4%p" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="37.0%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="_" />
-    <Key
-        latin:keyLabel="-" />
-</merge>
diff --git a/java/res/xml-xlarge/kbd_qwerty_row4_url.xml b/java/res/xml-xlarge/kbd_qwerty_row4_url.xml
deleted file mode 100644
index 420d136eb3ec66d3f20140c6761d5137dd6aa5fb..0000000000000000000000000000000000000000
--- a/java/res/xml-xlarge/kbd_qwerty_row4_url.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Spacer
-        latin:horizontalGap="15.1%p" />
-    <Key
-        latin:keyLabel=".com"
-        latin:keyOutputText=".com"
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_domains"
-        latin:keyWidth="16.4%p" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="37.0%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="-"
-        latin:temporaryShiftKeyLabel="/"
-        latin:keyHintIcon="@drawable/key_hint_slash_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters="/" />
-    <Key
-        latin:keyLabel="_"
-        latin:temporaryShiftKeyLabel=":"
-        latin:keyHintIcon="@drawable/key_hint_colon_holo"
-        latin:popupKeyboard="@xml/kbd_popup_template"
-        latin:popupCharacters=":" />
-</merge>
diff --git a/java/res/xml/kbd_qwerty_black_row4.xml b/java/res/xml/kbd_qwerty_black_row4.xml
index 330ddda42056db1443bdca47a87b5329ec6d7c14..2b9ef7f90904a328a07953f70534245c93593c5f 100644
--- a/java/res/xml/kbd_qwerty_black_row4.xml
+++ b/java/res/xml/kbd_qwerty_black_row4.xml
@@ -22,314 +22,141 @@
     xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
 >
     <Row
-        latin:keyboardMode="@+id/mode_normal"
         latin:keyWidth="10%p"
         latin:rowEdgeFlags="bottom"
     >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:keyLabel=":-)"
-            latin:keyOutputText=":-) "
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_smileys"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="20%p" />
-        <Key
-            latin:codes="@integer/key_tab"
-            latin:keyIcon="@drawable/sym_bkeyboard_tab"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
-            latin:keyWidth="20%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_normal_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_bkeyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_bkeyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_bkeyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_bkeyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:keyLabel=":-)"
-            latin:keyOutputText=":-) "
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_smileys"
-            latin:keyWidth="25%p"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_bkeyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-        <Key
-            latin:codes="@integer/key_f1" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_bkeyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p" />
-        <Key
-            latin:codes="@integer/key_tab"
-            latin:keyIcon="@drawable/sym_bkeyboard_tab"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_tab" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_bkeyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="15%p"
-            latin:keyEdgeFlags="right" />
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_symbol_key"
+                    latin:keyWidth="20%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_f1" />
+                <switch>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_bkeyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="20%p" />
+                        <Key
+                            latin:codes="@integer/key_tab"
+                            latin:keyIcon="@drawable/sym_bkeyboard_tab"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
+                            latin:keyWidth="20%p" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_bkeyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="40%p" />
+                    </default>
+                </switch>
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_symbol_key"
+                    latin:keyWidth="15%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_bkeyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
+                <Key
+                    latin:codes="@integer/key_f1" />
+                <switch>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_bkeyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="30%p" />
+                        <Key
+                            latin:codes="@integer/key_tab"
+                            latin:keyIcon="@drawable/sym_bkeyboard_tab"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_tab" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_bkeyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="30%p" />
+                    </default>
+                </switch>
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="15%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
     </Row>
 </merge>
diff --git a/java/res/xml/kbd_qwerty_row4.xml b/java/res/xml/kbd_qwerty_row4.xml
index 17b7c523519faf841d0b57db7bc5e93b10151576..2e2b32e3f7ec6609db7be2c6779a7a5da34cd5ff 100644
--- a/java/res/xml/kbd_qwerty_row4.xml
+++ b/java/res/xml/kbd_qwerty_row4.xml
@@ -22,371 +22,159 @@
     xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
 >
     <Row
-        latin:keyboardMode="@+id/mode_normal"
         latin:keyWidth="10%p"
         latin:rowEdgeFlags="bottom"
     >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="40%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel=":-)"
-            latin:keyOutputText=":-) "
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_smileys"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="20%p"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_tab"
-            latin:keyIcon="@drawable/sym_keyboard_tab"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
-            latin:keyWidth="20%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="20%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_normal_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_keyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_url_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_keyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_email_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_keyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="25%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_im_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_keyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel=":-)"
-            latin:keyOutputText=":-) "
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_smileys"
-            latin:keyWidth="25%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_webentry_with_settings_key"
-        latin:keyWidth="10%p"
-        latin:rowEdgeFlags="bottom"
-    >
-        <Key
-            latin:codes="@integer/key_symbol"
-            latin:keyLabel="@string/label_symbol_key"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="left" />
-        <Key
-            latin:codes="@integer/key_settings"
-            latin:keyIcon="@drawable/sym_keyboard_settings"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_f1"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_space"
-            latin:keyIcon="@drawable/sym_keyboard_space"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-            latin:keyWidth="30%p"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_tab"
-            latin:keyIcon="@drawable/sym_keyboard_tab"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
-            latin:isModifier="true" />
-        <Key
-            latin:keyLabel="."
-            latin:keyHintIcon="@drawable/hint_popup"
-            latin:popupKeyboard="@xml/popup_punctuation"
-            latin:isModifier="true" />
-        <Key
-            latin:codes="@integer/key_return"
-            latin:keyIcon="@drawable/sym_keyboard_return"
-            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-            latin:keyWidth="15%p"
-            latin:isModifier="true"
-            latin:keyEdgeFlags="right" />
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_symbol_key"
+                    latin:keyWidth="20%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_f1"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_keyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true" />
+                        <Key
+                            latin:codes="@integer/key_tab"
+                            latin:keyIcon="@drawable/sym_keyboard_tab"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_keyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="40%p"
+                            latin:isModifier="true" />
+                    </default>
+                </switch>
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_symbol_key"
+                    latin:keyWidth="15%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_keyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_f1"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_keyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="30%p"
+                            latin:isModifier="true" />
+                        <Key
+                            latin:codes="@integer/key_tab"
+                            latin:keyIcon="@drawable/sym_keyboard_tab"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_tab"
+                            latin:isModifier="true" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_space"
+                            latin:keyIcon="@drawable/sym_keyboard_space"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                            latin:keyWidth="30%p"
+                            latin:isModifier="true" />
+                    </default>
+                </switch>
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <case
+                        latin:mode="web"
+                    >
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="15%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                     </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
     </Row>
 </merge>
diff --git a/java/res/xml/kbd_symbols.xml b/java/res/xml/kbd_symbols.xml
index 608ddda8e163ff393c5625a15a6a3e22ed2f6c18..55b7681f9c47063d04c224399a870936e8af6aa6 100644
--- a/java/res/xml/kbd_symbols.xml
+++ b/java/res/xml/kbd_symbols.xml
@@ -142,64 +142,5 @@
             latin:isRepeatable="true"
             latin:keyEdgeFlags="right" />
     </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_im" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_im_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_row4_common_with_settings_key" />
-    </Row>
+    <include latin:keyboardLayout="@xml/kbd_symbols_row4" />
 </Keyboard>
diff --git a/java/res/xml/kbd_symbols_black.xml b/java/res/xml/kbd_symbols_black.xml
index 9e401a1cd221cb31959391b5eae4bfb550d080fb..ea021fb011a7be38bad04adc89a6ca5c8113c9ea 100644
--- a/java/res/xml/kbd_symbols_black.xml
+++ b/java/res/xml/kbd_symbols_black.xml
@@ -141,64 +141,5 @@
             latin:isRepeatable="true"
             latin:keyEdgeFlags="right" />
     </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_im" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_im_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_black_row4_common_with_settings_key" />
-    </Row>
+    <include latin:keyboardLayout="@xml/kbd_symbols_black_row4" />
 </Keyboard>
diff --git a/java/res/xml/kbd_symbols_black_row4.xml b/java/res/xml/kbd_symbols_black_row4.xml
new file mode 100644
index 0000000000000000000000000000000000000000..d1ed5271782b432e34eb58da7a2873b43e4292f3
--- /dev/null
+++ b/java/res/xml/kbd_symbols_black_row4.xml
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:rowEdgeFlags="bottom"
+    >
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="20%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_f1" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_bkeyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="40%p" />
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="15%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_bkeyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
+                <Key
+                    latin:codes="@integer/key_f1" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_bkeyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="30%p" />
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
+    </Row>
+</merge>
diff --git a/java/res/xml/kbd_symbols_black_row4_common.xml b/java/res/xml/kbd_symbols_black_row4_common.xml
deleted file mode 100644
index 7433eca7fad7a944ceb249448a802e0788a126c0..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_black_row4_common.xml
+++ /dev/null
@@ -1,46 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_f1" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_bkeyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml
deleted file mode 100644
index bbb16991900ecada4e4190112d885374ba6d3083..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_black_row4_common_with_settings_key.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_bkeyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-    <Key
-        latin:codes="@integer/key_f1" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_bkeyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="25%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_black_row4_im.xml b/java/res/xml/kbd_symbols_black_row4_im.xml
deleted file mode 100644
index a1546b7b5e619fd50526b229ca85c8aa4dbaf384..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_black_row4_im.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_f1" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml
deleted file mode 100644
index 4cab461e757904360deffb68061e1c5984e551cc..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_black_row4_im_with_settings_key.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_bkeyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-    <Key
-        latin:codes="@integer/key_f1" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="25%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_row4.xml b/java/res/xml/kbd_symbols_row4.xml
new file mode 100644
index 0000000000000000000000000000000000000000..4b3dd90710d1261951d3b25dd4096a3a29f542ec
--- /dev/null
+++ b/java/res/xml/kbd_symbols_row4.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:rowEdgeFlags="bottom"
+    >
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="20%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_f1"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_keyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="40%p"
+                    latin:isModifier="true" />
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="15%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_keyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_f1"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_keyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="30%p"
+                    latin:isModifier="true" />
+                <Key
+                    latin:keyLabel="."
+                    latin:keyHintIcon="@drawable/hint_popup"
+                    latin:popupKeyboard="@xml/popup_punctuation"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
+    </Row>
+</merge>
diff --git a/java/res/xml/kbd_symbols_row4_common.xml b/java/res/xml/kbd_symbols_row4_common.xml
deleted file mode 100644
index ef7cdcaff856c38968c774d80fbc5797aa18fd04..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_row4_common.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_f1"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml
deleted file mode 100644
index 54b85429cf15096a2ea013ba6b176d3e1722ee72..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_row4_common_with_settings_key.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_keyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_f1"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="25%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_row4_im.xml b/java/res/xml/kbd_symbols_row4_im.xml
deleted file mode 100644
index c7d679bc4a9d70a5bbb1e77cceb8c893c6245e09..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_row4_im.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_f1"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml
deleted file mode 100644
index 7cc209b6b15cf15cf8e68d3cfb34148fc0b7711b..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_row4_im_with_settings_key.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_keyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_f1"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="."
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_punctuation"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="25%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift.xml b/java/res/xml/kbd_symbols_shift.xml
index b8f8faeb21bf01a08b91179e61a4423b10082431..52796561d500f997f75469a58a4ef5842002f838 100644
--- a/java/res/xml/kbd_symbols_shift.xml
+++ b/java/res/xml/kbd_symbols_shift.xml
@@ -121,64 +121,5 @@
             latin:isRepeatable="true"
             latin:keyEdgeFlags="right" />
     </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_im" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_im_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4_common_with_settings_key" />
-    </Row>
+    <include latin:keyboardLayout="@xml/kbd_symbols_shift_row4" />
 </Keyboard>
diff --git a/java/res/xml/kbd_symbols_shift_black.xml b/java/res/xml/kbd_symbols_shift_black.xml
index 34684a65b282b7f0eb10515fa32b857877fb2d46..895bcef726cfa7f179bc9ffd68c5447619ec22bd 100644
--- a/java/res/xml/kbd_symbols_shift_black.xml
+++ b/java/res/xml/kbd_symbols_shift_black.xml
@@ -120,64 +120,5 @@
             latin:isRepeatable="true"
             latin:keyEdgeFlags="right" />
     </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_im" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_normal_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_url_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_email_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_im_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_im_with_settings_key" />
-    </Row>
-    <Row
-        latin:keyboardMode="@+id/mode_symbols_webentry_with_settings_key"
-        latin:rowEdgeFlags="bottom"
-    >
-        <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4_common_with_settings_key" />
-    </Row>
+    <include latin:keyboardLayout="@xml/kbd_symbols_shift_black_row4" />
 </Keyboard>
diff --git a/java/res/xml/kbd_symbols_shift_black_row4.xml b/java/res/xml/kbd_symbols_shift_black_row4.xml
new file mode 100644
index 0000000000000000000000000000000000000000..e18ab211a5340b3afb64df7f8de6a198e52844b1
--- /dev/null
+++ b/java/res/xml/kbd_symbols_shift_black_row4.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:rowEdgeFlags="bottom"
+    >
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="20%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:keyLabel="„" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_bkeyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="40%p" />
+                <Key
+                    latin:keyLabel="…" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="15%p"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_bkeyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
+                <Key
+                    latin:keyLabel="„" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_bkeyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="30%p" />
+                <Key
+                    latin:keyLabel="…" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_bkeyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
+    </Row>
+</merge>
diff --git a/java/res/xml/kbd_symbols_shift_black_row4_common.xml b/java/res/xml/kbd_symbols_shift_black_row4_common.xml
deleted file mode 100644
index beb5b3d678f564fca7151300b61ca92adefc6081..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_black_row4_common.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="„" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p" />
-    <Key
-        latin:keyLabel="…" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_bkeyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml
deleted file mode 100644
index 97f882a5a611c889ddf6ba299b406bc0196529b7..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_black_row4_common_with_settings_key.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_bkeyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-    <Key
-        latin:keyLabel="„" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p" />
-    <Key
-        latin:keyLabel="…" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_bkeyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="25%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_black_row4_im.xml b/java/res/xml/kbd_symbols_shift_black_row4_im.xml
deleted file mode 100644
index c0263c2151565372fa7d81f11b9e32c531b12608..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_black_row4_im.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="„" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p" />
-    <Key
-        latin:keyLabel="…" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="20%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml
deleted file mode 100644
index 14d6a0b5166c86ddd7e206d814967dcd8ef47119..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_black_row4_im_with_settings_key.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_bkeyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings" />
-    <Key
-        latin:keyLabel="„" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_bkeyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p" />
-    <Key
-        latin:keyLabel="…" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="25%p"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_row4.xml b/java/res/xml/kbd_symbols_shift_row4.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f0df1307b8acf6373159b6d4e45fb58e0557fd9f
--- /dev/null
+++ b/java/res/xml/kbd_symbols_shift_row4.xml
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2010, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+    <Row
+        latin:rowEdgeFlags="bottom"
+    >
+        <switch>
+            <case
+                latin:settingsKey="false"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="20%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:keyLabel="„"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_keyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="40%p"
+                    latin:isModifier="true" />
+                <Key
+                    latin:keyLabel="…"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="20%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+            <case
+                latin:settingsKey="true"
+            >
+                <Key
+                    latin:codes="@integer/key_symbol"
+                    latin:keyLabel="@string/label_alpha_key"
+                    latin:keyWidth="15%p"
+                    latin:isModifier="true"
+                    latin:keyEdgeFlags="left" />
+                <Key
+                    latin:codes="@integer/key_settings"
+                    latin:keyIcon="@drawable/sym_keyboard_settings"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
+                    latin:isModifier="true" />
+                <Key
+                    latin:keyLabel="„"
+                    latin:isModifier="true" />
+                <Key
+                    latin:codes="@integer/key_space"
+                    latin:keyIcon="@drawable/sym_keyboard_space"
+                    latin:iconPreview="@drawable/sym_keyboard_feedback_space"
+                    latin:keyWidth="30%p"
+                    latin:isModifier="true" />
+                <Key
+                    latin:keyLabel="…"
+                    latin:isModifier="true" />
+                <switch>
+                    <case
+                        latin:mode="im"
+                    >
+                        <Key
+                            latin:keyLabel=":-)"
+                            latin:keyOutputText=":-) "
+                            latin:keyHintIcon="@drawable/hint_popup"
+                            latin:popupKeyboard="@xml/popup_smileys"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </case>
+                    <default>
+                        <Key
+                            latin:codes="@integer/key_return"
+                            latin:keyIcon="@drawable/sym_keyboard_return"
+                            latin:iconPreview="@drawable/sym_keyboard_feedback_return"
+                            latin:keyWidth="25%p"
+                            latin:isModifier="true"
+                            latin:keyEdgeFlags="right" />
+                    </default>
+                </switch>
+            </case>
+        </switch>
+    </Row>
+</merge>
diff --git a/java/res/xml/kbd_symbols_shift_row4_common.xml b/java/res/xml/kbd_symbols_shift_row4_common.xml
deleted file mode 100644
index 4d5199e88be1c2091132a83cd15b5f20a76f04d6..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_row4_common.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="„"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="…"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml
deleted file mode 100644
index df570ea1b6eaaba0d4ea81e02420fb374b8f21e4..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_row4_common_with_settings_key.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_keyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="„"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="…"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_return"
-        latin:keyIcon="@drawable/sym_keyboard_return"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_return"
-        latin:keyWidth="25%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_row4_im.xml b/java/res/xml/kbd_symbols_shift_row4_im.xml
deleted file mode 100644
index 69c6092546c18b2709242e2d5e76721685bc865e..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_row4_im.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:keyLabel="„"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="40%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="…"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="20%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml b/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml
deleted file mode 100644
index aad6e400bdf0082fda89d8647d747c9484219f5f..0000000000000000000000000000000000000000
--- a/java/res/xml/kbd_symbols_shift_row4_im_with_settings_key.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
-**
-** Copyright 2010, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
--->
-
-<merge
-    xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
->
-    <Key
-        latin:codes="@integer/key_symbol"
-        latin:keyLabel="@string/label_alpha_key"
-        latin:keyWidth="15%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="left" />
-    <Key
-        latin:codes="@integer/key_settings"
-        latin:keyIcon="@drawable/sym_keyboard_settings"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_settings"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="„"
-        latin:isModifier="true" />
-    <Key
-        latin:codes="@integer/key_space"
-        latin:keyIcon="@drawable/sym_keyboard_space"
-        latin:iconPreview="@drawable/sym_keyboard_feedback_space"
-        latin:keyWidth="30%p"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel="…"
-        latin:isModifier="true" />
-    <Key
-        latin:keyLabel=":-)"
-        latin:keyOutputText=":-) "
-        latin:keyHintIcon="@drawable/hint_popup"
-        latin:popupKeyboard="@xml/popup_smileys"
-        latin:keyWidth="25%p"
-        latin:isModifier="true"
-        latin:keyEdgeFlags="right" />
-</merge>
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboard.java b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
index e5b2756d4f2ff5270e1216bcdc6eb66da2025556..be0a6a28a55aeeecf7ab94cae631fe4a4191555b 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboard.java
@@ -16,6 +16,8 @@
 
 package com.android.inputmethod.latin;
 
+import com.android.inputmethod.latin.KeyboardSwitcher.KeyboardId;
+
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.Context;
@@ -103,8 +105,7 @@ public class BaseKeyboard {
     /** Height of the screen */
     private final int mDisplayHeight;
 
-    /** Keyboard mode, or zero, if none.  */
-    private final int mKeyboardMode;
+    protected final KeyboardId mId;
 
     // Variables for pre-computing nearest keys.
 
@@ -139,9 +140,6 @@ public class BaseKeyboard {
          */
         public int rowEdgeFlags;
 
-        /** The keyboard mode for this row */
-        public int mode;
-
         private final BaseKeyboard parent;
 
         private Row(BaseKeyboard parent) {
@@ -168,7 +166,6 @@ public class BaseKeyboard {
             a = res.obtainAttributes(Xml.asAttributeSet(parser),
                     R.styleable.BaseKeyboard_Row);
             rowEdgeFlags = a.getInt(R.styleable.BaseKeyboard_Row_rowEdgeFlags, 0);
-            mode = a.getResourceId(R.styleable.BaseKeyboard_Row_keyboardMode, 0);
         }
     }
 
@@ -456,19 +453,32 @@ public class BaseKeyboard {
      * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
      */
     public BaseKeyboard(Context context, int xmlLayoutResId) {
-        this(context, xmlLayoutResId, 0);
+        this(context, xmlLayoutResId, null);
     }
 
     /**
-     * Creates a keyboard from the given xml key layout file. Weeds out rows
-     * that have a keyboard mode defined but don't match the specified mode.
+     * Creates a keyboard from the given keyboard identifier.
+     * @param context the application or service context
+     * @param id keyboard identifier
+     */
+    public BaseKeyboard(Context context, KeyboardId id) {
+        this(context, id.getXmlId(), id);
+    }
+
+    /**
+     * Creates a keyboard from the given xml key layout file.
      * @param context the application or service context
      * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
-     * @param modeId keyboard mode identifier
-     * @param width sets width of keyboard
-     * @param height sets height of keyboard
+     * @param id keyboard identifier
      */
-    public BaseKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
+    private BaseKeyboard(Context context, int xmlLayoutResId, KeyboardId id) {
+        this(context, xmlLayoutResId, id,
+                context.getResources().getDisplayMetrics().widthPixels,
+                context.getResources().getDisplayMetrics().heightPixels);
+    }
+
+    private BaseKeyboard(Context context, int xmlLayoutResId, KeyboardId id, int width,
+            int height) {
         Resources res = context.getResources();
         GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
         GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
@@ -481,23 +491,10 @@ public class BaseKeyboard {
         setKeyWidth(mDisplayWidth / 10);
         mDefaultVerticalGap = 0;
         mDefaultHeight = mDefaultWidth;
-        mKeyboardMode = modeId;
+        mId = id;
         loadKeyboard(context, xmlLayoutResId);
     }
 
-    /**
-     * Creates a keyboard from the given xml key layout file. Weeds out rows
-     * that have a keyboard mode defined but don't match the specified mode.
-     * @param context the application or service context
-     * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
-     * @param modeId keyboard mode identifier
-     */
-    public BaseKeyboard(Context context, int xmlLayoutResId, int modeId) {
-        this(context, xmlLayoutResId, modeId,
-                context.getResources().getDisplayMetrics().widthPixels,
-                context.getResources().getDisplayMetrics().heightPixels);
-    }
-
     /**
      * <p>Creates a blank keyboard from the given resource file and populates it with the specified
      * characters in left-to-right, top-to-bottom fashion, using the specified number of columns.
@@ -608,10 +605,6 @@ public class BaseKeyboard {
         return mDisplayWidth;
     }
 
-    public int getKeyboardMode() {
-        return mKeyboardMode;
-    }
-
     public boolean setShifted(boolean shiftState) {
         for (final Key key : mShiftKeys) {
             key.on = shiftState;
diff --git a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
index 628e764b56c8958a63897d16a6d2f61f13032392..496f65174101e61f87541b37e7597ef80d29bca0 100644
--- a/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
+++ b/java/src/com/android/inputmethod/latin/BaseKeyboardParser.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
 
 import com.android.inputmethod.latin.BaseKeyboard.Key;
 import com.android.inputmethod.latin.BaseKeyboard.Row;
+import com.android.inputmethod.latin.KeyboardSwitcher.KeyboardId;
 
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -52,7 +53,7 @@ import java.util.List;
  *     ...
  *   &gt;/Keyboard&lt;
  * </pre>
- * The xml file which is included in other file must have &gt;merge&lt; as root element, such as:
+ * The XML file which is included in other file must have &gt;merge&lt; as root element, such as:
  * <pre>
  *   &gt;!-- xml/other_keys.xml --&lt;
  *   &gt;merge&lt;
@@ -70,6 +71,38 @@ import java.util.List;
  *     ...
  *   &gt;/merge&lt;
  * </pre>
+ * You can also use switch-case-default tags to select Rows and Keys.
+ * <pre>
+ *   &gt;switch&lt;
+ *     &gt;case case_attribute*&lt;
+ *       &gt;!-- Any valid tags at switch position --&lt;
+ *     &gt;/case&lt;
+ *     ...
+ *     &gt;default&lt;
+ *       &gt;!-- Any valid tags at switch position --&lt;
+ *     &gt;/default&lt;
+ *   &gt;/switch&lt;
+ * </pre>
+ *
+ * TODO: These are some random ideas to improve this parser.
+ * - can specify keyWidth attribute by multiplication of default keyWidth
+ *   for example: keyWidth="200%b" ("b" stands for "base")
+ * - can declare style and specify styles within tags.
+ *   for example:
+ *     &gt;switch&lt;
+ *       &gt;case colorScheme="white"&lt;
+ *         &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
+ *           &gt;item name="keyIcon"&lt;@drawable/sym_keyboard_shift"&gt;/item&lt;
+ *         &gt;/declare-style&lt;
+ *       &gt;/case&lt;
+ *       &gt;case colorScheme="black"&lt;
+ *         &gt;declare-style name="shift-key" parentStyle="modifier-key"&lt;
+ *           &gt;item name="keyIcon"&lt;@drawable/sym_bkeyboard_shift"&gt;/item&lt;
+ *         &gt;/declare-style&lt;
+ *       &gt;/case&lt;
+ *     &gt;/switch&lt;
+ *     ...
+ *     &gt;Key include-style="shift-key" ... /&lt;
  */
 public class BaseKeyboardParser {
     private static final String TAG = "BaseKeyboardParser";
@@ -83,6 +116,17 @@ public class BaseKeyboardParser {
     private static final String TAG_SPACER = "Spacer";
     private static final String TAG_INCLUDE = "include";
     private static final String TAG_MERGE = "merge";
+    private static final String TAG_SWITCH = "switch";
+    private static final String TAG_CASE = "case";
+    private static final String TAG_DEFAULT = "default";
+
+    // String representation of KeyboardSwitcher.MODE_xxx.
+    private static final String MODE_TEXT = "text";
+    private static final String MODE_URL = "url";
+    private static final String MODE_EMAIL = "email";
+    private static final String MODE_IM = "im";
+    private static final String MODE_WEB = "web";
+    private static final String MODE_PHONE = "phone";
 
     private final BaseKeyboard mKeyboard;
     private final Resources mResources;
@@ -143,7 +187,7 @@ public class BaseKeyboardParser {
         a.recycle();
     }
 
-    private void parseKeyboardContent(XmlResourceParser parser, final List<Key> keys)
+    private void parseKeyboardContent(XmlResourceParser parser, List<Key> keys)
             throws XmlPullParserException, IOException {
         if (DEBUG_PARSER) debugEnterMethod("parseKeyboardContent", keys == null);
         int event;
@@ -153,14 +197,13 @@ public class BaseKeyboardParser {
                 if (DEBUG_TAG) debugStartTag("parseKeyboardContent", tag, keys == null);
                 if (TAG_ROW.equals(tag)) {
                     Row row = mKeyboard.createRowFromXml(mResources, parser);
-                    if (keys != null && maybeStartRow(row)) {
-                        parseRowContent(parser, row, keys);
-                    } else {
-                        // Skip entire <Row></Row>
-                        parseRowContent(parser, row, null);
-                    }
+                    if (keys != null)
+                        startRow(row);
+                    parseRowContent(parser, row, keys);
                 } else if (TAG_INCLUDE.equals(tag)) {
                     parseIncludeKeyboardContent(parser, keys);
+                } else if (TAG_SWITCH.equals(tag)) {
+                    parseSwitchKeyboardContent(parser, keys);
                 } else {
                     throw new IllegalStartTag(parser, TAG_ROW);
                 }
@@ -170,6 +213,8 @@ public class BaseKeyboardParser {
                 if (TAG_KEYBOARD.equals(tag)) {
                     endKeyboard(mKeyboard.getVerticalGap());
                     break;
+                } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
+                    break;
                 } else if (TAG_MERGE.equals(tag)) {
                     break;
                 } else {
@@ -194,6 +239,8 @@ public class BaseKeyboardParser {
                     parseSpacer(parser, keys);
                 } else if (TAG_INCLUDE.equals(tag)) {
                     parseIncludeRowContent(parser, row, keys);
+                } else if (TAG_SWITCH.equals(tag)) {
+                    parseSwitchRowContent(parser, row, keys);
                 } else {
                     throw new IllegalStartTag(parser, TAG_KEY);
                 }
@@ -204,6 +251,8 @@ public class BaseKeyboardParser {
                     if (keys != null)
                         endRow();
                     break;
+                } else if (TAG_CASE.equals(tag) || TAG_DEFAULT.equals(tag)) {
+                    break;
                 } else if (TAG_MERGE.equals(tag)) {
                     break;
                 } else {
@@ -237,7 +286,7 @@ public class BaseKeyboardParser {
         } else {
             final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
                     R.styleable.BaseKeyboard);
-            int gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap,
+            final int gap = getDimensionOrFraction(a, R.styleable.BaseKeyboard_horizontalGap,
                     mKeyboard.getKeyboardWidth(), 0);
             a.recycle();
             checkEndTag(TAG_SPACER, parser);
@@ -247,17 +296,20 @@ public class BaseKeyboardParser {
 
     private void parseIncludeKeyboardContent(XmlResourceParser parser, List<Key> keys)
             throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseIncludeKeyboardContent", keys == null);
         parseIncludeInternal(parser, null, keys);
+        if (DEBUG_PARSER) debugLeaveMethod("parseIncludeKeyboardContent", keys == null);
     }
 
     private void parseIncludeRowContent(XmlResourceParser parser, Row row, List<Key> keys)
             throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseIncludeRowContent", keys == null);
         parseIncludeInternal(parser, row, keys);
+        if (DEBUG_PARSER) debugLeaveMethod("parseIncludeRowContent", keys == null);
     }
 
     private void parseIncludeInternal(XmlResourceParser parser, Row row, List<Key> keys)
             throws XmlPullParserException, IOException {
-        if (DEBUG_PARSER) debugEnterMethod("parseInclude", keys == null);
         if (keys == null) {
             checkEndTag(TAG_INCLUDE, parser);
         } else {
@@ -272,7 +324,6 @@ public class BaseKeyboardParser {
                 throw new ParseException("No keyboardLayout attribute in <include/>", parser);
             parseMerge(mResources.getLayout(keyboardLayout), row, keys);
         }
-        if (DEBUG_PARSER) debugLeaveMethod("parseInclude", keys == null);
     }
 
     private void parseMerge(XmlResourceParser parser, Row row, List<Key> keys)
@@ -281,7 +332,7 @@ public class BaseKeyboardParser {
         int event;
         while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
             if (event == XmlResourceParser.START_TAG) {
-                String tag = parser.getName();
+                final String tag = parser.getName();
                 if (DEBUG_TAG) debugStartTag("parseMerge", tag, keys == null);
                 if (TAG_MERGE.equals(tag)) {
                     if (row == null) {
@@ -299,6 +350,113 @@ public class BaseKeyboardParser {
         if (DEBUG_PARSER) debugLeaveMethod("parseMerge", keys == null);
     }
 
+    private void parseSwitchKeyboardContent(XmlResourceParser parser, List<Key> keys)
+            throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseSwitchKeyboardContent", keys == null);
+        parseSwitchInternal(parser, null, keys);
+        if (DEBUG_PARSER) debugLeaveMethod("parseSwitchKeyboardContent", keys == null);
+    }
+
+    private void parseSwitchRowContent(XmlResourceParser parser, Row row, List<Key> keys)
+            throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseSwitchRowContent", keys == null);
+        parseSwitchInternal(parser, row, keys);
+        if (DEBUG_PARSER) debugLeaveMethod("parseSwitchRowContent", keys == null);
+    }
+
+    private void parseSwitchInternal(XmlResourceParser parser, Row row, List<Key> keys)
+            throws XmlPullParserException, IOException {
+        boolean selected = false;
+        int event;
+        if (DEBUG_TAG) Log.d(TAG, "parseSwitchInternal: id=" + mKeyboard.mId);
+        while ((event = parser.next()) != XmlResourceParser.END_DOCUMENT) {
+            if (event == XmlResourceParser.START_TAG) {
+                final String tag = parser.getName();
+                if (DEBUG_TAG) debugStartTag("parseSwitchInternal", tag, keys == null);
+                if (TAG_CASE.equals(tag)) {
+                    selected |= parseCase(parser, row, selected ? null : keys);
+                } else if (TAG_DEFAULT.equals(tag)) {
+                    selected |= parseDefault(parser, row, selected ? null : keys);
+                } else {
+                    throw new IllegalStartTag(parser, TAG_KEY);
+                }
+            } else if (event == XmlResourceParser.END_TAG) {
+                final String tag = parser.getName();
+                if (DEBUG_TAG) debugEndTag("parseRowContent", tag, keys == null);
+                if (TAG_SWITCH.equals(tag)) {
+                    break;
+                } else {
+                    throw new IllegalEndTag(parser, TAG_KEY);
+                }
+            }
+        }
+    }
+
+    private boolean parseCase(XmlResourceParser parser, Row row, List<Key> keys)
+            throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseCase", keys == null);
+        final boolean selected = parseCaseCondition(parser);
+        if (row == null) {
+            // Processing Rows.
+            parseKeyboardContent(parser, selected ? keys : null);
+        } else {
+            // Processing Keys.
+            parseRowContent(parser, row, selected ? keys : null);
+        }
+        if (DEBUG_PARSER) debugLeaveMethod("parseCase", keys == null || !selected);
+        return selected;
+    }
+
+    private boolean parseCaseCondition(XmlResourceParser parser) {
+        final BaseKeyboard keyboard = mKeyboard;
+        final TypedArray a = mResources.obtainAttributes(Xml.asAttributeSet(parser),
+                R.styleable.BaseKeyboard_Case);
+        final String mode = a.getString(R.styleable.BaseKeyboard_Case_mode);
+        final String settingsKey = a.getString(R.styleable.BaseKeyboard_Case_settingsKey);
+        final String voiceKey = a.getString(R.styleable.BaseKeyboard_Case_voiceKey);
+        a.recycle();
+
+        final KeyboardId id = keyboard.mId;
+        if (id == null)
+            return true;
+        final boolean modeMatched = (mode == null
+                || id.mMode == parseModeString(mode));
+        final boolean settingsKeyMatched = (settingsKey == null
+                || id.mHasSettingsKey == Boolean.parseBoolean(settingsKey));
+        final boolean voiceKeyMatched = (voiceKey == null
+                || id.mHasVoiceKey == Boolean.parseBoolean(voiceKey));
+        final boolean selected = modeMatched && settingsKeyMatched && voiceKeyMatched;
+        if (DEBUG_TAG) {
+            Log.d(TAG, "parseCaseCondition: " + Boolean.toString(selected).toUpperCase()
+                    + (mode != null ? " mode=" + mode : "")
+                    + (settingsKey != null ? " settingsKey="+settingsKey : "")
+                    + (voiceKey != null ? " voiceKey=" + voiceKey : ""));
+        }
+        return selected;
+    }
+
+    private static int parseModeString(String mode) {
+        if (mode.equals(MODE_TEXT)) return KeyboardSwitcher.MODE_TEXT;
+        if (mode.equals(MODE_URL)) return KeyboardSwitcher.MODE_URL;
+        if (mode.equals(MODE_EMAIL)) return KeyboardSwitcher.MODE_EMAIL;
+        if (mode.equals(MODE_IM)) return KeyboardSwitcher.MODE_IM;
+        if (mode.equals(MODE_WEB)) return KeyboardSwitcher.MODE_WEB;
+        if (mode.equals(MODE_PHONE)) return KeyboardSwitcher.MODE_PHONE;
+        throw new RuntimeException("uknown mode attribute in Keyboard XML: " + mode);
+    }
+
+    private boolean parseDefault(XmlResourceParser parser, Row row, List<Key> keys)
+            throws XmlPullParserException, IOException {
+        if (DEBUG_PARSER) debugEnterMethod("parseDefault", keys == null);
+        if (row == null) {
+            parseKeyboardContent(parser, keys);
+        } else {
+            parseRowContent(parser, row, keys);
+        }
+        if (DEBUG_PARSER) debugLeaveMethod("parseDefault", keys == null);
+        return true;
+    }
+
     private static void checkEndTag(String tag, XmlResourceParser parser)
             throws XmlPullParserException, IOException {
         if (parser.next() == XmlResourceParser.END_TAG && tag.equals(parser.getName()))
@@ -306,18 +464,9 @@ public class BaseKeyboardParser {
         throw new NonEmptyTag(tag, parser);
     }
 
-    // return true if the row is valid for this keyboard mode
-    private boolean maybeStartRow(Row row) {
-        if (DEBUG_TAG)
-            Log.d(TAG, String.format("startRow: mode=0x%08x keyboardMode=0x%08x",
-                    row.mode, mKeyboard.getKeyboardMode()));
-        if (row.mode == 0 || row.mode == mKeyboard.getKeyboardMode()) {
-            mCurrentX = 0;
-            mCurrentRow = row;
-            return true;
-        } else {
-            return false;
-        }
+    private void startRow(Row row) {
+        mCurrentX = 0;
+        mCurrentRow = row;
     }
 
     private void endRow() {
diff --git a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
index 05bda659132cee6d00a927498c50c2891383155a..7307fcfbb5e474b5e8bd90b6000201808271902e 100644
--- a/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/KeyboardSwitcher.java
@@ -40,76 +40,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     public static final int MODE_WEB = 4;
     public static final int MODE_PHONE = 5;
 
-    // Main keyboard layouts without the settings key
-    private static final int KEYBOARDMODE_NORMAL = R.id.mode_normal;
-    private static final int KEYBOARDMODE_URL = R.id.mode_url;
-    private static final int KEYBOARDMODE_EMAIL = R.id.mode_email;
-    private static final int KEYBOARDMODE_IM = R.id.mode_im;
-    private static final int KEYBOARDMODE_WEB = R.id.mode_webentry;
-    private static final int[] QWERTY_MODES = {
-            KEYBOARDMODE_NORMAL,
-            KEYBOARDMODE_URL,
-            KEYBOARDMODE_EMAIL,
-            KEYBOARDMODE_IM,
-            KEYBOARDMODE_WEB,
-            0 /* for MODE_PHONE */ };
-    // Main keyboard layouts with the settings key
-    private static final int KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY =
-            R.id.mode_normal_with_settings_key;
-    private static final int KEYBOARDMODE_URL_WITH_SETTINGS_KEY =
-            R.id.mode_url_with_settings_key;
-    private static final int KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY =
-            R.id.mode_email_with_settings_key;
-    private static final int KEYBOARDMODE_IM_WITH_SETTINGS_KEY =
-            R.id.mode_im_with_settings_key;
-    private static final int KEYBOARDMODE_WEB_WITH_SETTINGS_KEY =
-            R.id.mode_webentry_with_settings_key;
-    private static final int[] QWERTY_WITH_SETTINGS_KEY_MODES = {
-            KEYBOARDMODE_NORMAL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_URL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_EMAIL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_IM_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_WEB_WITH_SETTINGS_KEY,
-            0 /* for MODE_PHONE */ };
-    private static final int[][] QWERTY_KEYBOARD_MODES = {
-            QWERTY_MODES, QWERTY_WITH_SETTINGS_KEY_MODES
-    };
-
-    // Symbols keyboard layouts without the settings key
-    private static final int KEYBOARDMODE_SYMBOLS_NORMAL = R.id.mode_symbols_normal;
-    private static final int KEYBOARDMODE_SYMBOLS_URL = R.id.mode_symbols_url;
-    private static final int KEYBOARDMODE_SYMBOLS_EMAIL = R.id.mode_symbols_email;
-    private static final int KEYBOARDMODE_SYMBOLS_IM = R.id.mode_symbols_im;
-    private static final int KEYBOARDMODE_SYMBOLS_WEB = R.id.mode_symbols_webentry;
-    private static final int[] SYMBOLS_MODES = {
-            KEYBOARDMODE_SYMBOLS_NORMAL,
-            KEYBOARDMODE_SYMBOLS_URL,
-            KEYBOARDMODE_SYMBOLS_EMAIL,
-            KEYBOARDMODE_SYMBOLS_IM,
-            KEYBOARDMODE_SYMBOLS_WEB,
-            0 /* for MODE_PHONE */ };
-    // Symbols keyboard layouts with the settings key
-    private static final int KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY =
-            R.id.mode_symbols_normal_with_settings_key;
-    private static final int KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY =
-            R.id.mode_symbols_url_with_settings_key;
-    private static final int KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY =
-            R.id.mode_symbols_email_with_settings_key;
-    private static final int KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY =
-            R.id.mode_symbols_im_with_settings_key;
-    private static final int KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY =
-            R.id.mode_symbols_webentry_with_settings_key;
-    private static final int[] SYMBOLS_WITH_SETTINGS_KEY_MODES = {
-            KEYBOARDMODE_SYMBOLS_NORMAL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_SYMBOLS_URL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_SYMBOLS_EMAIL_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_SYMBOLS_IM_WITH_SETTINGS_KEY,
-            KEYBOARDMODE_SYMBOLS_WEB_WITH_SETTINGS_KEY,
-            0 /* for MODE_PHONE */ };
-    private static final int[][] SYMBOLS_KEYBOARD_MODES = {
-            SYMBOLS_MODES, SYMBOLS_WITH_SETTINGS_KEY_MODES
-    };
-
     public static final String DEFAULT_LAYOUT_ID = "4";
     public static final String PREF_KEYBOARD_LAYOUT = "pref_keyboard_layout_20100902";
     private static final int[] THEMES = new int [] {
@@ -121,14 +51,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     private static final int CHAR_THEME_COLOR_BLACK = 1;
 
     // Tables which contains resource ids for each character theme color
-    private static final int[] KBD_PHONE = new int[] {R.xml.kbd_phone, R.xml.kbd_phone_black};
+    private static final int[] KBD_PHONE = new int[] {
+            R.xml.kbd_phone, R.xml.kbd_phone_black
+    };
     private static final int[] KBD_PHONE_SYMBOLS = new int[] {
-        R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black};
+            R.xml.kbd_phone_symbols, R.xml.kbd_phone_symbols_black
+    };
     private static final int[] KBD_SYMBOLS = new int[] {
-        R.xml.kbd_symbols, R.xml.kbd_symbols_black};
+            R.xml.kbd_symbols, R.xml.kbd_symbols_black
+    };
     private static final int[] KBD_SYMBOLS_SHIFT = new int[] {
-        R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black};
-    private static final int[] KBD_QWERTY = new int[] {R.xml.kbd_qwerty, R.xml.kbd_qwerty_black};
+            R.xml.kbd_symbols_shift, R.xml.kbd_symbols_shift_black
+    };
+    private static final int[] KBD_QWERTY = new int[] {
+            R.xml.kbd_qwerty, R.xml.kbd_qwerty_black
+    };
 
     private static final int SYMBOLS_MODE_STATE_NONE = 0;
     private static final int SYMBOLS_MODE_STATE_BEGIN = 1;
@@ -184,9 +121,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         final boolean hasSettingsKey = mHasSettingsKey;
         final boolean hasVoiceKey = mVoiceButtonEnabled && !mVoiceButtonOnPrimary;
         final int imeOptions = mImeOptions;
-        mSymbolsId = new KeyboardId(locale, orientation, SYMBOLS_KEYBOARD_MODES, mode,
+        mSymbolsId = new KeyboardId(locale, orientation, mode,
                 KBD_SYMBOLS, colorScheme, hasSettingsKey, hasVoiceKey, imeOptions, true);
-        mSymbolsShiftedId = new KeyboardId(locale, orientation, SYMBOLS_KEYBOARD_MODES, mode,
+        mSymbolsShiftedId = new KeyboardId(locale, orientation, mode,
                 KBD_SYMBOLS_SHIFT, colorScheme, hasSettingsKey, hasVoiceKey, imeOptions, true);
     }
 
@@ -194,10 +131,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
      * Represents the parameters necessary to construct a new LatinKeyboard,
      * which also serve as a unique identifier for each keyboard type.
      */
-    private static class KeyboardId {
+    public static class KeyboardId {
         public final Locale mLocale;
         public final int mOrientation;
-        public final int[][] mKeyboardModes;
         public final int mMode;
         public final int[] mXmlArray;
         public final int mColorScheme;
@@ -208,12 +144,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
 
         private final int mHashCode;
 
-        public KeyboardId(Locale locale, int orientation, int[][] keyboardModes, int mode,
+        public KeyboardId(Locale locale, int orientation, int mode,
                 int[] xmlArray, int colorScheme, boolean hasSettingsKey, boolean hasVoiceKey,
                 int imeOptions, boolean enableShiftLock) {
             this.mLocale = locale;
             this.mOrientation = orientation;
-            this.mKeyboardModes = keyboardModes;
             this.mMode = mode;
             this.mXmlArray = xmlArray;
             this.mColorScheme = colorScheme;
@@ -225,7 +160,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             this.mHashCode = Arrays.hashCode(new Object[] {
                     locale,
                     orientation,
-                    keyboardModes,
                     mode,
                     xmlArray,
                     colorScheme,
@@ -236,6 +170,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             });
         }
 
+        public int getXmlId() {
+            return mXmlArray[mColorScheme];
+        }
+
+        public boolean isAlphabetMode() {
+            return mXmlArray == KBD_QWERTY;
+        }
+
         @Override
         public boolean equals(Object other) {
             return other instanceof KeyboardId && equals((KeyboardId) other);
@@ -244,7 +186,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         private boolean equals(KeyboardId other) {
             return other.mLocale.equals(this.mLocale)
                 && other.mOrientation == this.mOrientation
-                && other.mKeyboardModes == this.mKeyboardModes
                 && other.mMode == this.mMode
                 && other.mXmlArray == this.mXmlArray
                 && other.mColorScheme == this.mColorScheme
@@ -261,33 +202,26 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
 
         @Override
         public String toString() {
-            if (DEBUG) {
-                return String.format("[%s %s %6s %5s imeOptions=0x%08x xml=0x%08x %s%s%s%s]",
-                        mLocale,
-                        (mOrientation == 1 ? "port" : "land"),
-                        (mKeyboardModes == QWERTY_KEYBOARD_MODES ? "alpha" : "symbol"),
-                        modeName(mMode),
-                        mImeOptions,
-                        mXmlArray[0],
-                        (mColorScheme == CHAR_THEME_COLOR_WHITE ? "white" : "black"),
-                        (mHasSettingsKey ? " hasSettingsKey" : ""),
-                        (mHasVoiceKey ? " hasVoiceKey" : ""),
-                        (mEnableShiftLock ? " enableShiftLock" : ""));
-            } else {
-                return super.toString();
-            }
+            return String.format("[%s %s %5s imeOptions=0x%08x xml=0x%08x %s%s%s%s]",
+                    mLocale,
+                    (mOrientation == 1 ? "port" : "land"),
+                    modeName(mMode),
+                    mImeOptions,
+                    mXmlArray[0],
+                    (mColorScheme == CHAR_THEME_COLOR_WHITE ? "white" : "black"),
+                    (mHasSettingsKey ? " hasSettingsKey" : ""),
+                    (mHasVoiceKey ? " hasVoiceKey" : ""),
+                    (mEnableShiftLock ? " enableShiftLock" : ""));
         }
 
         private static String modeName(int mode) {
-            if (DEBUG) {
-                switch (mode) {
-                case MODE_TEXT: return "text";
-                case MODE_URL: return "url";
-                case MODE_EMAIL: return "email";
-                case MODE_IM: return "im";
-                case MODE_WEB: return "web";
-                case MODE_PHONE: return "phone";
-                }
+            switch (mode) {
+            case MODE_TEXT: return "text";
+            case MODE_URL: return "url";
+            case MODE_EMAIL: return "email";
+            case MODE_IM: return "im";
+            case MODE_WEB: return "web";
+            case MODE_PHONE: return "phone";
             }
             return null;
         }
@@ -304,6 +238,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             loadKeyboardInternal(mode, imeOptions, voiceButtonEnabled, voiceButtonOnPrimary,
                     false);
         } catch (RuntimeException e) {
+            Log.w(TAG, e);
             LatinImeLogger.logOnException(mode + "," + imeOptions, e);
         }
     }
@@ -345,10 +280,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
             conf.locale = mLanguageSwitcher.getInputLocale();
             res.updateConfiguration(conf, null);
 
-            final int keyboardMode = id.mKeyboardModes[id.mHasSettingsKey ? 1 : 0][id.mMode];
-            final int xml = id.mXmlArray[id.mColorScheme];
-            keyboard = new LatinKeyboard(mInputMethodService, xml, keyboardMode, id.mColorScheme,
-                    id.mHasSettingsKey, id.mHasVoiceKey, id.mImeOptions);
+            final int xml = id.getXmlId();
+            keyboard = new LatinKeyboard(mInputMethodService, id);
             keyboard.setVoiceMode(
                     hasVoiceKey(xml == R.xml.kbd_symbols || xml == R.xml.kbd_symbols_black),
                     mVoiceButtonEnabled);
@@ -383,20 +316,17 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
         final int charColorId = getCharColorId();
         final int[] xmlArray;
         final boolean enableShiftLock;
-        final int[][] keyboardModes;
 
         if (isSymbols) {
-            keyboardModes = SYMBOLS_KEYBOARD_MODES;
             xmlArray = mode == MODE_PHONE ? KBD_PHONE_SYMBOLS : KBD_SYMBOLS;
             enableShiftLock = false;
         } else {  // QWERTY
-            keyboardModes = QWERTY_KEYBOARD_MODES;
             xmlArray = mode == MODE_PHONE ? KBD_PHONE : KBD_QWERTY;
             enableShiftLock = mode == MODE_PHONE ? false : true;
         }
         final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
         final Locale locale = mLanguageSwitcher.getInputLocale();
-        return new KeyboardId(locale, orientation, keyboardModes, mode, xmlArray,
+        return new KeyboardId(locale, orientation, mode, xmlArray,
                 charColorId, mHasSettingsKey, hasVoiceKey, imeOptions, enableShiftLock);
     }
 
@@ -405,7 +335,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
     }
     
     public boolean isAlphabetMode() {
-        return mCurrentId != null && mCurrentId.mKeyboardModes == QWERTY_KEYBOARD_MODES;
+        return mCurrentId != null && mCurrentId.isAlphabetMode();
     }
 
     public void setShifted(boolean shifted) {
diff --git a/java/src/com/android/inputmethod/latin/LatinKeyboard.java b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
index 883069ae61188989900dc10cc700b466833223da..e1673fb7bde3142ea280a8b21f21250aa7c17fa0 100644
--- a/java/src/com/android/inputmethod/latin/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/latin/LatinKeyboard.java
@@ -70,7 +70,7 @@ public class LatinKeyboard extends BaseKeyboard {
     private LanguageSwitcher mLanguageSwitcher;
     private final Resources mRes;
     private final Context mContext;
-    private int mMode;  // TODO: remove this and use the corresponding mode in the parent class
+    private int mMode; // TODO: remove this and use the corresponding mode in the parent class
     // Whether this keyboard has voice icon on it
     private boolean mHasVoiceButton;
     // Whether voice icon is enabled at all
@@ -113,14 +113,12 @@ public class LatinKeyboard extends BaseKeyboard {
 
     private static int sSpacebarVerticalCorrection;
 
-    public LatinKeyboard(Context context, int xmlLayoutResId, int mode, int colorScheme,
-            boolean hasSettingsKey, boolean hasVoiceKey, int imeOptions) {
-        // TODO: to be used: colorScheme, hasSettingsKey, hasVoiceKey, imeOptions.
-        super(context, xmlLayoutResId, mode);
+    public LatinKeyboard(Context context, KeyboardSwitcher.KeyboardId id) {
+        super(context, id);
         final Resources res = context.getResources();
         mContext = context;
         mRes = res;
-        mMode = mode;
+        mMode = id.mMode;
         mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked);
         mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked);
         setDefaultBounds(mShiftLockPreviewIcon);
@@ -138,6 +136,7 @@ public class LatinKeyboard extends BaseKeyboard {
         setDefaultBounds(m123MicPreviewIcon);
         sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
                 R.dimen.spacebar_vertical_correction);
+        final int xmlLayoutResId = id.getXmlId();
         mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty
                 || xmlLayoutResId == R.xml.kbd_qwerty_black;
         mSpaceKeyIndex = indexOf(LatinIME.KEYCODE_SPACE);