From c984336a9589edb855b790613eb12cdecf236682 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 15:20:41 +0300 Subject: [PATCH 1/4] added filters to explore view --- .../thesocialnotework/ExploreFragment.java | 180 +++++++++++++++--- .../ara/sagi/thesocialnotework/Utils.java | 3 +- 2 files changed, 159 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java index 89fe590..5a7bd99 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/ExploreFragment.java @@ -4,6 +4,7 @@ package com.android_app.matan.ara.sagi.thesocialnotework; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; +import android.location.Location; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; @@ -57,14 +58,17 @@ public class ExploreFragment extends Fragment { private LinearLayout exploreFilters; private boolean dateFilterIsVisible = false; private boolean locationFilterIsVisible = false; + private Long dateFilterSelection; + private float locationFilterSelection; + private GPSUtils gpsUtils; // private boolean userFilterIsVisible = false; private final String day = "24 hours"; private final String week = "Week"; private final String month = "Month"; - private final String hundredMeters = "100 meters"; - private final String kilometer = "1 Km"; - private final String threeKilometer = "3 Km"; + private final String hundredMeters = "1 K"; + private final String kilometer = "10 Km"; + private final String threeKilometer = "100 Km"; // private final String mine = "Mine"; // private final String others = "Others"; // private final String all = "All"; @@ -81,12 +85,16 @@ public class ExploreFragment extends Fragment { View view = inflater.inflate(R.layout.fragment_explore, container, false); parent = (MainActivity) getActivity(); + gpsUtils = parent.getGPSUtils(); user = parent.getUser(); notes = new ArrayList<>(); //Get Views list_notes = (ListView) view.findViewById(R.id.list_notes); noteListAdapter = new ListAdapter(parent, notes); list_notes.setOnItemClickListener(new ItemClickedListener()); + dateFilterSelection = Utils.MONTH_MILI; + locationFilterSelection = Utils.DISTANCE_LONG; + dateFilter = (ImageButton) view.findViewById(R.id.explore_date_filter); @@ -96,6 +104,10 @@ public class ExploreFragment extends Fragment { map_medium_filter = (Button) view.findViewById(R.id.explore_medium_filter); map_large_filter = (Button) view.findViewById(R.id.explore_large_filter); + map_small_filter.setOnClickListener(button1ClickListener); + map_medium_filter.setOnClickListener(button2ClickListener); + map_large_filter.setOnClickListener(button3ClickListener); + exploreFilters = (LinearLayout) view.findViewById(R.id.explore_filter_options); dateFilter.setOnClickListener(new View.OnClickListener() { @@ -115,6 +127,7 @@ public class ExploreFragment extends Fragment { map_medium_filter.setText(week); map_large_filter.setText(month); } + setButtonsColor(); } }); @@ -135,28 +148,10 @@ public class ExploreFragment extends Fragment { map_medium_filter.setText(kilometer); map_large_filter.setText(threeKilometer); } + setButtonsColor(); } }); -// userFilter.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View v) { -// if (userFilterIsVisible) { -// userFilterIsVisible = false; -// exploreFilters.setVisibility(View.GONE); -// } else { -// exploreFilters.setVisibility(View.VISIBLE); -// userFilterIsVisible = true; -// dateFilterIsVisible = false; -// locationFilterIsVisible = false; -// -// // set text button in the right filter string -// map_small_filter.setText(mine); -// map_medium_filter.setText(others); -// map_large_filter.setText(all); -// } -// } -// }); // TODO: choose a default filter for openning explore mode @@ -193,7 +188,8 @@ public class ExploreFragment extends Fragment { time.setTime(noteObject.getLong("created_at")); notes.add(Utils.getNoteFromJsonObj(noteObject, time)); } - list_notes.setAdapter(noteListAdapter); +// list_notes.setAdapter(noteListAdapter); + updateShowedNotes(); Utils.dismissLoadingDialog(); } catch (Exception e) { Log.e(TAG, "newNoteSuccess:" + e.getMessage()); @@ -295,5 +291,143 @@ public class ExploreFragment extends Fragment { } } + //all buttons listener + public View.OnClickListener button1ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_SMALL; + } + + //date filters + else { + dateFilterSelection = Utils.DAY_MILI; + + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + //all buttons listener + public View.OnClickListener button2ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_MEDIUM; + } + + //date filters + else { + dateFilterSelection = Utils.WEEK_MILI; + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + //all buttons listener + public View.OnClickListener button3ClickListener = new View.OnClickListener() { + @Override + public void onClick(final View v) { + + //location filter + if (locationFilterIsVisible) { + locationFilterSelection = Utils.DISTANCE_LONG; + } + + //date filters + else { + dateFilterSelection = Utils.MONTH_MILI; + } + //change colors of buttons and update visible notes + setButtonsColor(); + updateShowedNotes(); + } + }; + + + //set main filter colors + private void setButtonsColor() { + + Log.d(TAG, "setButtonsColor: start"); + //set date filter colors + if (dateFilterIsVisible) { + dateFilter.setBackgroundColor(Utils.filterColor); + if (dateFilterSelection == Utils.DAY_MILI) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (dateFilterSelection == Utils.WEEK_MILI) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + dateFilter.setBackgroundResource(android.R.drawable.btn_default); + } + + //set distance filter colors + if (locationFilterIsVisible) { + locationFilter.setBackgroundColor(Utils.filterColor); + if (locationFilterSelection == Utils.DISTANCE_SMALL) { + map_small_filter.setBackgroundColor(Utils.filterColor); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else if (locationFilterSelection == Utils.DISTANCE_MEDIUM) { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundColor(Utils.filterColor); + map_large_filter.setBackgroundResource(android.R.drawable.btn_default); + } else { + map_small_filter.setBackgroundResource(android.R.drawable.btn_default); + map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); + map_large_filter.setBackgroundColor(Utils.filterColor); + } + } else { + locationFilter.setBackgroundResource(android.R.drawable.btn_default); + } + } + + public void updateShowedNotes() { + List presentedNotes = new ArrayList<>(); + long timeDifference; + float distance; + //get current date and location + Location currLocation = new Location(gpsUtils.getLocation()); + Date now = new Date(); + Location targetLocation = new Location("");//provider name is unecessary + Date targetDate; + + for (Note note : notes) { +// get note location and date + targetLocation.setLatitude(note.getLat());//your coords of course + targetLocation.setLongitude(note.getLon()); + targetDate = new Date(note.getTimestamp()); + //get time and date differences + timeDifference = now.getTime() - targetDate.getTime(); + distance = currLocation.distanceTo(targetLocation); + //add to currently presented list according to filters. + if (timeDifference <= dateFilterSelection + && distance <= locationFilterSelection){ + presentedNotes.add(note); + } + + } + + + noteListAdapter.updateList(presentedNotes); + list_notes.setAdapter(noteListAdapter); + } + } diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java index e580c68..3e7ff2a 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/Utils.java @@ -48,7 +48,8 @@ public class Utils { private static boolean mLocationPermission = false; private static boolean mCameraPermission = false; private static SharedPreferences prefs; - public static int filterColor = Color.parseColor("#33adff"); + public static int filterColor = Color.parseColor("#33adff"), circleColor =0x6666a3ff; + public static final long DAY_MILI = 86400000L,WEEK_MILI = 604800000L,MONTH_MILI = 2592000000L; public static final float DISTANCE_SMALL = 1000,DISTANCE_MEDIUM = 10000,DISTANCE_LONG = 100000; From f07af145c9f8cad4e71f2cacf3ec8a54079bbd39 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 15:21:01 +0300 Subject: [PATCH 2/4] added circle to map --- .../sagi/thesocialnotework/GmapFragment.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index 81a2a81..81861f3 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; import android.location.Location; import android.net.Uri; import android.os.AsyncTask; @@ -37,6 +38,8 @@ import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; +import com.google.android.gms.maps.model.Circle; +import com.google.android.gms.maps.model.CircleOptions; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; @@ -81,6 +84,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { private Long dateFilterSelection; private float locationFilterSelection; List listOfNotes; + private Circle onMapCircle; private final String day = "24 hours"; private final String week = "Week"; @@ -236,9 +240,9 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition cameraPosition) { - if (cameraPosition.zoom > MAX_ZOOM) { - getMap().animateCamera(CameraUpdateFactory.zoomTo(MAX_ZOOM)); - } +// if (cameraPosition.zoom > MAX_ZOOM) { +// getMap().animateCamera(CameraUpdateFactory.zoomTo(MAX_ZOOM)); +// } if (cameraPosition.zoom < MIN_ZOOM) { getMap().animateCamera(CameraUpdateFactory.zoomTo(MIN_ZOOM)); } @@ -253,6 +257,16 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } + + updateLocationCircle(); + //add circle around user locaiton +// onMapCircle = mMap.addCircle(new CircleOptions() +// .center(new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude())) +// .radius(locationFilterSelection) +// .fillColor(Utils.circleColor)); + + + mMap.setMyLocationEnabled(true); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM)); @@ -271,6 +285,16 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } + private void updateLocationCircle() { + if(onMapCircle!=null){ + onMapCircle.remove(); + } + onMapCircle = mMap.addCircle(new CircleOptions() + .center(new LatLng(gpsUtils.getLatitude(), gpsUtils.getLongitude())) + .radius(locationFilterSelection) + .fillColor(Utils.circleColor)); + } + GoogleMap.InfoWindowAdapter infoWindowAdapter = new GoogleMap.InfoWindowAdapter() { // Use default InfoWindow frame @Override public View getInfoWindow(Marker args) { @@ -537,6 +561,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); map_large_filter.setBackgroundColor(Utils.filterColor); } + updateLocationCircle(); } else { locationFilter.setBackgroundResource(android.R.drawable.btn_default); } @@ -570,6 +595,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } Log.d(TAG, "updateShowedNotes: ======= markers presented: "+ presentedNotes.size()+"============="); mMap.clear(); + updateLocationCircle(); new getMarkersFromNotes(mMap, eventMarkerMap).execute(presentedNotes); } From 555805b3205c2d830841e4fa0a5a0c3cced0dfe3 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 15:24:54 +0300 Subject: [PATCH 3/4] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java --- .../matan/ara/sagi/thesocialnotework/GmapFragment.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index 24a3e03..ef87c20 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -40,6 +40,8 @@ import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.BitmapDescriptor; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.google.android.gms.maps.model.CameraPosition; +import com.google.android.gms.maps.model.Circle; +import com.google.android.gms.maps.model.CircleOptions; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; @@ -84,6 +86,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { private Long dateFilterSelection; private float locationFilterSelection; List listOfNotes; + private Circle onMapCircle; private final String day = "24 hours"; private final String week = "Week"; From fc0b4dda2c3328c50e7cf80be315df75bfac33e7 Mon Sep 17 00:00:00 2001 From: Aran Zaiger Date: Sun, 10 Jul 2016 15:29:14 +0300 Subject: [PATCH 4/4] Merge branch 'master' of https://github.com/sagidayan/TheSocialNotework-Android # Conflicts: # app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java --- .../matan/ara/sagi/thesocialnotework/GmapFragment.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java index ef87c20..b216eb2 100644 --- a/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java +++ b/app/src/main/java/com/android_app/matan/ara/sagi/thesocialnotework/GmapFragment.java @@ -70,7 +70,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { private GoogleMap mMap; private GPSUtils gpsUtils; private MainActivity mainActivity; - private final int MAX_ZOOM = 16, MIN_ZOOM = 9, DEFAULT_ZOOM = 12; + private final int MAX_ZOOM = 16, MIN_ZOOM = 8, DEFAULT_ZOOM = 12; private HashMap eventMarkerMap; private ImageButton dateFilter; private ImageButton locationFilter; @@ -258,6 +258,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { if (ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mainActivity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } + updateLocationCircle(); mMap.setMyLocationEnabled(true); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, DEFAULT_ZOOM)); @@ -563,6 +564,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { map_medium_filter.setBackgroundResource(android.R.drawable.btn_default); map_large_filter.setBackgroundColor(Utils.filterColor); } + updateLocationCircle(); } else { locationFilter.setBackgroundResource(android.R.drawable.btn_default); } @@ -596,6 +598,7 @@ public class GmapFragment extends Fragment implements OnMapReadyCallback { } Log.d(TAG, "updateShowedNotes: ======= markers presented: "+ presentedNotes.size()+"============="); mMap.clear(); + updateLocationCircle(); new getMarkersFromNotes(mMap, eventMarkerMap).execute(presentedNotes); }