Compare commits
9 Commits
route_deta
...
follow-rou
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2c320dd14 | ||
|
|
ce264d78bc | ||
|
|
f8acc35c5b | ||
|
|
e5e0916555 | ||
|
|
c738deab23 | ||
|
|
223e77cdc8 | ||
|
|
7c9dc07c3d | ||
|
|
187f45b770 | ||
|
|
04487b77a7 |
@@ -28,6 +28,10 @@ public enum RouteHandler {
|
|||||||
this.routeFinishedListener = routeFinishedListener;
|
this.routeFinishedListener = routeFinishedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RouteFinishedListener getRouteFinishedListener() {
|
||||||
|
return routeFinishedListener;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStepCount() {
|
public int getStepCount() {
|
||||||
return stepCount;
|
return stepCount;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.a1.nextlocation.data;
|
package com.a1.nextlocation.data;
|
||||||
|
|
||||||
import org.osmdroid.views.overlay.Polyline;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,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 timeWalkedRoute = 0;
|
private long timeWalked = 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<>();
|
||||||
|
|
||||||
@@ -19,12 +26,12 @@ public enum StaticData {
|
|||||||
distanceTraveled += d;
|
distanceTraveled += d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTimeWalkedRoute() {
|
public long getTimeWalked() {
|
||||||
return timeWalkedRoute;
|
return timeWalked;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTimeWalked(long time) {
|
public void addTimeWalked(long time) {
|
||||||
timeWalkedRoute += time;
|
timeWalked += time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ import android.os.Bundle;
|
|||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
import com.a1.nextlocation.data.Coupon;
|
import com.a1.nextlocation.data.Coupon;
|
||||||
@@ -46,7 +43,7 @@ public class StatisticFragment extends Fragment {
|
|||||||
distance.setText("" + String.format("%.1f",dist) + " km");
|
distance.setText("" + String.format("%.1f",dist) + " km");
|
||||||
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
|
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
|
||||||
|
|
||||||
long seconds = StaticData.INSTANCE.getTimeWalkedRoute() / 1000;
|
long seconds = StaticData.INSTANCE.getTimeWalked() / 1000;
|
||||||
long p1 = seconds % 60;
|
long p1 = seconds % 60;
|
||||||
long p2 = seconds / 60;
|
long p2 = seconds / 60;
|
||||||
long p3 = p2 % 60;
|
long p3 = p2 % 60;
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ public class LocationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void coordinateDoublesTest(){
|
public void coordinateDoublesTest(){
|
||||||
double[] testDoubles = new double[2];
|
double[] testDoubles = new double[2];
|
||||||
testDoubles[0] = 15.4;
|
testDoubles[0] = 27.5;
|
||||||
testDoubles[1] = 27.5;
|
testDoubles[1] = 15.4;
|
||||||
|
|
||||||
double [] expectedCoordAsDouble = testDoubles;
|
double [] expectedCoordAsDouble = testDoubles;
|
||||||
String expectedStringFromDouble = "15.4,27.5";
|
String expectedStringFromDouble = "15.4,27.5";
|
||||||
|
|||||||
67
app/src/test/java/com/a1/nextlocation/RouteHandlerTest.java
Normal file
67
app/src/test/java/com/a1/nextlocation/RouteHandlerTest.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package com.a1.nextlocation;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Route;
|
||||||
|
import com.a1.nextlocation.data.RouteHandler;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.osmdroid.views.overlay.Polyline;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
public class RouteHandlerTest {
|
||||||
|
private RouteHandler routeHandler;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init(){
|
||||||
|
routeHandler = RouteHandler.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRouteLine(){
|
||||||
|
Polyline mPol = mock(Polyline.class);
|
||||||
|
routeHandler.setCurrentRouteLine(mPol);
|
||||||
|
assertEquals(mPol, routeHandler.getCurrentRouteLine());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStepCount(){
|
||||||
|
int expected = 0;
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
routeHandler.addStep();
|
||||||
|
expected++;
|
||||||
|
}
|
||||||
|
assertEquals(expected, routeHandler.getStepCount());
|
||||||
|
expected += 10;
|
||||||
|
assertNotEquals(expected, routeHandler.getStepCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRouteFollowing(){
|
||||||
|
Route testRoute = new Route("");
|
||||||
|
routeHandler.followRoute(testRoute);
|
||||||
|
boolean expected = true;
|
||||||
|
assertEquals(expected, routeHandler.isFollowingRoute(testRoute));
|
||||||
|
assertEquals(expected, routeHandler.isFollowingRoute());
|
||||||
|
assertEquals(testRoute, routeHandler.getCurrentRoute());
|
||||||
|
|
||||||
|
routeHandler.finishRoute();
|
||||||
|
assertNull(routeHandler.getCurrentRoute());
|
||||||
|
|
||||||
|
routeHandler.followRoute(new Route("FALSEROUTENAME"));
|
||||||
|
assertNotEquals(expected, routeHandler.isFollowingRoute(testRoute));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test(){
|
||||||
|
routeHandler.setRouteFinishedListener(() -> {
|
||||||
|
System.out.println("TEST");
|
||||||
|
});
|
||||||
|
assertNotNull(routeHandler.getRouteFinishedListener());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -90,4 +90,13 @@ public class RouteTest {
|
|||||||
assertEquals(expectedAfter, route.getTotalTime());
|
assertEquals(expectedAfter, route.getTotalTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDescription(){
|
||||||
|
route.setDescription("TEST");
|
||||||
|
String expected = "TEST";
|
||||||
|
assertEquals(expected, route.getDescription());
|
||||||
|
route.setDescription("FALSETEST");
|
||||||
|
assertNotEquals(expected, route.getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
49
app/src/test/java/com/a1/nextlocation/StaticDataTest.java
Normal file
49
app/src/test/java/com/a1/nextlocation/StaticDataTest.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package com.a1.nextlocation;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.a1.nextlocation.data.StaticData;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
|
||||||
|
public class StaticDataTest {
|
||||||
|
private StaticData staticData;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init(){
|
||||||
|
staticData = StaticData.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistance(){
|
||||||
|
staticData.addDistance(2356.234);
|
||||||
|
double expected = 2356.234;
|
||||||
|
assertEquals(expected, staticData.getDistanceTraveled(), 0.01);
|
||||||
|
staticData.addDistance(234342.1);
|
||||||
|
assertNotEquals(expected, staticData.getDistanceTraveled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTimeWalked(){
|
||||||
|
staticData.addTimeWalked(3456);
|
||||||
|
long expected = 3456;
|
||||||
|
assertEquals(expected, staticData.getTimeWalked());
|
||||||
|
staticData.addTimeWalked(3445);
|
||||||
|
assertNotEquals(expected, staticData.getTimeWalked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitedLocation(){
|
||||||
|
Location testLocation = new Location("test", "test", "test", "test");
|
||||||
|
staticData.visitLocation(testLocation);
|
||||||
|
int expected = 1;
|
||||||
|
assertEquals(expected, staticData.getLocationsVisited());
|
||||||
|
staticData.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
|
||||||
|
assertNotEquals(expected, staticData.getLocationsVisited());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user