Auto-show IME for dialogs on large screens.

On a large screen the IME is not going to as significantly
cover a pan & scan window, so allow it to auto-show if the
app hasn't otherwise specified its visibility.

Also some fixes here and there.

Change-Id: I10227ec59c43454e06e6870633f53426f4d78b83
diff --git a/core/java/android/content/res/Configuration.java b/core/java/android/content/res/Configuration.java
index 935d234..31119d7 100644
--- a/core/java/android/content/res/Configuration.java
+++ b/core/java/android/content/res/Configuration.java
@@ -104,7 +104,7 @@
     public boolean isLayoutSizeAtLeast(int size) {
         int cur = screenLayout&SCREENLAYOUT_SIZE_MASK;
         if (cur == SCREENLAYOUT_SIZE_UNDEFINED) return false;
-        return size >= cur;
+        return cur >= size;
     }
 
     public static final int TOUCHSCREEN_UNDEFINED = 0;
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 761c5d9..cb7d0e2 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -54,7 +54,6 @@
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.TypedValue;
-import android.view.InputQueue.FinishedCallback;
 import android.view.View.MeasureSpec;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityManager;
@@ -775,7 +774,7 @@
                     baseSize = (int)mTmpValue.getDimension(packageMetrics);
                 }
                 if (DEBUG_DIALOG) Log.v(TAG, "Window " + mView + ": baseSize=" + baseSize);
-                if (desiredWindowWidth > baseSize) {
+                if (baseSize != 0 && desiredWindowWidth > baseSize) {
                     int maxHeight = (desiredWindowHeight*2)/3;
                     childWidthMeasureSpec = getRootMeasureSpec(baseSize, lp.width);
                     childHeightMeasureSpec = getRootMeasureSpec(desiredWindowHeight, lp.height);
diff --git a/core/res/res/values-xlarge/config.xml b/core/res/res/values-xlarge/config.xml
index 2f1f4cf..4c8bbe6 100644
--- a/core/res/res/values-xlarge/config.xml
+++ b/core/res/res/values-xlarge/config.xml
@@ -34,7 +34,7 @@
     <integer name="config_longPressOnHomeBehavior">0</integer>
 
     <!-- see comment in values/config.xml -->
-    <dimen name="config_prefDialogWidth">440dp</dimen>
+    <dimen name="config_prefDialogWidth">580dp</dimen>
     
 </resources>
 
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index c7bfdc8..95200fa 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -55,7 +55,6 @@
 import android.os.IInterface;
 import android.os.Message;
 import android.os.Parcel;
-import android.os.Parcelable;
 import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
@@ -125,6 +124,7 @@
     private static final String SUBTYPE_MODE_VOICE = "voice";
 
     final Context mContext;
+    final Resources mRes;
     final Handler mHandler;
     final InputMethodSettings mSettings;
     final SettingsObserver mSettingsObserver;
@@ -468,6 +468,7 @@
 
     public InputMethodManagerService(Context context, StatusBarManagerService statusBar) {
         mContext = context;
+        mRes = context.getResources();
         mHandler = new Handler(this);
         mIWindowManager = IWindowManager.Stub.asInterface(
                 ServiceManager.getService(Context.WINDOW_SERVICE));
@@ -1214,11 +1215,22 @@
                 }
                 mCurFocusedWindow = windowToken;
 
+                // Should we auto-show the IME even if the caller has not
+                // specified what should be done with it?
+                // We only do this automatically if the window can resize
+                // to accommodate the IME (so what the user sees will give
+                // them good context without input information being obscured
+                // by the IME) or if running on a large screen where there
+                // is more room for the target window + IME.
+                final boolean doAutoShow =
+                        (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
+                                == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
+                        || mRes.getConfiguration().isLayoutSizeAtLeast(
+                                Configuration.SCREENLAYOUT_SIZE_LARGE);
+                        
                 switch (softInputMode&WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE) {
                     case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
-                        if (!isTextEditor || (softInputMode &
-                                WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
-                                != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) {
+                        if (!isTextEditor || !doAutoShow) {
                             if (WindowManager.LayoutParams.mayUseInputMethod(windowFlags)) {
                                 // There is no focus view, and this window will
                                 // be behind any soft input window, so hide the
@@ -1226,13 +1238,15 @@
                                 if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
                                 hideCurrentInputLocked(InputMethodManager.HIDE_NOT_ALWAYS, null);
                             }
-                        } else if (isTextEditor && (softInputMode &
-                                WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST)
-                                == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
-                                && (softInputMode &
-                                        WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
+                        } else if (isTextEditor && doAutoShow && (softInputMode &
+                                WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0) {
                             // There is a focus view, and we are navigating forward
                             // into the window, so show the input window for the user.
+                            // We only do this automatically if the window an resize
+                            // to accomodate the IME (so what the user sees will give
+                            // them good context without input information being obscured
+                            // by the IME) or if running on a large screen where there
+                            // is more room for the target window + IME.
                             if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
                             showCurrentInputLocked(InputMethodManager.SHOW_IMPLICIT, null);
                         }
@@ -1544,7 +1558,7 @@
         map.clear();
 
         PackageManager pm = mContext.getPackageManager();
-        final Configuration config = mContext.getResources().getConfiguration();
+        final Configuration config = mRes.getConfiguration();
         final boolean haveHardKeyboard = config.keyboard == Configuration.KEYBOARD_QWERTY;
         String disabledSysImes = Settings.Secure.getString(mContext.getContentResolver(),
                 Secure.DISABLED_SYSTEM_INPUT_METHODS);
@@ -1944,7 +1958,7 @@
             return null;
         }
         if (TextUtils.isEmpty(locale)) {
-            locale = mContext.getResources().getConfiguration().locale.toString();
+            locale = mRes.getConfiguration().locale.toString();
         }
         final String language = locale.substring(0, 2);
         boolean partialMatchFound = false;