Fix for 2175289 : Can't get keyboard in search dialog after switching to landscape

The auto complete drop down was obscuring the keyboard. This fix checks if the
screen is in landscape mode and forces the keyboard in front when necessary.
diff --git a/core/java/android/app/SearchDialog.java b/core/java/android/app/SearchDialog.java
index bf9b021..ebc64d7 100644
--- a/core/java/android/app/SearchDialog.java
+++ b/core/java/android/app/SearchDialog.java
@@ -19,23 +19,25 @@
 
 import static android.app.SuggestionsAdapter.getColumnString;
 
+import java.util.WeakHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
 import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
 import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
 import android.os.SystemClock;
 import android.provider.Browser;
 import android.speech.RecognizerIntent;
@@ -43,11 +45,8 @@
 import android.text.InputType;
 import android.text.TextUtils;
 import android.text.TextWatcher;
-import android.util.AndroidRuntimeException;
 import android.util.AttributeSet;
 import android.util.Log;
-import android.util.Patterns;
-import android.view.ContextThemeWrapper;
 import android.view.Gravity;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
@@ -69,10 +68,6 @@
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.AdapterView.OnItemSelectedListener;
 
-import java.util.ArrayList;
-import java.util.WeakHashMap;
-import java.util.concurrent.atomic.AtomicLong;
-
 /**
  * Search dialog. This is controlled by the 
  * SearchManager and runs in the current foreground process.
@@ -154,6 +149,16 @@
         mVoiceAppSearchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
         mVoiceAppSearchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         mSearchManager = searchManager;
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
+        context.registerReceiver(new BroadcastReceiver() {
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
+                    onConfigurationChanged();
+                }
+            }
+        }, filter);
     }
 
     /**
@@ -394,10 +399,18 @@
             updateSearchAppIcon();
             updateSearchBadge();
             updateQueryHint();
+            if (isLandscapeMode(getContext())) {
+                mSearchAutoComplete.ensureImeVisible(true);
+            }
             mSearchAutoComplete.showDropDownAfterLayout();
-        } 
+        }
     }
-    
+
+    static boolean isLandscapeMode(Context context) {
+        return context.getResources().getConfiguration().orientation
+                == Configuration.ORIENTATION_LANDSCAPE;
+    }
+
     /**
      * Update the UI according to the info in the current value of {@link #mSearchable}.
      */
@@ -983,7 +996,7 @@
                 mSearchAutoComplete.setSelection(selPoint);
                 mSearchAutoComplete.setListSelection(0);
                 mSearchAutoComplete.clearListSelection();
-                mSearchAutoComplete.ensureImeVisible();
+                mSearchAutoComplete.ensureImeVisible(true);
                 
                 return true;
             }
@@ -1362,6 +1375,11 @@
                 InputMethodManager inputManager = (InputMethodManager)
                         getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                 inputManager.showSoftInput(this, 0);
+                // If in landscape mode, then make sure that
+                // the ime is in front of the dropdown.
+                if (isLandscapeMode(getContext())) {
+                    ensureImeVisible(true);
+                }
             }
         }
                 
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index ed63787..65f7cdb 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -17,9 +17,11 @@
 package android.widget;
 
 import android.content.Context;
+import android.content.res.Configuration;
 import android.content.res.TypedArray;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable.Orientation;
 import android.text.Editable;
 import android.text.Selection;
 import android.text.TextUtils;
@@ -210,10 +212,10 @@
      * Private hook into the on click event, dispatched from {@link PassThroughClickListener}
      */
     private void onClickImpl() {
-        // If the dropdown is showing, bring it back in front of the soft
-        // keyboard when the user touches the text field.
-        if (mPopup.isShowing() && isInputMethodNotNeeded()) {
-            ensureImeVisible();
+        // If the dropdown is showing, bring the keyboard to the front
+        // when the user touches the text field.
+        if (mPopup.isShowing()) {
+            ensureImeVisible(true);
         }
     }
 
@@ -1114,11 +1116,13 @@
     
     /**
      * Ensures that the drop down is not obscuring the IME.
-     * 
+     * @param visible whether the ime should be in front. If false, the ime is pushed to
+     * the background.
      * @hide internal used only here and SearchDialog
      */
-    public void ensureImeVisible() {
-        mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
+    public void ensureImeVisible(boolean visible) {
+        mPopup.setInputMethodMode(visible
+                ? PopupWindow.INPUT_METHOD_NEEDED : PopupWindow.INPUT_METHOD_NOT_NEEDED);
         showDropDown();
     }