Merge "Import TextUtils.getCapsMode to fix it internally (A1)" into jb-mr1-dev
diff --git a/java/res/drawable/btn_keyboard_key.xml b/java/res/drawable/btn_keyboard_key.xml
index 45578e5..797bc10 100644
--- a/java/res/drawable/btn_keyboard_key.xml
+++ b/java/res/drawable/btn_keyboard_key.xml
@@ -17,8 +17,8 @@
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 
     <!-- Toggle keys. Use checkable/checked state. -->
-    
-    <item android:state_checkable="true" android:state_checked="true" 
+
+    <item android:state_checkable="true" android:state_checked="true"
           android:state_pressed="true"
           android:drawable="@drawable/btn_keyboard_key_pressed_on" />
     <item android:state_checkable="true" android:state_pressed="true"
@@ -34,5 +34,5 @@
           android:drawable="@drawable/btn_keyboard_key_pressed" />
     <item
           android:drawable="@drawable/btn_keyboard_key_normal" />
-          
+
 </selector>
diff --git a/java/res/values-af/bools.xml b/java/res/values-af/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-af/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ar/bools.xml b/java/res/values-ar/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ar/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-be/bools.xml b/java/res/values-be/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-be/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-bg/bools.xml b/java/res/values-bg/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-bg/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ca/bools.xml b/java/res/values-ca/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ca/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-cs/bools.xml b/java/res/values-cs/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-cs/bools.xml
+++ b/java/res/values-cs/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-da/bools.xml b/java/res/values-da/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-da/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-de/bools.xml b/java/res/values-de/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-de/bools.xml
+++ b/java/res/values-de/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-el/bools.xml b/java/res/values-el/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-el/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-en/bools.xml b/java/res/values-en/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-en/bools.xml
+++ b/java/res/values-en/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-eo/bools.xml b/java/res/values-eo/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-eo/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-es/bools.xml b/java/res/values-es/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-es/bools.xml
+++ b/java/res/values-es/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-et/bools.xml b/java/res/values-et/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-et/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-fa/bools.xml b/java/res/values-fa/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-fa/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-fi/bools.xml b/java/res/values-fi/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-fi/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-fr/bools.xml b/java/res/values-fr/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-fr/bools.xml
+++ b/java/res/values-fr/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-hi/bools.xml b/java/res/values-hi/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-hi/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-hr/bools.xml b/java/res/values-hr/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-hr/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-hu/bools.xml b/java/res/values-hu/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-hu/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-in/bools.xml b/java/res/values-in/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-in/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-is/bools.xml b/java/res/values-is/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-is/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-it/bools.xml b/java/res/values-it/bools.xml
index 897f4b3..c289e5b 100644
--- a/java/res/values-it/bools.xml
+++ b/java/res/values-it/bools.xml
@@ -1,22 +1,24 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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 
+**     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 
+** 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.
 */
 -->
 <resources>
-	<bool name="im_is_default">true</bool>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-iw/bools.xml b/java/res/values-iw/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-iw/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ka/bools.xml b/java/res/values-ka/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ka/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ky/bools.xml b/java/res/values-ky/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ky/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-land/dimens.xml b/java/res/values-land/dimens.xml
index fdd9434..c78c25f 100644
--- a/java/res/values-land/dimens.xml
+++ b/java/res/values-land/dimens.xml
@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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 
+**     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 
+** 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.
 */
 -->
diff --git a/java/res/values-lt/bools.xml b/java/res/values-lt/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-lt/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-lv/bools.xml b/java/res/values-lv/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-lv/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-mk/bools.xml b/java/res/values-mk/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-mk/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ms/bools.xml b/java/res/values-ms/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ms/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-nb/bools.xml b/java/res/values-nb/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-nb/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-nl/bools.xml b/java/res/values-nl/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-nl/bools.xml
+++ b/java/res/values-nl/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-pl/bools.xml b/java/res/values-pl/bools.xml
index dabfff8..c289e5b 100644
--- a/java/res/values-pl/bools.xml
+++ b/java/res/values-pl/bools.xml
@@ -18,5 +18,7 @@
 */
 -->
 <resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
     <bool name="im_is_default">true</bool>
 </resources>
diff --git a/java/res/values-pt/bools.xml b/java/res/values-pt/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-pt/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ro/bools.xml b/java/res/values-ro/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ro/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-ru/bools.xml b/java/res/values-ru/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-ru/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-sk/bools.xml b/java/res/values-sk/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-sk/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-sl/bools.xml b/java/res/values-sl/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-sl/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-sr/bools.xml b/java/res/values-sr/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-sr/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-sv/bools.xml b/java/res/values-sv/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-sv/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-sw/bools.xml b/java/res/values-sw/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-sw/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-th/bools.xml b/java/res/values-th/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-th/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-tl/bools.xml b/java/res/values-tl/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-tl/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-tr/bools.xml b/java/res/values-tr/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-tr/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-uk/bools.xml b/java/res/values-uk/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-uk/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-vi/bools.xml b/java/res/values-vi/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-vi/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values-zu/bools.xml b/java/res/values-zu/bools.xml
new file mode 100644
index 0000000..840d20c
--- /dev/null
+++ b/java/res/values-zu/bools.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2012, 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.
+*/
+-->
+<resources>
+    <!-- Whether this input method should be used as the default for a locale. Override it
+         for supported languages. -->
+    <bool name="im_is_default">true</bool>
+</resources>
diff --git a/java/res/values/bools.xml b/java/res/values/bools.xml
index 0069596..10d2179 100644
--- a/java/res/values/bools.xml
+++ b/java/res/values/bools.xml
@@ -19,6 +19,6 @@
 -->
 <resources>
     <!-- Whether this input method should be used as the default for a locale. Override it
-         for latin languages. -->
+         for supported languages. -->
     <bool name="im_is_default">false</bool>
 </resources>
diff --git a/java/res/values/dimens.xml b/java/res/values/dimens.xml
index d92a715..0fb8877 100644
--- a/java/res/values/dimens.xml
+++ b/java/res/values/dimens.xml
@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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 
+**     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 
+** 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.
 */
 -->
diff --git a/java/res/xml/kbd_more_keys_keyboard_template.xml b/java/res/xml/kbd_more_keys_keyboard_template.xml
index 8e977c5..537973d 100644
--- a/java/res/xml/kbd_more_keys_keyboard_template.xml
+++ b/java/res/xml/kbd_more_keys_keyboard_template.xml
@@ -1,19 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-/* 
+/*
 **
 ** Copyright 2008, 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 
+** 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 
+**     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 
+** 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.
 */
 -->
diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml
index 613e9f6..7a8c6a9 100644
--- a/java/res/xml/method.xml
+++ b/java/res/xml/method.xml
@@ -76,6 +76,8 @@
     zz: QWERTY/qwerty
     -->
 <!-- TODO: use <lang>_keyboard icon instead of a common keyboard icon. -->
+<!-- Note: SupportTouchPositionCorrection extra value is obsolete and maintained for backward
+     compatibility. -->
 <!-- If IME doesn't have an applicable subtype, the first subtype will be used as a default
      subtype.-->
 <input-method xmlns:android="http://schemas.android.com/apk/res/android"
@@ -83,132 +85,154 @@
         android:isDefault="@bool/im_is_default">
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_en_US"
+            android:subtypeId="-921088104"
             android:imeSubtypeLocale="en_US"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_en_GB"
+            android:subtypeId="-1337596075"
             android:imeSubtypeLocale="en_GB"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="TrySuppressingImeSwitcher,AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1872175968"
             android:imeSubtypeLocale="af"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1494081088"
             android:imeSubtypeLocale="ar"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="499361881"
             android:imeSubtypeLocale="be"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="195674344"
             android:imeSubtypeLocale="bg"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=bulgarian"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_bulgarian_bds"
+            android:subtypeId="1599191706"
             android:imeSubtypeLocale="bg"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=bulgarian_bds"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-756735787"
             android:imeSubtypeLocale="ca"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="758984400"
             android:imeSubtypeLocale="cs"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="770990173"
             android:imeSubtypeLocale="da"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="774684257"
             android:imeSubtypeLocale="de"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="242746067"
             android:imeSubtypeLocale="el"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=greek"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1083200842"
             android:imeSubtypeLocale="eo"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="816242702"
             android:imeSubtypeLocale="es"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-332580523"
             android:imeSubtypeLocale="et"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=nordic,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1100561836"
             android:imeSubtypeLocale="fa"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=farsi"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="835636643"
             android:imeSubtypeLocale="fi"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="843948332"
             android:imeSubtypeLocale="fr"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-354699631"
             android:imeSubtypeLocale="fr_CA"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="963984255"
             android:imeSubtypeLocale="hi"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=hindi"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="901206634"
             android:imeSubtypeLocale="hr"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="903977197"
             android:imeSubtypeLocale="hu"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
@@ -216,18 +240,21 @@
     <!-- Java uses the deprecated "in" code instead of the standard "id" code for Indonesian. -->
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="2108597344"
             android:imeSubtypeLocale="in"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="2113214949"
             android:imeSubtypeLocale="is"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="931682827"
             android:imeSubtypeLocale="it"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
@@ -235,102 +262,119 @@
     <!-- Java uses the deprecated "iw" code instead of the standard "he" code for Hebrew. -->
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1727731901"
             android:imeSubtypeLocale="iw"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1846648426"
             android:imeSubtypeLocale="ka"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=georgian"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="775494660"
             android:imeSubtypeLocale="ky"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-2094941373"
             android:imeSubtypeLocale="lt"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-2093094331"
             android:imeSubtypeLocale="lv"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1353667716"
             android:imeSubtypeLocale="mk"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=south_slavic"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-2067235743"
             android:imeSubtypeLocale="ms"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1058205204"
             android:imeSubtypeLocale="nb"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1067440414"
             android:imeSubtypeLocale="nl"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1124698716"
             android:imeSubtypeLocale="pl"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-889195354"
             android:imeSubtypeLocale="pt_BR"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-486540198"
             android:imeSubtypeLocale="pt_PT"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1927784072"
             android:imeSubtypeLocale="ro"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1983547218"
             android:imeSubtypeLocale="ru"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1902849005"
             android:imeSubtypeLocale="sk"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1901925484"
             android:imeSubtypeLocale="sl"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="2009405806"
             android:imeSubtypeLocale="sr"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="SupportTouchPositionCorrection"
@@ -338,12 +382,14 @@
     <!-- TODO: Uncomment once we can handle IETF language tag with script name specified.
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_serbian_cyrillic"
+            android:subtypeId="XXXXXX"
             android:imeSubtypeLocale="sr"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_serbian_latin"
+            android:subtypeId="XXXXXX"
             android:imeSubtypeLocale="sr-Latn"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
@@ -351,54 +397,63 @@
     -->
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1219821379"
             android:imeSubtypeLocale="sv"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1891766753"
             android:imeSubtypeLocale="sw"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="529847764"
             android:imeSubtypeLocale="th"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=thai"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-259881489"
             android:imeSubtypeLocale="tl"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=spanish,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1244756446"
             android:imeSubtypeLocale="tr"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="1048856876"
             android:imeSubtypeLocale="uk"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=east_slavic"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1818808594"
             android:imeSubtypeLocale="vi"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_generic"
+            android:subtypeId="-1693209738"
             android:imeSubtypeLocale="zu"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable"
     />
     <subtype android:icon="@drawable/ic_subtype_keyboard"
             android:label="@string/subtype_no_language_qwerty"
+            android:subtypeId="-1573262419"
             android:imeSubtypeLocale="zz"
             android:imeSubtypeMode="keyboard"
             android:imeSubtypeExtraValue="KeyboardLayoutSet=qwerty,AsciiCapable,EnabledWhenDefaultIsNotAsciiCapable"
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 27c3cc3..cf89567 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -855,9 +855,10 @@
     }
 
     @Override
