From ddc163988a7e2e910ff3cac26ed580bac123fda0 Mon Sep 17 00:00:00 2001
From: Jean Chalard <jchalard@google.com>
Date: Mon, 14 Apr 2014 15:33:30 +0900
Subject: [PATCH] [IL134] Add an alternative path to getCurrentAutoCapsState

Bug: 8636060

Change-Id: I959e13d34910adad028ed6174f92029ff690eeeb
---
 .../inputmethod/keyboard/KeyboardSwitcher.java |  5 +++--
 .../keyboard/internal/KeyboardState.java       | 18 ++++++++++++------
 .../android/inputmethod/latin/LatinIME.java    |  3 ++-
 .../internal/MockKeyboardSwitcher.java         | 13 ++++++++++++-
 4 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 949f037940..1f8db4c230 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -230,8 +230,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
         mState.onPressKey(code, isSinglePointer, currentAutoCapsState);
     }
 
-    public void onReleaseKey(final int code, final boolean withSliding) {
-        mState.onReleaseKey(code, withSliding);
+    public void onReleaseKey(final int code, final boolean withSliding,
+            final int currentAutoCapsState, final int currentRecapitalizeState) {
+        mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState);
     }
 
     public void onFinishSlidingInput() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
index ec0b5c95f8..12870fba72 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java
@@ -28,7 +28,7 @@ import com.android.inputmethod.latin.utils.RecapitalizeStatus;
  * This class contains all keyboard state transition logic.
  *
  * The input events are {@link #onLoadKeyboard()}, {@link #onSaveKeyboardState()},
- * {@link #onPressKey(int,boolean,int)}, {@link #onReleaseKey(int,boolean)},
+ * {@link #onPressKey(int,boolean,int)}, {@link #onReleaseKey(int,boolean,int,int)},
  * {@link #onCodeInput(int,int)}, {@link #onFinishSlidingInput()},
  * {@link #onUpdateShiftState(int,int)}, {@link #onResetKeyboardStateToAlphabet()}.
  *
@@ -49,10 +49,13 @@ public final class KeyboardState {
         public void setSymbolsKeyboard();
         public void setSymbolsShiftedKeyboard();
 
+        // Legacy method. TODO: remove the following method.
+        public void requestUpdatingShiftState();
         /**
          * Request to call back {@link KeyboardState#onUpdateShiftState(int, int)}.
          */
-        public void requestUpdatingShiftState();
+        public void requestUpdatingShiftState(final int currentAutoCapsState,
+                final int currentRecapitalizeState);
 
         public void startDoubleTapShiftKeyTimer();
         public boolean isInDoubleTapShiftKeyTimeout();
@@ -373,13 +376,14 @@ public final class KeyboardState {
         }
     }
 
-    public void onReleaseKey(final int code, final boolean withSliding) {
+    public void onReleaseKey(final int code, final boolean withSliding,
+            final int currentAutoCapsState, final int currentRecapitalizeState) {
         if (DEBUG_EVENT) {
             Log.d(TAG, "onReleaseKey: code=" + Constants.printableCode(code)
                     + " sliding=" + withSliding + " " + this);
         }
         if (code == Constants.CODE_SHIFT) {
-            onReleaseShift(withSliding);
+            onReleaseShift(withSliding, currentAutoCapsState, currentRecapitalizeState);
         } else if (code == Constants.CODE_CAPSLOCK) {
             setShiftLocked(!mAlphabetShiftState.isShiftLocked());
         } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
@@ -513,7 +517,8 @@ public final class KeyboardState {
         }
     }
 
-    private void onReleaseShift(final boolean withSliding) {
+    private void onReleaseShift(final boolean withSliding, final int currentAutoCapsState,
+            final int currentRecapitalizeState) {
         if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
             // We are recapitalizing. We should match the keyboard state to the recapitalize
             // state in priority.
@@ -536,7 +541,8 @@ public final class KeyboardState {
                 // After chording input, automatic shift state may have been changed depending on
                 // what characters were input.
                 mShiftKeyState.onRelease();
-                mSwitchActions.requestUpdatingShiftState();
+                mSwitchActions.requestUpdatingShiftState(currentAutoCapsState,
+                        currentRecapitalizeState);
                 return;
             } else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) {
                 // In shift locked state, shift has been pressed and slid out to other key.
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 84558ca244..083e5b8a35 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1574,7 +1574,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
     // press matching call is {@link #onPressKey(int,int,boolean)} above.
     @Override
     public void onReleaseKey(final int primaryCode, final boolean withSliding) {
-        mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding);
+        mKeyboardSwitcher.onReleaseKey(primaryCode, withSliding, getCurrentAutoCapsState(),
+                getCurrentRecapitalizeState());
 
         // If accessibility is on, ensure the user receives keyboard state updates.
         if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
diff --git a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
index 6e3e37add8..7b1a2355c3 100644
--- a/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
+++ b/tests/src/com/android/inputmethod/keyboard/internal/MockKeyboardSwitcher.java
@@ -129,6 +129,12 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
         mState.onUpdateShiftState(mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
     }
 
+    @Override
+    public void requestUpdatingShiftState(final int currentAutoCapsState,
+            final int currentRecapitalizeState) {
+        mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState);
+    }
+
     @Override
     public void startDoubleTapShiftKeyTimer() {
         mIsInDoubleTapShiftKeyTimeout = true;
@@ -161,7 +167,12 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
     }
 
     public void onReleaseKey(final int code, final boolean withSliding) {
-        mState.onReleaseKey(code, withSliding);
+        onReleaseKey(code, withSliding, mAutoCapsState, RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE);
+    }
+
+    public void onReleaseKey(final int code, final boolean withSliding,
+            final int currentAutoCapsState, final int currentRecapitalizeState) {
+        mState.onReleaseKey(code, withSliding, currentAutoCapsState, currentRecapitalizeState);
         if (mLongPressTimeoutCode == code) {
             mLongPressTimeoutCode = 0;
         }
-- 
GitLab