Merge "Add utilities to read header values."
diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 53051d0..27a5cad 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -145,6 +145,7 @@
         <attr name="gestureSamplingMinimumDistance" format="fraction" />
         <!-- Parameters for gesture recognition (msec) and (keyWidth%/sec) -->
         <attr name="gestureRecognitionMinimumTime" format="integer" />
+        <attr name="gestureRecognitionUpdateTime" format="integer" />
         <attr name="gestureRecognitionSpeedThreshold" format="fraction" />
         <!-- Suppress showing key preview duration after batch input in millisecond -->
         <attr name="suppressKeyPreviewAfterBatchInputDuration" format="integer" />
diff --git a/java/res/values/colors.xml b/java/res/values/colors.xml
new file mode 100644
index 0000000..da4d87c
--- /dev/null
+++ b/java/res/values/colors.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- Color resources for default, and Gingerbread theme. -->
+    <color name="highlight_color_default">#FFFCAE00</color>
+    <color name="key_text_color_default">@android:color/white</color>
+    <color name="key_text_shadow_color_default">#BB000000</color>
+    <color name="key_text_inactivated_color_default">@android:color/white</color>
+    <color name="key_hint_letter_color_default">#80000000</color>
+    <color name="key_hint_label_color_default">#E0E0E4E5</color>
+    <color name="key_shifted_letter_hint_inactivated_color_default">#66E0E4E5</color>
+    <color name="key_shifted_letter_hint_activated_color_default">#CCE0E4E5</color>
+    <color name="spacebar_text_color_default">#FFC0C0C0</color>
+    <color name="spacebar_text_shadow_color_default">#80000000</color>
+    <color name="typed_word_color_default">@android:color/white</color>
+    <color name="gesture_floating_preview_color_default">#C0000000</color>
+    <!-- Color resources for Stone theme. -->
+    <color name="key_text_color_stone">@android:color/black</color>
+    <color name="key_text_shadow_color_stone">@android:color/white</color>
+    <color name="key_text_inactivated_color_stone">#FF808080</color>
+    <color name="key_hint_letter_color_stone">#80000000</color>
+    <color name="key_hint_label_color_stone">#E0000000</color>
+    <color name="key_shifted_letter_hint_inactivated_color_stone">#66000000</color>
+    <color name="key_shifted_letter_hint_activated_color_stone">#CC000000</color>
+    <color name="spacebar_text_color_stone">@android:color/black</color>
+    <color name="spacebar_text_shadow_color_stone">#D0FFFFFF</color>
+    <!-- Color resources for IceCreamSandwich theme. -->
+    <color name="highlight_color_ics">@android:color/holo_blue_light</color>
+    <color name="key_text_color_ics">@android:color/white</color>
+    <color name="key_text_shadow_color_ics">@android:color/transparent</color>
+    <color name="key_text_inactivated_color_ics">#66E0E4E5</color>
+    <color name="key_hint_letter_color_ics">#80000000</color>
+    <color name="key_hint_label_color_ics">#A0FFFFFF</color>
+    <color name="key_shifted_letter_hint_inactivated_color_ics">#66E0E4E5</color>
+    <color name="key_shifted_letter_hint_activated_color_ics">@android:color/white</color>
+    <color name="spacebar_text_color_ics">#FFC0C0C0</color>
+    <color name="spacebar_text_shadow_color_ics">#80000000</color>
+    <color name="typed_word_color_ics">@color/highlight_color_ics</color>
+</resources>
diff --git a/java/res/values/config.xml b/java/res/values/config.xml
index cb13587..78c5f18 100644
--- a/java/res/values/config.xml
+++ b/java/res/values/config.xml
@@ -86,6 +86,7 @@
     <fraction name="config_gesture_sampling_minimum_distance">16.6666%</fraction>
     <!-- Parameters for gesture recognition (msec) and (keyWidth%/sec) -->
     <integer name="config_gesture_recognition_minimum_time">100</integer>
+    <integer name="config_gesture_recognition_update_time">300</integer>
     <fraction name="config_gesture_recognition_speed_threshold">550%</fraction>
     <!-- Suppress showing key preview duration after batch input in millisecond -->
     <integer name="config_suppress_key_preview_after_batch_input_duration">1000</integer>
diff --git a/java/res/values/styles.xml b/java/res/values/styles.xml
index 4766a22..a60e449 100644
--- a/java/res/values/styles.xml
+++ b/java/res/values/styles.xml
@@ -43,32 +43,31 @@
         <item name="keyHintLabelRatio">@fraction/key_hint_label_ratio</item>
         <item name="keyShiftedLetterHintRatio">@fraction/key_uppercase_letter_ratio</item>
         <item name="keyTypeface">normal</item>
-        <item name="keyTextColor">#FFFFFFFF</item>
-        <item name="keyTextInactivatedColor">#FFFFFFFF</item>
-        <item name="keyHintLetterColor">#80000000</item>
-        <item name="keyHintLabelColor">#E0E0E4E5</item>
-        <item name="keyShiftedLetterHintInactivatedColor">#66E0E4E5</item>
-        <item name="keyShiftedLetterHintActivatedColor">#CCE0E4E5</item>
+        <item name="keyTextColor">@color/key_text_color_default</item>
+        <item name="keyTextInactivatedColor">@color/key_text_color_default</item>
+        <item name="keyHintLetterColor">@color/key_hint_letter_color_default</item>
+        <item name="keyHintLabelColor">@color/key_hint_label_color_default</item>
+        <item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_default</item>
+        <item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_default</item>
         <item name="keyLabelHorizontalPadding">@dimen/key_label_horizontal_padding</item>
         <item name="keyHintLetterPadding">@dimen/key_hint_letter_padding</item>
         <item name="keyPopupHintLetterPadding">@dimen/key_popup_hint_letter_padding</item>
         <item name="keyShiftedLetterHintPadding">@dimen/key_uppercase_letter_padding</item>
         <item name="keyPreviewLayout">@layout/key_preview</item>
-        <item name="keyPreviewTextColor">#FFFFFFFF</item>
+        <item name="keyPreviewTextColor">@color/key_text_color_default</item>
         <item name="keyPreviewOffset">@dimen/key_preview_offset</item>
         <item name="keyPreviewHeight">@dimen/key_preview_height</item>
         <item name="keyPreviewTextRatio">@fraction/key_preview_text_ratio</item>
         <item name="keyPreviewLingerTimeout">@integer/config_key_preview_linger_timeout</item>
         <item name="moreKeysLayout">@layout/more_keys_keyboard</item>
         <item name="verticalCorrection">@dimen/keyboard_vertical_correction</item>
-        <item name="keyTextShadowColor">#BB000000</item>
+        <item name="keyTextShadowColor">@color/key_text_shadow_color_default</item>
         <item name="keyTextShadowRadius">2.75</item>
         <item name="backgroundDimAlpha">128</item>
-        <!-- android:color/holo_blue_light=#FF33B5E5 -->
         <item name="gestureFloatingPreviewTextSize">@dimen/gesture_floating_preview_text_size</item>
-        <item name="gestureFloatingPreviewTextColor">@android:color/holo_blue_light</item>
+        <item name="gestureFloatingPreviewTextColor">@color/highlight_color_default</item>
         <item name="gestureFloatingPreviewTextOffset">@dimen/gesture_floating_preview_text_offset</item>
-        <item name="gestureFloatingPreviewColor">#C0000000</item>
+        <item name="gestureFloatingPreviewColor">@color/gesture_floating_preview_color_default</item>
         <item name="gestureFloatingPreviewHorizontalPadding">@dimen/gesture_floating_preview_horizontal_padding</item>
         <item name="gestureFloatingPreviewVerticalPadding">@dimen/gesture_floating_preview_vertical_padding</item>
         <item name="gestureFloatingPreviewRoundRadius">@dimen/gesture_floating_preview_round_radius</item>
@@ -76,7 +75,7 @@
         <item name="gesturePreviewTrailFadeoutStartDelay">@integer/config_gesture_preview_trail_fadeout_start_delay</item>
         <item name="gesturePreviewTrailFadeoutDuration">@integer/config_gesture_preview_trail_fadeout_duration</item>
         <item name="gesturePreviewTrailUpdateInterval">@integer/config_gesture_preview_trail_update_interval</item>
-        <item name="gesturePreviewTrailColor">@android:color/holo_blue_light</item>
+        <item name="gesturePreviewTrailColor">@color/highlight_color_default</item>
         <item name="gesturePreviewTrailStartWidth">@dimen/gesture_preview_trail_start_width</item>
         <item name="gesturePreviewTrailEndWidth">@dimen/gesture_preview_trail_end_width</item>
         <!-- Common attributes of MainKeyboardView -->
@@ -105,6 +104,7 @@
         <item name="gestureDynamicDistanceThresholdTo">@fraction/config_gesture_dynamic_distance_threshold_to</item>
         <item name="gestureSamplingMinimumDistance">@fraction/config_gesture_sampling_minimum_distance</item>
         <item name="gestureRecognitionMinimumTime">@integer/config_gesture_recognition_minimum_time</item>
+        <item name="gestureRecognitionUpdateTime">@integer/config_gesture_recognition_update_time</item>
         <item name="gestureRecognitionSpeedThreshold">@fraction/config_gesture_recognition_speed_threshold</item>
         <item name="suppressKeyPreviewAfterBatchInputDuration">@integer/config_suppress_key_preview_after_batch_input_duration</item>
     </style>
@@ -114,8 +114,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">true</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FFC0C0C0</item>
-        <item name="spacebarTextShadowColor">#80000000</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_default</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_default</item>
     </style>
     <style
         name="MoreKeysKeyboard"
@@ -144,10 +144,10 @@
         parent="SuggestionsStripBackgroundStyle"
     >
         <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
-        <item name="colorValidTypedWord">#FFFCAE00</item>
-        <item name="colorTypedWord">@android:color/white</item>
-        <item name="colorAutoCorrect">#FFFCAE00</item>
-        <item name="colorSuggested">#FFFCAE00</item>
+        <item name="colorValidTypedWord">@color/highlight_color_default</item>
+        <item name="colorTypedWord">@color/typed_word_color_default</item>
+        <item name="colorAutoCorrect">@color/highlight_color_default</item>
+        <item name="colorSuggested">@color/highlight_color_default</item>
         <item name="alphaObsoleted">50%</item>
         <item name="suggestionsCountInStrip">@integer/suggestions_count_in_strip</item>
         <item name="centerSuggestionPercentile">@fraction/center_suggestion_percentile</item>
@@ -187,8 +187,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">true</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FFC0C0C0</item>
-        <item name="spacebarTextShadowColor">#80000000</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_default</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_default</item>
     </style>
     <!-- Theme "Stone" -->
     <style
@@ -207,13 +207,13 @@
         parent="KeyboardView"
     >
         <item name="keyBackground">@drawable/btn_keyboard_key_stone</item>
-        <item name="keyTextColor">#FF000000</item>
-        <item name="keyTextInactivatedColor">#FF808080</item>
-        <item name="keyHintLetterColor">#80000000</item>
-        <item name="keyHintLabelColor">#E0000000</item>
-        <item name="keyShiftedLetterHintInactivatedColor">#66000000</item>
-        <item name="keyShiftedLetterHintActivatedColor">#CC000000</item>
-        <item name="keyTextShadowColor">#FFFFFFFF</item>
+        <item name="keyTextColor">@color/key_text_color_stone</item>
+        <item name="keyTextInactivatedColor">@color/key_text_inactivated_color_stone</item>
+        <item name="keyHintLetterColor">@color/key_hint_letter_color_stone</item>
+        <item name="keyHintLabelColor">@color/key_hint_label_color_stone</item>
+        <item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_stone</item>
+        <item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_stone</item>
+        <item name="keyTextShadowColor">@color/key_text_shadow_color_stone</item>
     </style>
     <style
         name="MainKeyboardView.Stone"
@@ -222,8 +222,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">true</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FF000000</item>
-        <item name="spacebarTextShadowColor">#D0FFFFFF</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_stone</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_stone</item>
     </style>
     <style
         name="MoreKeysKeyboard.Stone"
@@ -239,8 +239,8 @@
         parent="MoreKeysKeyboardView"
     >
         <item name="keyBackground">@drawable/btn_keyboard_key_stone</item>
-        <item name="keyTextColor">#FF000000</item>
-        <item name="keyTextShadowColor">#FFFFFFFF</item>
+        <item name="keyTextColor">@color/key_text_color_stone</item>
+        <item name="keyTextShadowColor">@color/key_text_shadow_color_stone</item>
     </style>
     <!-- Theme "Stone bold" -->
     <style
@@ -263,8 +263,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">true</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FF000000</item>
-        <item name="spacebarTextShadowColor">#D0FFFFFF</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_stone</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_stone</item>
     </style>
     <!-- Theme "Gingerbread" -->
     <style
@@ -292,8 +292,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">true</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FFC0C0C0</item>
-        <item name="spacebarTextShadowColor">#80000000</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_default</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_default</item>
     </style>
     <style
         name="MoreKeysKeyboard.Gingerbread"
@@ -330,16 +330,18 @@
         <item name="android:background">@drawable/keyboard_background_holo</item>
         <item name="keyBackground">@drawable/btn_keyboard_key_ics</item>
         <item name="keyTypeface">bold</item>
-        <item name="keyTextInactivatedColor">#66E0E4E5</item>
-        <item name="keyHintLetterColor">#80000000</item>
-        <item name="keyHintLabelColor">#A0FFFFFF</item>
-        <item name="keyShiftedLetterHintInactivatedColor">#66E0E4E5</item>
-        <item name="keyShiftedLetterHintActivatedColor">#FFFFFFFF</item>
+        <item name="keyTextInactivatedColor">@color/key_text_inactivated_color_ics</item>
+        <item name="keyHintLetterColor">@color/key_hint_letter_color_ics</item>
+        <item name="keyHintLabelColor">@color/key_hint_label_color_ics</item>
+        <item name="keyShiftedLetterHintInactivatedColor">@color/key_shifted_letter_hint_inactivated_color_ics</item>
+        <item name="keyShiftedLetterHintActivatedColor">@color/key_shifted_letter_hint_activated_color_ics</item>
         <item name="keyPreviewLayout">@layout/key_preview_ics</item>
-        <item name="keyPreviewTextColor">#FFFFFFFF</item>
+        <item name="keyPreviewTextColor">@color/key_text_color_ics</item>
         <item name="keyPreviewOffset">@dimen/key_preview_offset_ics</item>
-        <item name="keyTextShadowColor">#00000000</item>
+        <item name="keyTextShadowColor">@color/key_text_shadow_color_ics</item>
         <item name="keyTextShadowRadius">0.0</item>
+        <item name="gestureFloatingPreviewTextColor">@color/highlight_color_ics</item>
+        <item name="gesturePreviewTrailColor">@color/highlight_color_ics</item>
     </style>
     <style
         name="MainKeyboardView.IceCreamSandwich"
@@ -348,8 +350,8 @@
         <item name="autoCorrectionSpacebarLedEnabled">false</item>
         <item name="autoCorrectionSpacebarLedIcon">@drawable/sym_keyboard_space_led_holo</item>
         <item name="spacebarTextRatio">@fraction/spacebar_text_ratio</item>
-        <item name="spacebarTextColor">#FFC0C0C0</item>
-        <item name="spacebarTextShadowColor">#80000000</item>
+        <item name="spacebarTextColor">@color/spacebar_text_color_ics</item>
+        <item name="spacebarTextShadowColor">@color/spacebar_text_shadow_color_ics</item>
     </style>
     <style
         name="MoreKeysKeyboard.IceCreamSandwich"
@@ -379,11 +381,10 @@
         parent="SuggestionsStripBackgroundStyle.IceCreamSandwich"
     >
         <item name="suggestionStripOption">autoCorrectBold|validTypedWordBold</item>
-        <!-- android:color/holo_blue_light=#FF33B5E5 -->
-        <item name="colorValidTypedWord">@android:color/holo_blue_light</item>
-        <item name="colorTypedWord">@android:color/holo_blue_light</item>
-        <item name="colorAutoCorrect">@android:color/holo_blue_light</item>
-        <item name="colorSuggested">@android:color/holo_blue_light</item>
+        <item name="colorValidTypedWord">@color/highlight_color_ics</item>
+        <item name="colorTypedWord">@color/highlight_color_ics</item>
+        <item name="colorAutoCorrect">@color/highlight_color_ics</item>
+        <item name="colorSuggested">@color/highlight_color_ics</item>
         <item name="alphaValidTypedWord">85%</item>
         <item name="alphaTypedWord">85%</item>
         <item name="alphaSuggested">70%</item>
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
index b9b6362..0ab84f7 100644
--- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
+++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java
@@ -36,6 +36,7 @@
 import com.android.inputmethod.keyboard.Keyboard;
 import com.android.inputmethod.keyboard.KeyboardView;
 import com.android.inputmethod.latin.CollectionUtils;
+import com.android.inputmethod.latin.CoordinateUtils;
 
 /**
  * Exposes a virtual view sub-tree for {@link KeyboardView} and generates
@@ -62,7 +63,7 @@
     private final Rect mTempBoundsInScreen = new Rect();
 
     /** The parent view's cached on-screen location. */
-    private final int[] mParentLocation = new int[2];
+    private final int[] mParentLocation = CoordinateUtils.newInstance();
 
     /** The virtual view identifier for the focused node. */
     private int mAccessibilityFocusedView = UNDEFINED;
@@ -180,7 +181,8 @@
 
             // Calculate the key's in-screen bounds.
             mTempBoundsInScreen.set(boundsInParent);
-            mTempBoundsInScreen.offset(mParentLocation[0], mParentLocation[1]);
+            mTempBoundsInScreen.offset(
+                    CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation));
 
             final Rect boundsInScreen = mTempBoundsInScreen;
 
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index 472f74b..d7cb5aa 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -45,6 +45,7 @@
 import com.android.inputmethod.keyboard.internal.PreviewPlacerView;
 import com.android.inputmethod.latin.CollectionUtils;
 import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.CoordinateUtils;
 import com.android.inputmethod.latin.LatinImeLogger;
 import com.android.inputmethod.latin.R;
 import com.android.inputmethod.latin.StaticInnerHandlerWrapper;
@@ -134,7 +135,7 @@
 
     // Preview placer view
     private final PreviewPlacerView mPreviewPlacerView;
-    private final int[] mCoordinates = new int[2];
+    private final int[] mCoordinates = CoordinateUtils.newInstance();
 
     // Key preview
     private static final int PREVIEW_ALPHA = 240;
@@ -832,10 +833,10 @@
             // In transient state.
             return;
         }
-        final int[] viewOrigin = new int[2];
+        final int[] viewOrigin = CoordinateUtils.newInstance();
         getLocationInWindow(viewOrigin);
         final DisplayMetrics dm = getResources().getDisplayMetrics();
-        if (viewOrigin[1] < dm.heightPixels / 4) {
+        if (CoordinateUtils.y(viewOrigin) < dm.heightPixels / 4) {
             // In transient state.
             return;
         }
@@ -850,7 +851,8 @@
             Log.w(TAG, "Cannot find android.R.id.content view to add PreviewPlacerView");
         } else {
             windowContentView.addView(mPreviewPlacerView);
-            mPreviewPlacerView.setKeyboardViewGeometry(viewOrigin[0], viewOrigin[1], width, height);
+            mPreviewPlacerView.setKeyboardViewGeometry(
+                    CoordinateUtils.x(viewOrigin), CoordinateUtils.y(viewOrigin), width, height);
         }
     }
 
@@ -940,7 +942,8 @@
         // parent key. If it doesn't fit in this {@link KeyboardView}, it is moved inward to fit and
         // the left/right background is used if such background is specified.
         final int statePosition;
-        int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2 + mCoordinates[0];
+        int previewX = key.getDrawX() - (previewWidth - keyDrawWidth) / 2
+                + CoordinateUtils.x(mCoordinates);
         if (previewX < 0) {
             previewX = 0;
             statePosition = STATE_LEFT;
@@ -952,7 +955,8 @@
         }
         // The key preview is placed vertically above the top edge of the parent key with an
         // arbitrary offset.
-        final int previewY = key.mY - previewHeight + mPreviewOffset + mCoordinates[1];
+        final int previewY = key.mY - previewHeight + mPreviewOffset
+                + CoordinateUtils.y(mCoordinates);
 
         if (background != null) {
             final int hasMoreKeys = (key.mMoreKeys != null) ? STATE_HAS_MOREKEYS : STATE_NORMAL;
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index d5f40ad..7e9e3ce 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -29,6 +29,7 @@
 import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.os.Message;
+import android.os.SystemClock;
 import android.preference.PreferenceManager;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -156,12 +157,14 @@
         private static final int MSG_REPEAT_KEY = 1;
         private static final int MSG_LONGPRESS_KEY = 2;
         private static final int MSG_DOUBLE_TAP = 3;
+        private static final int MSG_UPDATE_BATCH_INPUT = 4;
 
         private final int mKeyRepeatStartTimeout;
         private final int mKeyRepeatInterval;
         private final int mLongPressKeyTimeout;
         private final int mLongPressShiftKeyTimeout;
         private final int mIgnoreAltCodeKeyTimeout;
+        private final int mGestureRecognitionUpdateTime;
 
         public KeyTimerHandler(final MainKeyboardView outerInstance,
                 final TypedArray mainKeyboardViewAttr) {
@@ -177,6 +180,8 @@
                     R.styleable.MainKeyboardView_longPressShiftKeyTimeout, 0);
             mIgnoreAltCodeKeyTimeout = mainKeyboardViewAttr.getInt(
                     R.styleable.MainKeyboardView_ignoreAltCodeKeyTimeout, 0);
+            mGestureRecognitionUpdateTime = mainKeyboardViewAttr.getInt(
+                    R.styleable.MainKeyboardView_gestureRecognitionUpdateTime, 0);
         }
 
         @Override
@@ -201,6 +206,10 @@
                     KeyboardSwitcher.getInstance().onLongPressTimeout(msg.arg1);
                 }
                 break;
+            case MSG_UPDATE_BATCH_INPUT:
+                tracker.updateBatchInputByTimer(SystemClock.uptimeMillis());
+                startUpdateBatchInputTimer(tracker);
+                break;
             }
         }
 
@@ -349,8 +358,24 @@
             cancelLongPressTimer();
         }
 
+        @Override
+        public void startUpdateBatchInputTimer(final PointerTracker tracker) {
+            if (mGestureRecognitionUpdateTime <= 0) {
+                return;
+            }
+            removeMessages(MSG_UPDATE_BATCH_INPUT, tracker);
+            sendMessageDelayed(obtainMessage(MSG_UPDATE_BATCH_INPUT, tracker),
+                    mGestureRecognitionUpdateTime);
+        }
+
+        @Override
+        public void cancelAllUpdateBatchInputTimers() {
+            removeMessages(MSG_UPDATE_BATCH_INPUT);
+        }
+
         public void cancelAllMessages() {
             cancelKeyTimers();
+            cancelAllUpdateBatchInputTimers();
         }
     }
 
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index 9c450e9..a698b0b 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -26,6 +26,7 @@
 import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
 import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
 import com.android.inputmethod.latin.Constants;
+import com.android.inputmethod.latin.CoordinateUtils;
 import com.android.inputmethod.latin.InputPointers;
 import com.android.inputmethod.latin.R;
 
@@ -34,7 +35,7 @@
  * detecting key presses and touch movements.
  */
 public final class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
-    private final int[] mCoordinates = new int[2];
+    private final int[] mCoordinates = CoordinateUtils.newInstance();
 
     private final KeyDetector mKeyDetector;
 
@@ -169,7 +170,7 @@
         window.setHeight(container.getMeasuredHeight());
         parentView.getLocationInWindow(mCoordinates);
         window.showAtLocation(parentView, Gravity.NO_GRAVITY,
-                x + mCoordinates[0], y + mCoordinates[1]);
+                x + CoordinateUtils.x(mCoordinates), y + CoordinateUtils.y(mCoordinates));
 
         mOriginX = x + container.getPaddingLeft();
         mOriginY = y + container.getPaddingTop();
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index c8052af..296a45f 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -94,6 +94,8 @@
         public void cancelDoubleTapTimer();
         public boolean isInDoubleTapTimeout();
         public void cancelKeyTimers();
+        public void startUpdateBatchInputTimer(PointerTracker tracker);
+        public void cancelAllUpdateBatchInputTimers();
 
         public static class Adapter implements TimerProxy {
             @Override
@@ -116,6 +118,10 @@
             public boolean isInDoubleTapTimeout() { return false; }
             @Override
             public void cancelKeyTimers() {}
+            @Override
+            public void startUpdateBatchInputTimer(PointerTracker tracker) {}
+            @Override
+            public void cancelAllUpdateBatchInputTimers() {}
         }
     }
 
@@ -705,27 +711,38 @@
         mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this));
     }
 
+    public void updateBatchInputByTimer(final long eventTime) {
+        final int gestureTime = (int)(eventTime - sGestureFirstDownTime);
+        mGestureStrokeWithPreviewPoints.duplicateLastPointWith(gestureTime);
+        updateBatchInput(eventTime);
+    }
+
     private void mayUpdateBatchInput(final long eventTime, final Key key) {
         if (key != null) {
-            synchronized (sAggregratedPointers) {
-                final GestureStroke stroke = mGestureStrokeWithPreviewPoints;
-                stroke.appendIncrementalBatchPoints(sAggregratedPointers);
-                final int size = sAggregratedPointers.getPointerSize();
-                if (size > sLastRecognitionPointSize
-                        && stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) {
-                    sLastRecognitionPointSize = size;
-                    sLastRecognitionTime = eventTime;
-                    if (DEBUG_LISTENER) {
-                        Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d",
-                                mPointerId, size));
-                    }
-                    mListener.onUpdateBatchInput(sAggregratedPointers);
-                }
-            }
+            updateBatchInput(eventTime);
         }
         mDrawingProxy.showGesturePreviewTrail(this, isOldestTrackerInQueue(this));
     }
 
+    private void updateBatchInput(final long eventTime) {
+        synchronized (sAggregratedPointers) {
+            final GestureStroke stroke = mGestureStrokeWithPreviewPoints;
+            stroke.appendIncrementalBatchPoints(sAggregratedPointers);
+            final int size = sAggregratedPointers.getPointerSize();
+            if (size > sLastRecognitionPointSize
+                    && stroke.hasRecognitionTimePast(eventTime, sLastRecognitionTime)) {
+                sLastRecognitionPointSize = size;
+                sLastRecognitionTime = eventTime;
+                if (DEBUG_LISTENER) {
+                    Log.d(TAG, String.format("[%d] onUpdateBatchInput: batchPoints=%d", mPointerId,
+                            size));
+                }
+                mTimerProxy.startUpdateBatchInputTimer(this);
+                mListener.onUpdateBatchInput(sAggregratedPointers);
+            }
+        }
+    }
+
     private void mayEndBatchInput(final long eventTime) {
         synchronized (sAggregratedPointers) {
             mGestureStrokeWithPreviewPoints.appendAllBatchPoints(sAggregratedPointers);
@@ -737,6 +754,7 @@
                         Log.d(TAG, String.format("[%d] onEndBatchInput   : batchPoints=%d",
                                 mPointerId, sAggregratedPointers.getPointerSize()));
                     }
+                    mTimerProxy.cancelAllUpdateBatchInputTimers();
                     mListener.onEndBatchInput(sAggregratedPointers);
                 }
             }
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
index 699aaea..80562cb 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
@@ -19,7 +19,6 @@
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.Rect;
-import android.graphics.RectF;
 import android.os.SystemClock;
 
 import com.android.inputmethod.latin.Constants;
@@ -118,98 +117,7 @@
                 / params.mTrailLingerDuration, 0.0f);
     }
 