-    public void showGesturePreviewTrail(final PointerTracker tracker) {
+    public void showGesturePreviewTrail(final PointerTracker tracker,
+            final boolean isOldestTracker) {
         locatePreviewPlacerView();
-        mPreviewPlacerView.invalidatePointer(tracker);
+        mPreviewPlacerView.invalidatePointer(tracker, isOldestTracker);
     }
 
     @Override
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 4887ac5..e762b23 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -80,7 +80,7 @@
         public void invalidateKey(Key key);
         public void showKeyPreview(PointerTracker tracker);
         public void dismissKeyPreview(PointerTracker tracker);
-        public void showGesturePreviewTrail(PointerTracker tracker);
+        public void showGesturePreviewTrail(PointerTracker tracker, boolean isOldestTracker);
     }
 
     public interface TimerProxy {
@@ -550,7 +550,7 @@
         }
         sInGesture = true;
         mListener.onStartBatchInput();
-        mDrawingProxy.showGesturePreviewTrail(this);
+        mDrawingProxy.showGesturePreviewTrail(this, true /* isOldestTracker */);
     }
 
     private void updateBatchInput(final long eventTime) {
@@ -567,7 +567,8 @@
                 mListener.onUpdateBatchInput(sAggregratedPointers);
             }
         }
-        mDrawingProxy.showGesturePreviewTrail(this);
+        final boolean isOldestTracker = sPointerTrackerQueue.getOldestElement() == this;
+        mDrawingProxy.showGesturePreviewTrail(this, isOldestTracker);
     }
 
     private void endBatchInput() {
@@ -584,7 +585,7 @@
                 clearBatchInputPointsOfAllPointerTrackers();
             }
         }
-        mDrawingProxy.showGesturePreviewTrail(this);
+        mDrawingProxy.showGesturePreviewTrail(this,  true /* isOldestTracker */);
     }
 
     private static void abortBatchInput() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
index e0858c0..c1a5cbe 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PointerTrackerQueue.java
@@ -73,6 +73,10 @@
         mArraySize = newSize;
     }
 
+    public synchronized Element getOldestElement() {
+        return (mArraySize == 0) ? null : mExpandableArrayOfActivePointers.get(0);
+    }
+
     public synchronized void releaseAllPointersOlderThan(final Element pointer,
             final long eventTime) {
         if (DEBUG) {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
index 7104e3a..3a85009 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java
@@ -188,7 +188,7 @@
         mDrawsGestureFloatingPreviewText = drawsGestureFloatingPreviewText;
     }
 
-    public void invalidatePointer(final PointerTracker tracker) {
+    public void invalidatePointer(final PointerTracker tracker, final boolean isOldestTracker) {
         GesturePreviewTrail trail;
         synchronized (mGesturePreviewTrails) {
             trail = mGesturePreviewTrails.get(tracker.mPointerId);
@@ -199,8 +199,10 @@
         }
         trail.addStroke(tracker.getGestureStrokeWithPreviewTrail(), tracker.getDownTime());
 
-        mLastPointerX = tracker.getLastX();
-        mLastPointerY = tracker.getLastY();
+        if (isOldestTracker) {
+            mLastPointerX = tracker.getLastX();
+            mLastPointerY = tracker.getLastY();
+        }
         // TODO: Should narrow the invalidate region.
         invalidate();
     }
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
index e1cb195..9a888ad 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java
@@ -17,6 +17,7 @@
 package com.android.inputmethod.latin;
 
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
 
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -359,7 +360,7 @@
             final ByteBuffer buffer = inStream.getChannel().map(
                     FileChannel.MapMode.READ_ONLY, 0, f.length());
             final int magic = buffer.getInt();
-            if (magic != BinaryDictInputOutput.VERSION_2_MAGIC_NUMBER) {
+            if (magic != FormatSpec.VERSION_2_MAGIC_NUMBER) {
                 return false;
             }
             final int formatVersion = buffer.getInt();
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index def978e..b93c17f 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -21,6 +21,7 @@
 import com.android.inputmethod.keyboard.ProximityInfo;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -90,8 +91,8 @@
     private final DictionaryController mLocalDictionaryController = new DictionaryController();
 
     private static final int BINARY_DICT_VERSION = 1;
-    private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
-            new BinaryDictInputOutput.FormatOptions(BINARY_DICT_VERSION);
+    private static final FormatSpec.FormatOptions FORMAT_OPTIONS =
+            new FormatSpec.FormatOptions(BINARY_DICT_VERSION);
 
     /**
      * Abstract method for loading the unigrams and bigrams of a given dictionary in a background
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d8b1c29..9194a97 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -825,7 +825,8 @@
         // we know for sure the cursor moved while we were composing and we should reset
         // the state.
         final boolean noComposingSpan = composingSpanStart == -1 && composingSpanEnd == -1;
-        if (!mExpectingUpdateSelection) {
+        if (!mExpectingUpdateSelection
+                && !mConnection.isBelatedExpectedUpdate(oldSelStart, newSelStart)) {
             // TAKE CARE: there is a race condition when we enter this test even when the user
             // did not explicitly move the cursor. This happens when typing fast, where two keys
             // turn this flag on in succession and both onUpdateSelection() calls arrive after
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index efda623..f77d686 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -642,4 +642,34 @@
         commitText(" " + textBeforeCursor.subSequence(0, 1), 1);
         return true;
     }
+
+    /**
+     * Heuristic to determine if this is an expected update of the cursor.
+     *
+     * Sometimes updates to the cursor position are late because of their asynchronous nature.
+     * This method tries to determine if this update is one, based on the values of the cursor
+     * position in the update, and the currently expected position of the cursor according to
+     * LatinIME's internal accounting. If this is not a belated expected update, then it should
+     * mean that the user moved the cursor explicitly.
+     * This is quite robust, but of course it's not perfect. In particular, it will fail in the
+     * case we get an update A, the user types in N characters so as to move the cursor to A+N but
+     * we don't get those, and then the user places the cursor between A and A+N, and we get only
+     * this update and not the ones in-between. This is almost impossible to achieve even trying
+     * very very hard.
+     *
+     * @param oldSelStart The value of the old cursor position in the update.
+     * @param newSelStart The value of the new cursor position in the update.
+     * @return whether this is a belated expected update or not.
+     */
+    public boolean isBelatedExpectedUpdate(final int oldSelStart, final int newSelStart) {
+        // If this is an update that arrives at our expected position, it's a belated update.
+        if (newSelStart == mCurrentCursorPosition) return true;
+        // If this is an update that moves the cursor from our expected position, it must be
+        // an explicit move.
+        if (oldSelStart == mCurrentCursorPosition) return false;
+        // The following returns true if newSelStart is between oldSelStart and
+        // mCurrentCursorPosition. We assume that if the updated position is between the old
+        // position and the expected position, then it must be a belated update.
+        return (newSelStart - oldSelStart) * (mCurrentCursorPosition - newSelStart) >= 0;
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
index 1f5f1f7..550e4e5 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryDictIOUtils.java
@@ -19,8 +19,8 @@
 import android.util.Log;
 
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
-import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FormatOptions;
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
+import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
 import com.android.inputmethod.latin.makedict.PendingAttribute;
diff --git a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
index fbcb5ea..ef10f72 100644
--- a/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
+++ b/java/src/com/android/inputmethod/latin/makedict/BinaryDictInputOutput.java
@@ -16,7 +16,8 @@
 
 package com.android.inputmethod.latin.makedict;
 
-import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.makedict.FormatSpec.FileHeader;
+import com.android.inputmethod.latin.makedict.FormatSpec.FormatOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
 import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
 import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
@@ -47,177 +48,6 @@
 
     private static final boolean DBG = MakedictLog.DBG;
 
-    /*
-     * Array of Node(FusionDictionary.Node) layout is as follows:
-     *
-     * g |
-     * r | the number of groups, 1 or 2 bytes.
-     * o | 1 byte = bbbbbbbb match
-     * u |   case 1xxxxxxx => xxxxxxx << 8 + next byte
-     * p |   otherwise => bbbbbbbb
-     * c |
-     * ount
-     *
-     * g |
-     * r | sequence of groups,
-     * o | the layout of each group is described below.
-     * u |
-     * ps
-     *
-     */
-
-    /* Node(CharGroup) layout is as follows:
-     *   | addressType                         xx     : mask with MASK_GROUP_ADDRESS_TYPE
-     *                                 2 bits, 00 = no children : FLAG_GROUP_ADDRESS_TYPE_NOADDRESS
-     * f |                                     01 = 1 byte      : FLAG_GROUP_ADDRESS_TYPE_ONEBYTE
-     * l |                                     10 = 2 bytes     : FLAG_GROUP_ADDRESS_TYPE_TWOBYTES
-     * a |                                     11 = 3 bytes     : FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
-     * g | has several chars ?         1 bit, 1 = yes, 0 = no   : FLAG_HAS_MULTIPLE_CHARS
-     * s | has a terminal ?            1 bit, 1 = yes, 0 = no   : FLAG_IS_TERMINAL
-     *   | has shortcut targets ?      1 bit, 1 = yes, 0 = no   : FLAG_HAS_SHORTCUT_TARGETS
-     *   | has bigrams ?               1 bit, 1 = yes, 0 = no   : FLAG_HAS_BIGRAMS
-     *   | is not a word ?             1 bit, 1 = yes, 0 = no   : FLAG_IS_NOT_A_WORD
-     *   | is blacklisted ?            1 bit, 1 = yes, 0 = no   : FLAG_IS_BLACKLISTED
-     *
-     * p |
-     * a | IF HAS_PARENT_ADDRESS (defined in the file header)
-     * r |     parent address, 3byte
-     * e | the address must be negative, so the absolute value of the address is stored.
-     * n |
-     * taddress
-     *
-     * c | IF FLAG_HAS_MULTIPLE_CHARS
-     * h |   char, char, char, char    n * (1 or 3 bytes) : use CharGroupInfo for i/o helpers
-     * a |   end                       1 byte, = 0
-     * r | ELSE
-     * s |   char                      1 or 3 bytes
-     *   | END
-     *
-     * f |
-     * r | IF FLAG_IS_TERMINAL
-     * e |   frequency                 1 byte
-     * q |
-     *
-     * c | IF 00 = FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = addressType
-     * h |   // nothing
-     * i | ELSIF 01 = FLAG_GROUP_ADDRESS_TYPE_ONEBYTE == addressType
-     * l |   children address, 1 byte
-     * d | ELSIF 10 = FLAG_GROUP_ADDRESS_TYPE_TWOBYTES == addressType
-     * r |   children address, 2 bytes
-     * e | ELSE // 11 = FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = addressType
-     * n |   children address, 3 bytes
-     * A | END
-     * d
-     * dress
-     *
-     *   | IF FLAG_IS_TERMINAL && FLAG_HAS_SHORTCUT_TARGETS
-     *   | shortcut string list
-     *   | IF FLAG_IS_TERMINAL && FLAG_HAS_BIGRAMS
-     *   | bigrams address list
-     *
-     * Char format is:
-     * 1 byte = bbbbbbbb match
-     * case 000xxxxx: xxxxx << 16 + next byte << 8 + next byte
-     * else: if 00011111 (= 0x1F) : this is the terminator. This is a relevant choice because
-     *       unicode code points range from 0 to 0x10FFFF, so any 3-byte value starting with
-     *       00011111 would be outside unicode.
-     * else: iso-latin-1 code
-     * This allows for the whole unicode range to be encoded, including chars outside of
-     * the BMP. Also everything in the iso-latin-1 charset is only 1 byte, except control
-     * characters which should never happen anyway (and still work, but take 3 bytes).
-     *
-     * bigram address list is:
-     * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no     : FLAG_ATTRIBUTE_HAS_NEXT
-     *           | addressSign = 1 bit,                 : FLAG_ATTRIBUTE_OFFSET_NEGATIVE
-     *           |                      1 = must take -address, 0 = must take +address
-     *           |                         xx : mask with MASK_ATTRIBUTE_ADDRESS_TYPE
-     *           | addressFormat = 2 bits, 00 = unused  : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
-     *           |                         01 = 1 byte  : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
-     *           |                         10 = 2 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES
-     *           |                         11 = 3 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES
-     *           | 4 bits : frequency         : mask with FLAG_ATTRIBUTE_FREQUENCY
-     * <address> | IF (01 == FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE == addressFormat)
-     *           |   read 1 byte, add top 4 bits
-     *           | ELSIF (10 == FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES == addressFormat)
-     *           |   read 2 bytes, add top 4 bits
-     *           | ELSE // 11 == FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES == addressFormat
-     *           |   read 3 bytes, add top 4 bits
-     *           | END
-     *           | if (FLAG_ATTRIBUTE_OFFSET_NEGATIVE) then address = -address
-     * if (FLAG_ATTRIBUTE_HAS_NEXT) goto bigram_and_shortcut_address_list_is
-     *
-     * shortcut string list is:
-     * <byte size> = GROUP_SHORTCUT_LIST_SIZE_SIZE bytes, big-endian: size of the list, in bytes.
-     * <flags>     = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
-     *               | reserved = 3 bits, must be 0
-     *               | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
-     * <shortcut>  = | string of characters at the char format described above, with the terminator
-     *               | used to signal the end of the string.
-     * if (FLAG_ATTRIBUTE_HAS_NEXT goto flags
-     */
-
-    private static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
-    public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
-    private static final int MINIMUM_SUPPORTED_VERSION = 1;
-    private static final int MAXIMUM_SUPPORTED_VERSION = 3;
-    private static final int NOT_A_VERSION_NUMBER = -1;
-    private static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
-    private static final int FIRST_VERSION_WITH_PARENT_ADDRESS = 3;
-
-    // These options need to be the same numeric values as the one in the native reading code.
-    private static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
-    private static final int HAS_PARENT_ADDRESS = 0x2;
-    private static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
-    private static final int CONTAINS_BIGRAMS_FLAG = 0x8;
-
-    // TODO: Make this value adaptative to content data, store it in the header, and
-    // use it in the reading code.
-    private static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
-
-    private static final int PARENT_ADDRESS_SIZE = 3;
-
-    private static final int MASK_GROUP_ADDRESS_TYPE = 0xC0;
-    private static final int FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = 0x00;
-    private static final int FLAG_GROUP_ADDRESS_TYPE_ONEBYTE = 0x40;
-    private static final int FLAG_GROUP_ADDRESS_TYPE_TWOBYTES = 0x80;
-    private static final int FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = 0xC0;
-
-    private static final int FLAG_HAS_MULTIPLE_CHARS = 0x20;
-
-    private static final int FLAG_IS_TERMINAL = 0x10;
-    private static final int FLAG_HAS_SHORTCUT_TARGETS = 0x08;
-    private static final int FLAG_HAS_BIGRAMS = 0x04;
-    private static final int FLAG_IS_NOT_A_WORD = 0x02;
-    private static final int FLAG_IS_BLACKLISTED = 0x01;
-
-    private static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
-    private static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
-    private static final int MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
-    private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
-    private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
-    private static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
-    private static final int FLAG_ATTRIBUTE_FREQUENCY = 0x0F;
-
-    private static final int GROUP_CHARACTERS_TERMINATOR = 0x1F;
-
-    private static final int GROUP_TERMINATOR_SIZE = 1;
-    private static final int GROUP_FLAGS_SIZE = 1;
-    private static final int GROUP_FREQUENCY_SIZE = 1;
-    private static final int GROUP_MAX_ADDRESS_SIZE = 3;
-    private static final int GROUP_ATTRIBUTE_FLAGS_SIZE = 1;
-    private static final int GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE = 3;
-    private static final int GROUP_SHORTCUT_LIST_SIZE_SIZE = 2;
-
-    private static final int NO_CHILDREN_ADDRESS = Integer.MIN_VALUE;
-    private static final int NO_PARENT_ADDRESS = 0;
-    private static final int INVALID_CHARACTER = -1;
-
-    private static final int MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT = 0x7F; // 127
-    private static final int MAX_CHARGROUPS_IN_A_NODE = 0x7FFF; // 32767
-
-    private static final int MAX_TERMINAL_FREQUENCY = 255;
-    private static final int MAX_BIGRAM_FREQUENCY = 15;
-
     // Arbitrary limit to how much passes we consider address size compression should
     // terminate in. At the time of this writing, our largest dictionary completes
     // compression in five passes.
@@ -280,40 +110,6 @@
     }
 
     /**
-     * Options about file format.
-     */
-    public static class FormatOptions {
-        public final int mVersion;
-        public final boolean mHasParentAddress;
-        public FormatOptions(final int version) {
-            this(version, false);
-        }
-        public FormatOptions(final int version, final boolean hasParentAddress) {
-            mVersion = version;
-            if (version < FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
-                throw new RuntimeException("Parent addresses are only supported with versions "
-                        + FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
-            }
-            mHasParentAddress = hasParentAddress;
-        }
-    }
-
-    /**
-     * Class representing file header.
-     */
-    private static final class FileHeader {
-        public final int mHeaderSize;
-        public final DictionaryOptions mDictionaryOptions;
-        public final FormatOptions mFormatOptions;
-        public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
-                final FormatOptions formatOptions) {
-            mHeaderSize = headerSize;
-            mDictionaryOptions = dictionaryOptions;
-            mFormatOptions = formatOptions;
-        }
-    }
-
-    /**
      * A class grouping utility function for our specific character encoding.
      */
     private static class CharEncoding {
@@ -349,7 +145,7 @@
         private static int getCharSize(final int character) {
             // See char encoding in FusionDictionary.java
             if (fitsOnOneByte(character)) return 1;
-            if (INVALID_CHARACTER == character) return 1;
+            if (FormatSpec.INVALID_CHARACTER == character) return 1;
             return 3;
         }
 
@@ -407,7 +203,7 @@
                     buffer[index++] = (byte)(0xFF & codePoint);
                 }
             }
-            buffer[index++] = GROUP_CHARACTERS_TERMINATOR;
+            buffer[index++] = FormatSpec.GROUP_CHARACTERS_TERMINATOR;
             return index - origin;
         }
 
@@ -431,7 +227,7 @@
                     buffer.write((byte) (0xFF & codePoint));
                 }
             }
