NULL inputType text fields should never show the IME.

Bug 3381317

Changes made in https://android-git.corp.google.com/g/#change,91880
displayed the IME onFocus. However, the test was not consistent to what
is done in touch event. textIsEditable is now checked too.

Change-Id: If11382c1c90a557839b87d62494253470c42b621
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index f35a438..255eb6c 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -49,6 +49,7 @@
 import android.view.WindowManager;
 import android.view.animation.AnimationUtils;
 import android.view.inputmethod.CompletionInfo;
+import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.ExtractedText;
 import android.view.inputmethod.ExtractedTextRequest;
 import android.view.inputmethod.InputBinding;
@@ -56,7 +57,6 @@
 import android.view.inputmethod.InputMethod;
 import android.view.inputmethod.InputMethodManager;
 import android.view.inputmethod.InputMethodSubtype;
-import android.view.inputmethod.EditorInfo;
 import android.widget.Button;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
@@ -1024,7 +1024,7 @@
      * there is no hard keyboard or the keyboard is hidden.  If you change what
      * this returns, you will need to call {@link #updateInputViewShown()}
      * yourself whenever the returned value may have changed to have it
-     * re-evalauted and applied.
+     * re-evaluated and applied.
      */
     public boolean onEvaluateInputViewShown() {
         Configuration config = getResources().getConfiguration();
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index d310237..3afc02c 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -16,6 +16,15 @@
 
 package android.view.inputmethod;
 
+import com.android.internal.os.HandlerCaller;
+import com.android.internal.view.IInputConnectionWrapper;
+import com.android.internal.view.IInputContext;
+import com.android.internal.view.IInputMethodCallback;
+import com.android.internal.view.IInputMethodClient;
+import com.android.internal.view.IInputMethodManager;
+import com.android.internal.view.IInputMethodSession;
+import com.android.internal.view.InputBindResult;
+
 import android.content.Context;
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -27,23 +36,12 @@
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
 import android.util.Log;
-import android.util.Pair;
 import android.util.PrintWriterPrinter;
 import android.util.Printer;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewRoot;
-import android.view.inputmethod.InputMethodSubtype;
-
-import com.android.internal.os.HandlerCaller;
-import com.android.internal.view.IInputConnectionWrapper;
-import com.android.internal.view.IInputContext;
-import com.android.internal.view.IInputMethodCallback;
-import com.android.internal.view.IInputMethodClient;
-import com.android.internal.view.IInputMethodManager;
-import com.android.internal.view.IInputMethodSession;
-import com.android.internal.view.InputBindResult;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -96,7 +94,7 @@
  * be aware of are:</p>
  * 
  * <ul>
- * <li> Properly set the {@link android.R.attr#inputType} if your editable
+ * <li> Properly set the {@link android.R.attr#inputType} in your editable
  * text views, so that the input method will have enough context to help the
  * user in entering text into them.
  * <li> Deal well with losing screen space when the input method is
@@ -389,6 +387,7 @@
             super(mainLooper, conn);
         }
 
+        @Override
         public boolean isActive() {
             return mActive;
         }
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index aac57ed..904bc47 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -372,7 +372,7 @@
         mTextPaint.density = getResources().getDisplayMetrics().density;
         mTextPaint.setCompatibilityScaling(
                 getResources().getCompatibilityInfo().applicationScale);
-        
+
         // If we get the paint from the skin, we should set it to left, since
         // the layout always wants it to be left.
         // mTextPaint.setTextAlign(Paint.Align.LEFT);
@@ -7125,11 +7125,14 @@
 
         super.onFocusChanged(focused, direction, previouslyFocusedRect);
 
-        // After super.onFocusChanged so that this TextView is registered and can ask for the IME
-        // Showing the IME while focus is moved using the D-Pad is a bad idea, however this does
-        // not happen in that case (using the arrows on a bluetooth keyboard).
-        if (focused) {
-            onTouchFinished(null);
+        // Performed after super.onFocusChanged so that this TextView is registered and can ask for
+        // the IME. Showing the IME while focus is moved using the D-Pad is a bad idea, however this
+        // does not happen in that case (using the arrows on a bluetooth keyboard).
+        if (focused && isTextEditable()) {
+            final InputMethodManager imm = (InputMethodManager)
+            getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+
+            imm.showSoftInput(this, 0, null);
         }
     }
 
@@ -7321,7 +7324,19 @@
                         csr = new CommitSelectionReceiver(oldSelStart, oldSelEnd);
                     }
 
-                    handled = onTouchFinished(csr);
+                    // Show the IME, except when selecting in read-only text.
+                    if (!mTextIsSelectable) {
+                        final InputMethodManager imm = (InputMethodManager)
+                                getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+
+                        handled |= imm.showSoftInput(this, 0, csr) && (csr != null);
+                    }
+
+                    stopSelectionActionMode();
+                    boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
+                    if (hasInsertionController() && !selectAllGotFocus) {
+                        getInsertionController().show();
+                    }
                 }
             }
 
@@ -7333,35 +7348,6 @@
         return superResult;
     }
 
-    /** Shows the IME if applicable, ends selection mode and displays the selection controller.
-     *
-     * This method is called at the end of a touch event, when the finger is lifted up.
-     * It is also called when the TextField gains focus indirectly through a dispatched event from
-     * one of its parents. We want to have the same behavior in that case.
-     *
-     * @param csr A (possibly null) callback called if the IME has been displayed
-     * @return true if the event was properly sent to the csr
-     */
-    private boolean onTouchFinished(CommitSelectionReceiver csr) {
-        boolean handled = false;
-
-        // Show the IME, except when selecting in read-only text.
-        if (!mTextIsSelectable) {
-            final InputMethodManager imm = (InputMethodManager)
-                    getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
-
-            handled = imm.showSoftInput(this, 0, csr) && (csr != null);
-        }
-
-        stopSelectionActionMode();
-        boolean selectAllGotFocus = mSelectAllOnFocus && mTouchFocusSelected;
-        if (hasInsertionController() && !selectAllGotFocus) {
-            getInsertionController().show();
-        }
-
-        return handled;
-    }
-
     private void prepareCursorControllers() {
         boolean windowSupportsHandles = false;