Display language name on spacebar even in symbol keyboard.

Bug: 3468634
Change-Id: I1a25eb71ddbd7efae6f40ea357714924a9d56dc4
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 93d3811..3297dc3 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -155,15 +155,7 @@
             boolean voiceButtonOnPrimary) {
         mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
         try {
-            if (mInputView == null) return;
-            final Keyboard oldKeyboard = mInputView.getKeyboard();
             loadKeyboardInternal(mode, attribute, voiceKeyEnabled, voiceButtonOnPrimary, false);
-            final Keyboard newKeyboard = mInputView.getKeyboard();
-            if (newKeyboard.isAlphaKeyboard()) {
-                final boolean localeChanged = (oldKeyboard == null)
-                        || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
-                mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
-            }
         } catch (RuntimeException e) {
             // Get KeyboardId to record which keyboard has been failed to load.
             final KeyboardId id = getKeyboardId(mode, attribute, false);
@@ -192,7 +184,15 @@
         makeSymbolsKeyboardIds();
         mCurrentId = id;
         mInputView.setPreviewEnabled(mInputMethodService.getPopupOn());
-        mInputView.setKeyboard(getKeyboard(id));
+        setKeyboard(getKeyboard(id));
+    }
+
+    private void setKeyboard(final Keyboard newKeyboard) {
+        final Keyboard oldKeyboard = mInputView.getKeyboard();
+        mInputView.setKeyboard(newKeyboard);
+        final boolean localeChanged = (oldKeyboard == null)
+                || !newKeyboard.mId.mLocale.equals(oldKeyboard.mId.mLocale);
+        mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged);
     }
 
     private LatinKeyboard getKeyboard(KeyboardId id) {
@@ -278,13 +278,16 @@
 
     public boolean isKeyboardAvailable() {
         if (mInputView != null)
-            return mInputView.getLatinKeyboard() != null;
+            return mInputView.getKeyboard() != null;
         return false;
     }
 
-    private LatinKeyboard getLatinKeyboard() {
-        if (mInputView != null)
-            return mInputView.getLatinKeyboard();
+    public LatinKeyboard getLatinKeyboard() {
+        if (mInputView != null) {
+            final Keyboard keyboard = mInputView.getKeyboard();
+            if (keyboard instanceof LatinKeyboard)
+                return (LatinKeyboard)keyboard;
+        }
         return null;
     }
 
@@ -550,7 +553,7 @@
             // indicator, we need to call enableShiftLock() and setShiftLocked(false).
             keyboard.setShifted(false);
         }
-        mInputView.setKeyboard(keyboard);
+        setKeyboard(keyboard);
     }
 
     public boolean isInMomentaryAutoModeSwitchState() {
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index e7246dd..6c3ad5e 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -66,7 +66,8 @@
         }
     }
 
-    public void setLatinKeyboard(LatinKeyboard newKeyboard) {
+    @Override
+    public void setKeyboard(Keyboard newKeyboard) {
         final LatinKeyboard oldKeyboard = getLatinKeyboard();
         if (oldKeyboard != null) {
             // Reset old keyboard state before switching to new keyboard.
@@ -80,7 +81,7 @@
         mLastRowY = (newKeyboard.getHeight() * 3) / 4;
     }
 
-    public LatinKeyboard getLatinKeyboard() {
+    private LatinKeyboard getLatinKeyboard() {
         Keyboard keyboard = getKeyboard();
         if (keyboard instanceof LatinKeyboard) {
             return (LatinKeyboard)keyboard;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 2a340ad..c9e7f8b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -321,7 +321,7 @@
             removeMessages(MSG_DISMISS_LANGUAGE_ON_SPACEBAR);
             final LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
             if (inputView != null) {
-                final LatinKeyboard keyboard = inputView.getLatinKeyboard();
+                final LatinKeyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
                 // The language is never displayed when the delay is zero.
                 if (mConfigDelayBeforeFadeoutLanguageOnSpacebar != 0)
                     inputView.setSpacebarTextFadeFactor(localeChanged ? 1.0f
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index dee3da4..ee9dab3 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -371,12 +371,10 @@
                 ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
         mIsNetworkConnected = !noConnection;
 
-        final LatinKeyboardView inputView = KeyboardSwitcher.getInstance().getInputView();
-        if (inputView != null) {
-            final LatinKeyboard keyboard = inputView.getLatinKeyboard();
-            if (keyboard != null) {
-                keyboard.updateShortcutKey(isShortcutAvailable(), inputView);
-            }
+        final KeyboardSwitcher switcher = KeyboardSwitcher.getInstance();
+        final LatinKeyboard keyboard = switcher.getLatinKeyboard();
+        if (keyboard != null) {
+            keyboard.updateShortcutKey(isShortcutAvailable(), switcher.getInputView());
         }
     }