Merge remote-tracking branch 'origin/follow-route' into follow-route
This commit is contained in:
@@ -9,7 +9,16 @@ public enum StaticData {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
private double distanceTraveled = 0;
|
private double distanceTraveled = 0;
|
||||||
private int locationsVisited = 0;
|
private int locationsVisited = 0;
|
||||||
private long timeWalked = 0;
|
private long timeWalkedRoute = 0;
|
||||||
|
private double zoom = 0;
|
||||||
|
|
||||||
|
public double getZoom() {
|
||||||
|
return zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZoom(double zoom) {
|
||||||
|
this.zoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.a1.nextlocation.fragments;
|
|||||||
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@@ -11,6 +12,7 @@ import android.location.LocationManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
@@ -34,6 +36,7 @@ import com.a1.nextlocation.recyclerview.LocationListManager;
|
|||||||
import org.osmdroid.api.IMapController;
|
import org.osmdroid.api.IMapController;
|
||||||
import org.osmdroid.config.Configuration;
|
import org.osmdroid.config.Configuration;
|
||||||
import org.osmdroid.util.GeoPoint;
|
import org.osmdroid.util.GeoPoint;
|
||||||
|
import org.osmdroid.views.CustomZoomButtonsController;
|
||||||
import org.osmdroid.views.MapView;
|
import org.osmdroid.views.MapView;
|
||||||
import org.osmdroid.views.overlay.ItemizedIconOverlay;
|
import org.osmdroid.views.overlay.ItemizedIconOverlay;
|
||||||
import org.osmdroid.views.overlay.Overlay;
|
import org.osmdroid.views.overlay.Overlay;
|
||||||
@@ -49,13 +52,14 @@ import java.util.List;
|
|||||||
|
|
||||||
public class HomeFragment extends Fragment implements LocationListener {
|
public class HomeFragment extends Fragment implements LocationListener {
|
||||||
private final String userAgent = "com.ai.nextlocation.fragments";
|
private final String userAgent = "com.ai.nextlocation.fragments";
|
||||||
public final static String MAPQUEST_API_KEY = "vuyXjqnAADpjeL9QwtgWGleIk95e36My";
|
|
||||||
private ImageButton imageButton;
|
private ImageButton imageButton;
|
||||||
private ImageButton stopButton;
|
private ImageButton stopButton;
|
||||||
private MapView mapView;
|
private MapView mapView;
|
||||||
|
|
||||||
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
|
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
|
||||||
private final String TAG = HomeFragment.class.getCanonicalName();
|
private final String TAG = HomeFragment.class.getCanonicalName();
|
||||||
// private RoadManager roadManager;
|
|
||||||
private Polyline roadOverlay;
|
private Polyline roadOverlay;
|
||||||
private int color;
|
private int color;
|
||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
@@ -92,11 +96,14 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
stopRoute();
|
stopRoute();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// show or hide the stop route button based on if we are following a route
|
||||||
if (RouteHandler.INSTANCE.isFollowingRoute()) {
|
if (RouteHandler.INSTANCE.isFollowingRoute()) {
|
||||||
stopButton.setVisibility(View.VISIBLE);
|
stopButton.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
stopButton.setVisibility(View.GONE);
|
stopButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//register as a listener for a result of the API
|
||||||
ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable);
|
ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -105,7 +112,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
* stops the current route
|
* stops the current route
|
||||||
*/
|
*/
|
||||||
private void stopRoute() {
|
private void stopRoute() {
|
||||||
Log.e(TAG, "stopRoute: STOPPING ROUTE" );
|
Log.d(TAG, "stopRoute: STOPPING ROUTE" );
|
||||||
RouteHandler.INSTANCE.finishRoute();
|
RouteHandler.INSTANCE.finishRoute();
|
||||||
stopButton.setVisibility(View.GONE);
|
stopButton.setVisibility(View.GONE);
|
||||||
Toast.makeText(requireContext(), getResources().getString(R.string.route_stop_toast), Toast.LENGTH_SHORT).show();
|
Toast.makeText(requireContext(), getResources().getString(R.string.route_stop_toast), Toast.LENGTH_SHORT).show();
|
||||||
@@ -128,7 +135,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
roadOverlay.setPoints(geoPoints);
|
roadOverlay.setPoints(geoPoints);
|
||||||
roadOverlay.setColor(color);
|
roadOverlay.setColor(color);
|
||||||
|
|
||||||
|
// pass the line to the route handler
|
||||||
RouteHandler.INSTANCE.setCurrentRouteLine(roadOverlay);
|
RouteHandler.INSTANCE.setCurrentRouteLine(roadOverlay);
|
||||||
Log.d(TAG, "onDirectionsAvailable: successfully added road!");
|
Log.d(TAG, "onDirectionsAvailable: successfully added road!");
|
||||||
|
|
||||||
@@ -174,7 +181,10 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
|
|
||||||
// add the zoom controller
|
// add the zoom controller
|
||||||
IMapController mapController = mapView.getController();
|
IMapController mapController = mapView.getController();
|
||||||
mapController.setZoom(15.0);
|
if (StaticData.INSTANCE.getZoom() == 0) {
|
||||||
|
StaticData.INSTANCE.setZoom(15.0);
|
||||||
|
}
|
||||||
|
mapController.setZoom(StaticData.INSTANCE.getZoom());
|
||||||
|
|
||||||
// add location manager and set the start point
|
// add location manager and set the start point
|
||||||
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||||
@@ -345,14 +355,18 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
|
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
|
||||||
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 10) {
|
// mark the location visited if we are less than 20 meters away
|
||||||
|
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 20) {
|
||||||
StaticData.INSTANCE.visitLocation(l);
|
StaticData.INSTANCE.visitLocation(l);
|
||||||
if (l.equals(last)) stopRoute();
|
if (l.equals(last)) stopRoute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StaticData.INSTANCE.setZoom(mapView.getZoomLevelDouble());
|
||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// empty override methods for the LocationListener
|
// empty override methods for the LocationListener
|
||||||
|
|||||||
Reference in New Issue
Block a user