diff options
| author | Amith Yamasani <yamasani@google.com> | 2010-12-15 16:04:57 -0800 |
|---|---|---|
| committer | Amith Yamasani <yamasani@google.com> | 2010-12-15 20:09:33 -0800 |
| commit | 4aedb39a49bda340f871c8fac2239de4fe549b03 (patch) | |
| tree | a79293d5907155490b34b49e08d11087eaabb068 /core/java/android/widget | |
| parent | 066460f3ba78ed22634939e8eaf0544ca9f56380 (diff) | |
| download | frameworks_base-4aedb39a49bda340f871c8fac2239de4fe549b03.zip frameworks_base-4aedb39a49bda340f871c8fac2239de4fe549b03.tar.gz frameworks_base-4aedb39a49bda340f871c8fac2239de4fe549b03.tar.bz2 | |
New SearchView assets and close-button behavior change.
Hide the close button in SearchView when there's no text in it and it's not iconified by default.
Bug: 3275206
Adds Holo.Light theme and fixes the query refinement icon.
Diffstat (limited to 'core/java/android/widget')
| -rw-r--r-- | core/java/android/widget/SearchView.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index e499e54..1820c3f 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -18,6 +18,8 @@ package android.widget; import static android.widget.SuggestionsAdapter.getColumnString; +import com.android.internal.R; + import android.app.PendingIntent; import android.app.SearchManager; import android.app.SearchableInfo; @@ -44,14 +46,11 @@ import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; -import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.TextView.OnEditorActionListener; -import com.android.internal.R; - import java.util.WeakHashMap; /** @@ -84,7 +83,7 @@ public class SearchView extends LinearLayout { private CursorAdapter mSuggestionsAdapter; private View mSearchButton; private View mSubmitButton; - private View mCloseButton; + private ImageView mCloseButton; private View mSearchEditFrame; private View mVoiceButton; private SearchAutoComplete mQueryTextView; @@ -189,7 +188,7 @@ public class SearchView extends LinearLayout { mSearchEditFrame = findViewById(R.id.search_edit_frame); mSubmitButton = findViewById(R.id.search_go_btn); - mCloseButton = findViewById(R.id.search_close_btn); + mCloseButton = (ImageView) findViewById(R.id.search_close_btn); mVoiceButton = findViewById(R.id.search_voice_btn); mSearchButton.setOnClickListener(mOnClickListener); @@ -252,7 +251,9 @@ public class SearchView extends LinearLayout { @Override public boolean requestFocus(int direction, Rect previouslyFocusedRect) { if (mClearingFocus || isIconified()) return false; - return mQueryTextView.requestFocus(direction, previouslyFocusedRect); + boolean result = mQueryTextView.requestFocus(direction, previouslyFocusedRect); + if (result) updateViewsVisibility(mIconifiedByDefault); + return result; } /** @hide */ @@ -263,6 +264,7 @@ public class SearchView extends LinearLayout { mQueryTextView.clearFocus(); setImeVisibility(false); mClearingFocus = false; + updateViewsVisibility(mIconifiedByDefault); } /** @@ -515,11 +517,21 @@ public class SearchView extends LinearLayout { mSearchButton.setVisibility(visCollapsed); mSubmitButton.setVisibility(mSubmitButtonEnabled && hasText ? visExpanded : GONE); mSearchEditFrame.setVisibility(visExpanded); + updateCloseButton(); updateVoiceButton(!hasText); requestLayout(); invalidate(); } + private void updateCloseButton() { + 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 || mQueryTextView.hasFocus(); + mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE); + mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET); + } + private void setImeVisibility(boolean visible) { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); @@ -812,6 +824,7 @@ public class SearchView extends LinearLayout { invalidate(); } updateVoiceButton(!hasText); + updateViewsVisibility(mIconifiedByDefault); if (mOnQueryChangeListener != null) { mOnQueryChangeListener.onQueryTextChanged(newText.toString()); } @@ -882,6 +895,10 @@ public class SearchView extends LinearLayout { } } + void onTextFocusChanged() { + updateCloseButton(); + } + private boolean onItemClicked(int position, int actionKey, String actionMsg) { if (mOnSuggestionListener == null || !mOnSuggestionListener.onSuggestionClicked(position)) { @@ -1283,6 +1300,12 @@ public class SearchView extends LinearLayout { } } + @Override + protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { + super.onFocusChanged(focused, direction, previouslyFocusedRect); + mSearchView.onTextFocusChanged(); + } + /** * We override this method so that we can allow a threshold of zero, * which ACTV does not. |
