From b2a1b4aec0e1e3d5fb96401fe41bc27547817748 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Thu, 16 Aug 2012 21:45:49 +0200 Subject: [PATCH] Add search functionality * AndroidManifest.xml: Register `DVDroidActivity' as searchable. * res/drawable-hdpi/menu_search.png: * res/drawable-mdpi/menu_search.png: New icons. * res/menu/main_activity.xml: Add a search icon to the main activity's action menu. * res/values/strings.xml: Add strings "search_hint" and "menu_search". * res/xml/searchable.xml: New configuration file. * src/ryuslash/org/dvdroid/DVDDataSource.java (getQuery): New function. * src/ryuslash/org/dvdroid/DVDroidActivity.java (getData): New overload, calls `getQuery' to search for something instead of everything. (onCreate): If a search has been started, search, don't just show everything. (onCreateOptionsMenu): Instantiate the `SearchView' in order to use it. --- AndroidManifest.xml | 3 +++ res/drawable-hdpi/menu_search.png | Bin 0 -> 1764 bytes res/drawable-mdpi/menu_search.png | Bin 0 -> 1394 bytes res/menu/main_activity.xml | 5 ++++ res/values/strings.xml | 2 ++ res/xml/searchable.xml | 5 ++++ src/ryuslash/org/dvdroid/DVDDataSource.java | 9 +++++++ src/ryuslash/org/dvdroid/DVDroidActivity.java | 22 +++++++++++++++++- 8 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 res/drawable-hdpi/menu_search.png create mode 100644 res/drawable-mdpi/menu_search.png create mode 100644 res/xml/searchable.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 9def811..83fd0c0 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -10,7 +10,10 @@ + + diff --git a/res/drawable-hdpi/menu_search.png b/res/drawable-hdpi/menu_search.png new file mode 100644 index 0000000000000000000000000000000000000000..f12e005ebe835c1dd2f6ae324224c3ee296d2d68 GIT binary patch literal 1764 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWuD@%qp275hW46K32*3xq68pHF_1f1wh>l3^w)^1&PVosU-?Y zsp*+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P zSBG=VuX=ZVUZK&Y$p$gc*{*!{ocg_ + diff --git a/res/values/strings.xml b/res/values/strings.xml index 0a4ee4d..f0269f5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,6 +1,8 @@ DVDroid + Search DVDs + Search Title... On wishlist Watched diff --git a/res/xml/searchable.xml b/res/xml/searchable.xml new file mode 100644 index 0000000..f0f4ef2 --- /dev/null +++ b/res/xml/searchable.xml @@ -0,0 +1,5 @@ + + + diff --git a/src/ryuslash/org/dvdroid/DVDDataSource.java b/src/ryuslash/org/dvdroid/DVDDataSource.java index e10fb24..7bfa92a 100644 --- a/src/ryuslash/org/dvdroid/DVDDataSource.java +++ b/src/ryuslash/org/dvdroid/DVDDataSource.java @@ -142,6 +142,15 @@ public class DVDDataSource return getListFromCursor(cursor); } + public List getQuery(String query) + { + String params[] = { "%" + query + "%" }; + Cursor cursor = database.query(SQLiteHelper.TABLE_DVD, + allColumns, "title LIKE ?", + params, null, null, "title"); + return getListFromCursor(cursor); + } + private DVD cursorToDVD(Cursor cursor) { DVD dvd = new DVD(); diff --git a/src/ryuslash/org/dvdroid/DVDroidActivity.java b/src/ryuslash/org/dvdroid/DVDroidActivity.java index 07fe1fb..ca65f13 100644 --- a/src/ryuslash/org/dvdroid/DVDroidActivity.java +++ b/src/ryuslash/org/dvdroid/DVDroidActivity.java @@ -3,6 +3,7 @@ package ryuslash.org.dvdroid; import java.util.List; import android.app.ListActivity; +import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -14,6 +15,7 @@ import android.view.View; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.SearchView; public class DVDroidActivity extends ListActivity implements ActionMode.Callback @@ -28,6 +30,11 @@ public class DVDroidActivity extends ListActivity return datasource.getCollection(); } + private List getData(String query) + { + return datasource.getQuery(query); + } + @Override protected void onActivityResult(int requestCode, int resultCode, @@ -80,7 +87,14 @@ public class DVDroidActivity extends ListActivity datasource = new DVDDataSource(this); datasource.open(); - List values = getData(); + Intent intent = getIntent(); + List values; + + if (Intent.ACTION_SEARCH.equals(intent.getAction())) { + values = getData(intent.getStringExtra(SearchManager.QUERY)); + } else { + values = getData(); + } ArrayAdapter adapter = new ArrayAdapter(this, @@ -104,6 +118,12 @@ public class DVDroidActivity extends ListActivity { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity, menu); + + // Get the SearchView and set the searchable configuration. + SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); + SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + return true; }