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..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..cfbef94 --- /dev/null +++ b/starter-code/ShoppingListWithSearch/.idea/misc.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + Android + + + Android Lint + + + Java + + + Java language level migration aidsJava + + + + + 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..0654e5c 100644 --- a/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml +++ b/starter-code/ShoppingListWithSearch/app/src/main/AndroidManifest.xml @@ -14,6 +14,8 @@ + 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..1862621 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,16 +2,22 @@ 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; import android.support.v7.widget.SearchView; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; 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; @@ -28,12 +34,37 @@ 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); + + Intent intent = getIntent(); + + } + + @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 cursor = ShoppingSQLiteOpenHelper.getInstance(this).getShoppingList(); + + + TextView textView = (TextView) findViewById(R.id.text); + textView.setText("Number of " + query + " in database: " + cursor.getCount()); + } } 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(); + searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); + return super.onCreateOptionsMenu(menu); } } diff --git a/starter-code/ShoppingListWithSearch/app/src/main/res/values/searchable.xml b/starter-code/ShoppingListWithSearch/app/src/main/res/values/searchable.xml new file mode 100644 index 0000000..a6b3dae --- /dev/null +++ b/starter-code/ShoppingListWithSearch/app/src/main/res/values/searchable.xml @@ -0,0 +1,2 @@ + + \ 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..dcf839e --- /dev/null +++ b/starter-code/ShoppingListWithSearch/app/src/main/res/xml/searchable.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file