Merge "Update dictionaries"
diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml
index a13021b..1581e5f 100644
--- a/java/res/xml/prefs.xml
+++ b/java/res/xml/prefs.xml
@@ -93,12 +93,14 @@
         <!-- TODO: Move these two options to the advanced settings. -->
         <CheckBoxPreference
             android:key="pref_gesture_floating_preview_text"
+            android:dependency="gesture_input"
             android:title="@string/gesture_floating_preview_text"
             android:summary="@string/gesture_floating_preview_text_summary"
             android:persistent="true"
             android:defaultValue="true" />
         <CheckBoxPreference
             android:key="pref_gesture_preview_trail"
+            android:dependency="gesture_input"
             android:title="@string/gesture_preview_trail"
             android:persistent="true"
             android:defaultValue="true" />
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
index a356eb1..a82fb79 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java
@@ -33,7 +33,7 @@
 public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel {
     private final int[] mCoordinates = CoordinateUtils.newInstance();
 
-    private final KeyDetector mKeyDetector;
+    protected final KeyDetector mKeyDetector;
     private Controller mController;
     protected KeyboardActionListener mListener;
     private int mOriginX;
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index dcfae73..91c4319 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -441,10 +441,10 @@
 
     // Returns true if keyboard has been changed by this callback.
     private boolean callListenerOnPressAndCheckKeyboardLayoutChange(final Key key) {
-        if (sInGesture) {
+        if (sInGesture || mIsDetectingGesture) {
             return false;
         }
-        final boolean ignoreModifierKey = mIsInSlidingKeyInputFromModifier && key.isModifier();
+        final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
         if (DEBUG_LISTENER) {
             Log.d(TAG, String.format("[%d] onPress    : %s%s%s", mPointerId,
                     KeyDetector.printableCode(key),
@@ -468,7 +468,7 @@
     // primaryCode is different from {@link Key#mCode}.
     private void callListenerOnCodeInput(final Key key, final int primaryCode, final int x,
             final int y, final long eventTime) {
-        final boolean ignoreModifierKey = mIsInSlidingKeyInputFromModifier && key.isModifier();
+        final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
         final boolean altersCode = key.altCodeWhileTyping() && mTimerProxy.isTypingState();
         final int code = altersCode ? key.getAltCode() : primaryCode;
         if (DEBUG_LISTENER) {
@@ -500,10 +500,10 @@
     // primaryCode is different from {@link Key#mCode}.
     private void callListenerOnRelease(final Key key, final int primaryCode,
             final boolean withSliding) {
-        if (sInGesture) {
+        if (sInGesture || mIsDetectingGesture) {
             return;
         }
-        final boolean ignoreModifierKey = mIsInSlidingKeyInputFromModifier && key.isModifier();
+        final boolean ignoreModifierKey = mIsInSlidingKeyInput && key.isModifier();
         if (DEBUG_LISTENER) {
             Log.d(TAG, String.format("[%d] onRelease  : %s%s%s%s", mPointerId,
                     Constants.printableCode(primaryCode),
diff --git a/java/src/com/android/inputmethod/latin/SettingsFragment.java b/java/src/com/android/inputmethod/latin/SettingsFragment.java
index 5405a5e..4c729ec 100644
--- a/java/src/com/android/inputmethod/latin/SettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/SettingsFragment.java
@@ -232,10 +232,6 @@
         } else if (key.equals(Settings.PREF_SHOW_LANGUAGE_SWITCH_KEY)) {
             setPreferenceEnabled(Settings.PREF_INCLUDE_OTHER_IMES_IN_LANGUAGE_SWITCH_LIST,
                     Settings.readShowsLanguageSwitchKey(prefs));
-        } else if (key.equals(Settings.PREF_GESTURE_INPUT)) {
-            final boolean gestureInputEnabled = Settings.readGestureInputEnabled(prefs, res);
-            setPreferenceEnabled(Settings.PREF_GESTURE_PREVIEW_TRAIL, gestureInputEnabled);
-            setPreferenceEnabled(Settings.PREF_GESTURE_FLOATING_PREVIEW_TEXT, gestureInputEnabled);
         } else if (key.equals(Settings.PREF_SHOW_SETUP_WIZARD_ICON)) {
             LauncherIconVisibilityManager.updateSetupWizardIconVisibility(getActivity());
         }
diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
index 94715cd..6509f39 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java
@@ -46,6 +46,12 @@
         updateKeyDrawParams(keyHeight);
     }
 
+    public void adjustVerticalCorrectionForModalMode() {
+        // Set vertical correction to zero (Reset more keys keyboard sliding allowance
+        // {@link R#dimen.more_keys_keyboard_slide_allowance}).
+        mKeyDetector.setKeyboard(getKeyboard(), -getPaddingLeft(), -getPaddingTop());
+    }
+
     @Override
     public void onCodeInput(final int code, final int x, final int y) {
         final int index = code - MoreSuggestions.SUGGESTION_CODE_BASE;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index 4ef36fa..2a21ec2 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -755,8 +755,7 @@
 
     @Override
     public boolean dispatchTouchEvent(final MotionEvent me) {
-        if (!mMoreSuggestionsView.isShowingInParent()
-                || mMoreSuggestionsMode == MORE_SUGGESTIONS_IN_MODAL_MODE) {
+        if (!mMoreSuggestionsView.isShowingInParent()) {
             mLastX = (int)me.getX();
             mLastY = (int)me.getY();
             if (mMoreSuggestionsSlidingDetector.onTouchEvent(me)) {
@@ -784,6 +783,7 @@
             } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
                 // Decided to be in the modal input mode
                 mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
+                mMoreSuggestionsView.adjustVerticalCorrectionForModalMode();
             }
             return true;
         }
diff --git a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
index 6d39d92..b704d08 100644
--- a/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
+++ b/tests/src/com/android/inputmethod/latin/makedict/BinaryDictIOTests.java
@@ -51,7 +51,7 @@
 @LargeTest
 public class BinaryDictIOTests extends AndroidTestCase {
     private static final String TAG = BinaryDictIOTests.class.getSimpleName();
-    private static final int MAX_UNIGRAMS = 1000;
+    private static final int MAX_UNIGRAMS = 100;
     private static final int UNIGRAM_FREQ = 10;
     private static final int BIGRAM_FREQ = 50;
     private static final int TOLERANCE_OF_BIGRAM_FREQ = 5;
@@ -135,11 +135,12 @@
         while (count > 0) {
             final long r = Math.abs(random.nextInt());
             if (r < 0) continue;
-            // Don't insert 0~20, but insert any other code point.
+            // Don't insert 0~0x20, but insert any other code point.
             // Code points are in the range 0~0x10FFFF.
-            final int candidateCodePoint = (int)(20 + r % (0x10FFFF - 20));
-            // Code points between 0xD800 and 0xDFFF are not valid.
-            if (candidateCodePoint >= 0xD800 && candidateCodePoint <= 0xDFFF) continue;
+            final int candidateCodePoint = (int)(0x20 + r % (Character.MAX_CODE_POINT - 0x20));
+            // Code points between MIN_ and MAX_SURROGATE are not valid on their own.
+            if (candidateCodePoint >= Character.MIN_SURROGATE
+                    && candidateCodePoint <= Character.MAX_SURROGATE) continue;
             builder.appendCodePoint(candidateCodePoint);
             --count;
         }