Use settings of the visibility of IME Switch button

Bug: 3141466

Change-Id: Ia5ef059af184d9c203a0065bf25b088e0529858e
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
index ddce6bf..a09fe28 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodButton.java
@@ -48,6 +48,11 @@
     // IME shortcut button is disabled.
     private static final int ID_IME_SHORTCUT_BUTTON = 0;
 
+    // These values are defined in Settings application.
+    private static final int ID_IME_BUTTON_VISIBILITY_AUTO = 0;
+    private static final int ID_IME_BUTTON_VISIBILITY_ALWAYS_SHOW = 1;
+    private static final int ID_IME_BUTTON_VISIBILITY_ALWAYS_HIDE = 2;
+
     // other services we wish to talk to
     private final InputMethodManager mImm;
     private final int mId;
@@ -164,8 +169,17 @@
     private boolean needsToShowIMEButton() {
         List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
         final int size = imis.size();
-        return size > 1
-                || (size == 1 && mImm.getEnabledInputMethodSubtypeList(imis.get(0)).size() > 1);
+        final int visibility = loadInputMethodSelectorVisibility();
+        switch (visibility) {
+            case ID_IME_BUTTON_VISIBILITY_AUTO:
+                return size > 1 || (size == 1
+                        && mImm.getEnabledInputMethodSubtypeList(imis.get(0)).size() > 1);
+            case ID_IME_BUTTON_VISIBILITY_ALWAYS_SHOW:
+                return true;
+            case ID_IME_BUTTON_VISIBILITY_ALWAYS_HIDE:
+                return false;
+        }
+        return false;
     }
 
     private void refreshStatusIcon(boolean keyboardShown) {
@@ -196,6 +210,11 @@
         }
     }
 
+    private int loadInputMethodSelectorVisibility() {
+        return Settings.Secure.getInt(getContext().getContentResolver(),
+                Settings.Secure.INPUT_METHOD_SELECTOR_VISIBILITY, ID_IME_BUTTON_VISIBILITY_AUTO);
+    }
+
     public void setIMEButtonVisible(IBinder token, boolean visible) {
         mToken = token;
         mKeyboardShown = visible ? needsToShowIMEButton() : false;