diff --git a/starter-code/ShoppingListWithSearch/.idea/.name b/starter-code/ShoppingListWithSearch/.idea/.name
new file mode 100644
index 0000000..10ee423
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/.name
@@ -0,0 +1 @@
+ShoppingListWithSearch
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/compiler.xml b/starter-code/ShoppingListWithSearch/.idea/compiler.xml
new file mode 100644
index 0000000..96cc43e
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/compiler.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/copyright/profiles_settings.xml b/starter-code/ShoppingListWithSearch/.idea/copyright/profiles_settings.xml
new file mode 100644
index 0000000..e7bedf3
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/dictionaries/ShowMe.xml b/starter-code/ShoppingListWithSearch/.idea/dictionaries/ShowMe.xml
new file mode 100644
index 0000000..02c1c32
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/dictionaries/ShowMe.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/gradle.xml b/starter-code/ShoppingListWithSearch/.idea/gradle.xml
new file mode 100644
index 0000000..39139a6
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/misc.xml b/starter-code/ShoppingListWithSearch/.idea/misc.xml
new file mode 100644
index 0000000..04c63e4
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/misc.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Android
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/modules.xml b/starter-code/ShoppingListWithSearch/.idea/modules.xml
new file mode 100644
index 0000000..27a232c
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/runConfigurations.xml b/starter-code/ShoppingListWithSearch/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/.idea/vcs.xml b/starter-code/ShoppingListWithSearch/.idea/vcs.xml
new file mode 100644
index 0000000..6564d52
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml b/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml
index 77155bc..6608a4f 100644
--- a/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml
+++ b/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml
@@ -13,7 +13,11 @@
+
+
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/MainActivity.java b/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/MainActivity.java
index ab2c048..f18289e 100644
--- a/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/MainActivity.java
+++ b/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/MainActivity.java
@@ -2,6 +2,7 @@
import android.app.SearchManager;
import android.content.Context;
+import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@@ -12,28 +13,69 @@
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
+import android.widget.TextView;
+import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private ListView mShoppingListView;
+ private ListView mShoppingListView2;
+
private CursorAdapter mCursorAdapter;
+ private CursorAdapter mCursorAdapter2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- mShoppingListView = (ListView)findViewById(R.id.shopping_list_view);
+ mShoppingListView = (ListView) findViewById(R.id.shopping_list_view);
+
Cursor cursor = ShoppingSQLiteOpenHelper.getInstance(MainActivity.this).getShoppingList();
- mCursorAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,new String[]{ShoppingSQLiteOpenHelper.COL_ITEM_NAME},new int[]{android.R.id.text1},0);
+ mCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, new String[]{ShoppingSQLiteOpenHelper.COL_ITEM_NAME}, new int[]{android.R.id.text1}, 0);
mShoppingListView.setAdapter(mCursorAdapter);
+
+ handleIntent(getIntent());
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main_menu, menu);
- return super.onCreateOptionsMenu(menu);
+ SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+ searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
+
+ return true;
}
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ handleIntent(intent);
+ }
+
+ private void handleIntent(Intent intent) {
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+// Toast.makeText(MainActivity.this, "Searching for " + query, Toast.LENGTH_SHORT).show();
+
+ Cursor cursor2 = ShoppingSQLiteOpenHelper.getInstance(this).searchShoppingList(query);
+ mCursorAdapter.swapCursor(cursor2);
+
+// mShoppingListView2 = (ListView) findViewById(R.id.shopping_list_view2);
+// Cursor cursor3 = ShoppingSQLiteOpenHelper.getInstance(MainActivity.this).searchShoppingListType(query);
+
+// mCursorAdapter2 = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor3, new String[]{ShoppingSQLiteOpenHelper.COL_ITEM_TYPE}, new int[]{android.R.id.text1}, 0);
+// mShoppingListView2.setAdapter(mCursorAdapter2);
+// mCursorAdapter2.swapCursor(cursor3);
+
+
+ TextView textViewResults = (TextView) findViewById(R.id.textViewResults);
+ textViewResults.setText("Showing results for \""+query+"\":\n");
+
+ }
+ }
+
+
}
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/ShoppingSQLiteOpenHelper.java b/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/ShoppingSQLiteOpenHelper.java
index f5a5974..579a8de 100644
--- a/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/ShoppingSQLiteOpenHelper.java
+++ b/starter-code/ShoppingListWithSearch/app/src/main/java/ly/generalassemb/drewmahrt/shoppinglistwithsearch/ShoppingSQLiteOpenHelper.java
@@ -104,6 +104,39 @@ public Cursor getShoppingList(){
return cursor;
}
+ public Cursor searchShoppingList(String query){
+
+ SQLiteDatabase db = this.getReadableDatabase();
+
+ Cursor cursor2 = db.query(SHOPPING_LIST_TABLE_NAME, // a. table
+ SHOPPING_COLUMNS, // b. column names
+ COL_ITEM_NAME+" LIKE ?", // c. selections
+ new String[]{"%"+query+"%"}, // d. selections args
+ null, // e. group by
+ null, // f. having+
+ null, // g. order by
+ null); // h. limit
+
+ return cursor2;
+ }
+
+ public Cursor searchShoppingListType(String query){
+
+ SQLiteDatabase db = this.getReadableDatabase();
+
+ Cursor cursor3 = db.query(SHOPPING_LIST_TABLE_NAME, // a. table
+ SHOPPING_COLUMNS, // b. column names
+ COL_ITEM_TYPE+" LIKE ?", // c. selections
+ new String[]{"%"+query+"%"}, // d. selections args
+ null, // e. group by
+ null, // f. having+
+ null, // g. order by
+ null); // h. limit
+
+ return cursor3;
+ }
+
+
public int deleteItem(int id){
SQLiteDatabase db = getWritableDatabase();
int deleteNum = db.delete(SHOPPING_LIST_TABLE_NAME,
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/res/layout/activity_main.xml b/starter-code/ShoppingListWithSearch/app/src/main/res/layout/activity_main.xml
index 20b1774..539b868 100644
--- a/starter-code/ShoppingListWithSearch/app/src/main/res/layout/activity_main.xml
+++ b/starter-code/ShoppingListWithSearch/app/src/main/res/layout/activity_main.xml
@@ -1,5 +1,5 @@
-
+ tools:context="ly.generalassemb.drewmahrt.shoppinglistwithsearch.MainActivity"
+ android:orientation="vertical">
-
-
+ android:layout_height="wrap_content"
+ android:id="@+id/textViewResults"
+ />
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -->
+
+
+
+
+
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/res/menu/main_menu.xml b/starter-code/ShoppingListWithSearch/app/src/main/res/menu/main_menu.xml
index 8c7082d..794f45b 100644
--- a/starter-code/ShoppingListWithSearch/app/src/main/res/menu/main_menu.xml
+++ b/starter-code/ShoppingListWithSearch/app/src/main/res/menu/main_menu.xml
@@ -4,7 +4,7 @@
+ app:showAsAction="always" />
\ No newline at end of file
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml b/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml
new file mode 100644
index 0000000..ff2422d
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file