diff options
23 files changed, 88 insertions, 10 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index e499e54a7328..1820c3fb0c8f 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. diff --git a/core/res/res/drawable-hdpi/ic_clear_off.png b/core/res/res/drawable-hdpi/ic_clear_disabled.png Binary files differindex d97c342d5369..d97c342d5369 100644 --- a/core/res/res/drawable-hdpi/ic_clear_off.png +++ b/core/res/res/drawable-hdpi/ic_clear_disabled.png diff --git a/core/res/res/drawable-hdpi/ic_clear.png b/core/res/res/drawable-hdpi/ic_clear_normal.png Binary files differindex 33ad8d4b891b..33ad8d4b891b 100644 --- a/core/res/res/drawable-hdpi/ic_clear.png +++ b/core/res/res/drawable-hdpi/ic_clear_normal.png diff --git a/core/res/res/drawable-hdpi/ic_clear_search_api_disabled_holo_light.png b/core/res/res/drawable-hdpi/ic_clear_search_api_disabled_holo_light.png Binary files differnew file mode 100644 index 000000000000..3edbd740858a --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_clear_search_api_disabled_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_clear_search_api_holo_light.png b/core/res/res/drawable-hdpi/ic_clear_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..90db01b5bcf1 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_clear_search_api_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_commit_search_api_holo_light.png b/core/res/res/drawable-hdpi/ic_commit_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..b01688fa3225 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_commit_search_api_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_go_search_api_holo_light.png b/core/res/res/drawable-hdpi/ic_go_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..7e1ba2adc627 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_go_search_api_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_search_api_holo_light.png b/core/res/res/drawable-hdpi/ic_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..72e207bc5dc8 --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_search_api_holo_light.png diff --git a/core/res/res/drawable-hdpi/ic_voice_search_api_holo_light.png b/core/res/res/drawable-hdpi/ic_voice_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..3481c982862c --- /dev/null +++ b/core/res/res/drawable-hdpi/ic_voice_search_api_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_clear_off.png b/core/res/res/drawable-mdpi/ic_clear_disabled.png Binary files differindex b9c3b4450568..b9c3b4450568 100644 --- a/core/res/res/drawable-mdpi/ic_clear_off.png +++ b/core/res/res/drawable-mdpi/ic_clear_disabled.png diff --git a/core/res/res/drawable-mdpi/ic_clear.png b/core/res/res/drawable-mdpi/ic_clear_normal.png Binary files differindex 86944a879b98..86944a879b98 100644 --- a/core/res/res/drawable-mdpi/ic_clear.png +++ b/core/res/res/drawable-mdpi/ic_clear_normal.png diff --git a/core/res/res/drawable-mdpi/ic_clear_search_api_disabled_holo_light.png b/core/res/res/drawable-mdpi/ic_clear_search_api_disabled_holo_light.png Binary files differnew file mode 100644 index 000000000000..3edbd740858a --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_clear_search_api_disabled_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_clear_search_api_holo_light.png b/core/res/res/drawable-mdpi/ic_clear_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..90db01b5bcf1 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_clear_search_api_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_commit_search_api_holo_light.png b/core/res/res/drawable-mdpi/ic_commit_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..b01688fa3225 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_commit_search_api_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_go_search_api_holo_light.png b/core/res/res/drawable-mdpi/ic_go_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..7e1ba2adc627 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_go_search_api_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_search_api_holo_light.png b/core/res/res/drawable-mdpi/ic_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..72e207bc5dc8 --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_search_api_holo_light.png diff --git a/core/res/res/drawable-mdpi/ic_voice_search_api_holo_light.png b/core/res/res/drawable-mdpi/ic_voice_search_api_holo_light.png Binary files differnew file mode 100644 index 000000000000..3481c982862c --- /dev/null +++ b/core/res/res/drawable-mdpi/ic_voice_search_api_holo_light.png diff --git a/core/res/res/drawable/ic_clear.xml b/core/res/res/drawable/ic_clear.xml new file mode 100644 index 000000000000..f3534964a804 --- /dev/null +++ b/core/res/res/drawable/ic_clear.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_enabled="false" + android:drawable="@drawable/ic_clear_disabled" /> + <item + android:drawable="@drawable/ic_clear_normal" /> +</selector> diff --git a/core/res/res/drawable/ic_clear_holo_light.xml b/core/res/res/drawable/ic_clear_holo_light.xml new file mode 100644 index 000000000000..8ba1e3c09a6b --- /dev/null +++ b/core/res/res/drawable/ic_clear_holo_light.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:state_enabled="false" + android:drawable="@drawable/ic_clear_search_api_disabled_holo_light" /> + <item + android:drawable="@drawable/ic_clear_search_api_holo_light" /> +</selector> diff --git a/core/res/res/layout/search_dropdown_item_icons_2line.xml b/core/res/res/layout/search_dropdown_item_icons_2line.xml index fcdf91b21859..53906f94e025 100644 --- a/core/res/res/layout/search_dropdown_item_icons_2line.xml +++ b/core/res/res/layout/search_dropdown_item_icons_2line.xml @@ -42,8 +42,8 @@ android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_alignParentBottom="true" - android:src="@android:drawable/edit_query" - android:background="@android:drawable/edit_query_background" + android:src="?attr/searchViewEditQuery" + android:background="?attr/searchViewEditQueryBackground" android:visibility="gone" /> <ImageView android:id="@android:id/icon2" diff --git a/core/res/res/layout/search_view.xml b/core/res/res/layout/search_view.xml index 0fb824f7c02c..bb7f7006899b 100644 --- a/core/res/res/layout/search_view.xml +++ b/core/res/res/layout/search_view.xml @@ -44,7 +44,7 @@ android:layout_width="wrap_content" android:layout_gravity="center_vertical" android:background="?android:attr/selectableItemBackground" - android:src="@android:drawable/ic_search" + android:src="?android:attr/searchViewSearchIcon" /> <LinearLayout diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 701b8cab0e31..98c9270c0faf 100755 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -667,6 +667,10 @@ <attr name="searchViewSearchIcon" format="reference" /> <!-- SearchView Voice button icon --> <attr name="searchViewVoiceIcon" format="reference" /> + <!-- SearchView query refinement icon --> + <attr name="searchViewEditQuery" format="reference" /> + <!-- SearchView query refinement icon background --> + <attr name="searchViewEditQueryBackground" format="reference" /> <!-- Specifies a drawable to use for the 'home as up' indicator. --> <attr name="homeAsUpIndicator" format="reference" /> diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml index f0f101e4ad82..87029ef84f22 100644 --- a/core/res/res/values/themes.xml +++ b/core/res/res/values/themes.xml @@ -269,6 +269,8 @@ <item name="searchViewSearchIcon">@android:drawable/ic_search</item> <item name="searchViewGoIcon">@android:drawable/ic_go</item> <item name="searchViewVoiceIcon">@android:drawable/ic_voice_search</item> + <item name="searchViewEditQuery">@android:drawable/ic_commit</item> + <item name="searchViewEditQueryBackground">?attr/selectableItemBackground</item> <!-- PreferenceFrameLayout attributes --> @@ -362,8 +364,13 @@ <item name="actionModePasteDrawable">@android:drawable/ic_menu_paste_light</item> <!-- SearchView attributes --> <item name="searchDropdownBackground">@android:drawable/search_dropdown_light</item> + <item name="searchViewCloseIcon">@android:drawable/ic_clear_holo_light</item> + <item name="searchViewSearchIcon">@android:drawable/ic_search_api_holo_light</item> + <item name="searchViewGoIcon">@android:drawable/ic_go_search_api_holo_light</item> + <item name="searchViewVoiceIcon">@android:drawable/ic_voice_search_api_holo_light</item> + <item name="searchViewEditQuery">@android:drawable/ic_commit_search_api_holo_light</item> </style> - + <!-- Variant of the light theme with no title bar --> <style name="Theme.Light.NoTitleBar"> <item name="android:windowNoTitle">true</item> |