2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package com.cyanogenmod.eleven.ui.activities;
16 import android.app.ActionBar;
17 import android.app.SearchManager;
18 import android.content.ComponentName;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.ServiceConnection;
22 import android.database.Cursor;
23 import android.media.AudioManager;
24 import android.os.Bundle;
25 import android.os.Handler;
26 import android.os.IBinder;
27 import android.provider.BaseColumns;
28 import android.provider.MediaStore;
29 import android.support.v4.app.FragmentActivity;
30 import android.support.v4.app.LoaderManager.LoaderCallbacks;
31 import android.support.v4.content.Loader;
32 import android.text.TextUtils;
33 import android.view.Menu;
34 import android.view.MenuItem;
35 import android.view.MotionEvent;
36 import android.view.View;
37 import android.view.inputmethod.InputMethodManager;
38 import android.widget.AbsListView;
39 import android.widget.AbsListView.OnScrollListener;
40 import android.widget.AdapterView;
41 import android.widget.AdapterView.OnItemClickListener;
42 import android.widget.ArrayAdapter;
43 import android.widget.ImageView;
44 import android.widget.LinearLayout;
45 import android.widget.ListView;
46 import android.widget.SearchView;
47 import android.widget.SearchView.OnQueryTextListener;
49 import com.cyanogenmod.eleven.Config;
50 import com.cyanogenmod.eleven.IElevenService;
51 import com.cyanogenmod.eleven.R;
52 import com.cyanogenmod.eleven.adapters.SummarySearchAdapter;
53 import com.cyanogenmod.eleven.loaders.WrappedAsyncTaskLoader;
54 import com.cyanogenmod.eleven.menu.FragmentMenuItems;
55 import com.cyanogenmod.eleven.model.AlbumArtistDetails;
56 import com.cyanogenmod.eleven.model.SearchResult;
57 import com.cyanogenmod.eleven.model.SearchResult.ResultType;
58 import com.cyanogenmod.eleven.provider.SearchHistory;
59 import com.cyanogenmod.eleven.recycler.RecycleHolder;
60 import com.cyanogenmod.eleven.sectionadapter.SectionAdapter;
61 import com.cyanogenmod.eleven.sectionadapter.SectionCreator;
62 import com.cyanogenmod.eleven.sectionadapter.SectionCreator.SimpleListLoader;
63 import com.cyanogenmod.eleven.sectionadapter.SectionListContainer;
64 import com.cyanogenmod.eleven.utils.ApolloUtils;
65 import com.cyanogenmod.eleven.utils.MusicUtils;
66 import com.cyanogenmod.eleven.utils.MusicUtils.ServiceToken;
67 import com.cyanogenmod.eleven.utils.NavUtils;
68 import com.cyanogenmod.eleven.utils.PopupMenuHelper;
69 import com.cyanogenmod.eleven.utils.SectionCreatorUtils;
70 import com.cyanogenmod.eleven.utils.SectionCreatorUtils.IItemCompare;
71 import com.cyanogenmod.eleven.widgets.IPopupMenuCallback;
72 import com.cyanogenmod.eleven.widgets.LoadingEmptyContainer;
73 import com.cyanogenmod.eleven.widgets.NoResultsContainer;
75 import java.util.ArrayList;
76 import java.util.Collections;
77 import java.util.List;
78 import java.util.TreeSet;
80 import static android.view.View.OnTouchListener;
81 import static com.cyanogenmod.eleven.utils.MusicUtils.mService;
84 * Provides the search interface for Apollo.
86 * @author Andrew Neal (andrewdneal@gmail.com)
88 public class SearchActivity extends FragmentActivity implements
89 LoaderCallbacks<SectionListContainer<SearchResult>>,
90 OnScrollListener, OnQueryTextListener, OnItemClickListener, ServiceConnection,
93 * Loading delay of 500ms so we don't flash the screen too much when loading new searches
95 private static int LOADING_DELAY = 500;
98 * Identifier for the search loader
100 private static int SEARCH_LOADER = 0;
103 * Identifier for the search history loader
105 private static int HISTORY_LOADER = 1;
110 private ServiceToken mToken;
115 private String mFilterString;
120 private ListView mListView;
123 * Used the filter the user's music
125 private SearchView mSearchView;
130 private InputMethodManager mImm;
133 * The view that container the no search results text and the loading progress bar
135 private LoadingEmptyContainer mLoadingEmptyContainer;
140 private SectionAdapter<SearchResult, SummarySearchAdapter> mAdapter;
143 * boolean tracking whether this is the search level when the user first enters search
144 * or if the user has clicked show all
146 private boolean mTopLevelSearch;
149 * If the user has clicked show all, this tells us what type (Artist, Album, etc)
151 private ResultType mSearchType;
154 * Search History loader callback
156 private SearchHistoryCallback mSearchHistoryCallback;
161 private ListView mSearchHistoryListView;
164 * This tracks our current visible state between the different views
173 private VisibleState mCurrentState;
176 * Handler for posting runnables
178 private Handler mHandler;
181 * A runnable to show the loading view that will be posted with a delay to prevent flashing
183 private Runnable mLoadingRunnable;
186 * Flag used to track if we are quitting so we don't flash loaders while finishing the activity
188 private boolean mQuitting = false;
193 private PopupMenuHelper mPopupMenuHelper;
199 public void onCreate(final Bundle savedInstanceState) {
200 super.onCreate(savedInstanceState);
202 mPopupMenuHelper = new PopupMenuHelper(this, getSupportFragmentManager()) {
203 private SearchResult mSelectedItem;
206 public PopupMenuType onPreparePopupMenu(int position) {
207 mSelectedItem = mAdapter.getTItem(position);
209 return PopupMenuType.SearchResult;
213 protected long[] getIdList() {
214 switch (mSelectedItem.mType) {
216 return MusicUtils.getSongListForArtist(SearchActivity.this,
219 return MusicUtils.getSongListForAlbum(SearchActivity.this,
222 return new long[] { mSelectedItem.mId };
224 return MusicUtils.getSongListForPlaylist(SearchActivity.this,
232 protected long getSourceId() {
233 return mSelectedItem.mId;
237 protected Config.IdType getSourceType() {
238 return mSelectedItem.mType.getSourceType();
242 protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
243 super.updateMenuIds(type, set);
245 if (mSelectedItem.mType == ResultType.Album) {
246 set.add(FragmentMenuItems.MORE_BY_ARTIST);
251 protected String getArtistName() {
252 return mSelectedItem.mArtist;
257 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
259 // Control the media volume
260 setVolumeControlStream(AudioManager.STREAM_MUSIC);
262 // Bind Apollo's service
263 mToken = MusicUtils.bindToService(this, this);
266 setContentView(R.layout.activity_search);
268 // get the input method manager
269 mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
271 // Initialize the adapter
272 SummarySearchAdapter adapter = new SummarySearchAdapter(this);
273 mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter);
275 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
276 mAdapter.setupHeaderParameters(R.layout.list_search_header, false);
277 mAdapter.setupFooterParameters(R.layout.list_search_footer, true);
278 mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
280 public void onPopupMenuClicked(View v, int position) {
281 mPopupMenuHelper.showPopupMenu(v, position);
285 mLoadingEmptyContainer = (LoadingEmptyContainer) findViewById(R.id.loading_empty_container);
286 // setup the no results container
287 NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer();
288 noResults.setMainText(R.string.empty_search);
289 noResults.setSecondaryText(R.string.empty_search_check);
293 // setup handler and runnable
294 mHandler = new Handler();
295 mLoadingRunnable = new Runnable() {
298 setState(VisibleState.Loading);
302 // Theme the action bar
303 final ActionBar actionBar = getActionBar();
304 actionBar.setDisplayHomeAsUpEnabled(true);
306 // Get the query String
307 mFilterString = getIntent().getStringExtra(SearchManager.QUERY);
309 // if we have a non-empty search string, this is a 2nd lvl search
310 if (!TextUtils.isEmpty(mFilterString)) {
311 mTopLevelSearch = false;
313 // get the search type to filter by
314 int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1);
315 if (type >= 0 && type < ResultType.values().length) {
316 mSearchType = ResultType.values()[type];
320 switch (mSearchType) {
322 resourceId = R.string.search_title_artists;
325 resourceId = R.string.search_title_albums;
328 resourceId = R.string.search_title_playlists;
331 resourceId = R.string.search_title_songs;
334 actionBar.setTitle(getString(resourceId, mFilterString).toUpperCase());
335 actionBar.setDisplayHomeAsUpEnabled(true);
338 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
340 // Start the loader for the query
341 getSupportLoaderManager().initLoader(SEARCH_LOADER, null, this);
343 mTopLevelSearch = true;
344 mSearchHistoryCallback = new SearchHistoryCallback();
346 // Start the loader for the search history
347 getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback);
352 * Sets up the list view
354 private void initListView() {
355 // Initialize the grid
356 mListView = (ListView)findViewById(R.id.list_base);
357 // Set the data behind the list
358 mListView.setAdapter(mAdapter);
359 // Release any references to the recycled Views
360 mListView.setRecyclerListener(new RecycleHolder());
361 // Show the albums and songs from the selected artist
362 mListView.setOnItemClickListener(this);
363 // To help make scrolling smooth
364 mListView.setOnScrollListener(this);
365 // sets the touch listener
366 mListView.setOnTouchListener(this);
367 // If we setEmptyView with mLoadingEmptyContainer it causes a crash in DragSortListView
368 // when updating the search. For now let's manually toggle visibility and come back
370 //mListView.setEmptyView(mLoadingEmptyContainer);
372 // load the search history list view
373 mSearchHistoryListView = (ListView)findViewById(R.id.list_search_history);
374 mSearchHistoryListView.setOnItemClickListener(new OnItemClickListener() {
376 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
377 String searchItem = (String)mSearchHistoryListView.getAdapter().getItem(position);
378 mSearchView.setQuery(searchItem, true);
381 mSearchHistoryListView.setOnTouchListener(this);
388 public Loader<SectionListContainer<SearchResult>> onCreateLoader(final int id,
390 IItemCompare<SearchResult> comparator = null;
392 // prep the loader in case the query takes a long time
395 // if we are at the top level, create a comparator to separate the different types into
396 // their own sections (artists, albums, etc)
397 if (mTopLevelSearch) {
398 comparator = SectionCreatorUtils.createSearchResultComparison(this);
401 return new SectionCreator<SearchResult>(this,
402 new SummarySearchLoader(this, mFilterString, mSearchType),
410 public boolean onCreateOptionsMenu(final Menu menu) {
411 // if we are not a top level search view, we do not need to create the search fields
412 if (!mTopLevelSearch) {
413 return super.onCreateOptionsMenu(menu);
417 getMenuInflater().inflate(R.menu.search, menu);
419 // Filter the list the user is looking it via SearchView
420 MenuItem searchItem = menu.findItem(R.id.menu_search);
421 mSearchView = (SearchView)searchItem.getActionView();
422 mSearchView.setOnQueryTextListener(this);
423 mSearchView.setQueryHint(getString(R.string.searchHint).toUpperCase());
425 // The SearchView has no way for you to customize or get access to the search icon in a
426 // normal fashion, so we need to manually look for the icon and change the
427 // layout params to hide it
428 mSearchView.setIconifiedByDefault(false);
429 mSearchView.setIconified(false);
430 int searchButtonId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
431 ImageView searchIcon = (ImageView)mSearchView.findViewById(searchButtonId);
432 searchIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
434 searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
436 public boolean onMenuItemActionExpand(MenuItem item) {
441 public boolean onMenuItemActionCollapse(MenuItem item) {
447 menu.findItem(R.id.menu_search).expandActionView();
449 return super.onCreateOptionsMenu(menu);
452 private void quit() {
461 protected void onDestroy() {
463 // Unbind from the service
464 if (mService != null) {
465 MusicUtils.unbindFromService(mToken);
474 public boolean onOptionsItemSelected(final MenuItem item) {
475 switch (item.getItemId()) {
476 case android.R.id.home:
482 return super.onOptionsItemSelected(item);
489 public void onLoadFinished(final Loader<SectionListContainer<SearchResult>> loader,
490 final SectionListContainer<SearchResult> data) {
491 // Check for any errors
492 if (data.mListResults.isEmpty()) {
495 // show the empty state
496 setState(VisibleState.Empty);
499 mAdapter.setData(data);
500 // show the search results
501 setState(VisibleState.SearchResults);
509 public void onLoaderReset(final Loader<SectionListContainer<SearchResult>> loader) {
517 public void onScrollStateChanged(final AbsListView view, final int scrollState) {
518 // Pause disk cache access to ensure smoother scrolling
519 if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
520 mAdapter.getUnderlyingAdapter().setPauseDiskCache(true);
522 mAdapter.getUnderlyingAdapter().setPauseDiskCache(false);
523 mAdapter.notifyDataSetChanged();
531 public boolean onQueryTextSubmit(final String query) {
532 // simulate an on query text change
533 onQueryTextChange(query);
534 // hide the input manager
540 public void hideInputManager() {
541 // When the search is "committed" by the user, then hide the keyboard so
542 // the user can more easily browse the list of results.
543 if (mSearchView != null) {
545 mImm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
547 mSearchView.clearFocus();
549 // add our search string
550 SearchHistory.getInstance(this).addSearchString(mFilterString);
555 * This posts a delayed for showing the loading screen. The reason for the delayed is we
556 * don't want to flash the loading icon very often since searches usually are pretty fast
558 public void setLoading() {
559 if (mCurrentState != VisibleState.Loading) {
560 if (!mHandler.hasCallbacks(mLoadingRunnable)) {
561 mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
567 * Sets the currently visible view
568 * @param state the current visible state
570 public void setState(VisibleState state) {
571 // remove any delayed runnables. This has to be before mCurrentState == state
572 // in case the state doesn't change but we've created a loading runnable
573 mHandler.removeCallbacks(mLoadingRunnable);
575 // if we are already looking at view already, just quit
576 if (mCurrentState == state) {
580 mCurrentState = state;
582 mSearchHistoryListView.setVisibility(View.INVISIBLE);
583 mListView.setVisibility(View.INVISIBLE);
584 mLoadingEmptyContainer.setVisibility(View.INVISIBLE);
586 switch (mCurrentState) {
588 mSearchHistoryListView.setVisibility(View.VISIBLE);
591 mListView.setVisibility(View.VISIBLE);
594 mLoadingEmptyContainer.setVisibility(View.VISIBLE);
595 mLoadingEmptyContainer.showNoResults();
598 mLoadingEmptyContainer.setVisibility(View.VISIBLE);
599 mLoadingEmptyContainer.showLoading();
608 public boolean onQueryTextChange(final String newText) {
613 if (TextUtils.isEmpty(newText)) {
614 if (!TextUtils.isEmpty(mFilterString)) {
616 getSupportLoaderManager().restartLoader(HISTORY_LOADER, null,
617 mSearchHistoryCallback);
618 getSupportLoaderManager().destroyLoader(SEARCH_LOADER);
624 // if the strings are the same, return
625 if (newText.equals(mFilterString)) {
629 // Called when the action bar search text has changed. Update
630 // the search filter, and restart the loader to do a new query
632 mFilterString = newText;
634 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
635 getSupportLoaderManager().restartLoader(SEARCH_LOADER, null, this);
636 getSupportLoaderManager().destroyLoader(HISTORY_LOADER);
644 public void onItemClick(final AdapterView<?> parent, final View view, final int position,
646 if (mAdapter.isSectionFooter(position)) {
647 // since a footer should be after a list item by definition, let's look up the type
648 // of the previous item
649 SearchResult item = mAdapter.getTItem(position - 1);
650 Intent intent = new Intent(this, SearchActivity.class);
651 intent.putExtra(SearchManager.QUERY, mFilterString);
652 intent.putExtra(SearchManager.SEARCH_MODE, item.mType.ordinal());
653 startActivity(intent);
655 SearchResult item = mAdapter.getTItem(position);
656 switch (item.mType) {
658 NavUtils.openArtistProfile(this, item.mArtist);
661 NavUtils.openAlbumProfile(this, item.mAlbum, item.mArtist, item.mId);
664 NavUtils.openPlaylist(this, item.mId, item.mTitle);
667 // If it's a song, play it and leave
668 final long[] list = new long[]{
671 MusicUtils.playAll(this, list, 0, -1, Config.IdType.NA, false);
681 public void onServiceConnected(final ComponentName name, final IBinder service) {
682 mService = IElevenService.Stub.asInterface(service);
689 public void onServiceDisconnected(final ComponentName name) {
694 * This class loads a search result summary of items
696 private static final class SummarySearchLoader extends SimpleListLoader<SearchResult> {
697 private final String mQuery;
698 private final ResultType mSearchType;
700 public SummarySearchLoader(final Context context, final String query,
701 final ResultType searchType) {
704 mSearchType = searchType;
708 * This creates a search result given the data at the cursor position
709 * @param cursor at the position for the item
710 * @param type the type of item to create
711 * @return the search result
713 protected SearchResult createSearchResult(final Cursor cursor, ResultType type) {
714 SearchResult item = null;
718 item = SearchResult.createPlaylistResult(cursor);
719 item.mSongCount = MusicUtils.getSongCountForPlaylist(getContext(), item.mId);
722 item = SearchResult.createSearchResult(cursor);
724 AlbumArtistDetails details = MusicUtils.getAlbumArtDetails(getContext(),
726 if (details != null) {
727 item.mArtist = details.mArtistName;
728 item.mAlbum = details.mAlbumName;
729 item.mAlbumId = details.mAlbumId;
736 item = SearchResult.createSearchResult(cursor);
744 public List<SearchResult> loadInBackground() {
745 // if we are doing a specific type search, run that one
746 if (mSearchType != null && mSearchType != ResultType.Unknown) {
747 return runSearchForType();
750 return runGenericSearch();
754 * This creates a search for a specific type given a filter string. This will return the
755 * full list of results that matches those two requirements
756 * @return the results for that search
758 protected List<SearchResult> runSearchForType() {
759 ArrayList<SearchResult> results = new ArrayList<SearchResult>();
760 Cursor cursor = null;
762 if (mSearchType == ResultType.Playlist) {
763 cursor = makePlaylistSearchCursor(getContext(), mQuery);
765 cursor = ApolloUtils.createSearchQueryCursor(getContext(), mQuery);
768 // pre-cache this index
769 final int mimeTypeIndex = cursor.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE);
771 if (cursor != null && cursor.moveToFirst()) {
773 boolean addResult = true;
775 if (mSearchType != ResultType.Playlist) {
776 // get the result type
777 ResultType type = ResultType.getResultType(cursor, mimeTypeIndex);
778 if (type != mSearchType) {
784 results.add(createSearchResult(cursor, mSearchType));
786 } while (cursor.moveToNext());
790 if (cursor != null) {
800 * This will run a search given a filter string and return the top NUM_RESULTS_TO_GET per
802 * @return the results for that search
804 public List<SearchResult> runGenericSearch() {
805 ArrayList<SearchResult> results = new ArrayList<SearchResult>();
806 // number of types to query for
807 final int numTypes = ResultType.getNumTypes();
809 // number of results we want
810 final int numResultsNeeded = Config.SEARCH_NUM_RESULTS_TO_GET * numTypes;
812 // current number of results we have
813 int numResultsAdded = 0;
815 // count for each result type
816 int[] numOfEachType = new int[numTypes];
818 // search playlists first
819 Cursor playlistCursor = makePlaylistSearchCursor(getContext(), mQuery);
820 if (playlistCursor != null && playlistCursor.moveToFirst()) {
823 SearchResult item = createSearchResult(playlistCursor, ResultType.Playlist);
827 } while (playlistCursor.moveToNext()
828 && numResultsAdded < Config.SEARCH_NUM_RESULTS_TO_GET);
830 // because we deal with playlists separately,
831 // just mark that we have the full # of playlists
832 // so that logic later can quit out early if full
833 numResultsAdded = Config.SEARCH_NUM_RESULTS_TO_GET;
836 playlistCursor.close();
837 playlistCursor = null;
840 // do fancy audio search
841 Cursor cursor = ApolloUtils.createSearchQueryCursor(getContext(), mQuery);
843 // pre-cache this index
844 final int mimeTypeIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE);
846 // walk through the cursor
847 if (cursor != null && cursor.moveToFirst()) {
849 // get the result type
850 ResultType type = ResultType.getResultType(cursor, mimeTypeIndex);
852 // if we still need this type
853 if (numOfEachType[type.ordinal()] < Config.SEARCH_NUM_RESULTS_TO_GET) {
854 // get the search result
855 SearchResult item = createSearchResult(cursor, type);
860 numOfEachType[type.ordinal()]++;
863 // if we have enough then quit
864 if (numResultsAdded >= numResultsNeeded) {
869 } while (cursor.moveToNext());
876 Collections.sort(results, SearchResult.COMPARATOR);
881 public static Cursor makePlaylistSearchCursor(final Context context,
882 final String searchTerms) {
883 if (TextUtils.isEmpty(searchTerms)) {
887 // trim out special characters like % or \ as well as things like "a" "and" etc
888 String trimmedSearchTerms = MusicUtils.getTrimmedName(searchTerms);
890 if (TextUtils.isEmpty(trimmedSearchTerms)) {
894 String[] keywords = trimmedSearchTerms.split(" ");
896 // prep the keyword for like search
897 for (int i = 0; i < keywords.length; i++) {
898 keywords[i] = "%" + keywords[i] + "%";
903 // make the where clause
904 for (int i = 0; i < keywords.length; i++) {
906 where = "name LIKE ?";
908 where += " AND name LIKE ?";
912 return context.getContentResolver().query(
913 MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
918 MediaStore.Audio.PlaylistsColumns.NAME
919 }, where, keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
924 * Loads the search history in the background and creates an array adapter
926 public static class SearchHistoryLoader extends WrappedAsyncTaskLoader<ArrayAdapter<String>> {
927 public SearchHistoryLoader(Context context) {
932 public ArrayAdapter<String> loadInBackground() {
933 ArrayList<String> strings = SearchHistory.getInstance(getContext()).getRecentSearches();
934 ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
935 R.layout.list_item_search_history, R.id.line_one);
936 adapter.addAll(strings);
942 * This handles the Loader callbacks for the search history
944 public class SearchHistoryCallback implements LoaderCallbacks<ArrayAdapter<String>> {
946 public Loader<ArrayAdapter<String>> onCreateLoader(int i, Bundle bundle) {
947 // prep the loader in case the query takes a long time
950 return new SearchHistoryLoader(SearchActivity.this);
954 public void onLoadFinished(Loader<ArrayAdapter<String>> searchHistoryAdapterLoader,
955 ArrayAdapter<String> searchHistoryAdapter) {
956 // show the search history
957 setState(VisibleState.SearchHistory);
959 mSearchHistoryListView.setAdapter(searchHistoryAdapter);
963 public void onLoaderReset(Loader<ArrayAdapter<String>> cursorAdapterLoader) {
964 ((ArrayAdapter)mSearchHistoryListView.getAdapter()).clear();
972 public void onScroll(final AbsListView view, final int firstVisibleItem,
973 final int visibleItemCount, final int totalItemCount) {
978 public boolean onTouch(View v, MotionEvent event) {