-            buffer.write(GROUP_CHARACTERS_TERMINATOR);
+            buffer.write(FormatSpec.GROUP_CHARACTERS_TERMINATOR);
         }
 
         /**
@@ -440,7 +236,7 @@
         private static String readString(final FusionDictionaryBufferInterface buffer) {
             final StringBuilder s = new StringBuilder();
             int character = readChar(buffer);
-            while (character != INVALID_CHARACTER) {
+            while (character != FormatSpec.INVALID_CHARACTER) {
                 s.appendCodePoint(character);
                 character = readChar(buffer);
             }
@@ -458,7 +254,9 @@
         private static int readChar(final FusionDictionaryBufferInterface buffer) {
             int character = buffer.readUnsignedByte();
             if (!fitsOnOneByte(character)) {
-                if (GROUP_CHARACTERS_TERMINATOR == character) return INVALID_CHARACTER;
+                if (FormatSpec.GROUP_CHARACTERS_TERMINATOR == character) {
+                    return FormatSpec.INVALID_CHARACTER;
+                }
                 character <<= 16;
                 character += buffer.readUnsignedShort();
             }
@@ -477,7 +275,7 @@
      */
     private static int getGroupCharactersSize(final CharGroup group) {
         int size = CharEncoding.getCharArraySize(group.mChars);
-        if (group.hasSeveralChars()) size += GROUP_TERMINATOR_SIZE;
+        if (group.hasSeveralChars()) size += FormatSpec.GROUP_TERMINATOR_SIZE;
         return size;
     }
 
