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/gradle.xml b/starter-code/ShoppingListWithSearch/.idea/gradle.xml
new file mode 100644
index 0000000..8d2df47
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/gradle.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
\ 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..efbef40
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/.idea/misc.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
\ 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..73178d9 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..7160324 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
@@ -1,7 +1,9 @@
package ly.generalassemb.drewmahrt.shoppinglistwithsearch;
import android.app.SearchManager;
+import android.app.SearchableInfo;
import android.content.Context;
+import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@@ -12,10 +14,13 @@
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 CursorAdapter mCursorAdapter;
+ ShoppingSQLiteOpenHelper mHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -28,12 +33,42 @@ protected void onCreate(Bundle savedInstanceState) {
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);
+
+ mHelper = ShoppingSQLiteOpenHelper.getInstance(MainActivity.this);
+
+ handleIntent(getIntent());
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ handleIntent(intent);
+ }
+
+ public void handleIntent(Intent intent){
+ if(Intent.ACTION_SEARCH.equals(intent.getAction())){
+ // Do The actual database search
+
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ Toast.makeText(MainActivity.this, "You are searched for " + query, Toast.LENGTH_SHORT).show();
+
+ Cursor newCursor = ShoppingSQLiteOpenHelper.getInstance(MainActivity.this).searchList(query);
+ mCursorAdapter.swapCursor(newCursor);
+
+ }
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main_menu, menu);
+ SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
+ SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
+
+ SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
+
+ searchView.setSearchableInfo(info);
+
return super.onCreateOptionsMenu(menu);
}
}
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..8aa73d5 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
@@ -17,7 +17,7 @@
/**
* Created by drewmahrt on 12/28/15.
*/
-public class ShoppingSQLiteOpenHelper extends SQLiteOpenHelper{
+public class ShoppingSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String TAG = ShoppingSQLiteOpenHelper.class.getCanonicalName();
private static final int DATABASE_VERSION = 7;
@@ -32,7 +32,7 @@ public class ShoppingSQLiteOpenHelper extends SQLiteOpenHelper{
private Context mHelperContext;
- public static final String[] SHOPPING_COLUMNS = {COL_ID,COL_ITEM_NAME,COL_ITEM_DESCRIPTION,COL_ITEM_PRICE,COL_ITEM_TYPE};
+ public static final String[] SHOPPING_COLUMNS = {COL_ID, COL_ITEM_NAME, COL_ITEM_DESCRIPTION, COL_ITEM_PRICE, COL_ITEM_TYPE};
private static final String CREATE_SHOPPING_LIST_TABLE =
"CREATE TABLE " + SHOPPING_LIST_TABLE_NAME +
@@ -46,8 +46,8 @@ public class ShoppingSQLiteOpenHelper extends SQLiteOpenHelper{
private static ShoppingSQLiteOpenHelper instance;
- public static ShoppingSQLiteOpenHelper getInstance(Context context){
- if(instance == null){
+ public static ShoppingSQLiteOpenHelper getInstance(Context context) {
+ if (instance == null) {
instance = new ShoppingSQLiteOpenHelper(context);
}
return instance;
@@ -61,10 +61,10 @@ private ShoppingSQLiteOpenHelper(Context context) {
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_SHOPPING_LIST_TABLE);
- try{
+ try {
loadShoppingInfo(db);
- }catch (Exception e){
- Log.e(TAG,e.toString());
+ } catch (Exception e) {
+ Log.e(TAG, e.toString());
}
}
@@ -75,7 +75,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
//Add new itinerary list
- public long addItem(String name, String description, String price, String type){
+ public long addItem(String name, String description, String price, String type) {
ContentValues values = new ContentValues();
values.put(COL_ITEM_NAME, name);
values.put(COL_ITEM_DESCRIPTION, description);
@@ -88,7 +88,7 @@ public long addItem(String name, String description, String price, String type){
return returnId;
}
- public Cursor getShoppingList(){
+ public Cursor getShoppingList() {
SQLiteDatabase db = this.getReadableDatabase();
@@ -104,7 +104,7 @@ public Cursor getShoppingList(){
return cursor;
}
- public int deleteItem(int id){
+ public int deleteItem(int id) {
SQLiteDatabase db = getWritableDatabase();
int deleteNum = db.delete(SHOPPING_LIST_TABLE_NAME,
COL_ID + " = ?",
@@ -132,12 +132,29 @@ private void loadShoppingInfo(SQLiteDatabase db) throws IOException {
long id = db.insert(SHOPPING_LIST_TABLE_NAME, null, values);
if (id < 0) {
Log.e(TAG, "unable to add entry");
- }else{
- Log.d(TAG,"Added item to database: "+strings[0]);
+ } else {
+ Log.d(TAG, "Added item to database: " + strings[0]);
}
}
} finally {
reader.close();
}
}
+
+ public Cursor searchList(String query) {
+ SQLiteDatabase db = this.getReadableDatabase();
+
+ Cursor cursorSearch = 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 cursorSearch;
+ }
+
}
+
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..83cb2cd 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
@@ -13,4 +13,10 @@
android:id="@+id/shopping_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
+
+
diff --git a/starter-code/ShoppingListWithSearch/app/src/main/res/layout/shopping_list_item.xml b/starter-code/ShoppingListWithSearch/app/src/main/res/layout/shopping_list_item.xml
new file mode 100644
index 0000000..15bb4a5
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/app/src/main/res/layout/shopping_list_item.xml
@@ -0,0 +1,9 @@
+
+
+
+
\ No newline at end of file
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..f3a3647 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
@@ -7,4 +7,5 @@
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="Search"/>
-
\ 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..583604f
--- /dev/null
+++ b/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml
@@ -0,0 +1,4 @@
+
+
\ No newline at end of file