-    static final class WorkingSet {
-        // Input
-        // Previous point (P1) coordinates and trail radius.
-        public float p1x, p1y;
-        public float r1;
-        // Current point (P2) coordinates and trail radius.
-        public float p2x, p2y;
-        public float r2;
-
-        // Output
-        // Closing point of arc at P1.
-        public float p1ax, p1ay;
-        // Opening point of arc at P1.
-        public float p1bx, p1by;
-        // Opening point of arc at P2.
-        public float p2ax, p2ay;
-        // Closing point of arc at P2.
-        public float p2bx, p2by;
-        // Start angle of the trail arcs.
-        public float aa;
-        // Sweep angle of the trail arc at P1.
-        public float a1;
-        public RectF arc1 = new RectF();
-        // Sweep angle of the trail arc at P2.
-        public float a2;
-        public RectF arc2 = new RectF();
-    }
-
-    private static final float RIGHT_ANGLE = (float)(Math.PI / 2.0d);
-    private static final float RADIAN_TO_DEGREE = (float)(180.0d / Math.PI);
-
-    private static boolean calculatePathPoints(final WorkingSet w) {
-        final float dx = w.p2x - w.p1x;
-        final float dy = w.p2y - w.p1y;
-        // Distance of the points.
-        final double l = Math.hypot(dx, dy);
-        if (Double.compare(0.0d, l) == 0) {
-            return false;
-        }
-        // Angle of the line p1-p2
-        final float a = (float)Math.atan2(dy, dx);
-        // Difference of trail cap radius.
-        final float dr = w.r2 - w.r1;
-        // Variation of angle at trail cap.
-        final float ar = (float)Math.asin(dr / l);
-        // The start angle of trail cap arc at P1.
-        final float aa = a - (RIGHT_ANGLE + ar);
-        // The end angle of trail cap arc at P2.
-        final float ab = a + (RIGHT_ANGLE + ar);
-        final float cosa = (float)Math.cos(aa);
-        final float sina = (float)Math.sin(aa);
-        final float cosb = (float)Math.cos(ab);
-        final float sinb = (float)Math.sin(ab);
-        w.p1ax = w.p1x + w.r1 * cosa;
-        w.p1ay = w.p1y + w.r1 * sina;
-        w.p1bx = w.p1x + w.r1 * cosb;
-        w.p1by = w.p1y + w.r1 * sinb;
-        w.p2ax = w.p2x + w.r2 * cosa;
-        w.p2ay = w.p2y + w.r2 * sina;
-        w.p2bx = w.p2x + w.r2 * cosb;
-        w.p2by = w.p2y + w.r2 * sinb;
-        w.aa = aa * RADIAN_TO_DEGREE;
-        final float ar2degree = ar * 2.0f * RADIAN_TO_DEGREE;
-        w.a1 = -180.0f + ar2degree;
-        w.a2 = 180.0f + ar2degree;
-        w.arc1.set(w.p1x, w.p1y, w.p1x, w.p1y);
-        w.arc1.inset(-w.r1, -w.r1);
-        w.arc2.set(w.p2x, w.p2y, w.p2x, w.p2y);
-        w.arc2.inset(-w.r2, -w.r2);
-        return true;
-    }
-
-    private static void createPath(final Path path, final WorkingSet w) {
-        path.rewind();
-        // Trail cap at P1.
-        path.moveTo(w.p1x, w.p1y);
-        path.arcTo(w.arc1, w.aa, w.a1);
-        // Trail cap at P2.
-        path.moveTo(w.p2x, w.p2y);
-        path.arcTo(w.arc2, w.aa, w.a2);
-        // Two trapezoids connecting P1 and P2.
-        path.moveTo(w.p1ax, w.p1ay);
-        path.lineTo(w.p1x, w.p1y);
-        path.lineTo(w.p1bx, w.p1by);
-        path.lineTo(w.p2bx, w.p2by);
-        path.lineTo(w.p2x, w.p2y);
-        path.lineTo(w.p2ax, w.p2ay);
-        path.close();
-    }
-
-    private final WorkingSet mWorkingSet = new WorkingSet();
-    private final Path mPath = new Path();
+    private final RoundedLine mRoundedLine = new RoundedLine();
 
     /**
      * Draw gesture preview trail
@@ -243,36 +151,35 @@
         if (startIndex < trailSize) {
             paint.setColor(params.mTrailColor);
             paint.setStyle(Paint.Style.FILL);
-            final Path path = mPath;
-            final WorkingSet w = mWorkingSet;
-            w.p1x = getXCoordValue(xCoords[startIndex]);
-            w.p1y = yCoords[startIndex];
+            final RoundedLine line = mRoundedLine;
+            int p1x = getXCoordValue(xCoords[startIndex]);
+            int p1y = yCoords[startIndex];
             int lastTime = sinceDown - eventTimes[startIndex];
             float maxWidth = getWidth(lastTime, params);
-            w.r1 = maxWidth / 2.0f;
+            float r1 = maxWidth / 2.0f;
             // Initialize bounds rectangle.
-            outBoundsRect.set((int)w.p1x, (int)w.p1y, (int)w.p1x, (int)w.p1y);
+            outBoundsRect.set(p1x, p1y, p1x, p1y);
             for (int i = startIndex + 1; i < trailSize - 1; i++) {
                 final int elapsedTime = sinceDown - eventTimes[i];
-                w.p2x = getXCoordValue(xCoords[i]);
-                w.p2y = yCoords[i];
+                final int p2x = getXCoordValue(xCoords[i]);
+                final int p2y = yCoords[i];
+                final float width = getWidth(elapsedTime, params);
+                final float r2 = width / 2.0f;
                 // Draw trail line only when the current point isn't a down point.
                 if (!isDownEventXCoord(xCoords[i])) {
                     final int alpha = getAlpha(elapsedTime, params);
                     paint.setAlpha(alpha);
-                    final float width = getWidth(elapsedTime, params);
-                    w.r2 = width / 2.0f;
-                    if (calculatePathPoints(w)) {
-                        createPath(path, w);
+                    final Path path = line.makePath(p1x, p1y, r1, p2x, p2y, r2);
+                    if (path != null) {
                         canvas.drawPath(path, paint);
-                        outBoundsRect.union((int)w.p2x, (int)w.p2y);
+                        outBoundsRect.union(p2x, p2y);
                     }
                     // Take union for the bounds.
                     maxWidth = Math.max(maxWidth, width);
                 }
-                w.p1x = w.p2x;
-                w.p1y = w.p2y;
-                w.r1 = w.r2;
+                p1x = p2x;
+                p1y = p2y;
+                r1 = r2;
                 lastTime = elapsedTime;
             }
             // Take care of trail line width.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
index aab14e9..a43e94a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
@@ -228,6 +228,17 @@
         return isStartOfAGesture;
     }
 
+    public void duplicateLastPointWith(final int time) {
+        final int lastIndex = mEventTimes.getLength() - 1;
+        if (lastIndex >= 0) {
+            final int x = mXCoordinates.get(lastIndex);
+            final int y = mYCoordinates.get(lastIndex);
+            // TODO: Have appendMajorPoint()
+            appendPoint(x, y, time);
+            updateIncrementalRecognitionSize(x, y, time);
+        }
+    }
+
     protected void reset() {
         mIncrementalRecognitionSize = 0;
         mLastIncrementalBatchSize = 0;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index 804a34b..25a1c6a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -486,6 +486,11 @@
                     // After chording input while normal state.
                     setShifted(UNSHIFT);
                 }
+                // After chording input, automatic shift state may have been changed depending on
+                // what characters were input.
+                mShiftKeyState.onRelease();
+                mSwitchActions.requestUpdatingShiftState();
+                return;
             } else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) {
                 // In shift locked state, shift has been pressed and slid out to other key.
                 setShiftLocked(true);
diff --git a/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java
new file mode 100644
index 0000000..1f52520
--- /dev/null
+++ b/java/src/com/android/inputmethod/keyboard/internal/RoundedLine.java
@@ -0,0 +1,103 @@
+/*
+ * 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.keyboard.internal;
+
+import android.graphics.Path;
+import android.graphics.RectF;
+
+public final class RoundedLine {
+    private final RectF mArc1 = new RectF();
+    private final RectF mArc2 = new RectF();
+    private final Path mPath = new Path();
+
+    private static final double RADIAN_TO_DEGREE = 180.0d / Math.PI;
+    private static final double RIGHT_ANGLE = Math.PI / 2.0d;
+
+    /**
+     * Make a rounded line path
+     *
+     * @param p1x the x-coordinate of the start point.
+     * @param p1y the y-coordinate of the start point.
+     * @param r1 the radius at the start point
+     * @param p2x the x-coordinate of the end point.
+     * @param p2y the y-coordinate of the end point.
+     * @param r2 the radius at the end point
+     * @return the path of rounded line
+     */
+    public Path makePath(final float p1x, final float p1y, final float r1,
+            final float p2x, final float p2y, final float r2) {
+        final double dx = p2x - p1x;
+        final double dy = p2y - p1y;
+        // Distance of the points.
+        final double l = Math.hypot(dx, dy);
+        if (Double.compare(0.0d, l) == 0) {
+            return null;
+        }
+        // Angle of the line p1-p2
+        final double a = Math.atan2(dy, dx);
+        // Difference of trail cap radius.
+        final double dr = r2 - r1;
+        // Variation of angle at trail cap.
+        final double ar = Math.asin(dr / l);
+        // The start angle of trail cap arc at P1.
+        final double aa = a - (RIGHT_ANGLE + ar);
+        // The end angle of trail cap arc at P2.
+        final double ab = a + (RIGHT_ANGLE + ar);
+        final float cosa = (float)Math.cos(aa);
+        final float sina = (float)Math.sin(aa);
+        final float cosb = (float)Math.cos(ab);
+        final float sinb = (float)Math.sin(ab);
+        // Closing point of arc at P1.
+        final float p1ax = p1x + r1 * cosa;
+        final float p1ay = p1y + r1 * sina;
+        // Opening point of arc at P1.
+        final float p1bx = p1x + r1 * cosb;
+        final float p1by = p1y + r1 * sinb;
+        // Opening point of arc at P2.
+        final float p2ax = p2x + r2 * cosa;
+        final float p2ay = p2y + r2 * sina;
+        // Closing point of arc at P2.
+        final float p2bx = p2x + r2 * cosb;
+        final float p2by = p2y + r2 * sinb;
+        // Start angle of the trail arcs.
+        final float angle = (float)(aa * RADIAN_TO_DEGREE);
+        final float ar2degree = (float)(ar * 2.0d * RADIAN_TO_DEGREE);
+        // Sweep angle of the trail arc at P1.
+        final float a1 = -180.0f + ar2degree;
+        // Sweep angle of the trail arc at P2.
+        final float a2 = 180.0f + ar2degree;
+        mArc1.set(p1x, p1y, p1x, p1y);
+        mArc1.inset(-r1, -r1);
+        mArc2.set(p2x, p2y, p2x, p2y);
+        mArc2.inset(-r2, -r2);
+
+        mPath.rewind();
+        // Trail cap at P1.
+        mPath.moveTo(p1x, p1y);
+        mPath.arcTo(mArc1, angle, a1);
+        // Trail cap at P2.
+        mPath.moveTo(p2x, p2y);
+        mPath.arcTo(mArc2, angle, a2);
+        // Two trapezoids connecting P1 and P2.
+        mPath.moveTo(p1ax, p1ay);
+        mPath.lineTo(p1x, p1y);
+        mPath.lineTo(p1bx, p1by);
+        mPath.lineTo(p2bx, p2by);
+        mPath.lineTo(p2x, p2y);
+        mPath.lineTo(p2ax, p2ay);
+        mPath.close();
+        return mPath;
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
index 96c08b3..08f08d2 100644
--- a/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
+++ b/java/src/com/android/inputmethod/latin/AdditionalSubtypeSettings.java
@@ -386,12 +386,11 @@
     public void onCreate(final Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
-        RichInputMethodManager.init(getActivity());
+        mPrefs = getPreferenceManager().getSharedPreferences();
+        RichInputMethodManager.init(getActivity(), mPrefs);
         mRichImm = RichInputMethodManager.getInstance();
         addPreferencesFromResource(R.xml.additional_subtype_settings);
         setHasOptionsMenu(true);
-
-        mPrefs = getPreferenceManager().getSharedPreferences();
     }
 
     @Override
diff --git a/java/src/com/android/inputmethod/latin/CoordinateUtils.java b/java/src/com/android/inputmethod/latin/CoordinateUtils.java
new file mode 100644
index 0000000..cd31772
--- /dev/null
+++ b/java/src/com/android/inputmethod/latin/CoordinateUtils.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+public final class CoordinateUtils {
+    private static final int INDEX_X = 0;
+    private static final int INDEX_Y = 1;
+    private static final int ARRAY_SIZE = INDEX_Y + 1;
+
+    private CoordinateUtils() {
+        // This utility class is not publicly instantiable.
+    }
+
+    public static int[] newInstance() {
+        return new int[ARRAY_SIZE];
+    }
+
+    public static int x(final int[] coords) {
+        return coords[INDEX_X];
+    }
+
+    public static int y(final int[] coords) {
+        return coords[INDEX_Y];
+    }
+}
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index dc3ad4f..0b49659 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -403,33 +403,28 @@
 
     @Override
     public void onCreate() {
-        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
-        mPrefs = prefs;
-        LatinImeLogger.init(this, prefs);
+        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+        mResources = getResources();
+
+        LatinImeLogger.init(this, mPrefs);
         if (ProductionFlag.IS_EXPERIMENTAL) {
-            ResearchLogger.getInstance().init(this, prefs);
+            ResearchLogger.getInstance().init(this, mPrefs);
         }
-        RichInputMethodManager.init(this);
+        RichInputMethodManager.init(this, mPrefs);
+        mRichImm = RichInputMethodManager.getInstance();
         SubtypeSwitcher.init(this);
-        KeyboardSwitcher.init(this, prefs);
+        KeyboardSwitcher.init(this, mPrefs);
         AccessibilityUtils.init(this);
 
         super.onCreate();
 
-        mRichImm = RichInputMethodManager.getInstance();
         mHandler.onCreate();
         DEBUG = LatinImeLogger.sDBG;
 
-        final Resources res = getResources();
-        mResources = res;
-
         loadSettings();
-
-        mRichImm.setAdditionalInputMethodSubtypes(mCurrentSettings.getAdditionalSubtypes());
-
         initSuggest();
 
-        mDisplayOrientation = res.getConfiguration().orientation;
+        mDisplayOrientation = mResources.getConfiguration().orientation;
 
         // Register to receive ringer mode change and network state change.
         // Also receive installation and removal of a dictionary pack.
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index 63dfd32..af0d61c 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -19,6 +19,7 @@
 import static com.android.inputmethod.latin.Constants.Subtype.KEYBOARD_MODE;
 
 import android.content.Context;
+import android.content.SharedPreferences;
 import android.os.IBinder;
 import android.view.inputmethod.InputMethodInfo;
 import android.view.inputmethod.InputMethodManager;
@@ -49,19 +50,34 @@
         return sInstance;
     }
 
-    public static void init(final Context context) {
-        sInstance.initInternal(context);
+    public static void init(final Context context, final SharedPreferences prefs) {
+        sInstance.initInternal(context, prefs);
+    }
+
+    private boolean isInitialized() {
+        return mImmWrapper != null;
     }
 
     private void checkInitialized() {
-        if (mImmWrapper == null) {
+        if (!isInitialized()) {
             throw new RuntimeException(TAG + " is used before initialization");
         }
     }
 
-    private void initInternal(final Context context) {
+    private void initInternal(final Context context, final SharedPreferences prefs) {
+        if (isInitialized()) {
+            return;
+        }
         mImmWrapper = new InputMethodManagerCompatWrapper(context);
         mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context);
+
+        // Initialize additional subtypes.
+        SubtypeLocale.init(context);
+        final String prefAdditionalSubtypes = SettingsValues.getPrefAdditionalSubtypes(
+                prefs, context.getResources());
+        final InputMethodSubtype[] additionalSubtypes =
+                AdditionalSubtype.createAdditionalSubtypesArray(prefAdditionalSubtypes);
+        setAdditionalInputMethodSubtypes(additionalSubtypes);
     }
 
     public InputMethodManager getInputMethodManager() {
diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java
index d6daa0d..8de64c1 100644
--- a/java/src/com/android/inputmethod/latin/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/SettingsValues.java
@@ -22,7 +22,6 @@
 import android.content.res.Resources;
 import android.util.Log;
 import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodSubtype;
 
 import com.android.inputmethod.keyboard.internal.KeySpecParser;
 import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
@@ -82,7 +81,6 @@
     private final int mVibrationDurationSettingsRawValue;
     @SuppressWarnings("unused") // TODO: Use this
     private final float mKeypressSoundVolumeRawValue;
-    private final InputMethodSubtype[] mAdditionalSubtypes;
     public final boolean mGestureInputEnabled;
     public final boolean mGesturePreviewTrailEnabled;
     public final boolean mGestureFloatingPreviewTextEnabled;
@@ -170,8 +168,6 @@
                 mAutoCorrectionThresholdRawValue);
         mVoiceKeyEnabled = mVoiceMode != null && !mVoiceMode.equals(voiceModeOff);
         mVoiceKeyOnMain = mVoiceMode != null && mVoiceMode.equals(voiceModeMain);
-        mAdditionalSubtypes = AdditionalSubtype.createAdditionalSubtypesArray(
-                getPrefAdditionalSubtypes(prefs, res));
         final boolean gestureInputEnabledByBuildConfig = res.getBoolean(
                 R.bool.config_gesture_input_enabled_by_build_config);
         mGestureInputEnabled = gestureInputEnabledByBuildConfig
@@ -375,10 +371,6 @@
         return res.getBoolean(R.bool.config_use_fullscreen_mode);
     }
 
-    public InputMethodSubtype[] getAdditionalSubtypes() {
-        return mAdditionalSubtypes;
-    }
-
     public static String getPrefAdditionalSubtypes(final SharedPreferences prefs,
             final Resources res) {
         final String predefinedPrefSubtypes = AdditionalSubtype.createPrefSubtypes(
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index 6cdd9e2..8cc09f3 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -34,6 +34,7 @@
 import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy;
 import com.android.inputmethod.keyboard.PointerTracker.KeyEventHandler;
 import com.android.inputmethod.keyboard.PointerTracker.TimerProxy;
+import com.android.inputmethod.latin.CoordinateUtils;
 import com.android.inputmethod.latin.R;
 
 /**
@@ -41,7 +42,7 @@
  * key presses and touch movements.
  */
 public final class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
-    private final int[] mCoordinates = new int[2];
+    private final int[] mCoordinates = CoordinateUtils.newInstance();
 
     final KeyDetector mModalPanelKeyDetector;
     private final KeyDetector mSlidingPanelKeyDetector;
@@ -163,7 +164,7 @@
         window.setHeight(container.getMeasuredHeight());
         parentView.getLocationInWindow(mCoordinates);
         window.showAtLocation(parentView, Gravity.NO_GRAVITY,
-                x + mCoordinates[0], y + mCoordinates[1]);
+                x + CoordinateUtils.x(mCoordinates), y + CoordinateUtils.y(mCoordinates));
 
         mOriginX = x + container.getPaddingLeft();
         mOriginY = y + container.getPaddingTop();
diff --git a/native/jni/Android.mk b/native/jni/Android.mk
index e87577e..c616be5 100644
--- a/native/jni/Android.mk
+++ b/native/jni/Android.mk
@@ -89,11 +89,11 @@
 
 ifeq ($(FLAG_DO_PROFILE), true)
     $(warning Making profiling version of native library)
-    LOCAL_SHARED_LIBRARIES += liblog
+    LOCAL_LDFLAGS += -llog
 else # FLAG_DO_PROFILE
 ifeq ($(FLAG_DBG), true)
     $(warning Making debug version of native library)
-    LOCAL_SHARED_LIBRARIES += liblog
+    LOCAL_LDFLAGS += -llog
 endif # FLAG_DBG
 endif # FLAG_DO_PROFILE
 
diff --git a/native/jni/src/binary_format.h b/native/jni/src/binary_format.h
index 1c211e4..86410fb 100644
--- a/native/jni/src/binary_format.h
+++ b/native/jni/src/binary_format.h
@@ -314,7 +314,7 @@
     /* See the note in attributeAddressSize. The same applies here */
 }
 
-static inline int shortcutByteSize(const uint8_t *const dict, const int pos) {
+static AK_FORCE_INLINE int shortcutByteSize(const uint8_t *const dict, const int pos) {
     return ((int)(dict[pos] << 8)) + (dict[pos + 1]);
 }
 
diff --git a/native/jni/src/char_utils.cpp b/native/jni/src/char_utils.cpp
index ede1155..f1148f4 100644
--- a/native/jni/src/char_utils.cpp
+++ b/native/jni/src/char_utils.cpp
@@ -26,79 +26,62 @@
   unsigned short small;
 };
 
-// Generated from http://unicode.org/Public/UNIDATA/UnicodeData.txt
-//
-// 1. Run the following code.  Bascially taken from
-//    Dictionary::toLowerCase(unsigned short c) in dictionary.cpp.
-//    Then, get the list of chars where cc != ccc.
-//
-//    unsigned short c, cc, ccc, ccc2;
-//    for (c = 0; c < 0xFFFF ; c++) {
-//        if (c < NELEMS(BASE_CHARS)) {
-//            cc = BASE_CHARS[c];
-//        } else {
-//            cc = c;
-//        }
-//
-//        // tolower
-//        int isBase = 0;
-//        if (cc >='A' && cc <= 'Z') {
-//            ccc = (cc | 0x20);
-//            ccc2 = ccc;
-//            isBase = 1;
-//        } else if (cc > 0x7F) {
-//            ccc = u_tolower(cc);
-//            ccc2 = latin_tolower(cc);
-//        } else {
-//            ccc = cc;
-//            ccc2 = ccc;
-//        }
-//        if (!isBase && cc != ccc) {
-//            wprintf(L" 0x%04X => 0x%04X => 0x%04X  %lc => %lc => %lc \n",
-//                    c, cc, ccc, c, cc, ccc);
-//            //assert(ccc == ccc2);
-//        }
-//    }
-//
-//    Initially, started with an empty latin_tolower() as below.
-//
-//    unsigned short latin_tolower(unsigned short c) {
-//        return c;
-//    }
-//
-//
-// 2. Process the list obtained by 1 by the following perl script and apply
-//    'sort -u' as well.  Get the SORTED_CHAR_MAP[].
-//    Note that '$1' in the perl script is 'cc' in the above C code.
-//
-//    while(<>) {
-//        / 0x\w* => 0x(\w*) =/;
-//        open(HDL, "grep -iw ^" . $1 . " UnicodeData.txt | ");
-//        $line = <HDL>;
-//        chomp $line;
-//        @cols = split(/;/, $line);
-//        print "    { 0x$1, 0x$cols[13] },  // $cols[1]\n";
-//    }
-//
-//
-// 3. Update the latin_tolower() function above with SORTED_CHAR_MAP.  Enable
-//    the assert(ccc == ccc2) above and confirm the function exits successfully.
-//
-// TODO: Regenerate this map by using the updated BASE_CHARS table in this file.
+/*
+ * How to update the SORTED_CHAR_MAP[] array.
+ *
+ * 1. Download http://unicode.org/Public/UNIDATA/UnicodeData.txt
+ *
+ * 2. Have a latest version of ICU4C dev package installed
+ *    (Note: the current data has been generated with version 4.8)
+ *    $ apt-get install libicu-dev
+ *
+ * 3. Build the following code
+ *    (You need this file, char_utils.h, and defines.h)
+ *    $ g++ -o char_utils -DUPDATING_CHAR_UTILS char_utils.cpp -licuuc
+ */
+#ifdef UPDATING_CHAR_UTILS
+#include <stdio.h>
+#include <unicode/uchar.h> // ICU4C
+
+extern "C" int main() {
+    for (unsigned short c = 0; c < 0xFFFF; c++) {
+        const unsigned short baseC = c < NELEMS(BASE_CHARS) ? BASE_CHARS[c] : c;
+        if (baseC <= 0x7F) continue;
+        const unsigned short icu4cLowerBaseC = u_tolower(baseC);
+        const unsigned short myLowerBaseC = latin_tolower(baseC);
+        if (baseC != icu4cLowerBaseC) {
+#ifdef CONFIRMING_CHAR_UTILS
+            if (icu4cLowerBaseC != myLowerBaseC) {
+                fprintf(stderr, "icu4cLowerBaseC != myLowerBaseC, 0x%04X, 0x%04X\n",
+                        icu4cLowerBaseC, myLowerBaseC);
+            }
+#else // CONFIRMING_CHAR_UTILS
+            printf("0x%04X, 0x%04X\n", baseC, icu4cLowerBaseC);
+#endif // CONFIRMING_CHAR_UTILS
+        }
+    }
+}
+#endif // UPDATING_CHAR_UTILS
+/*
+ * 4. Process the list with UnicodeData.txt
+ *    (You need UnicodeData.txt in the current directory)
+ *    $ ./char_utils | sort -u | \
+ *      perl -e 'open(FH, "UnicodeData.txt"); @buf = <FH>; close(FH); \
+ *      while(<>){/0x(\w*), 0x(\w*)/; @lines = grep(/^$1/, @buf); @cols = split(/;/, $lines[0]); \
+ *      print "    { 0x$1, 0x$cols[13] },  // $cols[1]\n";}'
+ *
+ * 5. Update the SORTED_CHAR_MAP[] array below with the output above.
+ *    Then, rebuild with -DCONFIRMING_CHAR_UTILS and confirm the program exits successfully.
+ *    $ g++ -o char_utils -DUPDATING_CHAR_UTILS -DCONFIRMING_CHAR_UTILS char_utils.cpp -licuuc
+ *    $ ./char_utils
+ *    $
+ */
 static const struct LatinCapitalSmallPair SORTED_CHAR_MAP[] = {
-    { 0x00C4, 0x00E4 },  // LATIN CAPITAL LETTER A WITH DIAERESIS
-    { 0x00C5, 0x00E5 },  // LATIN CAPITAL LETTER A WITH RING ABOVE
     { 0x00C6, 0x00E6 },  // LATIN CAPITAL LETTER AE
     { 0x00D0, 0x00F0 },  // LATIN CAPITAL LETTER ETH
-    { 0x00D1, 0x00F1 },  // LATIN CAPITAL LETTER N WITH TILDE
-    { 0x00D5, 0x00F5 },  // LATIN CAPITAL LETTER O WITH TILDE
-    { 0x00D6, 0x00F6 },  // LATIN CAPITAL LETTER O WITH DIAERESIS
-    { 0x00D8, 0x00F8 },  // LATIN CAPITAL LETTER O WITH STROKE
-    { 0x00DC, 0x00FC },  // LATIN CAPITAL LETTER U WITH DIAERESIS
     { 0x00DE, 0x00FE },  // LATIN CAPITAL LETTER THORN
     { 0x0110, 0x0111 },  // LATIN CAPITAL LETTER D WITH STROKE
     { 0x0126, 0x0127 },  // LATIN CAPITAL LETTER H WITH STROKE
-    { 0x0141, 0x0142 },  // LATIN CAPITAL LETTER L WITH STROKE
     { 0x014A, 0x014B },  // LATIN CAPITAL LETTER ENG
     { 0x0152, 0x0153 },  // LATIN CAPITAL LIGATURE OE
     { 0x0166, 0x0167 },  // LATIN CAPITAL LETTER T WITH STROKE
@@ -137,15 +120,12 @@
     { 0x01B8, 0x01B9 },  // LATIN CAPITAL LETTER EZH REVERSED
     { 0x01BC, 0x01BD },  // LATIN CAPITAL LETTER TONE FIVE
     { 0x01E4, 0x01E5 },  // LATIN CAPITAL LETTER G WITH STROKE
-    { 0x01EA, 0x01EB },  // LATIN CAPITAL LETTER O WITH OGONEK
     { 0x01F6, 0x0195 },  // LATIN CAPITAL LETTER HWAIR
     { 0x01F7, 0x01BF },  // LATIN CAPITAL LETTER WYNN
     { 0x021C, 0x021D },  // LATIN CAPITAL LETTER YOGH
     { 0x0220, 0x019E },  // LATIN CAPITAL LETTER N WITH LONG RIGHT LEG
     { 0x0222, 0x0223 },  // LATIN CAPITAL LETTER OU
     { 0x0224, 0x0225 },  // LATIN CAPITAL LETTER Z WITH HOOK
-    { 0x0226, 0x0227 },  // LATIN CAPITAL LETTER A WITH DOT ABOVE
-    { 0x022E, 0x022F },  // LATIN CAPITAL LETTER O WITH DOT ABOVE
     { 0x023A, 0x2C65 },  // LATIN CAPITAL LETTER A WITH STROKE
     { 0x023B, 0x023C },  // LATIN CAPITAL LETTER C WITH STROKE
     { 0x023D, 0x019A },  // LATIN CAPITAL LETTER L WITH BAR
@@ -322,6 +302,7 @@
     { 0x0520, 0x0521 },  // CYRILLIC CAPITAL LETTER EL WITH MIDDLE HOOK
     { 0x0522, 0x0523 },  // CYRILLIC CAPITAL LETTER EN WITH MIDDLE HOOK
     { 0x0524, 0x0525 },  // CYRILLIC CAPITAL LETTER PE WITH DESCENDER
+    { 0x0526, 0x0527 },  // CYRILLIC CAPITAL LETTER SHHA WITH DESCENDER
     { 0x0531, 0x0561 },  // ARMENIAN CAPITAL LETTER AYB
     { 0x0532, 0x0562 },  // ARMENIAN CAPITAL LETTER BEN
     { 0x0533, 0x0563 },  // ARMENIAN CAPITAL LETTER GIM
@@ -795,6 +776,7 @@
     { 0xA65A, 0xA65B },  // CYRILLIC CAPITAL LETTER BLENDED YUS
     { 0xA65C, 0xA65D },  // CYRILLIC CAPITAL LETTER IOTIFIED CLOSED LITTLE YUS
     { 0xA65E, 0xA65F },  // CYRILLIC CAPITAL LETTER YN
+    { 0xA660, 0xA661 },  // CYRILLIC CAPITAL LETTER REVERSED TSE
     { 0xA662, 0xA663 },  // CYRILLIC CAPITAL LETTER SOFT DE
     { 0xA664, 0xA665 },  // CYRILLIC CAPITAL LETTER SOFT EL
     { 0xA666, 0xA667 },  // CYRILLIC CAPITAL LETTER SOFT EM
@@ -860,6 +842,13 @@
     { 0xA784, 0xA785 },  // LATIN CAPITAL LETTER INSULAR S
     { 0xA786, 0xA787 },  // LATIN CAPITAL LETTER INSULAR T
     { 0xA78B, 0xA78C },  // LATIN CAPITAL LETTER SALTILLO
+    { 0xA78D, 0x0265 },  // LATIN CAPITAL LETTER TURNED H
+    { 0xA790, 0xA791 },  // LATIN CAPITAL LETTER N WITH DESCENDER
+    { 0xA7A0, 0xA7A1 },  // LATIN CAPITAL LETTER G WITH OBLIQUE STROKE
+    { 0xA7A2, 0xA7A3 },  // LATIN CAPITAL LETTER K WITH OBLIQUE STROKE
+    { 0xA7A4, 0xA7A5 },  // LATIN CAPITAL LETTER N WITH OBLIQUE STROKE
+    { 0xA7A6, 0xA7A7 },  // LATIN CAPITAL LETTER R WITH OBLIQUE STROKE
+    { 0xA7A8, 0xA7A9 },  // LATIN CAPITAL LETTER S WITH OBLIQUE STROKE
     { 0xFF21, 0xFF41 },  // FULLWIDTH LATIN CAPITAL LETTER A
     { 0xFF22, 0xFF42 },  // FULLWIDTH LATIN CAPITAL LETTER B
     { 0xFF23, 0xFF43 },  // FULLWIDTH LATIN CAPITAL LETTER C
@@ -943,12 +932,14 @@
     /* U+00D0 */ 0x00D0, 0x004E, 0x004F, 0x004F, 0x004F, 0x004F, 0x004F, 0x00D7,
     /* U+00D8 */ 0x004F, 0x0055, 0x0055, 0x0055, 0x0055, 0x0059, 0x00DE, 0x0073,
         // U+00D8: Manually changed from 00D8 to 004F
+          // TODO: Check if it's really acceptable to consider Ø a diacritical variant of O
         // U+00DF: Manually changed from 00DF to 0073
     /* U+00E0 */ 0x0061, 0x0061, 0x0061, 0x0061, 0x0061, 0x0061, 0x00E6, 0x0063,
     /* U+00E8 */ 0x0065, 0x0065, 0x0065, 0x0065, 0x0069, 0x0069, 0x0069, 0x0069,
     /* U+00F0 */ 0x00F0, 0x006E, 0x006F, 0x006F, 0x006F, 0x006F, 0x006F, 0x00F7,
     /* U+00F8 */ 0x006F, 0x0075, 0x0075, 0x0075, 0x0075, 0x0079, 0x00FE, 0x0079,
         // U+00F8: Manually changed from 00F8 to 006F
+          // TODO: Check if it's really acceptable to consider ø a diacritical variant of o
     /* U+0100 */ 0x0041, 0x0061, 0x0041, 0x0061, 0x0041, 0x0061, 0x0043, 0x0063,
     /* U+0108 */ 0x0043, 0x0063, 0x0043, 0x0063, 0x0043, 0x0063, 0x0044, 0x0064,
     /* U+0110 */ 0x0110, 0x0111, 0x0045, 0x0065, 0x0045, 0x0065, 0x0045, 0x0065,
@@ -977,19 +968,45 @@
     /* U+01B8 */ 0x01B8, 0x01B9, 0x01BA, 0x01BB, 0x01BC, 0x01BD, 0x01BE, 0x01BF,
     /* U+01C0 */ 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x0044, 0x0044, 0x0064, 0x004C,
     /* U+01C8 */ 0x004C, 0x006C, 0x004E, 0x004E, 0x006E, 0x0041, 0x0061, 0x0049,
-    /* U+01D0 */ 0x0069, 0x004F, 0x006F, 0x0055, 0x0075, 0x00DC, 0x00FC, 0x00DC,
-    /* U+01D8 */ 0x00FC, 0x00DC, 0x00FC, 0x00DC, 0x00FC, 0x01DD, 0x00C4, 0x00E4,
-    /* U+01E0 */ 0x0226, 0x0227, 0x00C6, 0x00E6, 0x01E4, 0x01E5, 0x0047, 0x0067,
-    /* U+01E8 */ 0x004B, 0x006B, 0x004F, 0x006F, 0x01EA, 0x01EB, 0x01B7, 0x0292,
+    /* U+01D0 */ 0x0069, 0x004F, 0x006F, 0x0055, 0x0075, 0x0055, 0x0075, 0x0055,
+        // U+01D5: Manually changed from 00DC to 0055
+        // U+01D6: Manually changed from 00FC to 0075
+        // U+01D7: Manually changed from 00DC to 0055
+    /* U+01D8 */ 0x0075, 0x0055, 0x0075, 0x0055, 0x0075, 0x01DD, 0x0041, 0x0061,
+        // U+01D8: Manually changed from 00FC to 0075
+        // U+01D9: Manually changed from 00DC to 0055
+        // U+01DA: Manually changed from 00FC to 0075
+        // U+01DB: Manually changed from 00DC to 0055
+        // U+01DC: Manually changed from 00FC to 0075
+        // U+01DE: Manually changed from 00C4 to 0041
+        // U+01DF: Manually changed from 00E4 to 0061
+    /* U+01E0 */ 0x0041, 0x0061, 0x00C6, 0x00E6, 0x01E4, 0x01E5, 0x0047, 0x0067,
+        // U+01E0: Manually changed from 0226 to 0041
+        // U+01E1: Manually changed from 0227 to 0061
+    /* U+01E8 */ 0x004B, 0x006B, 0x004F, 0x006F, 0x004F, 0x006F, 0x01B7, 0x0292,
+        // U+01EC: Manually changed from 01EA to 004F
+        // U+01ED: Manually changed from 01EB to 006F
     /* U+01F0 */ 0x006A, 0x0044, 0x0044, 0x0064, 0x0047, 0x0067, 0x01F6, 0x01F7,
-    /* U+01F8 */ 0x004E, 0x006E, 0x00C5, 0x00E5, 0x00C6, 0x00E6, 0x00D8, 0x00F8,
+    /* U+01F8 */ 0x004E, 0x006E, 0x0041, 0x0061, 0x00C6, 0x00E6, 0x004F, 0x006F,
+        // U+01FA: Manually changed from 00C5 to 0041
+        // U+01FB: Manually changed from 00E5 to 0061
+        // U+01FE: Manually changed from 00D8 to 004F
+          // TODO: Check if it's really acceptable to consider Ø a diacritical variant of O
+        // U+01FF: Manually changed from 00F8 to 006F
+          // TODO: Check if it's really acceptable to consider ø a diacritical variant of o
     /* U+0200 */ 0x0041, 0x0061, 0x0041, 0x0061, 0x0045, 0x0065, 0x0045, 0x0065,
     /* U+0208 */ 0x0049, 0x0069, 0x0049, 0x0069, 0x004F, 0x006F, 0x004F, 0x006F,
     /* U+0210 */ 0x0052, 0x0072, 0x0052, 0x0072, 0x0055, 0x0075, 0x0055, 0x0075,
     /* U+0218 */ 0x0053, 0x0073, 0x0054, 0x0074, 0x021C, 0x021D, 0x0048, 0x0068,
     /* U+0220 */ 0x0220, 0x0221, 0x0222, 0x0223, 0x0224, 0x0225, 0x0041, 0x0061,
-    /* U+0228 */ 0x0045, 0x0065, 0x00D6, 0x00F6, 0x00D5, 0x00F5, 0x004F, 0x006F,
-    /* U+0230 */ 0x022E, 0x022F, 0x0059, 0x0079, 0x0234, 0x0235, 0x0236, 0x0237,
+    /* U+0228 */ 0x0045, 0x0065, 0x004F, 0x006F, 0x004F, 0x006F, 0x004F, 0x006F,
+        // U+022A: Manually changed from 00D6 to 004F
+        // U+022B: Manually changed from 00F6 to 006F
+        // U+022C: Manually changed from 00D5 to 004F
+        // U+022D: Manually changed from 00F5 to 006F
+    /* U+0230 */ 0x004F, 0x006F, 0x0059, 0x0079, 0x0234, 0x0235, 0x0236, 0x0237,
+        // U+0230: Manually changed from 022E to 004F
+        // U+0231: Manually changed from 022F to 006F
     /* U+0238 */ 0x0238, 0x0239, 0x023A, 0x023B, 0x023C, 0x023D, 0x023E, 0x023F,
     /* U+0240 */ 0x0240, 0x0241, 0x0242, 0x0243, 0x0244, 0x0245, 0x0246, 0x0247,
     /* U+0248 */ 0x0248, 0x0249, 0x024A, 0x024B, 0x024C, 0x024D, 0x024E, 0x024F,
diff --git a/native/jni/src/defines.h b/native/jni/src/defines.h
index ebdff7f..c504cec 100644
--- a/native/jni/src/defines.h
+++ b/native/jni/src/defines.h
@@ -167,15 +167,15 @@
     }
     AKLOGI("Total time is %6.3f ms.",
             profile_buf[PROF_BUF_SIZE - 1] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC));
-    float all = 0;
+    float all = 0.0f;
     for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
         all += profile_buf[i];
     }