@@ -487,13 +285,14 @@
      * @return the size of the group count, either 1 or 2 bytes.
      */
     private static int getGroupCountSize(final int count) {
-        if (MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= count) {
+        if (FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= count) {
             return 1;
-        } else if (MAX_CHARGROUPS_IN_A_NODE >= count) {
+        } else if (FormatSpec.MAX_CHARGROUPS_IN_A_NODE >= count) {
             return 2;
         } else {
-            throw new RuntimeException("Can't have more than " + MAX_CHARGROUPS_IN_A_NODE
-                    + " groups in a node (found " + count + ")");
+            throw new RuntimeException("Can't have more than "
+                    + FormatSpec.MAX_CHARGROUPS_IN_A_NODE + " groups in a node (found " + count
+                    + ")");
         }
     }
 
@@ -510,14 +309,14 @@
      * Compute the size of a shortcut in bytes.
      */
     private static int getShortcutSize(final WeightedString shortcut) {
-        int size = GROUP_ATTRIBUTE_FLAGS_SIZE;
+        int size = FormatSpec.GROUP_ATTRIBUTE_FLAGS_SIZE;
         final String word = shortcut.mWord;
         final int length = word.length();
         for (int i = 0; i < length; i = word.offsetByCodePoints(i, 1)) {
             final int codePoint = word.codePointAt(i);
             size += CharEncoding.getCharSize(codePoint);
         }
-        size += GROUP_TERMINATOR_SIZE;
+        size += FormatSpec.GROUP_TERMINATOR_SIZE;
         return size;
     }
 
@@ -529,7 +328,7 @@
      */
     private static int getShortcutListSize(final ArrayList<WeightedString> shortcutList) {
         if (null == shortcutList) return 0;
-        int size = GROUP_SHORTCUT_LIST_SIZE_SIZE;
+        int size = FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
         for (final WeightedString shortcut : shortcutList) {
             size += getShortcutSize(shortcut);
         }
@@ -546,11 +345,12 @@
     private static int getCharGroupMaximumSize(final CharGroup group, final FormatOptions options) {
         int size = getGroupHeaderSize(group, options);
         // If terminal, one byte for the frequency
-        if (group.isTerminal()) size += GROUP_FREQUENCY_SIZE;
-        size += GROUP_MAX_ADDRESS_SIZE; // For children address
+        if (group.isTerminal()) size += FormatSpec.GROUP_FREQUENCY_SIZE;
+        size += FormatSpec.GROUP_MAX_ADDRESS_SIZE; // For children address
         size += getShortcutListSize(group.mShortcutTargets);
         if (null != group.mBigrams) {
-            size += (GROUP_ATTRIBUTE_FLAGS_SIZE + GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE)
+            size += (FormatSpec.GROUP_ATTRIBUTE_FLAGS_SIZE
+                    + FormatSpec.GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE)
                     * group.mBigrams.size();
         }
         return size;
@@ -577,14 +377,14 @@
      * Helper method to hide the actual value of the no children address.
      */
     private static boolean hasChildrenAddress(final int address) {
-        return NO_CHILDREN_ADDRESS != address;
+        return FormatSpec.NO_CHILDREN_ADDRESS != address;
     }
 
     /**
      * Helper method to check whether the CharGroup has a parent address.
      */
     private static boolean hasParentAddress(final FormatOptions options) {
-        return options.mVersion >= FIRST_VERSION_WITH_PARENT_ADDRESS
+        return options.mVersion >= FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS
                 && options.mHasParentAddress;
     }
 
@@ -596,9 +396,10 @@
      */
     private static int getGroupHeaderSize(final CharGroup group, final FormatOptions options) {
         if (hasParentAddress(options)) {
-            return GROUP_FLAGS_SIZE + PARENT_ADDRESS_SIZE + getGroupCharactersSize(group);
+            return FormatSpec.GROUP_FLAGS_SIZE + FormatSpec.PARENT_ADDRESS_SIZE
+                    + getGroupCharactersSize(group);
         } else {
-            return GROUP_FLAGS_SIZE + getGroupCharactersSize(group);
+            return FormatSpec.GROUP_FLAGS_SIZE + getGroupCharactersSize(group);
         }
     }
 
@@ -698,7 +499,7 @@
                 group.mCachedAddress = node.mCachedAddress + size;
             }
             int groupSize = getGroupHeaderSize(group, formatOptions);
-            if (group.isTerminal()) groupSize += GROUP_FREQUENCY_SIZE;
+            if (group.isTerminal()) groupSize += FormatSpec.GROUP_FREQUENCY_SIZE;
             if (null != group.mChildren) {
                 final int offsetBasePoint = groupSize + node.mCachedAddress + size;
                 final int offset = group.mChildren.mCachedAddress - offsetBasePoint;
@@ -711,10 +512,10 @@
             if (null != group.mBigrams) {
                 for (WeightedString bigram : group.mBigrams) {
                     final int offsetBasePoint = groupSize + node.mCachedAddress + size
-                            + GROUP_FLAGS_SIZE;
+                            + FormatSpec.GROUP_FLAGS_SIZE;
                     final int addressOfBigram = findAddressOfWord(dict, bigram.mWord);
                     final int offset = addressOfBigram - offsetBasePoint;
-                    groupSize += getByteSize(offset) + GROUP_FLAGS_SIZE;
+                    groupSize += getByteSize(offset) + FormatSpec.GROUP_FLAGS_SIZE;
                 }
             }
             group.mCachedSize = groupSize;
@@ -854,20 +655,20 @@
     private static byte makeCharGroupFlags(final CharGroup group, final int groupAddress,
             final int childrenOffset) {
         byte flags = 0;
-        if (group.mChars.length > 1) flags |= FLAG_HAS_MULTIPLE_CHARS;
+        if (group.mChars.length > 1) flags |= FormatSpec.FLAG_HAS_MULTIPLE_CHARS;
         if (group.mFrequency >= 0) {
-            flags |= FLAG_IS_TERMINAL;
+            flags |= FormatSpec.FLAG_IS_TERMINAL;
         }
         if (null != group.mChildren) {
             switch (getByteSize(childrenOffset)) {
              case 1:
-                 flags |= FLAG_GROUP_ADDRESS_TYPE_ONEBYTE;
+                 flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_ONEBYTE;
                  break;
              case 2:
-                 flags |= FLAG_GROUP_ADDRESS_TYPE_TWOBYTES;
+                 flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_TWOBYTES;
                  break;
              case 3:
-                 flags |= FLAG_GROUP_ADDRESS_TYPE_THREEBYTES;
+                 flags |= FormatSpec.FLAG_GROUP_ADDRESS_TYPE_THREEBYTES;
                  break;
              default:
                  throw new RuntimeException("Node with a strange address");
@@ -877,19 +678,19 @@
             if (DBG && 0 == group.mShortcutTargets.size()) {
                 throw new RuntimeException("0-sized shortcut list must be null");
             }
-            flags |= FLAG_HAS_SHORTCUT_TARGETS;
+            flags |= FormatSpec.FLAG_HAS_SHORTCUT_TARGETS;
         }
         if (null != group.mBigrams) {
             if (DBG && 0 == group.mBigrams.size()) {
                 throw new RuntimeException("0-sized bigram list must be null");
             }
-            flags |= FLAG_HAS_BIGRAMS;
+            flags |= FormatSpec.FLAG_HAS_BIGRAMS;
         }
         if (group.mIsNotAWord) {
-            flags |= FLAG_IS_NOT_A_WORD;
+            flags |= FormatSpec.FLAG_IS_NOT_A_WORD;
         }
         if (group.mIsBlacklistEntry) {
-            flags |= FLAG_IS_BLACKLISTED;
+            flags |= FormatSpec.FLAG_IS_BLACKLISTED;
         }
         return flags;
     }
@@ -906,17 +707,17 @@
      */
     private static final int makeBigramFlags(final boolean more, final int offset,
             int bigramFrequency, final int unigramFrequency, final String word) {
-        int bigramFlags = (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0)
-                + (offset < 0 ? FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
+        int bigramFlags = (more ? FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT : 0)
+                + (offset < 0 ? FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE : 0);
         switch (getByteSize(offset)) {
         case 1:
-            bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
+            bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE;
             break;
         case 2:
-            bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
+            bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES;
             break;
         case 3:
-            bigramFlags |= FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
+            bigramFlags |= FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES;
             break;
         default:
             throw new RuntimeException("Strange offset size");
@@ -951,7 +752,8 @@
         // approximation. (0.5 to get the first step start, and 0.5 to get the middle of the
         // step pointed by the discretized frequency.
         final float stepSize =
-                (MAX_TERMINAL_FREQUENCY - unigramFrequency) / (1.5f + MAX_BIGRAM_FREQUENCY);
+                (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency)
+                / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY);
         final float firstStepStart = 1 + unigramFrequency + (stepSize / 2.0f);
         final int discretizedFrequency = (int)((bigramFrequency - firstStepStart) / stepSize);
         // If the bigram freq is less than half-a-step higher than the unigram freq, we get -1
@@ -960,7 +762,7 @@
         // small over-estimation that we get in this case. TODO: actually remove this bigram
         // if discretizedFrequency < 0.
         final int finalBigramFrequency = discretizedFrequency > 0 ? discretizedFrequency : 0;
-        bigramFlags += finalBigramFrequency & FLAG_ATTRIBUTE_FREQUENCY;
+        bigramFlags += finalBigramFrequency & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY;
         return bigramFlags;
     }
 
@@ -971,10 +773,10 @@
             final FormatOptions formatOptions) {
         final DictionaryOptions options = dictionary.mOptions;
         final boolean hasBigrams = dictionary.hasBigrams();
-        return (options.mFrenchLigatureProcessing ? FRENCH_LIGATURE_PROCESSING_FLAG : 0)
-                + (options.mGermanUmlautProcessing ? GERMAN_UMLAUT_PROCESSING_FLAG : 0)
-                + (hasBigrams ? CONTAINS_BIGRAMS_FLAG : 0)
-                + (formatOptions.mHasParentAddress ? HAS_PARENT_ADDRESS : 0);
+        return (options.mFrenchLigatureProcessing ? FormatSpec.FRENCH_LIGATURE_PROCESSING_FLAG : 0)
+                + (options.mGermanUmlautProcessing ? FormatSpec.GERMAN_UMLAUT_PROCESSING_FLAG : 0)
+                + (hasBigrams ? FormatSpec.CONTAINS_BIGRAMS_FLAG : 0)
+                + (formatOptions.mHasParentAddress ? FormatSpec.HAS_PARENT_ADDRESS : 0);
     }
 
     /**
@@ -985,7 +787,8 @@
      * @return the flags
      */
     private static final int makeShortcutFlags(final boolean more, final int frequency) {
-        return (more ? FLAG_ATTRIBUTE_HAS_NEXT : 0) + (frequency & FLAG_ATTRIBUTE_FREQUENCY);
+        return (more ? FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT : 0)
+                + (frequency & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY);
     }
 
     /**
@@ -1025,18 +828,20 @@
                     + index + " <> " + group.mCachedAddress);
             groupAddress += getGroupHeaderSize(group, formatOptions);
             // Sanity checks.
-            if (DBG && group.mFrequency > MAX_TERMINAL_FREQUENCY) {
-                throw new RuntimeException("A node has a frequency > " + MAX_TERMINAL_FREQUENCY
+            if (DBG && group.mFrequency > FormatSpec.MAX_TERMINAL_FREQUENCY) {
+                throw new RuntimeException("A node has a frequency > "
+                        + FormatSpec.MAX_TERMINAL_FREQUENCY
                         + " : " + group.mFrequency);
             }
-            if (group.mFrequency >= 0) groupAddress += GROUP_FREQUENCY_SIZE;
+            if (group.mFrequency >= 0) groupAddress += FormatSpec.GROUP_FREQUENCY_SIZE;
             final int childrenOffset = null == group.mChildren
-                    ? NO_CHILDREN_ADDRESS : group.mChildren.mCachedAddress - groupAddress;
+                    ? FormatSpec.NO_CHILDREN_ADDRESS
+                            : group.mChildren.mCachedAddress - groupAddress;
             byte flags = makeCharGroupFlags(group, groupAddress, childrenOffset);
             buffer[index++] = flags;
 
             if (hasParentAddress(formatOptions)) {
-                if (parentAddress == NO_PARENT_ADDRESS) {
+                if (parentAddress == FormatSpec.NO_PARENT_ADDRESS) {
                     // this node is the root node.
                     buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
                 } else {
@@ -1052,7 +857,7 @@
 
             index = CharEncoding.writeCharArray(group.mChars, buffer, index);
             if (group.hasSeveralChars()) {
-                buffer[index++] = GROUP_CHARACTERS_TERMINATOR;
+                buffer[index++] = FormatSpec.GROUP_CHARACTERS_TERMINATOR;
             }
             if (group.mFrequency >= 0) {
                 buffer[index++] = (byte) group.mFrequency;
@@ -1064,8 +869,8 @@
             // Write shortcuts
             if (null != group.mShortcutTargets) {
                 final int indexOfShortcutByteSize = index;
-                index += GROUP_SHORTCUT_LIST_SIZE_SIZE;
-                groupAddress += GROUP_SHORTCUT_LIST_SIZE_SIZE;
+                index += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
+                groupAddress += FormatSpec.GROUP_SHORTCUT_LIST_SIZE_SIZE;
                 final Iterator<WeightedString> shortcutIterator = group.mShortcutTargets.iterator();
                 while (shortcutIterator.hasNext()) {
                     final WeightedString target = shortcutIterator.next();
@@ -1187,28 +992,30 @@
         // parents. As long as this is ensured, the dictionary file may grow to any size.
 
         final int version = formatOptions.mVersion;
-        if (version < MINIMUM_SUPPORTED_VERSION || version > MAXIMUM_SUPPORTED_VERSION) {
+        if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
+                || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
             throw new UnsupportedFormatException("Requested file format version " + version
                     + ", but this implementation only supports versions "
-                    + MINIMUM_SUPPORTED_VERSION + " through " + MAXIMUM_SUPPORTED_VERSION);
+                    + FormatSpec.MINIMUM_SUPPORTED_VERSION + " through "
+                    + FormatSpec.MAXIMUM_SUPPORTED_VERSION);
         }
 
         ByteArrayOutputStream headerBuffer = new ByteArrayOutputStream(256);
 
         // The magic number in big-endian order.
-        if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
+        if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
             // Magic number for version 2+.
-            headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 24)));
-            headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 16)));
-            headerBuffer.write((byte) (0xFF & (VERSION_2_MAGIC_NUMBER >> 8)));
-            headerBuffer.write((byte) (0xFF & VERSION_2_MAGIC_NUMBER));
+            headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 24)));
+            headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 16)));
+            headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_2_MAGIC_NUMBER >> 8)));
+            headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_2_MAGIC_NUMBER));
             // Dictionary version.
             headerBuffer.write((byte) (0xFF & (version >> 8)));
             headerBuffer.write((byte) (0xFF & version));
         } else {
             // Magic number for version 1.
-            headerBuffer.write((byte) (0xFF & (VERSION_1_MAGIC_NUMBER >> 8)));
-            headerBuffer.write((byte) (0xFF & VERSION_1_MAGIC_NUMBER));
+            headerBuffer.write((byte) (0xFF & (FormatSpec.VERSION_1_MAGIC_NUMBER >> 8)));
+            headerBuffer.write((byte) (0xFF & FormatSpec.VERSION_1_MAGIC_NUMBER));
             // Dictionary version.
             headerBuffer.write((byte) (0xFF & version));
         }
@@ -1216,7 +1023,7 @@
         final int options = makeOptionsValue(dict, formatOptions);
         headerBuffer.write((byte) (0xFF & (options >> 8)));
         headerBuffer.write((byte) (0xFF & options));
-        if (version >= FIRST_VERSION_WITH_HEADER_SIZE) {
+        if (version >= FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
             final int headerSizeOffset = headerBuffer.size();
             // Placeholder to be written later with header size.
             for (int i = 0; i < 4; ++i) {
@@ -1275,7 +1082,7 @@
     // Input methods: Read a binary dictionary to memory.
     // readDictionaryBinary is the public entry point for them.
 
-    private static final int[] CHARACTER_BUFFER = new int[MAX_WORD_LENGTH];
+    private static final int[] CHARACTER_BUFFER = new int[FormatSpec.MAX_WORD_LENGTH];
     private static CharGroupInfo readCharGroup(final FusionDictionaryBufferInterface buffer,
             final int originalGroupAddress, final FormatOptions options) {
         int addressPointer = originalGroupAddress;
@@ -1288,11 +1095,11 @@
             parentAddress = -buffer.readUnsignedInt24();
             addressPointer += 3;
         } else {
-            parentAddress = NO_PARENT_ADDRESS;
+            parentAddress = FormatSpec.NO_PARENT_ADDRESS;
         }
 
         final int characters[];
-        if (0 != (flags & FLAG_HAS_MULTIPLE_CHARS)) {
+        if (0 != (flags & FormatSpec.FLAG_HAS_MULTIPLE_CHARS)) {
             int index = 0;
             int character = CharEncoding.readChar(buffer);
             addressPointer += CharEncoding.getCharSize(character);
@@ -1311,33 +1118,33 @@
             characters = new int[] { character };
         }
         final int frequency;
-        if (0 != (FLAG_IS_TERMINAL & flags)) {
+        if (0 != (FormatSpec.FLAG_IS_TERMINAL & flags)) {
             ++addressPointer;
             frequency = buffer.readUnsignedByte();
         } else {
             frequency = CharGroup.NOT_A_TERMINAL;
         }
         int childrenAddress = addressPointer;
-        switch (flags & MASK_GROUP_ADDRESS_TYPE) {
-        case FLAG_GROUP_ADDRESS_TYPE_ONEBYTE:
+        switch (flags & FormatSpec.MASK_GROUP_ADDRESS_TYPE) {
+        case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_ONEBYTE:
             childrenAddress += buffer.readUnsignedByte();
             addressPointer += 1;
             break;
-        case FLAG_GROUP_ADDRESS_TYPE_TWOBYTES:
+        case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_TWOBYTES:
             childrenAddress += buffer.readUnsignedShort();
             addressPointer += 2;
             break;
-        case FLAG_GROUP_ADDRESS_TYPE_THREEBYTES:
+        case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_THREEBYTES:
             childrenAddress += buffer.readUnsignedInt24();
             addressPointer += 3;
             break;
-        case FLAG_GROUP_ADDRESS_TYPE_NOADDRESS:
+        case FormatSpec.FLAG_GROUP_ADDRESS_TYPE_NOADDRESS:
         default:
-            childrenAddress = NO_CHILDREN_ADDRESS;
+            childrenAddress = FormatSpec.NO_CHILDREN_ADDRESS;
             break;
         }
         ArrayList<WeightedString> shortcutTargets = null;
-        if (0 != (flags & FLAG_HAS_SHORTCUT_TARGETS)) {
+        if (0 != (flags & FormatSpec.FLAG_HAS_SHORTCUT_TARGETS)) {
             final int pointerBefore = buffer.position();
             shortcutTargets = new ArrayList<WeightedString>();
             buffer.readUnsignedShort(); // Skip the size
@@ -1345,29 +1152,30 @@
                 final int targetFlags = buffer.readUnsignedByte();
                 final String word = CharEncoding.readString(buffer);
                 shortcutTargets.add(new WeightedString(word,
-                        targetFlags & FLAG_ATTRIBUTE_FREQUENCY));
-                if (0 == (targetFlags & FLAG_ATTRIBUTE_HAS_NEXT)) break;
+                        targetFlags & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY));
+                if (0 == (targetFlags & FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT)) break;
             }
             addressPointer += buffer.position() - pointerBefore;
         }
         ArrayList<PendingAttribute> bigrams = null;
-        if (0 != (flags & FLAG_HAS_BIGRAMS)) {
+        if (0 != (flags & FormatSpec.FLAG_HAS_BIGRAMS)) {
             bigrams = new ArrayList<PendingAttribute>();
             while (true) {
                 final int bigramFlags = buffer.readUnsignedByte();
                 ++addressPointer;
-                final int sign = 0 == (bigramFlags & FLAG_ATTRIBUTE_OFFSET_NEGATIVE) ? 1 : -1;
+                final int sign = 0 == (bigramFlags & FormatSpec.FLAG_ATTRIBUTE_OFFSET_NEGATIVE)
+                        ? 1 : -1;
                 int bigramAddress = addressPointer;
-                switch (bigramFlags & MASK_ATTRIBUTE_ADDRESS_TYPE) {
-                case FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE:
+                switch (bigramFlags & FormatSpec.MASK_ATTRIBUTE_ADDRESS_TYPE) {
+                case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE:
                     bigramAddress += sign * buffer.readUnsignedByte();
                     addressPointer += 1;
                     break;
-                case FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES:
+                case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES:
                     bigramAddress += sign * buffer.readUnsignedShort();
                     addressPointer += 2;
                     break;
-                case FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES:
+                case FormatSpec.FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES:
                     final int offset = (buffer.readUnsignedByte() << 16)
                             + buffer.readUnsignedShort();
                     bigramAddress += sign * offset;
@@ -1376,9 +1184,9 @@
                 default:
                     throw new RuntimeException("Has bigrams with no address");
                 }
-                bigrams.add(new PendingAttribute(bigramFlags & FLAG_ATTRIBUTE_FREQUENCY,
+                bigrams.add(new PendingAttribute(bigramFlags & FormatSpec.FLAG_ATTRIBUTE_FREQUENCY,
                         bigramAddress));
-                if (0 == (bigramFlags & FLAG_ATTRIBUTE_HAS_NEXT)) break;
+                if (0 == (bigramFlags & FormatSpec.FLAG_ATTRIBUTE_HAS_NEXT)) break;
             }
         }
         return new CharGroupInfo(originalGroupAddress, addressPointer, flags, characters, frequency,
@@ -1390,10 +1198,10 @@
      */
     private static int readCharGroupCount(final FusionDictionaryBufferInterface buffer) {
         final int msb = buffer.readUnsignedByte();
-        if (MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= msb) {
+        if (FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT >= msb) {
             return msb;
         } else {
-            return ((MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT & msb) << 8)
+            return ((FormatSpec.MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT & msb) << 8)
                     + buffer.readUnsignedByte();
         }
     }
@@ -1432,16 +1240,16 @@
         return result;
     }
 
-    private static int[] sGetWordBuffer = new int[MAX_WORD_LENGTH];
+    private static int[] sGetWordBuffer = new int[FormatSpec.MAX_WORD_LENGTH];
     private static String getWordAtAddressWithParentAddress(
             final FusionDictionaryBufferInterface buffer, final int headerSize, final int address,
             final FormatOptions options) {
         final StringBuilder builder = new StringBuilder();
 
         int currentAddress = address;
-        int index = MAX_WORD_LENGTH - 1;
+        int index = FormatSpec.MAX_WORD_LENGTH - 1;
         // the length of the path from the root to the leaf is limited by MAX_WORD_LENGTH
-        for (int count = 0; count < MAX_WORD_LENGTH; ++count) {
+        for (int count = 0; count < FormatSpec.MAX_WORD_LENGTH; ++count) {
             buffer.position(currentAddress + headerSize);
             final CharGroupInfo currentInfo = readCharGroup(buffer, currentAddress, options);
             for (int i = 0; i < currentInfo.mCharacters.length; ++i) {
@@ -1449,11 +1257,11 @@
                         currentInfo.mCharacters[currentInfo.mCharacters.length - i - 1];
             }
 
-            if (currentInfo.mParentAddress == NO_PARENT_ADDRESS) break;
+            if (currentInfo.mParentAddress == FormatSpec.NO_PARENT_ADDRESS) break;
             currentAddress = currentInfo.mParentAddress + currentInfo.mOriginalAddress;
         }
 
-        return new String(sGetWordBuffer, index + 1, MAX_WORD_LENGTH - index - 1);
+        return new String(sGetWordBuffer, index + 1, FormatSpec.MAX_WORD_LENGTH - index - 1);
     }
 
     private static String getWordAtAddressWithoutParentAddress(
@@ -1544,13 +1352,13 @@
                 }
                 nodeContents.add(
                         new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
-                                0 != (info.mFlags & FLAG_IS_NOT_A_WORD),
-                                0 != (info.mFlags & FLAG_IS_BLACKLISTED), children));
+                                0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
+                                0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED), children));
             } else {
                 nodeContents.add(
                         new CharGroup(info.mCharacters, shortcutTargets, bigrams, info.mFrequency,
-                                0 != (info.mFlags & FLAG_IS_NOT_A_WORD),
-                                0 != (info.mFlags & FLAG_IS_BLACKLISTED)));
+                                0 != (info.mFlags & FormatSpec.FLAG_IS_NOT_A_WORD),
+                                0 != (info.mFlags & FormatSpec.FLAG_IS_BLACKLISTED)));
             }
             groupOffset = info.mEndAddress;
         }
