Merge "Reorganize settings in Google Keyboard" into lmp-dev
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index e487516..60665f8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -18,7 +18,6 @@
 
 import android.content.Context;
 import android.content.SharedPreferences;
-import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.preference.PreferenceManager;
 import android.util.Log;
@@ -256,13 +255,12 @@
     }
 
     public void onToggleEmojiKeyboard() {
-        if (mKeyboardLayoutSet == null) {
-            return;
-        }
-        if (isShowingEmojiPalettes()) {
-            setAlphabetKeyboard();
-        } else {
+        if (mKeyboardLayoutSet == null || !isShowingEmojiPalettes()) {
+            mLatinIME.startShowingInputView();
             setEmojiKeyboard();
+        } else {
+            mLatinIME.stopShowingInputView();
+            setAlphabetKeyboard();
         }
     }
 
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index ebe4361..9df3a2a 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -42,6 +42,7 @@
     final public boolean mApplicationSpecifiedCompletionOn;
     final public boolean mShouldInsertSpacesAutomatically;
     final public boolean mShouldShowVoiceInputKey;
+    final public boolean mIsGeneralTextInput;
     final private int mInputType;
     final private EditorInfo mEditorInfo;
     final private String mPackageNameForPrivateImeOptions;
@@ -76,6 +77,7 @@
             mApplicationSpecifiedCompletionOn = false;
             mShouldInsertSpacesAutomatically = false;
             mShouldShowVoiceInputKey = false;
+            mIsGeneralTextInput = false;
             return;
         }
         // inputClass == InputType.TYPE_CLASS_TEXT
@@ -117,6 +119,15 @@
                 || (!flagAutoCorrect && !flagMultiLine);
 
         mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode;
+
+        // If we come here, inputClass is always TYPE_CLASS_TEXT
+        mIsGeneralTextInput = InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS != variation
+                && InputType.TYPE_TEXT_VARIATION_PASSWORD != variation
+                && InputType.TYPE_TEXT_VARIATION_PHONETIC != variation
+                && InputType.TYPE_TEXT_VARIATION_URI != variation
+                && InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD != variation
+                && InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS != variation
+                && InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD != variation;
     }
 
     public boolean isTypeNull() {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 86fe642..84b2d27 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -52,7 +52,6 @@
 import android.view.inputmethod.CompletionInfo;
 import android.view.inputmethod.CursorAnchorInfo;
 import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethod;
 import android.view.inputmethod.InputMethodSubtype;
 import android.widget.TextView;
 
@@ -87,8 +86,8 @@
 import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
 import com.android.inputmethod.latin.utils.ApplicationUtils;
 import com.android.inputmethod.latin.utils.CapsModeUtils;
-import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils;
 import com.android.inputmethod.latin.utils.CoordinateUtils;
+import com.android.inputmethod.latin.utils.CursorAnchorInfoUtils;
 import com.android.inputmethod.latin.utils.DialogUtils;
 import com.android.inputmethod.latin.utils.DistracterFilterCheckingExactMatchesAndSuggestions;
 import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
@@ -162,6 +161,9 @@
     private final SubtypeSwitcher mSubtypeSwitcher;
     private final SubtypeState mSubtypeState = new SubtypeState();
     private final SpecialKeyDetector mSpecialKeyDetector;
+    // Working variable for {@link #startShowingInputView()} and
+    // {@link #onEvaluateInputViewShown()}.
+    private boolean mIsExecutingStartShowingInputView;
 
     // Object for reacting to adding/removing a dictionary pack.
     private final BroadcastReceiver mDictionaryPackInstallReceiver =
@@ -1187,22 +1189,24 @@
         outInsets.visibleTopInsets = visibleTopY;
     }
 
-    @Override
-    public boolean onEvaluateInputViewShown() {
-        // Always show {@link InputView}.
-        return true;
+    public void startShowingInputView() {
+        mIsExecutingStartShowingInputView = true;
+        // This {@link #showWindow(boolean)} will eventually call back
+        // {@link #onEvaluateInputViewShown()}.
+        showWindow(true /* showInput */);
+        mIsExecutingStartShowingInputView = false;
+    }
+
+    public void stopShowingInputView() {
+        showWindow(false /* showInput */);
     }
 
     @Override
-    public boolean onShowInputRequested(final int flags, final boolean configChange) {
-        final SettingsValues settingsValues = mSettings.getCurrent();
-        if ((flags & InputMethod.SHOW_EXPLICIT) == 0 && settingsValues.mHasHardwareKeyboard) {
-            // Even when IME is implicitly shown and physical keyboard is connected, we should
-            // show {@link InputView}.
-            // See {@link InputMethodService#onShowInputRequested(int,boolean)}.
+    public boolean onEvaluateInputViewShown() {
+        if (mIsExecutingStartShowingInputView) {
             return true;
         }
-        return super.onShowInputRequested(flags, configChange);
+        return super.onEvaluateInputViewShown();
     }
 
     @Override
@@ -1221,9 +1225,8 @@
             // hack for now.  Let's get rid of this once the framework gets fixed.
             final EditorInfo ei = getCurrentInputEditorInfo();
             return !(ei != null && ((ei.imeOptions & EditorInfo.IME_FLAG_NO_EXTRACT_UI) != 0));
-        } else {
-            return false;
         }
+        return false;
     }
 
     @Override
@@ -1273,9 +1276,8 @@
         if (null == keyboard) {
             return CoordinateUtils.newCoordinateArray(codePoints.length,
                     Constants.NOT_A_COORDINATE, Constants.NOT_A_COORDINATE);
-        } else {
-            return keyboard.getCoordinates(codePoints);
         }
+        return keyboard.getCoordinates(codePoints);
     }
 
     // Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 308f3b4..5c742a8 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -148,7 +148,8 @@
                 ? Settings.readShowsLanguageSwitchKey(prefs) : true /* forcibly */;
         mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true);
         mUsePersonalizedDicts = prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
-        mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true);
+        mUseDoubleSpacePeriod = prefs.getBoolean(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true)
+                && inputAttributes.mIsGeneralTextInput;
         mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
         mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
         mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);