From 74c8e806eb0fecc9395b6ed1c9ff16f8ea93023d Mon Sep 17 00:00:00 2001 From: acjones212 Date: Wed, 3 Feb 2016 14:05:37 -0500 Subject: [PATCH] Shopping List App --- .idea/.name | 1 + .idea/Search-View-Lab.iml | 9 + .idea/compiler.xml | 22 + .idea/copyright/profiles_settings.xml | 3 + .idea/dictionaries/chrisjones.xml | 3 + .idea/misc.xml | 123 +++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 707 ++++++++++++++++++ .../ShoppingListWithSearch/.idea/.name | 1 + .../ShoppingListWithSearch/.idea/compiler.xml | 22 + .../.idea/copyright/profiles_settings.xml | 3 + .../.idea/dictionaries/chrisjones.xml | 3 + .../ShoppingListWithSearch/.idea/gradle.xml | 18 + .../ShoppingListWithSearch/.idea/misc.xml | 155 ++++ .../ShoppingListWithSearch/.idea/modules.xml | 9 + .../.idea/runConfigurations.xml | 12 + .../ShoppingListWithSearch/.idea/vcs.xml | 6 + .../app/src/main/AndroidManifest.xml | 4 +- .../shoppinglistwithsearch/MainActivity.java | 50 +- .../ShoppingSQLiteOpenHelper.java | 12 + .../app/src/main/res/layout/activity_main.xml | 8 +- .../app/src/main/res/xml/searchable.xml | 4 + 23 files changed, 1177 insertions(+), 12 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/Search-View-Lab.iml create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/dictionaries/chrisjones.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/.name create mode 100644 starter-code/ShoppingListWithSearch/.idea/compiler.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/copyright/profiles_settings.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/dictionaries/chrisjones.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/gradle.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/misc.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/modules.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/runConfigurations.xml create mode 100644 starter-code/ShoppingListWithSearch/.idea/vcs.xml create mode 100644 starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..380b02b --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Search-View-Lab \ No newline at end of file diff --git a/.idea/Search-View-Lab.iml b/.idea/Search-View-Lab.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Search-View-Lab.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/dictionaries/chrisjones.xml b/.idea/dictionaries/chrisjones.xml new file mode 100644 index 0000000..6e26c3a --- /dev/null +++ b/.idea/dictionaries/chrisjones.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f782a7d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + Android Lint + + + C/C++ + + + Code style issuesJava + + + Compiler issuesJava + + + Declaration orderC/C++ + + + Finalization issuesJava + + + Groovy + + + Inheritance issuesJava + + + J2ME issuesJava + + + Java + + + Java language level migration aidsJava + + + JavaBeans issuesJava + + + Numeric issuesJava + + + OtherGroovy + + + Performance issuesJava + + + Probable bugsJava + + + Security issuesJava + + + Serialization issuesJava + + + Type checksC/C++ + + + Verbose or redundant code constructsJava + + + + + Android + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ad4618d --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..68fa32c --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,707 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1454520840647 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file 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/chrisjones.xml b/starter-code/ShoppingListWithSearch/.idea/dictionaries/chrisjones.xml new file mode 100644 index 0000000..6e26c3a --- /dev/null +++ b/starter-code/ShoppingListWithSearch/.idea/dictionaries/chrisjones.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..1bbc21d --- /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..cab8e98 --- /dev/null +++ b/starter-code/ShoppingListWithSearch/.idea/misc.xml @@ -0,0 +1,155 @@ + + + + + + + + + + + + + + + + + + + + + Android Lint + + + C/C++ + + + Code style issuesJava + + + Compiler issuesJava + + + Declaration orderC/C++ + + + Finalization issuesJava + + + Groovy + + + Inheritance issuesJava + + + J2ME issuesJava + + + Java + + + Java language level migration aidsJava + + + JavaBeans issuesJava + + + Numeric issuesJava + + + OtherGroovy + + + Performance issuesJava + + + Probable bugsJava + + + Security issuesJava + + + Serialization issuesJava + + + Type checksC/C++ + + + Verbose or redundant code constructsJava + + + + + 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..40fc21d 100644 --- a/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml +++ b/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml @@ -11,9 +11,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..529fba1 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,39 +1,73 @@ package ly.generalassemb.drewmahrt.shoppinglistwithsearch; import android.app.SearchManager; -import android.content.Context; +import android.app.SearchableInfo; +import android.content.Intent; import android.database.Cursor; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v4.widget.SimpleCursorAdapter; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.SearchView; import android.view.Menu; import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.CursorAdapter; import android.widget.ListView; -import android.widget.SimpleCursorAdapter; +import android.widget.Toast; public class MainActivity extends AppCompatActivity { private ListView mShoppingListView; - private CursorAdapter mCursorAdapter; + private SimpleCursorAdapter mCursorAdapter; @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.resultListView); 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); mShoppingListView.setAdapter(mCursorAdapter); + + handleIntent(getIntent()); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(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, "You are searching for " + query, Toast.LENGTH_SHORT).show(); + + ShoppingSQLiteOpenHelper helper= ShoppingSQLiteOpenHelper.getInstance(this); + Cursor cursor=helper.getList(query); + if(cursor==null){ + Toast.makeText(this,"Cursor is null",Toast.LENGTH_SHORT).show(); + + } + + mCursorAdapter.swapCursor(cursor); + //TextView resultTextView = (TextView) findViewById(R.id.resultTextView); + //resultTextView.setText(query + cursor.getString(1)); + } + } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.main_menu, menu); - return super.onCreateOptionsMenu(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 true; } } 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..51c805a 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 @@ -140,4 +140,16 @@ private void loadShoppingInfo(SQLiteDatabase db) throws IOException { reader.close(); } } + + public Cursor getList(String query){ + SQLiteDatabase db = this.getReadableDatabase(); + + Cursor cursor = db.query(SHOPPING_LIST_TABLE_NAME, + SHOPPING_COLUMNS, COL_ITEM_NAME + " = ?", + new String[]{query}, + null,null,null,null); + + return cursor; + + } } 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..377f5a2 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 @@ -10,7 +10,9 @@ tools:context="ly.generalassemb.drewmahrt.shoppinglistwithsearch.MainActivity"> + android:id="@+id/resultListView" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Search for items"/> + 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..c9b9c67 --- /dev/null +++ b/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml @@ -0,0 +1,4 @@ + +