diff options
author | Amith Yamasani <yamasani@google.com> | 2011-07-22 11:53:47 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2011-07-22 14:14:59 -0700 |
commit | 763bc076527b183204b8ef82711f9b404bed53db (patch) | |
tree | 36390feff84252c3143208d8410558e0cebc6d20 | |
parent | 423f0ed494d30bbae1a02c059769f0211f1e4d81 (diff) | |
download | frameworks_base-763bc076527b183204b8ef82711f9b404bed53db.zip frameworks_base-763bc076527b183204b8ef82711f9b404bed53db.tar.gz frameworks_base-763bc076527b183204b8ef82711f9b404bed53db.tar.bz2 |
Implement CollapsibleActionView on SearchView.
Automatically handle expanding and collapsing in an ActionBar using
the new callback for Collapsible ActionViews.
Also clear the query text when collapsing.
Make sure that the 'x' doesn't show when in expanded mode with no text.
Change-Id: I7cba009c7cc9a1c264ec11c76315353cbde55c6c
-rw-r--r-- | api/current.txt | 4 | ||||
-rw-r--r-- | core/java/android/widget/SearchView.java | 47 |
2 files changed, 43 insertions, 8 deletions
diff --git a/api/current.txt b/api/current.txt index f88001d..7af8e3a 100644 --- a/api/current.txt +++ b/api/current.txt @@ -26197,7 +26197,7 @@ package android.widget { method public int timePassed(); } - public class SearchView extends android.widget.LinearLayout { + public class SearchView extends android.widget.LinearLayout implements android.view.CollapsibleActionView { ctor public SearchView(android.content.Context); ctor public SearchView(android.content.Context, android.util.AttributeSet); method public java.lang.CharSequence getQuery(); @@ -26206,6 +26206,8 @@ package android.widget { method public boolean isIconified(); method public boolean isQueryRefinementEnabled(); method public boolean isSubmitButtonEnabled(); + method public void onActionViewCollapsed(); + method public void onActionViewExpanded(); method public void setIconified(boolean); method public void setIconifiedByDefault(boolean); method public void setMaxWidth(int); diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index b2d1a1e..55b73df 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -45,6 +45,7 @@ import android.text.style.ImageSpan; import android.util.AttributeSet; import android.util.Log; import android.util.TypedValue; +import android.view.CollapsibleActionView; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; @@ -58,18 +59,30 @@ import com.android.internal.R; import java.util.WeakHashMap; /** - * A widget that provides a user interface for the user to enter a search query and submit a - * request to a search provider. Shows a list of query suggestions or results, if - * available, and allows the user to pick a suggestion or result to launch into. + * A widget that provides a user interface for the user to enter a search query and submit a request + * to a search provider. Shows a list of query suggestions or results, if available, and allows the + * user to pick a suggestion or result to launch into. * - * <p>For more information, see the <a href="{@docRoot}guide/topics/search/index.html">Search</a> - * documentation.<p> + * <p> + * When the SearchView is used in an ActionBar as an action view for a collapsible menu item, it + * needs to be set to iconified by default using {@link #setIconifiedByDefault(boolean) + * setIconifiedByDefault(true)}. This is the default, so nothing needs to be done. + * </p> + * <p> + * If you want the search field to always be visible, then call setIconifiedByDefault(false). + * </p> * + * <p> + * For more information, see the <a href="{@docRoot}guide/topics/search/index.html">Search</a> + * documentation. + * <p> + * + * @see android.view.MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW * @attr ref android.R.styleable#SearchView_iconifiedByDefault * @attr ref android.R.styleable#SearchView_maxWidth * @attr ref android.R.styleable#SearchView_queryHint */ -public class SearchView extends LinearLayout { +public class SearchView extends LinearLayout implements CollapsibleActionView { private static final boolean DBG = false; private static final String LOG_TAG = "SearchView"; @@ -100,6 +113,7 @@ public class SearchView extends LinearLayout { private int mMaxWidth; private boolean mVoiceButtonEnabled; private CharSequence mUserQuery; + private boolean mExpandedInActionView; private SearchableInfo mSearchable; private Bundle mAppSearchData; @@ -623,7 +637,7 @@ public class SearchView extends LinearLayout { final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText()); // Should we show the close button? It is not shown if there's no focus, // field is not iconified by default and there is no text in it. - final boolean showClose = hasText || mIconifiedByDefault; + final boolean showClose = hasText || (mIconifiedByDefault && !mExpandedInActionView); mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE); mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET); } @@ -1022,6 +1036,25 @@ public class SearchView extends LinearLayout { super.onAttachedToWindow(); } + /** + * {@inheritDoc} + */ + @Override + public void onActionViewCollapsed() { + mQueryTextView.setText(""); + setIconified(true); + mExpandedInActionView = false; + } + + /** + * {@inheritDoc} + */ + @Override + public void onActionViewExpanded() { + mExpandedInActionView = true; + setIconified(false); + } + private void adjustDropDownSizeAndPosition() { if (mDropDownAnchor.getWidth() > 1) { Resources res = getContext().getResources(); |