Merge change 2835 into donut
* changes: Add framework support for scrolling to the "More results..." list item when it is clicked.
This commit is contained in:
@@ -1275,10 +1275,27 @@ public class SearchDialog extends Dialog implements OnItemClickListener, OnItemS
|
||||
private void handleCursorRespondIntent(Intent intent) {
|
||||
Cursor c = mSuggestionsAdapter.getCursor();
|
||||
if (c != null) {
|
||||
c.respond(intent.getExtras());
|
||||
Bundle response = c.respond(intent.getExtras());
|
||||
|
||||
// The SHOW_CORPUS_SELECTORS command to the cursor also returns a value in
|
||||
// its bundle, keyed by the same command string, which contains the index
|
||||
// of the "More results..." list item, which we use to instruct the
|
||||
// AutoCompleteTextView's list to scroll to that item when the item is
|
||||
// clicked.
|
||||
if (response.containsKey(SuggestionsAdapter.SHOW_CORPUS_SELECTORS)) {
|
||||
int indexOfMore = response.getInt(SuggestionsAdapter.SHOW_CORPUS_SELECTORS);
|
||||
mSuggestionsAdapter.setListItemToSelect(indexOfMore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the list item selection in the AutoCompleteTextView's ListView.
|
||||
*/
|
||||
public void setListSelection(int index) {
|
||||
mSearchAutoComplete.setListSelection(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the previous component that was searched, so that we can go
|
||||
* back to it.
|
||||
|
||||
@@ -50,6 +50,11 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
||||
// so we can correctly display (or not display) the 'working' spinner in the search dialog.
|
||||
public static final String IS_WORKING = "isWorking";
|
||||
|
||||
// The value used to tell a cursor to display the corpus selectors, if this is global
|
||||
// search. Also returns the index of the more results item to allow the SearchDialog
|
||||
// to tell the ListView to scroll to that list item.
|
||||
public static final String SHOW_CORPUS_SELECTORS = "showCorpusSelectors";
|
||||
|
||||
private static final boolean DBG = false;
|
||||
private static final String LOG_TAG = "SuggestionsAdapter";
|
||||
|
||||
@@ -68,6 +73,13 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
||||
private int mIconBitmap1Col;
|
||||
private int mIconBitmap2Col;
|
||||
|
||||
// This value is stored in SuggestionsAdapter by the SearchDialog to indicate whether
|
||||
// a particular list item should be selected upon the next call to notifyDataSetChanged.
|
||||
// This is used to indicate the index of the "More results..." list item so that when
|
||||
// the data set changes after a click of "More results...", we can correctly tell the
|
||||
// ListView to scroll to the right line item. It gets reset to -1 every time it is consumed.
|
||||
private int mListItemToSelect = -1;
|
||||
|
||||
public SuggestionsAdapter(Context context, SearchDialog searchDialog, SearchableInfo searchable,
|
||||
WeakHashMap<String, Drawable> outsideDrawablesCache, boolean globalSearchMode) {
|
||||
super(context,
|
||||
@@ -134,6 +146,19 @@ class SuggestionsAdapter extends ResourceCursorAdapter {
|
||||
public void notifyDataSetChanged() {
|
||||
super.notifyDataSetChanged();
|
||||
updateWorking();
|
||||
if (mListItemToSelect != -1) {
|
||||
mSearchDialog.setListSelection(mListItemToSelect);
|
||||
mListItemToSelect = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the list item to select upon next call of {@link #notifyDataSetChanged()},
|
||||
* in order to let us scroll the "More results..." list item to the top of the screen
|
||||
* (or as close as it can get) when clicked.
|
||||
*/
|
||||
public void setListItemToSelect(int index) {
|
||||
mListItemToSelect = index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user