Merge "Fix that long pressing shift on symbol keyboard registers caps lock code"
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 3f30165..75fba94 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -160,7 +160,7 @@
         return other instanceof KeyboardId && equals((KeyboardId) other);
     }
 
-    boolean equals(KeyboardId other) {
+    private boolean equals(KeyboardId other) {
         return other.mLocale.equals(this.mLocale)
             && other.mOrientation == this.mOrientation
             && other.mWidth == this.mWidth
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 552a3cd..a4080f1 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -161,24 +161,25 @@
         }
     }
 
+    public void onHideWindow() {
+        mWindowWidth = 0;
+        mIsAutoCorrectionActive = false;
+    }
+
     @SuppressWarnings("unused")
     public void onSizeChanged(int w, int h, int oldw, int oldh) {
+        // TODO: This hack should be removed when display metric returns a proper width.
+        // Until then, the behavior of KeyboardSwitcher is suboptimal on a device that has a
+        // vertical system navigation bar in landscape screen orientation, for instance.
         final int width = mInputMethodService.getWindow().getWindow().getDecorView().getWidth();
         // If the window width hasn't fixed yet or keyboard doesn't exist, nothing to do with.
         if (width == 0 || mCurrentId == null)
             return;
         // The window width is fixed.
         mWindowWidth = width;
-        // If this is the first time the {@link KeyboardView} has been shown, no need to reload
-        // keyboard.
-        if (oldw == 0 && oldh == 0)
-            return;
         // Reload keyboard with new width.
         final int orientation = mInputMethodService.getResources().getConfiguration().orientation;
         final KeyboardId newId = mCurrentId.cloneWithNewGeometry(orientation, width);
-        // If the new keyboard is the same as the current one, no need to reload it.
-        if (newId.equals(mCurrentId))
-            return;
         setKeyboard(getKeyboard(newId));
     }
 
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index f648357..6b6a453 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -674,6 +674,7 @@
 
     private void startLongPressTimer(int keyIndex) {
         Key key = getKey(keyIndex);
+        if (key == null) return;
         if (key.mCode == Keyboard.CODE_SHIFT) {
             if (sLongPressShiftKeyTimeout > 0) {
                 mTimerProxy.startLongPressTimer(sLongPressShiftKeyTimeout, keyIndex, this);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index d9d4214..ddc69f1 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -872,7 +872,7 @@
     @Override
     public void hideWindow() {
         LatinImeLogger.commit();
-        mKeyboardSwitcher.onAutoCorrectionStateChanged(false);
+        mKeyboardSwitcher.onHideWindow();
 
         if (TRACE) Debug.stopMethodTracing();
         if (mOptionsDialog != null && mOptionsDialog.isShowing()) {