Fixed the suggestions in the compatibility SearchView. #653

Closed
wants to merge 1 commit into from
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() {