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
11 changed files with 196 additions and 52 deletions

View File

@@ -1,35 +1,43 @@
[
{
"name": "Evenementen Route",
"name": "rondje stad",
"locations": [
{
"name":"Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates":"51.59096518753322, 4.783727736123234"
"coordinates":"51.59096518753322, 4.783727736123234",
"description":"4811GK Breda",
"imageUrl":"NULL"
},
{
"name":"Prison Escape Kloosterlaan 168",
"coordinates":"51.59058740778487, 4.784723144974098"
"coordinates":"51.59058740778487, 4.784723144974098",
"description":"4811EE Breda",
"imageUrl":"NULL"
},
{
"name":"De Koepel - FutureDome Events Nassausingel 26",
"coordinates":"51.59025697138579, 4.787354025225596"
"coordinates":"51.59025697138579, 4.787354025225596",
"description":"4811HP Breda",
"imageUrl":"NULL"
},
{
"name":"MEZZ Breda Keizerstraat 101",
"coordinates":"51.5837840024532, 4.779037836841554"
"coordinates":"51.5837840024532, 4.779037836841554",
"description":"4811HL Breda",
"imageUrl":"NULL"
},
{
"name":"Het Klooster Breda Schorsmolenstraat 13",
"coordinates":"51.58765659148822, 4.764801414019652"
"coordinates":"51.58765659148822, 4.764801414019652",
"description":"4811VN Breda",
"imageUrl":"NULL"
}
],
"totalDistance": 1073.0,
"totalTime": 342342,
"description": "Deze route laat u leuke events verspreid door breda zien! Probeer de escaperooms uit, een event bij de koepel, of een leuk feest bij MEZZ! Met deze route loopt u langs ze allemaal.",
"imageURL": "escaping_room"
"totalTime": 342342
},
{
"name": "Hongerige Route",
"name": "Obesi Route",
"locations": [
{
"name": "McDonald's Breda Karnemelkstraat",
@@ -63,8 +71,6 @@
}
],
"totalDistance": 955.0,
"totalTime": 342342,
"description": "Met deze route bezoekt u alle snackbars en restaurants in het centrum van Breda!",
"imageURL": "kees_kroket"
"totalTime": 342342
}
]

View File

@@ -18,7 +18,6 @@ public class Route implements Parcelable {
private String description;
private List<Location> locations;
private float totalDistance;
private String imageURL;
private int totalTime;
public Route(@NotNull String name) {
@@ -70,10 +69,6 @@ public class Route implements Parcelable {
return totalDistance;
}
public String getImageURL(){
return this.imageURL;
}
public int getTotalTime() {
//TODO calculate total time according to all locations in list

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

@@ -1,7 +1,6 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -12,7 +11,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -28,7 +26,10 @@ import java.util.List;
public class RouteDetailFragment extends Fragment {
private Route route;
private ImageView imageView;
private TextView routeDetailText;
private TextView routeName;
private TextView totalDistance;
private ImageButton imageButton;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -44,23 +45,18 @@ public class RouteDetailFragment extends Fragment {
this.route = getArguments().getParcelable("route");
}
this.imageView = view.findViewById(R.id.route_detail_image);
Context context = this.imageView.getContext();
int id = context.getResources().getIdentifier(this.route.getImageURL(), "drawable", context.getPackageName());
this.imageView.setImageResource(id);
this.routeName = view.findViewById(R.id.route_title);
this.routeName.setText(this.route.getName());
TextView routeName = view.findViewById(R.id.route_title);
routeName.setText(this.route.getName());
this.routeDetailText = view.findViewById(R.id.reoute_detail_tekst);
this.routeDetailText.setText(this.route.getDescription());
TextView routeDetailText = view.findViewById(R.id.reoute_detail_tekst);
routeDetailText.setText(this.route.getDescription());
TextView totalDistance = view.findViewById(R.id.total_distance);
this.totalDistance = view.findViewById(R.id.total_distance);
String distance_tekst = getResources().getString(R.string.total_distance_route);
totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
this.totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
ImageButton imageButton = view.findViewById(R.id.route_detail_back_button);
imageButton.setOnClickListener(v -> {
this.imageButton = view.findViewById(R.id.route_detail_back_button);
this.imageButton.setOnClickListener(v -> {
RouteFragment routeFragment = new RouteFragment();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeFragment).addToBackStack(null).commit();
});

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