Get rid of Key.needsSpecialPopupHint and related

Change-Id: I28e87ea3af9581f12094770b42f113e9018886c4
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 028e3fd..8330c31 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -125,8 +125,6 @@
     private boolean mHighlightOn;
     /** Key is enabled and responds on press */
     private boolean mEnabled = true;
-    /** Whether this key needs to show the "..." popup hint for special purposes */
-    private boolean mNeedsSpecialPopupHint;
 
     // RTL parenthesis character swapping map.
     private static final Map<Integer, Integer> sRtlParenthesisMap = new HashMap<Integer, Integer>();
@@ -449,14 +447,6 @@
         return (mLabelFlags & LABEL_FLAGS_HAS_POPUP_HINT) != 0;
     }
 
-    public void setNeedsSpecialPopupHint(boolean needsSpecialPopupHint) {
-        mNeedsSpecialPopupHint = needsSpecialPopupHint;
-    }
-
-    public boolean needsSpecialPopupHint() {
-        return mNeedsSpecialPopupHint;
-    }
-
     public boolean hasUppercaseLetter() {
         return (mLabelFlags & LABEL_FLAGS_HAS_UPPERCASE_LETTER) != 0;
     }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index c7b600b..16f27b4 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -165,8 +165,8 @@
             // If the cached keyboard had been switched to another keyboard while the language was
             // displayed on its spacebar, it might have had arbitrary text fade factor. In such
             // case, we should reset the text fade factor. It is also applicable to shortcut key.
+            mKeyboardView.updateSpacebar();
             latinKeyboard.updateSpacebarLanguage(0.0f,
-                    Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
                     mSubtypeSwitcher.needsToDisplayLanguage(latinKeyboard.mId.mLocale));
             latinKeyboard.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady());
         }
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index e1c4617..a174fd9 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -712,8 +712,7 @@
             }
         }
 
-        if ((key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0)
-                || key.needsSpecialPopupHint()) {
+        if (key.hasPopupHint() && key.mMoreKeys != null && key.mMoreKeys.length > 0) {
             drawKeyPopupHint(key, canvas, paint, params);
         }
     }
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
index 655f16c..2979110 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
@@ -55,10 +55,8 @@
     private final int mSpacebarTextShadowColor;
     private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache =
             new HashMap<Integer, BitmapDrawable>();
-    private final boolean mIsSpacebarTriggeringPopupByLongPress;
 
     private boolean mAutoCorrectionSpacebarLedOn;
-    private boolean mMultipleEnabledIMEsOrSubtypes;
     private boolean mNeedsToDisplayLanguage;
     private float mSpacebarTextFadeFactor = 0.0f;
 
@@ -83,9 +81,6 @@
 
         mShortcutKey = getKey(CODE_SHORTCUT);
         mEnabledShortcutIcon = (mShortcutKey != null) ? mShortcutKey.getIcon() : null;
-        final int longPressSpaceKeyTimeout =
-                mRes.getInteger(R.integer.config_long_press_space_key_timeout);
-        mIsSpacebarTriggeringPopupByLongPress = (longPressSpaceKeyTimeout > 0);
 
         final TypedArray a = context.obtainStyledAttributes(
                 null, R.styleable.LatinKeyboard, R.attr.latinKeyboardStyle, R.style.LatinKeyboard);
@@ -123,10 +118,8 @@
 
     // TODO: Move this drawing method to LatinKeyboardView.
     // TODO: Use Key.keyLabel to draw language name of spacebar.
-    public Key updateSpacebarLanguage(float fadeFactor, boolean multipleEnabledIMEsOrSubtypes,
-            boolean needsToDisplayLanguage) {
+    public Key updateSpacebarLanguage(float fadeFactor, boolean needsToDisplayLanguage) {
         mSpacebarTextFadeFactor = fadeFactor;
-        mMultipleEnabledIMEsOrSubtypes = multipleEnabledIMEsOrSubtypes;
         mNeedsToDisplayLanguage = needsToDisplayLanguage;
         updateSpacebarIcon();
         return mSpaceKey;
@@ -173,9 +166,6 @@
 
     private void updateSpacebarIcon() {
         if (mSpaceKey == null) return;
-        final boolean shouldShowInputMethodPicker = mIsSpacebarTriggeringPopupByLongPress
-                && mMultipleEnabledIMEsOrSubtypes;
-        mSpaceKey.setNeedsSpecialPopupHint(shouldShowInputMethodPicker);
         if (mNeedsToDisplayLanguage) {
             mSpaceKey.setIcon(getSpaceDrawable(mId.mLocale));
         } else if (mAutoCorrectionSpacebarLedOn) {
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index a5d9283..55fc5f9 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -20,6 +20,7 @@
 import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.os.Message;
 import android.text.TextUtils;
 import android.util.AttributeSet;
@@ -60,6 +61,10 @@
 
     private static final boolean ENABLE_CAPSLOCK_BY_DOUBLETAP = true;
 
+    // For drawing spacebar.
+    private final boolean mIsSpacebarTriggeringPopupByLongPress;
+    private boolean mMultipleEnabledIMEsOrSubtypes;
+
     private final SuddenJumpingTouchEventHandler mTouchScreenRegulator;
 
     // Timing constants
@@ -247,6 +252,10 @@
         mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
 
         PointerTracker.init(mHasDistinctMultitouch, getContext());
+
+        final int longPressSpaceKeyTimeout =
+                res.getInteger(R.integer.config_long_press_space_key_timeout);
+        mIsSpacebarTriggeringPopupByLongPress = (longPressSpaceKeyTimeout > 0);
     }
 
     public void startIgnoringDoubleTap() {
@@ -685,4 +694,21 @@
         // Reflection doesn't support calling superclass methods.
         return false;
     }
+
+    public void updateSpacebar() {
+        mMultipleEnabledIMEsOrSubtypes = Utils.hasMultipleEnabledIMEsOrSubtypes(
+                true /* include aux subtypes */);
+    }
+
+    @Override
+    /* package */ void onDrawKeyTopVisuals(Key key, Canvas canvas, Paint paint,
+            KeyDrawParams params) {
+        super.onDrawKeyTopVisuals(key, canvas, paint, params);
+
+        // Whether space key needs to show the "..." popup hint for special purposes
+        if (key.mCode == Keyboard.CODE_SPACE && mIsSpacebarTriggeringPopupByLongPress
+                && mMultipleEnabledIMEsOrSubtypes) {
+            super.drawKeyPopupHint(key, canvas, paint, params);
+        }
+    }
 }
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index f24dc3f..64bd506 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -344,9 +344,9 @@
             if (inputView == null) return;
             final Keyboard keyboard = inputView.getKeyboard();
             if (keyboard instanceof LatinKeyboard && keyboard == oldKeyboard) {
+                inputView.updateSpacebar();
                 final Key updatedKey = ((LatinKeyboard)keyboard).updateSpacebarLanguage(
                         fadeFactor,
-                        Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */),
                         SubtypeSwitcher.getInstance().needsToDisplayLanguage(keyboard.mId.mLocale));
                 inputView.invalidateKey(updatedKey);
             }