@@ -1585,7 +1393,7 @@
             final Map<Integer, String> words, final Map<Integer, Integer> frequencies,
             final Map<Integer, ArrayList<PendingAttribute>> bigrams,
             final FormatOptions formatOptions) {
-        int[] pushedChars = new int[MAX_WORD_LENGTH + 1];
+        int[] pushedChars = new int[FormatSpec.MAX_WORD_LENGTH + 1];
 
         Stack<Position> stack = new Stack<Position>();
         int index = 0;
@@ -1664,10 +1472,10 @@
     private static int getFormatVersion(final FusionDictionaryBufferInterface buffer)
             throws IOException {
         final int magic_v1 = buffer.readUnsignedShort();
-        if (VERSION_1_MAGIC_NUMBER == magic_v1) return buffer.readUnsignedByte();
+        if (FormatSpec.VERSION_1_MAGIC_NUMBER == magic_v1) return buffer.readUnsignedByte();
         final int magic_v2 = (magic_v1 << 16) + buffer.readUnsignedShort();
-        if (VERSION_2_MAGIC_NUMBER == magic_v2) return buffer.readUnsignedShort();
-        return NOT_A_VERSION_NUMBER;
+        if (FormatSpec.VERSION_2_MAGIC_NUMBER == magic_v2) return buffer.readUnsignedShort();
+        return FormatSpec.NOT_A_VERSION_NUMBER;
     }
 
     /**
@@ -1678,10 +1486,11 @@
     private static int checkFormatVersion(final FusionDictionaryBufferInterface buffer)
             throws IOException, UnsupportedFormatException {
         final int version = getFormatVersion(buffer);
-        if (version < MINIMUM_SUPPORTED_VERSION || version > MAXIMUM_SUPPORTED_VERSION) {
+        if (version < FormatSpec.MINIMUM_SUPPORTED_VERSION
+                || version > FormatSpec.MAXIMUM_SUPPORTED_VERSION) {
             throw new UnsupportedFormatException("This file has version " + version
                     + ", but this implementation does not support versions above "
-                    + MAXIMUM_SUPPORTED_VERSION);
+                    + FormatSpec.MAXIMUM_SUPPORTED_VERSION);
         }
         return version;
     }
@@ -1699,7 +1508,7 @@
 
         final HashMap<String, String> attributes = new HashMap<String, String>();
         final int headerSize;
-        if (version < FIRST_VERSION_WITH_HEADER_SIZE) {
+        if (version < FormatSpec.FIRST_VERSION_WITH_HEADER_SIZE) {
             headerSize = buffer.position();
         } else {
             headerSize = buffer.readInt();
@@ -1713,10 +1522,10 @@
 
         final FileHeader header = new FileHeader(headerSize,
                 new FusionDictionary.DictionaryOptions(attributes,
-                        0 != (optionsFlags & GERMAN_UMLAUT_PROCESSING_FLAG),
-                        0 != (optionsFlags & FRENCH_LIGATURE_PROCESSING_FLAG)),
+                        0 != (optionsFlags & FormatSpec.GERMAN_UMLAUT_PROCESSING_FLAG),
+                        0 != (optionsFlags & FormatSpec.FRENCH_LIGATURE_PROCESSING_FLAG)),
                 new FormatOptions(version,
-                        0 != (optionsFlags & HAS_PARENT_ADDRESS)));
+                        0 != (optionsFlags & FormatSpec.HAS_PARENT_ADDRESS)));
         return header;
     }
 
@@ -1809,7 +1618,8 @@
             final ByteBuffer buffer = inStream.getChannel().map(
                     FileChannel.MapMode.READ_ONLY, 0, file.length());
             final int version = getFormatVersion(new ByteBufferWrapper(buffer));
-            return (version >= MINIMUM_SUPPORTED_VERSION && version <= MAXIMUM_SUPPORTED_VERSION);
+            return (version >= FormatSpec.MINIMUM_SUPPORTED_VERSION
+                    && version <= FormatSpec.MAXIMUM_SUPPORTED_VERSION);
         } catch (FileNotFoundException e) {
             return false;
         } catch (IOException e) {
@@ -1836,8 +1646,8 @@
      */
     public static int reconstructBigramFrequency(final int unigramFrequency,
             final int bigramFrequency) {
-        final float stepSize = (MAX_TERMINAL_FREQUENCY - unigramFrequency)
-                / (1.5f + MAX_BIGRAM_FREQUENCY);
+        final float stepSize = (FormatSpec.MAX_TERMINAL_FREQUENCY - unigramFrequency)
+                / (1.5f + FormatSpec.MAX_BIGRAM_FREQUENCY);
         final float resultFreqFloat = (float)unigramFrequency
                 + stepSize * (bigramFrequency + 1.0f);
         return (int)resultFreqFloat;
diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
new file mode 100644
index 0000000..1707ccc
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.inputmethod.latin.makedict;
+
+import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.makedict.FusionDictionary.DictionaryOptions;
+
+/**
+ * Dictionary File Format Specification.
+ */
+public final class FormatSpec {
+
+    /*
+     * Array of Node(FusionDictionary.Node) layout is as follows:
+     *
+     * g |
+     * r | the number of groups, 1 or 2 bytes.
+     * o | 1 byte = bbbbbbbb match
+     * u |   case 1xxxxxxx => xxxxxxx << 8 + next byte
+     * p |   otherwise => bbbbbbbb
+     * c |
+     * ount
+     *
+     * g |
+     * r | sequence of groups,
+     * o | the layout of each group is described below.
+     * u |
+     * ps
+     *
+     */
+
+    /* Node(CharGroup) layout is as follows:
+     *   | addressType                         xx     : mask with MASK_GROUP_ADDRESS_TYPE
+     *                                 2 bits, 00 = no children : FLAG_GROUP_ADDRESS_TYPE_NOADDRESS
+     * f |                                     01 = 1 byte      : FLAG_GROUP_ADDRESS_TYPE_ONEBYTE
+     * l |                                     10 = 2 bytes     : FLAG_GROUP_ADDRESS_TYPE_TWOBYTES
+     * a |                                     11 = 3 bytes     : FLAG_GROUP_ADDRESS_TYPE_THREEBYTES
+     * g | has several chars ?         1 bit, 1 = yes, 0 = no   : FLAG_HAS_MULTIPLE_CHARS
+     * s | has a terminal ?            1 bit, 1 = yes, 0 = no   : FLAG_IS_TERMINAL
+     *   | has shortcut targets ?      1 bit, 1 = yes, 0 = no   : FLAG_HAS_SHORTCUT_TARGETS
+     *   | has bigrams ?               1 bit, 1 = yes, 0 = no   : FLAG_HAS_BIGRAMS
+     *   | is not a word ?             1 bit, 1 = yes, 0 = no   : FLAG_IS_NOT_A_WORD
+     *   | is blacklisted ?            1 bit, 1 = yes, 0 = no   : FLAG_IS_BLACKLISTED
+     *
+     * p |
+     * a | IF HAS_PARENT_ADDRESS (defined in the file header)
+     * r |     parent address, 3byte
+     * e | the address must be negative, so the absolute value of the address is stored.
+     * n |
+     * taddress
+     *
+     * c | IF FLAG_HAS_MULTIPLE_CHARS
+     * h |   char, char, char, char    n * (1 or 3 bytes) : use CharGroupInfo for i/o helpers
+     * a |   end                       1 byte, = 0
+     * r | ELSE
+     * s |   char                      1 or 3 bytes
+     *   | END
+     *
+     * f |
+     * r | IF FLAG_IS_TERMINAL
+     * e |   frequency                 1 byte
+     * q |
+     *
+     * c | IF 00 = FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = addressType
+     * h |   // nothing
+     * i | ELSIF 01 = FLAG_GROUP_ADDRESS_TYPE_ONEBYTE == addressType
+     * l |   children address, 1 byte
+     * d | ELSIF 10 = FLAG_GROUP_ADDRESS_TYPE_TWOBYTES == addressType
+     * r |   children address, 2 bytes
+     * e | ELSE // 11 = FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = addressType
+     * n |   children address, 3 bytes
+     * A | END
+     * d
+     * dress
+     *
+     *   | IF FLAG_IS_TERMINAL && FLAG_HAS_SHORTCUT_TARGETS
+     *   | shortcut string list
+     *   | IF FLAG_IS_TERMINAL && FLAG_HAS_BIGRAMS
+     *   | bigrams address list
+     *
+     * Char format is:
+     * 1 byte = bbbbbbbb match
+     * case 000xxxxx: xxxxx << 16 + next byte << 8 + next byte
+     * else: if 00011111 (= 0x1F) : this is the terminator. This is a relevant choice because
+     *       unicode code points range from 0 to 0x10FFFF, so any 3-byte value starting with
+     *       00011111 would be outside unicode.
+     * else: iso-latin-1 code
+     * This allows for the whole unicode range to be encoded, including chars outside of
+     * the BMP. Also everything in the iso-latin-1 charset is only 1 byte, except control
+     * characters which should never happen anyway (and still work, but take 3 bytes).
+     *
+     * bigram address list is:
+     * <flags> = | hasNext = 1 bit, 1 = yes, 0 = no     : FLAG_ATTRIBUTE_HAS_NEXT
+     *           | addressSign = 1 bit,                 : FLAG_ATTRIBUTE_OFFSET_NEGATIVE
+     *           |                      1 = must take -address, 0 = must take +address
+     *           |                         xx : mask with MASK_ATTRIBUTE_ADDRESS_TYPE
+     *           | addressFormat = 2 bits, 00 = unused  : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
+     *           |                         01 = 1 byte  : FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE
+     *           |                         10 = 2 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES
+     *           |                         11 = 3 bytes : FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES
+     *           | 4 bits : frequency         : mask with FLAG_ATTRIBUTE_FREQUENCY
+     * <address> | IF (01 == FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE == addressFormat)
+     *           |   read 1 byte, add top 4 bits
+     *           | ELSIF (10 == FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES == addressFormat)
+     *           |   read 2 bytes, add top 4 bits
+     *           | ELSE // 11 == FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES == addressFormat
+     *           |   read 3 bytes, add top 4 bits
+     *           | END
+     *           | if (FLAG_ATTRIBUTE_OFFSET_NEGATIVE) then address = -address
+     * if (FLAG_ATTRIBUTE_HAS_NEXT) goto bigram_and_shortcut_address_list_is
+     *
+     * shortcut string list is:
+     * <byte size> = GROUP_SHORTCUT_LIST_SIZE_SIZE bytes, big-endian: size of the list, in bytes.
+     * <flags>     = | hasNext = 1 bit, 1 = yes, 0 = no : FLAG_ATTRIBUTE_HAS_NEXT
+     *               | reserved = 3 bits, must be 0
+     *               | 4 bits : frequency : mask with FLAG_ATTRIBUTE_FREQUENCY
+     * <shortcut>  = | string of characters at the char format described above, with the terminator
+     *               | used to signal the end of the string.
+     * if (FLAG_ATTRIBUTE_HAS_NEXT goto flags
+     */
+
+    static final int VERSION_1_MAGIC_NUMBER = 0x78B1;
+    public static final int VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
+    static final int MINIMUM_SUPPORTED_VERSION = 1;
+    static final int MAXIMUM_SUPPORTED_VERSION = 3;
+    static final int NOT_A_VERSION_NUMBER = -1;
+    static final int FIRST_VERSION_WITH_HEADER_SIZE = 2;
+    static final int FIRST_VERSION_WITH_PARENT_ADDRESS = 3;
+
+    // These options need to be the same numeric values as the one in the native reading code.
+    static final int GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
+    static final int HAS_PARENT_ADDRESS = 0x2;
+    static final int FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
+    static final int CONTAINS_BIGRAMS_FLAG = 0x8;
+
+    // TODO: Make this value adaptative to content data, store it in the header, and
+    // use it in the reading code.
+    static final int MAX_WORD_LENGTH = Constants.Dictionary.MAX_WORD_LENGTH;
+
+    static final int PARENT_ADDRESS_SIZE = 3;
+
+    static final int MASK_GROUP_ADDRESS_TYPE = 0xC0;
+    static final int FLAG_GROUP_ADDRESS_TYPE_NOADDRESS = 0x00;
+    static final int FLAG_GROUP_ADDRESS_TYPE_ONEBYTE = 0x40;
+    static final int FLAG_GROUP_ADDRESS_TYPE_TWOBYTES = 0x80;
+    static final int FLAG_GROUP_ADDRESS_TYPE_THREEBYTES = 0xC0;
+
+    static final int FLAG_HAS_MULTIPLE_CHARS = 0x20;
+
+    static final int FLAG_IS_TERMINAL = 0x10;
+    static final int FLAG_HAS_SHORTCUT_TARGETS = 0x08;
+    static final int FLAG_HAS_BIGRAMS = 0x04;
+    static final int FLAG_IS_NOT_A_WORD = 0x02;
+    static final int FLAG_IS_BLACKLISTED = 0x01;
+
+    static final int FLAG_ATTRIBUTE_HAS_NEXT = 0x80;
+    static final int FLAG_ATTRIBUTE_OFFSET_NEGATIVE = 0x40;
+    static final int MASK_ATTRIBUTE_ADDRESS_TYPE = 0x30;
+    static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_ONEBYTE = 0x10;
+    static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_TWOBYTES = 0x20;
+    static final int FLAG_ATTRIBUTE_ADDRESS_TYPE_THREEBYTES = 0x30;
+    static final int FLAG_ATTRIBUTE_FREQUENCY = 0x0F;
+
+    static final int GROUP_CHARACTERS_TERMINATOR = 0x1F;
+
+    static final int GROUP_TERMINATOR_SIZE = 1;
+    static final int GROUP_FLAGS_SIZE = 1;
+    static final int GROUP_FREQUENCY_SIZE = 1;
+    static final int GROUP_MAX_ADDRESS_SIZE = 3;
+    static final int GROUP_ATTRIBUTE_FLAGS_SIZE = 1;
+    static final int GROUP_ATTRIBUTE_MAX_ADDRESS_SIZE = 3;
+    static final int GROUP_SHORTCUT_LIST_SIZE_SIZE = 2;
+
+    static final int NO_CHILDREN_ADDRESS = Integer.MIN_VALUE;
+    static final int NO_PARENT_ADDRESS = 0;
+    static final int INVALID_CHARACTER = -1;
+
+    static final int MAX_CHARGROUPS_FOR_ONE_BYTE_CHARGROUP_COUNT = 0x7F; // 127
+    static final int MAX_CHARGROUPS_IN_A_NODE = 0x7FFF; // 32767
+
+    static final int MAX_TERMINAL_FREQUENCY = 255;
+    static final int MAX_BIGRAM_FREQUENCY = 15;
+
+    /**
+     * Options about file format.
+     */
+    public static class FormatOptions {
+        public final int mVersion;
+        public final boolean mHasParentAddress;
+        public FormatOptions(final int version) {
+            this(version, false);
+        }
+        public FormatOptions(final int version, final boolean hasParentAddress) {
+            mVersion = version;
+            if (version < FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS && hasParentAddress) {
+                throw new RuntimeException("Parent addresses are only supported with versions "
+                        + FormatSpec.FIRST_VERSION_WITH_PARENT_ADDRESS + " and ulterior.");
+            }
+            mHasParentAddress = hasParentAddress;
+        }
+    }
+
+    /**
+     * Class representing file header.
+     */
+    static final class FileHeader {
+        public final int mHeaderSize;
+        public final DictionaryOptions mDictionaryOptions;
+        public final FormatOptions mFormatOptions;
+        public FileHeader(final int headerSize, final DictionaryOptions dictionaryOptions,
+                final FormatOptions formatOptions) {
+            mHeaderSize = headerSize;
+            mDictionaryOptions = dictionaryOptions;
+            mFormatOptions = formatOptions;
+        }
+    }
+
+    private FormatSpec() {
+        // This utility class is not publicly instantiable.
+    }
+}
diff --git a/native/jni/src/geometry_utils.h b/native/jni/src/geometry_utils.h
index f30e9fc..bad5eda 100644
--- a/native/jni/src/geometry_utils.h
+++ b/native/jni/src/geometry_utils.h
@@ -25,14 +25,17 @@
 
 #define M_PI_F 3.14159265f
 
+#define ROUND_FLOAT_10000(f) ((f) < 1000.0f && (f) > 0.001f) \
+        ? (floorf((f) * 10000.0f) / 10000.0f) : (f)
+
+#define SQUARE_FLOAT(x) ((x) * (x))
+
 namespace latinime {
 
-static inline float squareFloat(float x) {
-    return x * x;
-}
-
 static inline float getSquaredDistanceFloat(float x1, float y1, float x2, float y2) {
-    return squareFloat(x1 - x2) + squareFloat(y1 - y2);
+    const float deltaX = x1 - x2;
+    const float deltaY = y1 - y2;
+    return SQUARE_FLOAT(deltaX) + SQUARE_FLOAT(deltaY);
 }
 
 static inline float getDistanceFloat(float x1, float y1, float x2, float y2) {
@@ -52,9 +55,11 @@
 }
 
 static inline float getAngleDiff(float a1, float a2) {
-    const float diff = fabsf(a1 - a2);
+    const float deltaA = fabsf(a1 - a2);
+    const float diff = ROUND_FLOAT_10000(deltaA);
     if (diff > M_PI_F) {
-        return 2.0f * M_PI_F - diff;
+        const float normalizedDiff = 2.0f * M_PI_F - diff;
+        return ROUND_FLOAT_10000(normalizedDiff);
     }
     return diff;
 }
@@ -76,7 +81,7 @@
     const float ray2y = y2 - y1;
 
     const float dotProduct = ray1x * ray2x + ray1y * ray2y;
-    const float lineLengthSqr = squareFloat(ray2x) + squareFloat(ray2y);
+    const float lineLengthSqr = SQUARE_FLOAT(ray2x) + SQUARE_FLOAT(ray2y);
     const float projectionLengthSqr = dotProduct / lineLengthSqr;
 
     float projectionX;
diff --git a/native/jni/src/proximity_info.cpp b/native/jni/src/proximity_info.cpp
index 9bb8b29..c9f83b6 100644
--- a/native/jni/src/proximity_info.cpp
+++ b/native/jni/src/proximity_info.cpp
@@ -67,7 +67,8 @@
                   && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
                   && sweetSpotCenterYs && sweetSpotRadii),
           mProximityCharsArray(new int32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE
-                  /* proximityGridLength */]) {
+                  /* proximityGridLength */]),
+          mCodeToKeyMap() {
     const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
     if (DEBUG_PROXIMITY_INFO) {
         AKLOGI("Create proximity info array %d", proximityGridLength);
@@ -88,22 +89,9 @@
     safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterXs, KEY_COUNT, mSweetSpotCenterXs);
     safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterYs, KEY_COUNT, mSweetSpotCenterYs);
     safeGetOrFillZeroFloatArrayRegion(env, sweetSpotRadii, KEY_COUNT, mSweetSpotRadii);