-    if (all == 0) all = 1;
+    if (all < 1.0f) all = 1.0f;
     for (int i = 0; i < PROF_BUF_SIZE - 1; ++i) {
-        if (profile_buf[i]) {
+        if (profile_buf[i] > 0.0f) {
             AKLOGI("(%d): Used %4.2f%%, %8.4f ms. Called %d times.",
-                    i, (profile_buf[i] * 100 / all),
+                    i, (profile_buf[i] * 100.0f / all),
                     profile_buf[i] * 1000.0f / static_cast<float>(CLOCKS_PER_SEC),
                     profile_counter[i]);
         }
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index 6bd46cc..4b08d6a 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -17,7 +17,7 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.android.inputmethod.latin.tests">
 
-    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
+    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16" />
 
     <uses-permission android:name="android.permission.READ_CONTACTS" />
 
diff --git a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
index 015c271..de323b0 100644
--- a/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/SpacebarTextTests.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.preference.PreferenceManager;
 import android.test.AndroidTestCase;
 import android.view.inputmethod.InputMethodSubtype;
 
@@ -41,7 +42,8 @@
     protected void setUp() throws Exception {
         super.setUp();
         final Context context = getContext();
-        RichInputMethodManager.init(context);
+        RichInputMethodManager.init(
+                context, PreferenceManager.getDefaultSharedPreferences(context));
         mRichImm = RichInputMethodManager.getInstance();
         mRes = context.getResources();
         SubtypeLocale.init(context);
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
index f5ad723..053bcb5 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/KeyboardStateMultiTouchTests.java
@@ -50,7 +50,7 @@
         pressKey(CODE_SYMBOL, SYMBOLS_UNSHIFTED);
         // Press/release symbol letter key.
         chordingPressAndReleaseKey('1', SYMBOLS_UNSHIFTED, SYMBOLS_UNSHIFTED);
-        // Release "123?" key, switch back to alphabet shift unshifted.
+        // Release "123?" key, switch back to alphabet unshifted.
         releaseKey(CODE_SYMBOL, ALPHABET_UNSHIFTED);
     }
 
@@ -330,7 +330,7 @@
         releaseKey('X', ALPHABET_MANUAL_SHIFTED);
         // Release 'Z' key
         releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
-        // Release shift key.
+        // Release shift key, switch back to alphabet shifted.
         releaseKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
     }
 
@@ -351,8 +351,24 @@
         releaseKey('X', ALPHABET_MANUAL_SHIFTED);
         // Release 'Z' key
         releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
-        // Release shift key.
+        // Release shift key, updated to alphabet unshifted.
         releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
+
+        // Update shift state with auto caps enabled.
+        pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
+
+        // Press shift key and hold, switch to alphabet shifted.
+        pressKey(CODE_SHIFT, ALPHABET_MANUAL_SHIFTED);
+        // Press 'X' key and hold
+        chordingPressKey('X', ALPHABET_MANUAL_SHIFTED);
+        // Release 'X' key
+        releaseKey('X', ALPHABET_MANUAL_SHIFTED);
+        // Press  key and hold, stays in alphabet shifted.
+        chordingPressKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_MANUAL_SHIFTED);
+        // Release 'Z' key
+        releaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_MANUAL_SHIFTED);
+        // Release shift key, updated to alphabet automatic shifted.
+        releaseKey(CODE_SHIFT, ALPHABET_AUTOMATIC_SHIFTED);
     }
 
     // Multi touch shift chording input in capitalize character mode.
