Add a missing setOnCloseListener and a new setIconfied method.

Keep track of the currently iconified state as well, if the app
wants to know.
diff --git a/api/current.xml b/api/current.xml
index a9abb141..310944f 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -234035,6 +234035,17 @@
  visibility="public"
 >
 </method>
+<method name="isIconified"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
 <method name="isSubmitButtonEnabled"
  return="boolean"
  abstract="false"
@@ -234046,6 +234057,19 @@
  visibility="public"
 >
 </method>
+<method name="setIconified"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="iconify" type="boolean">
+</parameter>
+</method>
 <method name="setIconifiedByDefault"
  return="void"
  abstract="false"
@@ -234059,6 +234083,19 @@
 <parameter name="iconified" type="boolean">
 </parameter>
 </method>
+<method name="setOnCloseListener"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="listener" type="android.widget.SearchView.OnCloseListener">
+</parameter>
+</method>
 <method name="setOnQueryChangeListener"
  return="void"
  abstract="false"
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index fe1c9da..57dc725 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -57,6 +57,7 @@
     private OnCloseListener mOnCloseListener;
 
     private boolean mIconifiedByDefault;
+    private boolean mIconified;
     private CursorAdapter mSuggestionsAdapter;
     private View mSearchButton;
     private View mSubmitButton;
@@ -139,8 +140,6 @@
         mQueryTextView.setOnItemClickListener(mOnItemClickListener);
         mQueryTextView.setOnItemSelectedListener(mOnItemSelectedListener);
 
-        mSubmitButtonEnabled = false;
-
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SearchView, 0, 0);
         setIconifiedByDefault(a.getBoolean(R.styleable.SearchView_iconifiedByDefault, true));
         a.recycle();
@@ -175,6 +174,15 @@
     }
 
     /**
+     * Sets a listener to inform when the user closes the SearchView.
+     *
+     * @param listener the listener to call when the user closes the SearchView.
+     */
+    public void setOnCloseListener(OnCloseListener listener) {
+        mOnCloseListener = listener;
+    }
+
+    /**
      * Sets a query string in the text field and optionally submits the query as well.
      *
      * @param query the query string. This replaces any query text already present in the
@@ -205,20 +213,54 @@
      * Sets the default or resting state of the search field. If true, a single search icon is
      * shown by default and expands to show the text field and other buttons when pressed. Also,
      * if the default state is iconified, then it collapses to that state when the close button
-     * is pressed.
+     * is pressed. Changes to this property will take effect immediately.
      *
-     * @param iconified
+     * <p>The default value is false.</p>
+     *
+     * @param iconified whether the search field should be iconified by default
      */
     public void setIconifiedByDefault(boolean iconified) {
         mIconifiedByDefault = iconified;
         updateViewsVisibility(iconified);
     }
 
+    /**
+     * Returns the default iconified state of the search field.
+     * @return
+     */
     public boolean isIconfiedByDefault() {
         return mIconifiedByDefault;
     }
 
     /**
+     * Iconifies or expands the SearchView. Any query text is cleared when iconified. This is
+     * a temporary state and does not override the default iconified state set by
+     * {@link #setIconifiedByDefault(boolean)}. If the default state is iconified, then
+     * a false here will only be valid until the user closes the field. And if the default
+     * state is expanded, then a true here will only clear the text field and not close it.
+     *
+     * @param iconify a true value will collapse the SearchView to an icon, while a false will
+     * expand it.
+     */
+    public void setIconified(boolean iconify) {
+        if (iconify) {
+            onCloseClicked();
+        } else {
+            onSearchClicked();
+        }
+    }
+
+    /**
+     * Returns the current iconified state of the SearchView.
+     *
+     * @return true if the SearchView is currently iconified, false if the search field is
+     * fully visible.
+     */
+    public boolean isIconified() {
+        return mIconified;
+    }
+
+    /**
      * Enables showing a submit button when the query is non-empty. In cases where the SearchView
      * is being used to filter the contents of the current activity and doesn't launch a separate
      * results activity, then the submit button should be disabled.
@@ -263,11 +305,12 @@
         return mSuggestionsAdapter;
     }
 
-    private void updateViewsVisibility(boolean collapsed) {
+    private void updateViewsVisibility(final boolean collapsed) {
+        mIconified = collapsed;
         // Visibility of views that are visible when collapsed
-        int visCollapsed = collapsed? VISIBLE : GONE;
+        final int visCollapsed = collapsed ? VISIBLE : GONE;
         // Visibility of views that are visible when expanded
-        int visExpanded = collapsed? GONE : VISIBLE;
+        final int visExpanded = collapsed ? GONE : VISIBLE;
 
         mSearchButton.setVisibility(visCollapsed);
         mSubmitButton.setVisibility(mSubmitButtonEnabled ? visExpanded : GONE);
@@ -322,7 +365,8 @@
         // entered query with the action key
         SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
         if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) {
-            launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mQueryTextView.getText().toString());
+            launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mQueryTextView.getText()
+                    .toString());
             return true;
         }