-    initializeCodePointToKeyIndex();
     initializeG();
 }
 
-// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
-// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
-void ProximityInfo::initializeCodePointToKeyIndex() {
-    memset(mCodePointToKeyIndex, -1, sizeof(mCodePointToKeyIndex));
-    for (int i = 0; i < KEY_COUNT; ++i) {
-        const int code = mKeyCodePoints[i];
-        if (0 <= code && code <= MAX_CHAR_CODE) {
-            mCodePointToKeyIndex[code] = i;
-        }
-    }
-}
-
 ProximityInfo::~ProximityInfo() {
     delete[] mProximityCharsArray;
 }
@@ -141,7 +129,9 @@
 
 static inline float getNormalizedSquaredDistanceFloat(float x1, float y1, float x2, float y2,
         float scale) {
-    return squareFloat((x1 - x2) / scale) + squareFloat((y1 - y2) / scale);
+    const float deltaX = x1 - x2;
+    const float deltaY = y1 - y2;
+    return (SQUARE_FLOAT(deltaX) + SQUARE_FLOAT(deltaY)) / SQUARE_FLOAT(scale);
 }
 
 float ProximityInfo::getNormalizedSquaredDistanceFromCenterFloat(
@@ -237,11 +227,12 @@
         // We do not have the coordinate data
         return NOT_AN_INDEX;
     }
