Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f4c2951 authored by Android (Google) Code Review's avatar Android (Google) Code Review Committed by The Android Open Source Project
Browse files

am b249890b: Merge change 2835 into donut

Merge commit 'b249890b'

* commit 'b249890b':
  Add framework support for scrolling to the "More results..." list item
parents ee01b1ca b249890b
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -1275,8 +1275,25 @@ 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);
    }
    
    /**
+25 −0
Original line number Diff line number Diff line
@@ -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;
    }
    
    /**