2 * Copyright (C) 2012 Andrew Neal Licensed under the Apache License, Version 2.0
3 * (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at
5 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
6 * or agreed to in writing, software distributed under the License is
7 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the specific language
9 * governing permissions and limitations under the License.
12 package com.cyngn.eleven.ui.activities;
14 import android.app.ActionBar;
15 import android.app.SearchManager;
16 import android.content.ComponentName;
17 import android.content.Context;
18 import android.content.Intent;
19 import android.content.ServiceConnection;
20 import android.database.Cursor;
21 import android.media.AudioManager;
22 import android.os.Bundle;
23 import android.os.Handler;
24 import android.os.IBinder;
25 import android.provider.BaseColumns;
26 import android.provider.MediaStore;
27 import android.support.v4.app.FragmentActivity;
28 import android.support.v4.app.LoaderManager.LoaderCallbacks;
29 import android.support.v4.content.Loader;
30 import android.text.TextUtils;
31 import android.view.Menu;
32 import android.view.MenuItem;
33 import android.view.MotionEvent;
34 import android.view.View;
35 import android.view.inputmethod.InputMethodManager;
36 import android.widget.AbsListView;
37 import android.widget.AbsListView.OnScrollListener;
38 import android.widget.AdapterView;
39 import android.widget.AdapterView.OnItemClickListener;
40 import android.widget.ArrayAdapter;
41 import android.widget.ImageView;
42 import android.widget.LinearLayout;
43 import android.widget.ListView;
44 import android.widget.SearchView;
45 import android.widget.SearchView.OnQueryTextListener;
47 import com.cyngn.eleven.Config;
48 import com.cyngn.eleven.IElevenService;
49 import com.cyngn.eleven.R;
50 import com.cyngn.eleven.adapters.SummarySearchAdapter;
51 import com.cyngn.eleven.loaders.WrappedAsyncTaskLoader;
52 import com.cyngn.eleven.menu.FragmentMenuItems;
53 import com.cyngn.eleven.model.AlbumArtistDetails;
54 import com.cyngn.eleven.model.SearchResult;
55 import com.cyngn.eleven.model.SearchResult.ResultType;
56 import com.cyngn.eleven.provider.SearchHistory;
57 import com.cyngn.eleven.recycler.RecycleHolder;
58 import com.cyngn.eleven.sectionadapter.SectionAdapter;
59 import com.cyngn.eleven.sectionadapter.SectionCreator;
60 import com.cyngn.eleven.sectionadapter.SectionCreator.SimpleListLoader;
61 import com.cyngn.eleven.sectionadapter.SectionListContainer;
62 import com.cyngn.eleven.utils.ApolloUtils;
63 import com.cyngn.eleven.utils.MusicUtils;
64 import com.cyngn.eleven.utils.MusicUtils.ServiceToken;
65 import com.cyngn.eleven.utils.NavUtils;
66 import com.cyngn.eleven.utils.PopupMenuHelper;
67 import com.cyngn.eleven.utils.SectionCreatorUtils;
68 import com.cyngn.eleven.utils.SectionCreatorUtils.IItemCompare;
69 import com.cyngn.eleven.widgets.IPopupMenuCallback;
70 import com.cyngn.eleven.widgets.LoadingEmptyContainer;
71 import com.cyngn.eleven.widgets.NoResultsContainer;
73 import java.util.ArrayList;
74 import java.util.Collections;
75 import java.util.List;
76 import java.util.TreeSet;
78 import static android.view.View.OnTouchListener;
79 import static com.cyngn.eleven.utils.MusicUtils.mService;
82 * Provides the search interface for Apollo.
84 * @author Andrew Neal (andrewdneal@gmail.com)
86 public class SearchActivity extends FragmentActivity implements
87 LoaderCallbacks<SectionListContainer<SearchResult>>,
88 OnScrollListener, OnQueryTextListener, OnItemClickListener, ServiceConnection,
91 * Loading delay of 500ms so we don't flash the screen too much when loading new searches
93 private static int LOADING_DELAY = 500;
96 * Identifier for the search loader
98 private static int SEARCH_LOADER = 0;
101 * Identifier for the search history loader
103 private static int HISTORY_LOADER = 1;
108 private ServiceToken mToken;
113 private String mFilterString;
118 private ListView mListView;
121 * Used the filter the user's music
123 private SearchView mSearchView;
128 private InputMethodManager mImm;
131 * The view that container the no search results text and the loading progress bar
133 private LoadingEmptyContainer mLoadingEmptyContainer;
138 private SectionAdapter<SearchResult, SummarySearchAdapter> mAdapter;
141 * boolean tracking whether this is the search level when the user first enters search
142 * or if the user has clicked show all
144 private boolean mTopLevelSearch;
147 * If the user has clicked show all, this tells us what type (Artist, Album, etc)
149 private ResultType mSearchType;
152 * Search History loader callback
154 private SearchHistoryCallback mSearchHistoryCallback;
159 private ListView mSearchHistoryListView;
162 * This tracks our current visible state between the different views
171 private VisibleState mCurrentState;
174 * Handler for posting runnables
176 private Handler mHandler;
179 * A runnable to show the loading view that will be posted with a delay to prevent flashing
181 private Runnable mLoadingRunnable;
184 * Flag used to track if we are quitting so we don't flash loaders while finishing the activity
186 private boolean mQuitting = false;
191 private PopupMenuHelper mPopupMenuHelper;
197 public void onCreate(final Bundle savedInstanceState) {
198 super.onCreate(savedInstanceState);
200 mPopupMenuHelper = new PopupMenuHelper(this, getSupportFragmentManager()) {
201 private SearchResult mSelectedItem;
204 public PopupMenuType onPreparePopupMenu(int position) {
205 mSelectedItem = mAdapter.getTItem(position);
207 return PopupMenuType.SearchResult;
211 protected long[] getIdList() {
212 switch (mSelectedItem.mType) {
214 return MusicUtils.getSongListForArtist(SearchActivity.this,
217 return MusicUtils.getSongListForAlbum(SearchActivity.this,
220 return new long[] { mSelectedItem.mId };
222 return MusicUtils.getSongListForPlaylist(SearchActivity.this,
230 protected long getSourceId() {
231 return mSelectedItem.mId;
235 protected Config.IdType getSourceType() {
236 return mSelectedItem.mType.getSourceType();
240 protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
241 super.updateMenuIds(type, set);
243 if (mSelectedItem.mType == ResultType.Album) {
244 set.add(FragmentMenuItems.MORE_BY_ARTIST);
249 protected String getArtistName() {
250 return mSelectedItem.mArtist;
255 overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
257 // Control the media volume
258 setVolumeControlStream(AudioManager.STREAM_MUSIC);
260 // Bind Apollo's service
261 mToken = MusicUtils.bindToService(this, this);
264 setContentView(R.layout.activity_search);
266 // get the input method manager
267 mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
269 // Initialize the adapter
270 SummarySearchAdapter adapter = new SummarySearchAdapter(this);
271 mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter);
273 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
274 mAdapter.setupHeaderParameters(R.layout.list_search_header, false);
275 mAdapter.setupFooterParameters(R.layout.list_search_footer, true);
276 mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
278 public void onPopupMenuClicked(View v, int position) {
279 mPopupMenuHelper.showPopupMenu(v, position);
283 mLoadingEmptyContainer = (LoadingEmptyContainer) findViewById(R.id.loading_empty_container);
284 // setup the no results container
285 NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer();
286 noResults.setMainText(R.string.empty_search);
287 noResults.setSecondaryText(R.string.empty_search_check);
291 // setup handler and runnable
292 mHandler = new Handler();
293 mLoadingRunnable = new Runnable() {
296 setState(VisibleState.Loading);
300 // Theme the action bar
301 final ActionBar actionBar = getActionBar();
302 actionBar.setHomeButtonEnabled(true);
303 actionBar.setIcon(R.drawable.ic_action_search);
305 // Get the query String
306 mFilterString = getIntent().getStringExtra(SearchManager.QUERY);
308 // if we have a non-empty search string, this is a 2nd lvl search
309 if (!TextUtils.isEmpty(mFilterString)) {
310 mTopLevelSearch = false;
312 // get the search type to filter by
313 int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1);
314 if (type >= 0 && type < ResultType.values().length) {
315 mSearchType = ResultType.values()[type];
319 switch (mSearchType) {
321 resourceId = R.string.search_title_artists;
324 resourceId = R.string.search_title_albums;
327 resourceId = R.string.search_title_playlists;
330 resourceId = R.string.search_title_songs;
333 actionBar.setTitle(getString(resourceId, mFilterString).toUpperCase());
334 actionBar.setDisplayHomeAsUpEnabled(true);
337 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
339 // Start the loader for the query
340 getSupportLoaderManager().initLoader(SEARCH_LOADER, null, this);
342 mTopLevelSearch = true;
343 mSearchHistoryCallback = new SearchHistoryCallback();
345 // Start the loader for the search history
346 getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback);
349 // set the background on the root view
350 getWindow().getDecorView().getRootView().setBackgroundColor(
351 getResources().getColor(R.color.background_color));
355 * Sets up the list view
357 private void initListView() {
358 // Initialize the grid
359 mListView = (ListView)findViewById(R.id.list_base);
360 // Set the data behind the list
361 mListView.setAdapter(mAdapter);
362 // Release any references to the recycled Views
363 mListView.setRecyclerListener(new RecycleHolder());
364 // Show the albums and songs from the selected artist
365 mListView.setOnItemClickListener(this);
366 // To help make scrolling smooth
367 mListView.setOnScrollListener(this);
368 // sets the touch listener
369 mListView.setOnTouchListener(this);
370 // If we setEmptyView with mLoadingEmptyContainer it causes a crash in DragSortListView
371 // when updating the search. For now let's manually toggle visibility and come back
373 //mListView.setEmptyView(mLoadingEmptyContainer);
375 // load the search history list view
376 mSearchHistoryListView = (ListView)findViewById(R.id.list_search_history);
377 mSearchHistoryListView.setOnItemClickListener(new OnItemClickListener() {
379 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
380 String searchItem = (String)mSearchHistoryListView.getAdapter().getItem(position);
381 mSearchView.setQuery(searchItem, true);
384 mSearchHistoryListView.setOnTouchListener(this);
391 public Loader<SectionListContainer<SearchResult>> onCreateLoader(final int id,
393 IItemCompare<SearchResult> comparator = null;
395 // prep the loader in case the query takes a long time
398 // set the no results string ahead of time in case the user changes the string whiel loading
399 NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer();
400 noResults.setMainHighlightText("\"" + mFilterString + "\"");
402 // if we are at the top level, create a comparator to separate the different types into
403 // their own sections (artists, albums, etc)
404 if (mTopLevelSearch) {
405 comparator = SectionCreatorUtils.createSearchResultComparison(this);
408 return new SectionCreator<SearchResult>(this,
409 new SummarySearchLoader(this, mFilterString, mSearchType),
417 public boolean onCreateOptionsMenu(final Menu menu) {
418 // if we are not a top level search view, we do not need to create the search fields
419 if (!mTopLevelSearch) {
420 return super.onCreateOptionsMenu(menu);
424 getMenuInflater().inflate(R.menu.search, menu);
426 // Filter the list the user is looking it via SearchView
427 MenuItem searchItem = menu.findItem(R.id.menu_search);
428 mSearchView = (SearchView)searchItem.getActionView();
429 mSearchView.setOnQueryTextListener(this);
430 mSearchView.setQueryHint(getString(R.string.searchHint).toUpperCase());
432 // The SearchView has no way for you to customize or get access to the search icon in a
433 // normal fashion, so we need to manually look for the icon and change the
434 // layout params to hide it
435 mSearchView.setIconifiedByDefault(false);
436 mSearchView.setIconified(false);
437 int searchButtonId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
438 ImageView searchIcon = (ImageView)mSearchView.findViewById(searchButtonId);
439 searchIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
441 searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
443 public boolean onMenuItemActionExpand(MenuItem item) {
448 public boolean onMenuItemActionCollapse(MenuItem item) {
454 menu.findItem(R.id.menu_search).expandActionView();
456 return super.onCreateOptionsMenu(menu);
459 private void quit() {
468 protected void onStart() {
470 MusicUtils.notifyForegroundStateChanged(this, true);
477 protected void onStop() {
479 MusicUtils.notifyForegroundStateChanged(this, false);
486 protected void onDestroy() {
488 // Unbind from the service
489 if (mService != null) {
490 MusicUtils.unbindFromService(mToken);
499 public boolean onOptionsItemSelected(final MenuItem item) {
500 switch (item.getItemId()) {
501 case android.R.id.home:
507 return super.onOptionsItemSelected(item);
514 public void onLoadFinished(final Loader<SectionListContainer<SearchResult>> loader,
515 final SectionListContainer<SearchResult> data) {
516 // Check for any errors
517 if (data.mListResults.isEmpty()) {
520 // show the empty state
521 setState(VisibleState.Empty);
524 mAdapter.setData(data);
525 // show the search results
526 setState(VisibleState.SearchResults);
534 public void onLoaderReset(final Loader<SectionListContainer<SearchResult>> loader) {
542 public void onScrollStateChanged(final AbsListView view, final int scrollState) {
543 // Pause disk cache access to ensure smoother scrolling
544 if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING
545 || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
546 mAdapter.getUnderlyingAdapter().setPauseDiskCache(true);
548 mAdapter.getUnderlyingAdapter().setPauseDiskCache(false);
549 mAdapter.notifyDataSetChanged();
557 public boolean onQueryTextSubmit(final String query) {
558 // simulate an on query text change
559 onQueryTextChange(query);
560 // hide the input manager
566 public void hideInputManager() {
567 // When the search is "committed" by the user, then hide the keyboard so
568 // the user can more easily browse the list of results.
569 if (mSearchView != null) {
571 mImm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
573 mSearchView.clearFocus();
575 // add our search string
576 SearchHistory.getInstance(this).addSearchString(mFilterString);
581 * This posts a delayed for showing the loading screen. The reason for the delayed is we
582 * don't want to flash the loading icon very often since searches usually are pretty fast
584 public void setLoading() {
585 if (mCurrentState != VisibleState.Loading) {
586 if (!mHandler.hasCallbacks(mLoadingRunnable)) {
587 mHandler.postDelayed(mLoadingRunnable, LOADING_DELAY);
593 * Sets the currently visible view
594 * @param state the current visible state
596 public void setState(VisibleState state) {
597 // remove any delayed runnables. This has to be before mCurrentState == state
598 // in case the state doesn't change but we've created a loading runnable
599 mHandler.removeCallbacks(mLoadingRunnable);
601 // if we are already looking at view already, just quit
602 if (mCurrentState == state) {
606 mCurrentState = state;
608 mSearchHistoryListView.setVisibility(View.INVISIBLE);
609 mListView.setVisibility(View.INVISIBLE);
610 mLoadingEmptyContainer.setVisibility(View.INVISIBLE);
612 switch (mCurrentState) {
614 mSearchHistoryListView.setVisibility(View.VISIBLE);
617 mListView.setVisibility(View.VISIBLE);
620 mLoadingEmptyContainer.setVisibility(View.VISIBLE);
621 mLoadingEmptyContainer.showNoResults();
624 mLoadingEmptyContainer.setVisibility(View.VISIBLE);
625 mLoadingEmptyContainer.showLoading();
634 public boolean onQueryTextChange(final String newText) {
639 if (TextUtils.isEmpty(newText)) {
640 if (!TextUtils.isEmpty(mFilterString)) {
642 getSupportLoaderManager().restartLoader(HISTORY_LOADER, null,
643 mSearchHistoryCallback);
644 getSupportLoaderManager().destroyLoader(SEARCH_LOADER);
650 // if the strings are the same, return
651 if (newText.equals(mFilterString)) {
655 // Called when the action bar search text has changed. Update
656 // the search filter, and restart the loader to do a new query
658 mFilterString = newText;
660 mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
661 getSupportLoaderManager().restartLoader(SEARCH_LOADER, null, this);
662 getSupportLoaderManager().destroyLoader(HISTORY_LOADER);
670 public void onItemClick(final AdapterView<?> parent, final View view, final int position,
672 if (mAdapter.isSectionFooter(position)) {
673 // since a footer should be after a list item by definition, let's look up the type
674 // of the previous item
675 SearchResult item = mAdapter.getTItem(position - 1);
676 Intent intent = new Intent(this, SearchActivity.class);
677 intent.putExtra(SearchManager.QUERY, mFilterString);
678 intent.putExtra(SearchManager.SEARCH_MODE, item.mType.ordinal());
679 startActivity(intent);
681 SearchResult item = mAdapter.getTItem(position);
682 switch (item.mType) {
684 NavUtils.openArtistProfile(this, item.mArtist);
687 NavUtils.openAlbumProfile(this, item.mAlbum, item.mArtist, item.mId);
690 NavUtils.openPlaylist(this, item.mId, item.mTitle);
693 // If it's a song, play it and leave
694 final long[] list = new long[]{
697 MusicUtils.playAll(this, list, 0, -1, Config.IdType.NA, false);
707 public void onServiceConnected(final ComponentName name, final IBinder service) {
708 mService = IElevenService.Stub.asInterface(service);
715 public void onServiceDisconnected(final ComponentName name) {
720 * This class loads a search result summary of items
722 private static final class SummarySearchLoader extends SimpleListLoader<SearchResult> {
723 private final String mQuery;
724 private final ResultType mSearchType;
726 public SummarySearchLoader(final Context context, final String query,
727 final ResultType searchType) {
730 mSearchType = searchType;
734 * This creates a search result given the data at the cursor position
735 * @param cursor at the position for the item
736 * @param type the type of item to create
737 * @return the search result
739 protected SearchResult createSearchResult(final Cursor cursor, ResultType type) {
740 SearchResult item = null;
744 item = SearchResult.createPlaylistResult(cursor);
745 item.mSongCount = MusicUtils.getSongCountForPlaylist(getContext(), item.mId);
748 item = SearchResult.createSearchResult(cursor);
750 AlbumArtistDetails details = MusicUtils.getAlbumArtDetails(getContext(),
752 if (details != null) {
753 item.mArtist = details.mArtistName;
754 item.mAlbum = details.mAlbumName;
755 item.mAlbumId = details.mAlbumId;
762 item = SearchResult.createSearchResult(cursor);
770 public List<SearchResult> loadInBackground() {
771 // if we are doing a specific type search, run that one
772 if (mSearchType != null && mSearchType != ResultType.Unknown) {
773 return runSearchForType();
776 return runGenericSearch();
780 * This creates a search for a specific type given a filter string. This will return the
781 * full list of results that matches those two requirements
782 * @return the results for that search
784 protected List<SearchResult> runSearchForType() {
785 ArrayList<SearchResult> results = new ArrayList<SearchResult>();
786 Cursor cursor = null;
788 if (mSearchType == ResultType.Playlist) {
789 cursor = makePlaylistSearchCursor(getContext(), mQuery);
791 cursor = ApolloUtils.createSearchQueryCursor(getContext(), mQuery);
794 // pre-cache this index
795 final int mimeTypeIndex = cursor.getColumnIndex(MediaStore.Audio.Media.MIME_TYPE);
797 if (cursor != null && cursor.moveToFirst()) {
799 boolean addResult = true;
801 if (mSearchType != ResultType.Playlist) {
802 // get the result type
803 ResultType type = ResultType.getResultType(cursor, mimeTypeIndex);
804 if (type != mSearchType) {
810 results.add(createSearchResult(cursor, mSearchType));
812 } while (cursor.moveToNext());
816 if (cursor != null) {
826 * This will run a search given a filter string and return the top NUM_RESULTS_TO_GET per
828 * @return the results for that search
830 public List<SearchResult> runGenericSearch() {
831 ArrayList<SearchResult> results = new ArrayList<SearchResult>();
832 // number of types to query for
833 final int numTypes = ResultType.getNumTypes();
835 // number of results we want
836 final int numResultsNeeded = Config.SEARCH_NUM_RESULTS_TO_GET * numTypes;
838 // current number of results we have
839 int numResultsAdded = 0;
841 // count for each result type
842 int[] numOfEachType = new int[numTypes];
844 // search playlists first
845 Cursor playlistCursor = makePlaylistSearchCursor(getContext(), mQuery);
846 if (playlistCursor != null && playlistCursor.moveToFirst()) {
849 SearchResult item = createSearchResult(playlistCursor, ResultType.Playlist);
853 } while (playlistCursor.moveToNext()
854 && numResultsAdded < Config.SEARCH_NUM_RESULTS_TO_GET);
856 // because we deal with playlists separately,
857 // just mark that we have the full # of playlists
858 // so that logic later can quit out early if full
859 numResultsAdded = Config.SEARCH_NUM_RESULTS_TO_GET;
862 playlistCursor.close();
863 playlistCursor = null;
866 // do fancy audio search
867 Cursor cursor = ApolloUtils.createSearchQueryCursor(getContext(), mQuery);
869 // pre-cache this index
870 final int mimeTypeIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE);
872 // walk through the cursor
873 if (cursor != null && cursor.moveToFirst()) {
875 // get the result type
876 ResultType type = ResultType.getResultType(cursor, mimeTypeIndex);
878 // if we still need this type
879 if (numOfEachType[type.ordinal()] < Config.SEARCH_NUM_RESULTS_TO_GET) {
880 // get the search result
881 SearchResult item = createSearchResult(cursor, type);
886 numOfEachType[type.ordinal()]++;
889 // if we have enough then quit
890 if (numResultsAdded >= numResultsNeeded) {
895 } while (cursor.moveToNext());
902 Collections.sort(results, SearchResult.COMPARATOR);
907 public static Cursor makePlaylistSearchCursor(final Context context,
908 final String searchTerms) {
909 if (TextUtils.isEmpty(searchTerms)) {
913 // trim out special characters like % or \ as well as things like "a" "and" etc
914 String trimmedSearchTerms = MusicUtils.getTrimmedName(searchTerms);
916 if (TextUtils.isEmpty(trimmedSearchTerms)) {
920 String[] keywords = trimmedSearchTerms.split(" ");
922 // prep the keyword for like search
923 for (int i = 0; i < keywords.length; i++) {
924 keywords[i] = "%" + keywords[i] + "%";
929 // make the where clause
930 for (int i = 0; i < keywords.length; i++) {
932 where = "name LIKE ?";
934 where += " AND name LIKE ?";
938 return context.getContentResolver().query(
939 MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
944 MediaStore.Audio.PlaylistsColumns.NAME
945 }, where, keywords, MediaStore.Audio.Playlists.DEFAULT_SORT_ORDER);
950 * Loads the search history in the background and creates an array adapter
952 public static class SearchHistoryLoader extends WrappedAsyncTaskLoader<ArrayAdapter<String>> {
953 public SearchHistoryLoader(Context context) {
958 public ArrayAdapter<String> loadInBackground() {
959 ArrayList<String> strings = SearchHistory.getInstance(getContext()).getRecentSearches();
960 ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
961 R.layout.list_item_search_history, R.id.line_one);
962 adapter.addAll(strings);
968 * This handles the Loader callbacks for the search history
970 public class SearchHistoryCallback implements LoaderCallbacks<ArrayAdapter<String>> {
972 public Loader<ArrayAdapter<String>> onCreateLoader(int i, Bundle bundle) {
973 // prep the loader in case the query takes a long time
976 return new SearchHistoryLoader(SearchActivity.this);
980 public void onLoadFinished(Loader<ArrayAdapter<String>> searchHistoryAdapterLoader,
981 ArrayAdapter<String> searchHistoryAdapter) {
982 // show the search history
983 setState(VisibleState.SearchHistory);
985 mSearchHistoryListView.setAdapter(searchHistoryAdapter);
989 public void onLoaderReset(Loader<ArrayAdapter<String>> cursorAdapterLoader) {
990 ((ArrayAdapter)mSearchHistoryListView.getAdapter()).clear();
998 public void onScroll(final AbsListView view, final int firstVisibleItem,
999 final int visibleItemCount, final int totalItemCount) {
1004 public boolean onTouch(View v, MotionEvent event) {