@@ -372,8 +388,8 @@
         releaseKey('X', ALPHABET_MANUAL_SHIFTED);
         // Release 'Z' key
         releaseKey('Z', ALPHABET_MANUAL_SHIFTED);
-        // Release shift key.
-        releaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED);
+        // Release shift key, updated to alphabet automatic shifted.
+        releaseKey(CODE_SHIFT, ALPHABET_AUTOMATIC_SHIFTED);
     }
 
     public void testLongPressShiftAndChording() {
diff --git a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
index 4e81de6..0f6fb73 100644
--- a/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
+++ b/tests/src/com/android/inputmethod/latin/SubtypeLocaleTests.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.Resources;
+import android.preference.PreferenceManager;
 import android.test.AndroidTestCase;
 import android.view.inputmethod.InputMethodSubtype;
 
@@ -37,7 +38,8 @@
     protected void setUp() throws Exception {
         super.setUp();
         final Context context = getContext();
-        RichInputMethodManager.init(context);
+        RichInputMethodManager.init(
+                context, PreferenceManager.getDefaultSharedPreferences(context));
         mRichImm = RichInputMethodManager.getInstance();
         mRes = context.getResources();
         SubtypeLocale.init(context);
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
index 159c1c1..666887a 100644
--- a/tools/dicttool/Android.mk
+++ b/tools/dicttool/Android.mk
@@ -21,18 +21,22 @@
 LATINIME_ANNOTATIONS_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/annotations
 MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_CORE_SOURCE_DIRECTORY)/makedict
 
-LOCAL_MAIN_SRC_FILES := $(call all-java-files-under,$(MAKEDICT_CORE_SOURCE_DIRECTORY))
-LOCAL_TOOL_SRC_FILES := $(call all-java-files-under,src)
-LOCAL_ANNOTATIONS_SRC_FILES := $(call all-java-files-under,$(LATINIME_ANNOTATIONS_SOURCE_DIRECTORY))
+LOCAL_MAIN_SRC_FILES := $(call all-java-files-under, $(MAKEDICT_CORE_SOURCE_DIRECTORY))
+LOCAL_TOOL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_ANNOTATIONS_SRC_FILES := \
+        $(call all-java-files-under, $(LATINIME_ANNOTATIONS_SOURCE_DIRECTORY))
 LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
         $(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
-        $(call all-java-files-under,tests) \
         $(LOCAL_ANNOTATIONS_SRC_FILES) \
         $(LATINIME_CORE_SOURCE_DIRECTORY)/Constants.java
 
+ifeq ($(DICTTOOL_UNITTEST), true)
+    LOCAL_SRC_FILES += $(call all-java-files-under, tests)
+    LOCAL_JAVA_LIBRARIES := junit
+endif
+
 LOCAL_JAR_MANIFEST := etc/manifest.txt
 LOCAL_MODULE := dicttool_aosp
-LOCAL_JAVA_LIBRARIES := junit
 
 include $(BUILD_HOST_JAVA_LIBRARY)
 include $(LOCAL_PATH)/etc/Android.mk
diff --git a/tools/dicttool/tests/etc/test-dicttool.sh b/tools/dicttool/tests/etc/test-dicttool.sh
index 0f3ed6d..0921207 100755
--- a/tools/dicttool/tests/etc/test-dicttool.sh
+++ b/tools/dicttool/tests/etc/test-dicttool.sh
@@ -13,5 +13,16 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+if [[ $(type -t mmm) != function ]]; then
+echo "Usage:" 1>&2
+echo "    source $0" 1>&2
+echo "  or" 1>&2
+echo "    . $0" 1>&2
+exit 1
+fi
+
+find out -name "dicttool_aosp*" -exec rm -rf {} \; > /dev/null 2>&1
+mmm -j8 external/junit
+DICTTOOL_UNITTEST=true mmm -j8 packages/inputmethods/LatinIME/tools/dicttool
 java -classpath ${ANDROID_HOST_OUT}/framework/junit.jar:${ANDROID_HOST_OUT}/framework/dicttool_aosp.jar junit.textui.TestRunner com.android.inputmethod.latin.makedict.BinaryDictInputOutputTest
 java -classpath ${ANDROID_HOST_OUT}/framework/junit.jar:${ANDROID_HOST_OUT}/framework/dicttool_aosp.jar junit.textui.TestRunner com.android.inputmethod.latin.dicttool.BinaryDictOffdeviceUtilsTests