Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed the suggestions in the compatibility SearchView. #653

Closed
wants to merge 1 commit into from

5 participants

@mattkranzler5

...ionsAdapter to use the SearchableInfo object to build the uri to query the ContentResolver with. Added missing drawables and defined the necessary attributes for the suggestions in the dropdown to work properly.

@mattkranzler5 mattkranzler5 Fixed the suggestions for the compatibility SearchView. Modified Sugg…
…estionsAdapter to use the SearchableInfo object to build the uri to query the ContentResolver with. Added missing drawables and defined the necessary attributes for the suggestions in the dropdown to work properly.
03720ca
@DSteve595

Yes!

@ngdinhtoan

Could you also fix suggestion behavior when user click on search view?
Currently, when we click on search view, it will hide suggestion list view. When we click again, it don't show suggestion again.
It should always show suggestion list when user click on search view (even it's focused) like native search view.

Code:
Call onQueryRefine(mQueryTextView.getText()); on click on mQueryTextView event.

(I'm not sure it is the best way, but atleast it works for me)

@JakeWharton
Owner

Merged to dev. Thanks!

@lity lity referenced this pull request from a commit in lity/ActionBarSherlock
@lity lity add test case to reproduce issue #653 0070602
@lity lity referenced this pull request from a commit in lity/ActionBarSherlock
@lity lity Add test case for issue #653(#791) 5e5a5a4
@tprochazka

Is this in 4.3.0 already?

@tprochazka

I will reply to myself. Yer it is supported from 4.3.0 ;-)

@ration ration referenced this pull request from a commit in ration/ratebeerforandroid
@erickok erickok Updated ActionBarSherlock to current dev branch head (to get search s…
…uggestions working in SearchView - see JakeWharton/ActionBarSherlock#653).
6a99564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 11, 2012
  1. @mattkranzler5

    Fixed the suggestions for the compatibility SearchView. Modified Sugg…

    mattkranzler5 authored mkranzler committed
    …estionsAdapter to use the SearchableInfo object to build the uri to query the ContentResolver with. Added missing drawables and defined the necessary attributes for the suggestions in the dropdown to work properly.
This page is out of date. Refresh to see the latest.
View
BIN  library/res/drawable-hdpi/abs__ic_commit_search_api_holo_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  library/res/drawable-hdpi/abs__ic_commit_search_api_holo_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  library/res/drawable-mdpi/abs__ic_commit_search_api_holo_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  library/res/drawable-mdpi/abs__ic_commit_search_api_holo_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  library/res/drawable-xhdpi/abs__ic_commit_search_api_holo_dark.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  library/res/drawable-xhdpi/abs__ic_commit_search_api_holo_light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
28 library/res/values/abs__styles.xml
@@ -409,4 +409,32 @@
<item name="android:textColor">?textColorPrimary</item>
<item name="android:textSize">14sp</item>
</style>
+
+ <style name="TextAppearance.Sherlock" parent="@android:style/TextAppearance"/>
+
+ <style name="TextAppearance.Sherlock.SearchResult">
+ <item name="android:textStyle">normal</item>
+ <item name="android:textColor">?android:attr/textColorPrimary</item>
+ <item name="android:textColorHint">?android:attr/textColorHint</item>
+ </style>
+
+ <style name="TextAppearance.Sherlock.SearchResult.Title">
+ <item name="android:textSize">18sp</item>
+ </style>
+
+ <style name="TextAppearance.Sherlock.SearchResult.Subtitle">
+ <item name="android:textSize">14sp</item>
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
+
+ <style name="TextAppearance.Sherlock.Light.SearchResult" parent="TextAppearance.Sherlock.SearchResult"/>
+
+ <style name="TextAppearance.Sherlock.Light.SearchResult.Title">
+ <item name="android:textSize">18sp</item>
+ </style>
+
+ <style name="TextAppearance.Sherlock.Light.SearchResult.Subtitle">
+ <item name="android:textSize">14sp</item>
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
</resources>
View
22 library/res/values/abs__themes.xml
@@ -62,6 +62,8 @@
<item name="textAppearanceSmall">@style/TextAppearance.Sherlock.Small</item>
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.Sherlock.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">@style/TextAppearance.Sherlock.Widget.PopupMenu.Small</item>
+ <item name="textAppearanceSearchResultTitle">@style/TextAppearance.Sherlock.SearchResult.Title</item>
+ <item name="textAppearanceSearchResultSubtitle">@style/TextAppearance.Sherlock.SearchResult.Subtitle</item>
<item name="popupMenuStyle">@style/Widget.Sherlock.PopupMenu</item>
<!-- Internal --><item name="listPopupWindowStyle">@style/Widget.Sherlock.ListPopupWindow</item>
@@ -75,6 +77,9 @@
<item name="searchViewVoiceIcon">@drawable/abs__ic_voice_search</item>
<item name="searchAutoCompleteTextView">@style/Widget.Sherlock.SearchAutoCompleteTextView</item>
<item name="android:dropDownHintAppearance">@style/TextAppearance.Sherlock.Widget.DropDownHint</item>
+ <item name="searchViewEditQuery">@drawable/abs__ic_commit_search_api_holo_dark</item>
+ <item name="searchViewEditQueryBackground">?selectableItemBackground</item>
+ <item name="searchResultListItemHeight">58dp</item>
<item name="windowActionBar">true</item>
<item name="windowActionModeOverlay">false</item>
@@ -130,6 +135,8 @@
<item name="textAppearanceSmall">@style/TextAppearance.Sherlock.Light.Small</item>
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.Sherlock.Light.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">@style/TextAppearance.Sherlock.Light.Widget.PopupMenu.Small</item>
+ <item name="textAppearanceSearchResultTitle">@style/TextAppearance.Sherlock.Light.SearchResult.Title</item>
+ <item name="textAppearanceSearchResultSubtitle">@style/TextAppearance.Sherlock.Light.SearchResult.Subtitle</item>
<item name="popupMenuStyle">@style/Widget.Sherlock.Light.PopupMenu</item>
<!-- Internal --><item name="listPopupWindowStyle">@style/Widget.Sherlock.Light.ListPopupWindow</item>
@@ -143,6 +150,9 @@
<item name="searchViewVoiceIcon">@drawable/abs__ic_voice_search_api_holo_light</item>
<item name="searchAutoCompleteTextView">@style/Widget.Sherlock.Light.SearchAutoCompleteTextView</item>
<item name="android:dropDownHintAppearance">@style/TextAppearance.Sherlock.Widget.DropDownHint</item>
+ <item name="searchViewEditQuery">@drawable/abs__ic_commit_search_api_holo_light</item>
+ <item name="searchViewEditQueryBackground">?selectableItemBackground</item>
+ <item name="searchResultListItemHeight">58dp</item>
<item name="windowActionBar">true</item>
<item name="windowActionModeOverlay">false</item>
@@ -171,6 +181,18 @@
<item name="actionModePopupWindowStyle">@style/Widget.Sherlock.PopupWindow.ActionMode</item>
<item name="actionModeShareDrawable">@drawable/abs__ic_menu_share_holo_dark</item>
+
+ <!-- We want the dark action bar SearchView stuff -->
+ <item name="searchDropdownBackground">@drawable/abs__search_dropdown_dark</item>
+ <item name="searchViewTextField">@drawable/abs__textfield_searchview_holo_dark</item>
+ <item name="searchViewTextFieldRight">@drawable/abs__textfield_searchview_right_holo_dark</item>
+ <item name="searchViewCloseIcon">@drawable/abs__ic_clear</item>
+ <item name="searchViewSearchIcon">@drawable/abs__ic_search</item>
+ <item name="searchViewGoIcon">@drawable/abs__ic_go</item>
+ <item name="searchViewVoiceIcon">@drawable/abs__ic_voice_search</item>
+ <item name="searchAutoCompleteTextView">@style/Widget.Sherlock.SearchAutoCompleteTextView</item>
+ <item name="android:dropDownHintAppearance">@style/TextAppearance.Sherlock.Widget.DropDownHint</item>
+ <item name="searchViewEditQuery">@drawable/abs__ic_commit_search_api_holo_dark</item>
</style>
View
33 library/src/com/actionbarsherlock/widget/SuggestionsAdapter.java
@@ -66,6 +66,7 @@
static final int REFINE_ALL = 2;
private SearchManager mSearchManager;
+ private SearchableInfo mSearchable;
private SearchView mSearchView;
private Context mProviderContext;
private WeakHashMap<String, Drawable.ConstantState> mOutsideDrawablesCache;
@@ -94,12 +95,13 @@
//private static final long DELETE_KEY_POST_DELAY = 500L;
public SuggestionsAdapter(Context context, SearchView searchView,
- SearchableInfo mSearchable, WeakHashMap<String, Drawable.ConstantState> outsideDrawablesCache) {
+ SearchableInfo searchable, WeakHashMap<String, Drawable.ConstantState> outsideDrawablesCache) {
super(context,
R.layout.abs__search_dropdown_item_icons_2line,
null, // no initial cursor
true); // auto-requery
mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
+ mSearchable = searchable;
mProviderContext = mContext;
mSearchView = searchView;
@@ -199,25 +201,48 @@ public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
}
public Cursor getSuggestions(String query, int limit) {
+ if (mSearchable == null) {
+ return null;
+ }
+
+ String authority = mSearchable.getSuggestAuthority();
+ if (authority == null) {
+ return null;
+ }
+
Uri.Builder uriBuilder = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(authority)
.query("") // TODO: Remove, workaround for a bug in Uri.writeToParcel()
.fragment(""); // TODO: Remove, workaround for a bug in Uri.writeToParcel()
+ // if content path provided, insert it now
+ final String contentPath = mSearchable.getSuggestPath();
+ if (contentPath != null) {
+ uriBuilder.appendEncodedPath(contentPath);
+ }
+
// append standard suggestion query path
uriBuilder.appendPath(SearchManager.SUGGEST_URI_PATH_QUERY);
+ // get the query selection, may be null
+ String selection = mSearchable.getSuggestSelection();
// inject query, either as selection args or inline
- uriBuilder.appendPath(query);
+ String[] selArgs = null;
+ if (selection != null) { // use selection if provided
+ selArgs = new String[] { query };
+ } else { // no selection, use REST pattern
+ uriBuilder.appendPath(query);
+ }
if (limit > 0) {
- uriBuilder.appendQueryParameter(SearchManager.SUGGEST_PARAMETER_LIMIT, String.valueOf(limit));
+ uriBuilder.appendQueryParameter("limit", String.valueOf(limit));
}
Uri uri = uriBuilder.build();
// finally, make the query
- return mContext.getContentResolver().query(uri, null, null, null, null);
+ return mContext.getContentResolver().query(uri, null, selection, selArgs, null);
}
public void close() {
Something went wrong with that request. Please try again.