9 Commits

Author SHA1 Message Date
Robin Koedood
b2c320dd14 [UPDATED] Route Test 2021-01-06 17:12:52 +01:00
Sem van der Hoeven
ce264d78bc rename 2021-01-06 17:09:11 +01:00
Robin Koedood
f8acc35c5b Merge remote-tracking branch 'origin/follow-route' into follow-route 2021-01-06 17:07:47 +01:00
Robin Koedood
e5e0916555 [ADD] Static Data Test 2021-01-06 17:07:26 +01:00
Sem van der Hoeven
c738deab23 commentssssssssssssssssssssss 2021-01-06 17:06:27 +01:00
Sem van der Hoeven
223e77cdc8 Merge branch 'follow-route' of https://github.com/SemvdH/Next-Location into follow-route 2021-01-06 16:57:08 +01:00
Sem van der Hoeven
7c9dc07c3d added keeping zoom level 2021-01-06 16:56:57 +01:00
Robin Koedood
187f45b770 Merge remote-tracking branch 'origin/follow-route' into follow-route 2021-01-06 16:56:21 +01:00
Robin Koedood
04487b77a7 [ADD] RouteHandler Test 2021-01-06 16:56:16 +01:00
8 changed files with 165 additions and 18 deletions

View File

@@ -28,6 +28,10 @@ public enum RouteHandler {
this.routeFinishedListener = routeFinishedListener;
}
public RouteFinishedListener getRouteFinishedListener() {
return routeFinishedListener;
}
public int getStepCount() {
return stepCount;
}

View File

@@ -1,7 +1,5 @@
package com.a1.nextlocation.data;
import org.osmdroid.views.overlay.Polyline;
import java.util.ArrayList;
/**
@@ -11,7 +9,16 @@ public enum StaticData {
INSTANCE;
private double distanceTraveled = 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<>();
@@ -19,12 +26,12 @@ public enum StaticData {
distanceTraveled += d;
}
public long getTimeWalkedRoute() {
return timeWalkedRoute;
public long getTimeWalked() {
return timeWalked;
}
public void addTimeWalked(long time) {
timeWalkedRoute += time;
timeWalked += time;
}

View File

@@ -2,6 +2,7 @@ package com.a1.nextlocation.fragments;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
@@ -11,6 +12,7 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
@@ -34,6 +36,7 @@ import com.a1.nextlocation.recyclerview.LocationListManager;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.CustomZoomButtonsController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.Overlay;
@@ -49,13 +52,14 @@ import java.util.List;
public class HomeFragment extends Fragment implements LocationListener {
private final String userAgent = "com.ai.nextlocation.fragments";
public final static String MAPQUEST_API_KEY = "vuyXjqnAADpjeL9QwtgWGleIk95e36My";
private ImageButton imageButton;
private ImageButton stopButton;
private MapView mapView;
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
private final String TAG = HomeFragment.class.getCanonicalName();
// private RoadManager roadManager;
private Polyline roadOverlay;
private int color;
private Location currentLocation;
@@ -92,11 +96,14 @@ public class HomeFragment extends Fragment implements LocationListener {
stopRoute();
});
// show or hide the stop route button based on if we are following a route
if (RouteHandler.INSTANCE.isFollowingRoute()) {
stopButton.setVisibility(View.VISIBLE);
} else {
stopButton.setVisibility(View.GONE);
}
//register as a listener for a result of the API
ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable);
return view;
}
@@ -105,7 +112,7 @@ public class HomeFragment extends Fragment implements LocationListener {
* stops the current route
*/
private void stopRoute() {
Log.e(TAG, "stopRoute: STOPPING ROUTE" );
Log.d(TAG, "stopRoute: STOPPING ROUTE" );
RouteHandler.INSTANCE.finishRoute();
stopButton.setVisibility(View.GONE);
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.setColor(color);
// pass the line to the route handler
RouteHandler.INSTANCE.setCurrentRouteLine(roadOverlay);
Log.d(TAG, "onDirectionsAvailable: successfully added road!");
@@ -174,7 +181,10 @@ public class HomeFragment extends Fragment implements LocationListener {
// add the zoom controller
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
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()) {
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);
if (l.equals(last)) stopRoute();
}
}
StaticData.INSTANCE.setZoom(mapView.getZoomLevelDouble());
});
t.start();
}
// empty override methods for the LocationListener

View File

@@ -5,15 +5,12 @@ import android.os.Bundle;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
@@ -46,7 +43,7 @@ public class StatisticFragment extends Fragment {
distance.setText("" + String.format("%.1f",dist) + " km");
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
long seconds = StaticData.INSTANCE.getTimeWalkedRoute() / 1000;
long seconds = StaticData.INSTANCE.getTimeWalked() / 1000;
long p1 = seconds % 60;
long p2 = seconds / 60;
long p3 = p2 % 60;

View File

@@ -68,8 +68,8 @@ public class LocationTest {
@Test
public void coordinateDoublesTest(){
double[] testDoubles = new double[2];
testDoubles[0] = 15.4;
testDoubles[1] = 27.5;
testDoubles[0] = 27.5;
testDoubles[1] = 15.4;
double [] expectedCoordAsDouble = testDoubles;
String expectedStringFromDouble = "15.4,27.5";

View 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());
}
}

View File

@@ -90,4 +90,13 @@ public class RouteTest {
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());
}
}

View 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());
}
}