-    const unsigned short baseLowerC = toBaseLowerCase(c);
-    if (baseLowerC > MAX_CHAR_CODE) {
-        return NOT_AN_INDEX;
+    const int baseLowerC = static_cast<int>(toBaseLowerCase(c));
+    hash_map_compat<int, int>::const_iterator mapPos = mCodeToKeyMap.find(baseLowerC);
+    if (mapPos != mCodeToKeyMap.end()) {
+        return mapPos->second;
     }
-    return mCodePointToKeyIndex[baseLowerC];
+    return NOT_AN_INDEX;
 }
 
 int ProximityInfo::getCodePointOf(const int keyIndex) const {
@@ -258,12 +249,8 @@
         const int lowerCode = toBaseLowerCase(code);
         mCenterXsG[i] = mKeyXCoordinates[i] + mKeyWidths[i] / 2;
         mCenterYsG[i] = mKeyYCoordinates[i] + mKeyHeights[i] / 2;
-        if (code != lowerCode && lowerCode >= 0 && lowerCode <= MAX_CHAR_CODE) {
-            mCodePointToKeyIndex[lowerCode] = i;
-            mKeyIndexToCodePointG[i] = lowerCode;
-        } else {
-            mKeyIndexToCodePointG[i] = code;
-        }
+        mCodeToKeyMap[lowerCode] = i;
+        mKeyIndexToCodePointG[i] = lowerCode;
     }
     for (int i = 0; i < KEY_COUNT; i++) {
         mKeyKeyDistancesG[i][i] = 0;
diff --git a/native/jni/src/proximity_info.h b/native/jni/src/proximity_info.h
index 45df6ff..2f258ef 100644
--- a/native/jni/src/proximity_info.h
+++ b/native/jni/src/proximity_info.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 
 #include "defines.h"
+#include "hash_map_compat.h"
 #include "jni.h"
 
 namespace latinime {
@@ -112,12 +113,9 @@
 
  private:
     DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
-    // The upper limit of the char code in mCodePointToKeyIndex
-    static const int MAX_CHAR_CODE = 127;
     static const float NOT_A_DISTANCE_FLOAT;
 
     int getStartIndexFromCoordinates(const int x, const int y) const;
-    void initializeCodePointToKeyIndex();
     void initializeG();
     float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
     float calculateSquaredDistanceFromSweetSpotCenter(
@@ -154,7 +152,7 @@
     float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
     float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
     float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
-    int mCodePointToKeyIndex[MAX_CHAR_CODE + 1];
+    hash_map_compat<int, int> mCodeToKeyMap;
 
     int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
     int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
diff --git a/native/jni/src/proximity_info_state.cpp b/native/jni/src/proximity_info_state.cpp
index 208b693..7e917a9 100644
--- a/native/jni/src/proximity_info_state.cpp
+++ b/native/jni/src/proximity_info_state.cpp
@@ -177,6 +177,10 @@
                 hypotf(mProximityInfo->getKeyboardWidth(), mProximityInfo->getKeyboardHeight())
                 * READ_FORWORD_LENGTH_SCALE);
         for (int i = 0; i < mInputSize; ++i) {
+            if (DEBUG_GEO_FULL) {
+                AKLOGI("Sampled(%d): x = %d, y = %d, time = %d", i, mInputXs[i], mInputYs[i],
+                        mTimes[i]);
+            }
             for (int j = max(i + 1, lastSavedInputSize); j < mInputSize; ++j) {
                 if (mLengthCache[j] - mLengthCache[i] >= readForwordLength) {
                     break;
diff --git a/native/jni/src/proximity_info_state.h b/native/jni/src/proximity_info_state.h
index fce4b5b..453b1de 100644
--- a/native/jni/src/proximity_info_state.h
+++ b/native/jni/src/proximity_info_state.h
@@ -37,8 +37,6 @@
     static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2 = 10;
     static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
             1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
-    // The upper limit of the char code in mCodeToKeyIndex
-    static const int MAX_CHAR_CODE = 127;
     static const float NOT_A_DISTANCE_FLOAT = -1.0f;
     static const int NOT_A_CODE = -1;
 
diff --git a/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java b/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
index 5fa740f..70f916c 100644
--- a/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
+++ b/tests/src/com/android/inputmethod/latin/UserHistoryDictIOUtilsTests.java
@@ -19,6 +19,7 @@
 import com.android.inputmethod.latin.UserHistoryDictIOUtils.BigramDictionaryInterface;
 import com.android.inputmethod.latin.UserHistoryDictIOUtils.OnAddWordListener;
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
 
@@ -45,8 +46,7 @@
     private static final int UNIGRAM_FREQUENCY = 50;
     private static final int BIGRAM_FREQUENCY = 100;
     private static final ArrayList<String> NOT_HAVE_BIGRAM = new ArrayList<String>();
-    private static final BinaryDictInputOutput.FormatOptions FORMAT_OPTIONS =
-            new BinaryDictInputOutput.FormatOptions(2);
+    private static final FormatSpec.FormatOptions FORMAT_OPTIONS = new FormatSpec.FormatOptions(2);
 
     /**
      * Return same frequency for all words and bigrams
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
index 523287b..328784b 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
@@ -19,6 +19,7 @@
 import com.android.inputmethod.latin.CollectionUtils;
 import com.android.inputmethod.latin.UserHistoryDictIOUtils;
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput.FusionDictionaryBufferInterface;
+import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary.CharGroup;
 import com.android.inputmethod.latin.makedict.FusionDictionary.Node;
 import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
@@ -62,8 +63,11 @@
     private static final SparseArray<List<Integer>> sChainBigrams =
             CollectionUtils.newSparseArray();
 
-    private static final BinaryDictInputOutput.FormatOptions VERSION2 =
-            new BinaryDictInputOutput.FormatOptions(2);
+    private static final FormatSpec.FormatOptions VERSION2 = new FormatSpec.FormatOptions(2);
+    private static final FormatSpec.FormatOptions VERSION3_WITHOUT_PARENTADDRESS =
+            new FormatSpec.FormatOptions(3, false);
+    private static final FormatSpec.FormatOptions VERSION3_WITH_PARENTADDRESS =
+            new FormatSpec.FormatOptions(3, true);
 
     private static final String[] CHARACTERS = {
         "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
@@ -80,7 +84,7 @@
         for (int i = 0; i < sWords.size(); ++i) {
             sChainBigrams.put(i, new ArrayList<Integer>());
             if (i > 0) {
-                sChainBigrams.get(i-1).add(i);
+                sChainBigrams.get(i - 1).add(i);
             }
         }
 
@@ -95,7 +99,7 @@
     /**
      * Makes new buffer according to BUFFER_TYPE.
      */
-    private FusionDictionaryBufferInterface getBuffer(final File file,final int bufferType) {
+    private FusionDictionaryBufferInterface getBuffer(final File file, final int bufferType) {
         FileInputStream inStream = null;
         try {
             inStream = new FileInputStream(file);
@@ -173,7 +177,8 @@
         }
     }
 
-    private long timeWritingDictToFile(final File file, final FusionDictionary dict) {
+    private long timeWritingDictToFile(final File file, final FusionDictionary dict,
+            final FormatSpec.FormatOptions formatOptions) {
 
         long now = -1, diff = -1;
 
@@ -181,7 +186,7 @@
             final FileOutputStream out = new FileOutputStream(file);
 
             now = System.currentTimeMillis();
-            BinaryDictInputOutput.writeDictionaryBinary(out, dict, VERSION2);
+            BinaryDictInputOutput.writeDictionaryBinary(out, dict, formatOptions);
             diff = System.currentTimeMillis() - now;
 
             out.flush();
@@ -226,6 +231,14 @@
         }
     }
 
+    private String outputOptions(final int bufferType,
+            final FormatSpec.FormatOptions formatOptions) {
+        String result = " : buffer type = "
+                + ((bufferType == USE_BYTE_BUFFER) ? "byte buffer" : "byte array");
+        result += " : version = " + formatOptions.mVersion;
+        return result + ", hasParentAddress = " + formatOptions.mHasParentAddress;
+    }
+
     // Tests for readDictionaryBinary and writeDictionaryBinary
 
     private long timeReadingAndCheckDict(final File file, final List<String> words,
@@ -243,7 +256,7 @@
         } catch (IOException e) {
             Log.e(TAG, "IOException while reading dictionary: " + e);
         } catch (UnsupportedFormatException e) {
-            Log.e(TAG, "Unsupported format: "+ e);
+            Log.e(TAG, "Unsupported format: " + e);
         }
 
         checkDictionary(dict, words, bigrams, shortcutMap);
@@ -253,7 +266,8 @@
     // Tests for readDictionaryBinary and writeDictionaryBinary
     private String runReadAndWrite(final List<String> words,
             final SparseArray<List<Integer>> bigrams, final Map<String, List<String>> shortcuts,
-            final int bufferType, final String message) {
+            final int bufferType, final FormatSpec.FormatOptions formatOptions,
+            final String message) {
         File file = null;
         try {
             file = File.createTempFile("runReadAndWrite", ".dict");
@@ -263,28 +277,34 @@
         assertNotNull(file);
 
         final FusionDictionary dict = new FusionDictionary(new Node(),
-                new FusionDictionary.DictionaryOptions(
-                        new HashMap<String,String>(), false, false));
+                new FusionDictionary.DictionaryOptions(new HashMap<String,String>(), false, false));
         addUnigrams(words.size(), dict, words, shortcuts);
         addBigrams(dict, words, bigrams);
         checkDictionary(dict, words, bigrams, shortcuts);
 
-        final long write = timeWritingDictToFile(file, dict);
+        final long write = timeWritingDictToFile(file, dict, formatOptions);
         final long read = timeReadingAndCheckDict(file, words, bigrams, shortcuts, bufferType);
 
-        return "PROF: read=" + read + "ms, write=" + write + "ms    :" + message +
-                " : buffer type = " + bufferType;
+        return "PROF: read=" + read + "ms, write=" + write + "ms :" + message
+                + " : " + outputOptions(bufferType, formatOptions);
+    }
+
+    private void runReadAndWriteTests(final List<String> results, final int bufferType,
+            final FormatSpec.FormatOptions formatOptions) {
+        results.add(runReadAndWrite(sWords, sEmptyBigrams, null /* shortcuts */, bufferType,
+                formatOptions, "unigram"));
+        results.add(runReadAndWrite(sWords, sChainBigrams, null /* shortcuts */, bufferType,
+                formatOptions, "chain"));
+        results.add(runReadAndWrite(sWords, sStarBigrams, null /* shortcuts */, bufferType,
+                formatOptions, "star"));
     }
 
     public void testReadAndWriteWithByteBuffer() {
         final List<String> results = CollectionUtils.newArrayList();
 
-        results.add(runReadAndWrite(sWords, sEmptyBigrams, null /* shortcuts */, USE_BYTE_BUFFER,
-                "unigram"));
-        results.add(runReadAndWrite(sWords, sChainBigrams, null /* shortcuts */, USE_BYTE_BUFFER,
-                "chain"));
-        results.add(runReadAndWrite(sWords, sStarBigrams, null /* shortcuts */, USE_BYTE_BUFFER,
-                "star"));
+        runReadAndWriteTests(results, USE_BYTE_BUFFER, VERSION2);
+        runReadAndWriteTests(results, USE_BYTE_BUFFER, VERSION3_WITHOUT_PARENTADDRESS);
+        runReadAndWriteTests(results, USE_BYTE_BUFFER, VERSION3_WITH_PARENTADDRESS);
 
         for (final String result : results) {
             Log.d(TAG, result);
@@ -294,12 +314,9 @@
     public void testReadAndWriteWithByteArray() {
         final List<String> results = CollectionUtils.newArrayList();
 
-        results.add(runReadAndWrite(sWords, sEmptyBigrams, null /* shortcuts */, USE_BYTE_ARRAY,
-                "unigram"));
-        results.add(runReadAndWrite(sWords, sChainBigrams, null /* shortcuts */, USE_BYTE_ARRAY,
-                "chain"));
-        results.add(runReadAndWrite(sWords, sStarBigrams, null /* shortcuts */, USE_BYTE_ARRAY,
-                "star"));
+        runReadAndWriteTests(results, USE_BYTE_ARRAY, VERSION2);
+        runReadAndWriteTests(results, USE_BYTE_ARRAY, VERSION3_WITHOUT_PARENTADDRESS);
+        runReadAndWriteTests(results, USE_BYTE_ARRAY, VERSION3_WITH_PARENTADDRESS);
 
         for (final String result : results) {
             Log.d(TAG, result);
@@ -391,7 +408,7 @@
 
     private String runReadUnigramsAndBigramsBinary(final List<String> words,
             final SparseArray<List<Integer>> bigrams, final int bufferType,
-            final String message) {
+            final FormatSpec.FormatOptions formatOptions, final String message) {
         File file = null;
         try {
             file = File.createTempFile("runReadUnigrams", ".dict");
@@ -407,25 +424,32 @@
         addUnigrams(words.size(), dict, words, null /* shortcutMap */);
         addBigrams(dict, words, bigrams);
 
-        timeWritingDictToFile(file, dict);
+        timeWritingDictToFile(file, dict, formatOptions);
 
         long wordMap = timeAndCheckReadUnigramsAndBigramsBinary(file, words, bigrams, bufferType);
         long fullReading = timeReadingAndCheckDict(file, words, bigrams, null /* shortcutMap */,
                 bufferType);
 
         return "readDictionaryBinary=" + fullReading + ", readUnigramsAndBigramsBinary=" + wordMap
-                + " : " + message + " : buffer type = " + bufferType;
+                + " : " + message + " : " + outputOptions(bufferType, formatOptions);
+    }
+
+    private void runReadUnigramsAndBigramsTests(final List<String> results, final int bufferType,
+            final FormatSpec.FormatOptions formatOptions) {
+        results.add(runReadUnigramsAndBigramsBinary(sWords, sEmptyBigrams, bufferType,
+                formatOptions, "unigram"));
+        results.add(runReadUnigramsAndBigramsBinary(sWords, sChainBigrams, bufferType,
+                formatOptions, "chain"));
+        results.add(runReadUnigramsAndBigramsBinary(sWords, sChainBigrams, bufferType,
+                formatOptions, "star"));
     }
 
     public void testReadUnigramsAndBigramsBinaryWithByteBuffer() {
         final List<String> results = CollectionUtils.newArrayList();
 
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sEmptyBigrams, USE_BYTE_BUFFER,
-                "unigram"));
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sChainBigrams, USE_BYTE_BUFFER,
-                "chain"));
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sStarBigrams, USE_BYTE_BUFFER,
-                "star"));
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_BUFFER, VERSION2);
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_BUFFER, VERSION3_WITHOUT_PARENTADDRESS);
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_BUFFER, VERSION3_WITH_PARENTADDRESS);
 
         for (final String result : results) {
             Log.d(TAG, result);
@@ -435,11 +459,9 @@
     public void testReadUnigramsAndBigramsBinaryWithByteArray() {
         final List<String> results = CollectionUtils.newArrayList();
 
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sEmptyBigrams, USE_BYTE_ARRAY,
-                "unigram"));
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sChainBigrams, USE_BYTE_ARRAY,
-                "chain"));
-        results.add(runReadUnigramsAndBigramsBinary(sWords, sStarBigrams, USE_BYTE_ARRAY, "star"));
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_ARRAY, VERSION2);
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_ARRAY, VERSION3_WITHOUT_PARENTADDRESS);
+        runReadUnigramsAndBigramsTests(results, USE_BYTE_ARRAY, VERSION3_WITH_PARENTADDRESS);
 
         for (final String result : results) {
             Log.d(TAG, result);
diff --git a/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java b/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java
index 7cd4564..a613770 100644
--- a/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java
+++ b/tools/dicttool/src/android/inputmethod/latin/dicttool/DictionaryMaker.java
@@ -17,6 +17,7 @@
 package com.android.inputmethod.latin.dicttool;
 
 import com.android.inputmethod.latin.makedict.BinaryDictInputOutput;
+import com.android.inputmethod.latin.makedict.FormatSpec;
 import com.android.inputmethod.latin.makedict.FusionDictionary;
 import com.android.inputmethod.latin.makedict.MakedictLog;
 import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
@@ -311,8 +312,7 @@
             final FusionDictionary dict, final int version)
             throws FileNotFoundException, IOException, UnsupportedFormatException {
         final File outputFile = new File(outputFilename);
-        final BinaryDictInputOutput.FormatOptions formatOptions =
-                new BinaryDictInputOutput.FormatOptions(version);
+        final FormatSpec.FormatOptions formatOptions = new FormatSpec.FormatOptions(version);
         BinaryDictInputOutput.writeDictionaryBinary(new FileOutputStream(outputFilename), dict,
                 formatOptions);
     }