Skip to content

Commit

Permalink
Added search bar to show movies chosen by user + changed some graphic…
Browse files Browse the repository at this point in the history
… elements
  • Loading branch information
Emiliano Iacopini committed May 22, 2022
2 parents e70af7b + 62e15aa commit 288cf9c
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 4 deletions.
44 changes: 44 additions & 0 deletions app/src/main/java/com/emidev/moviesincisco/MapsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));

Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/com/emidev/moviesincisco/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -149,7 +159,8 @@ public static ArrayList<MovieLocation> 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"));
Expand Down
Binary file added app/src/main/res/drawable/cisco_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_search_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/search_bar_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<corners
android:radius="250dp"/>
</shape>
20 changes: 17 additions & 3 deletions app/src/main/res/layout/activity_maps.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,25 @@

<ImageView
android:id="@+id/ciscoLogo"
android:layout_width="wrap_content"
android:layout_height="300dp"
android:src="@drawable/cisco"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_alignParentStart="true"
android:src="@drawable/cisco_title"
android:translationZ="45dp"/>

<androidx.appcompat.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
map:queryHint="Search for a movie"
android:layout_marginTop="60dp"
android:translationZ="46dp"
map:searchIcon="@drawable/ic_baseline_search_24"
android:layout_marginHorizontal="20dp"
map:iconifiedByDefault="false"
android:background="@drawable/search_bar_background"/>

<ImageButton
android:id="@+id/switchButton"
android:layout_width="75dp"
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
<!-- Status bar color. -->
<item name="android:statusBarColor" >@android:color/transparent</item>
<!-- Customize your theme here. -->
<item name="autoCompleteTextViewStyle">@style/SearchAutoCompleteTextView</item>
</style>
<style name="SearchAutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">@color/black</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
</style>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
<!-- Status bar color. -->
<item name="android:statusBarColor" >@android:color/transparent</item>
<!-- Customize your theme here. -->
<item name="autoCompleteTextViewStyle">@style/SearchAutoCompleteTextView</item>
</style>
<style name="SearchAutoCompleteTextView" parent="Widget.AppCompat.Light.AutoCompleteTextView">
<item name="android:textColor">@color/black</item>
<item name="android:textColorHint">@android:color/darker_gray</item>
</style>
</resources>

0 comments on commit 288cf9c

Please sign in to comment.