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.
This commit is contained in:
parent
f30b4fcd3a
commit
b2a1b4aec0
8 changed files with 45 additions and 1 deletions
|
@ -10,7 +10,10 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
<activity android:name="AddDVDActivity" />
|
||||
</application>
|
||||
|
|
BIN
res/drawable-hdpi/menu_search.png
Normal file
BIN
res/drawable-hdpi/menu_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
res/drawable-mdpi/menu_search.png
Normal file
BIN
res/drawable-mdpi/menu_search.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -4,4 +4,9 @@
|
|||
android:title="@string/main_menu_add"
|
||||
android:showAsAction="ifRoom|withText"
|
||||
android:icon="@drawable/add" />
|
||||
<item android:id="@+id/menu_search"
|
||||
android:title="@string/menu_search"
|
||||
android:icon="@drawable/menu_search"
|
||||
android:showAsAction="collapseActionView|ifRoom"
|
||||
android:actionViewClass="android.widget.SearchView" />
|
||||
</menu>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">DVDroid</string>
|
||||
<string name="search_hint">Search DVDs</string>
|
||||
<string name="menu_search">Search</string>
|
||||
<string name="name_entry">Title...</string>
|
||||
<string name="wishlist_entry">On wishlist</string>
|
||||
<string name="watched_entry">Watched</string>
|
||||
|
|
5
res/xml/searchable.xml
Normal file
5
res/xml/searchable.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name"
|
||||
android:hint="@string/search_hint">
|
||||
</searchable>
|
|
@ -142,6 +142,15 @@ public class DVDDataSource
|
|||
return getListFromCursor(cursor);
|
||||
}
|
||||
|
||||
public List<DVD> 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();
|
||||
|
|
|
@ -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<DVD> 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<DVD> values = getData();
|
||||
Intent intent = getIntent();
|
||||
List<DVD> values;
|
||||
|
||||
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
|
||||
values = getData(intent.getStringExtra(SearchManager.QUERY));
|
||||
} else {
|
||||
values = getData();
|
||||
}
|
||||
|
||||
ArrayAdapter<DVD> adapter =
|
||||
new ArrayAdapter<DVD>(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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue