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 0000000..f12e005 Binary files /dev/null and b/res/drawable-hdpi/menu_search.png differ diff --git a/res/drawable-mdpi/menu_search.png b/res/drawable-mdpi/menu_search.png new file mode 100644 index 0000000..587d9e0 Binary files /dev/null and b/res/drawable-mdpi/menu_search.png differ diff --git a/res/menu/main_activity.xml b/res/menu/main_activity.xml index d2f94bd..ddb7d7a 100644 --- a/res/menu/main_activity.xml +++ b/res/menu/main_activity.xml @@ -4,4 +4,9 @@ android:title="@string/main_menu_add" android:showAsAction="ifRoom|withText" android:icon="@drawable/add" /> + 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; }