diff --git a/app/src/main/java/com/emidev/moviesincisco/MapsActivity.java b/app/src/main/java/com/emidev/moviesincisco/MapsActivity.java index fd09df3..547493e 100644 --- a/app/src/main/java/com/emidev/moviesincisco/MapsActivity.java +++ b/app/src/main/java/com/emidev/moviesincisco/MapsActivity.java @@ -4,6 +4,7 @@ import androidx.annotation.NonNull; import androidx.appcompat.content.res.AppCompatResources; +import androidx.appcompat.widget.SearchView; import androidx.fragment.app.FragmentActivity; import androidx.room.Room; @@ -23,6 +24,7 @@ import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.RotateAnimation; +import android.view.inputmethod.InputMethodManager; import android.widget.GridLayout; import android.widget.ImageButton; import android.widget.ImageView; @@ -102,6 +104,7 @@ private void setUpClusterer() { private void addItems() { //Add cluster items in close proximity + clusterManager.clearItems(); for(int i = 0; i < movies.size(); i++) { MovieLocation current = movies.get(i); Log.d("Movies", current.getTitle()); @@ -135,6 +138,21 @@ public void onAnimationEnd(Animator animation) { }); } + //function to search markers + private void searchMarkers(String query) { + //Clear the map + clusterManager.clearItems(); + //Add the items that match the query + for(int i = 0; i < movies.size(); i++) { + MovieLocation current = movies.get(i); + if(current.getTitle().toLowerCase().contains(query.toLowerCase())) { + clusterManager.addItem(current); + } + } + //Update the map + clusterManager.cluster(); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -300,6 +318,32 @@ public void onMapLoaded() { //Setting up the map clusterer setUpClusterer(); + SearchView searchView = findViewById(R.id.searchView); + + searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + searchMarkers(query); + searchView.clearFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + Objects.requireNonNull(imm).hideSoftInputFromWindow(searchView.getWindowToken(), 0); + return true; + } + + @Override + public boolean onQueryTextChange(String s) { + if(s.length() > 0) { + searchMarkers(s); + return true; + } else { + Log.d("Search", "Clearing markers"); + addItems(); + return false; + } + } + + }); + //Setting a custom adapter to show a window when a marker is clicked for every marker clusterManager.getMarkerCollection().setInfoWindowAdapter(new MovieInfoViewAdapter(LayoutInflater.from(this), this, renderer)); diff --git a/app/src/main/java/com/emidev/moviesincisco/Parser.java b/app/src/main/java/com/emidev/moviesincisco/Parser.java index 7386cb9..cf94897 100644 --- a/app/src/main/java/com/emidev/moviesincisco/Parser.java +++ b/app/src/main/java/com/emidev/moviesincisco/Parser.java @@ -22,6 +22,16 @@ public class Parser { private final static Semaphore mutex = new Semaphore(1); private final static Locator locator = new Locator(); + private static String trimDash(String str) { + if(str.charAt(0) == '-') { + str = str.substring(1); + } + if(str.charAt(str.length() - 1) == '-') { + str = str.substring(0, str.length() - 1); + } + return str; + } + public static boolean parseCredits(InputStreamReader file, MovieLocation movie) throws ParseException, JSONException, IOException { String path = null; @@ -149,7 +159,8 @@ public static ArrayList parseMovies(InputStreamReader file) throw for (int i = 0; i < doc.size(); i++) { JSONObject movie = (JSONObject) doc.get(i); MovieLocation m = new MovieLocation(); - m.setTitle(((String) movie.get("title")).split("Season")[0].trim()); + m.setTitle(trimDash(((String) movie.get("title")).split("Season")[0].trim())); + if(movie.get("locations") != null) { Log.d("LocationOfJSONFile", (String) movie.get("locations")); m.setLocation((String) movie.get("locations")); diff --git a/app/src/main/res/drawable/cisco_title.png b/app/src/main/res/drawable/cisco_title.png new file mode 100644 index 0000000..d531ffa Binary files /dev/null and b/app/src/main/res/drawable/cisco_title.png differ diff --git a/app/src/main/res/drawable/ic_baseline_search_24.xml b/app/src/main/res/drawable/ic_baseline_search_24.xml new file mode 100644 index 0000000..a5687c6 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_search_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/search_bar_background.xml b/app/src/main/res/drawable/search_bar_background.xml new file mode 100644 index 0000000..d38fe22 --- /dev/null +++ b/app/src/main/res/drawable/search_bar_background.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml index 8e64236..d32981f 100644 --- a/app/src/main/res/layout/activity_maps.xml +++ b/app/src/main/res/layout/activity_maps.xml @@ -175,11 +175,25 @@ + + @android:color/transparent + @style/SearchAutoCompleteTextView + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 4b3e709..f209a0f 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -14,5 +14,10 @@ @android:color/transparent + @style/SearchAutoCompleteTextView + + \ No newline at end of file