diff --git a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java index 6616043..ebc0642 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/fragment/MapsFragment.java @@ -22,6 +22,9 @@ import android.os.Environment; import android.util.Base64; 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.util.Log; @@ -65,6 +68,7 @@ import java.io.FileInputStream; import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import retrofit2.Call; @@ -108,6 +112,9 @@ private ArrayList done_vid = new ArrayList<>(); private boolean flag = false; private ArrayList mMarker = new ArrayList<>(); + private ArrayList checkedList = new ArrayList<>(); + HashMap menuItemMap = new HashMap<>(); + public MapsFragment() { } @@ -264,7 +271,7 @@ public void onLocationChanged(Location location) { //category = ((MainActivity) getActivity()).getCheckedCidList(); loc=location; - if(category.size() != before_category) { + if(checkedList.size() != before_category) { for(Marker marker : mMarker) { marker.remove(); } @@ -272,7 +279,7 @@ done_vid = new ArrayList<>(); mMarker = new ArrayList<>(); } - before_category = category.size(); + before_category = checkedList.size(); LatLng current = new LatLng(location.getLatitude(), location.getLongitude()); if (googlemap != null) { if (count == 0) { @@ -302,7 +309,7 @@ } if (flag == false || done_vid.size() == 0) { if (v.getCategory().size() >= 2) { - for (String category : category) {// ArrayList(ハンバーガーメニューでしていされた1つ以上のカテゴリーを比較する) + for (String category : checkedList) {// ArrayList(ハンバーガーメニューでしていされた1つ以上のカテゴリーを比較する) for (String cid : v.getCategory()) { if (category.equals(cid)) { Marker m; @@ -316,7 +323,7 @@ } } } else { - for (String category : category) {// ArrayList(ハンバーガーメニューでしていされた1つ以上のカテゴリーを比較する) + for (String category : checkedList) {// ArrayList(ハンバーガーメニューでしていされた1つ以上のカテゴリーを比較する) for (String cid : v.getCategory()) { Category category_info = ((MainActivity) getActivity()).getCategory(cid); if (category.equals(cid)) { @@ -582,6 +589,44 @@ return timeLabel; } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setHasOptionsMenu(true); + } + + + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + super.onCreateOptionsMenu(menu, inflater); + HashMap categories = MainActivity.getCategories(); + + int id=0; + for(Category category : categories.values()){ + String name = category.getName(); + String cid = category.getcId(); + MenuItem newItem = menu.add(Menu.NONE, id, Menu.NONE, name); + menuItemMap.put(newItem.getItemId(),cid); + newItem.setCheckable(true); + newItem.setChecked(true); + checkedList.add(cid); + id++; + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + String cid = menuItemMap.get(item.getItemId()); + + if(item.isChecked()){ + checkedList.remove(cid); + }else{ + checkedList.add(cid); + } + item.setChecked(!item.isChecked()); + return super.onOptionsItemSelected(item); + } + }