Compare commits
1 Commits
follow-rou
...
route_deta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c921a76dc4 |
@@ -1,43 +1,35 @@
|
||||
[
|
||||
{
|
||||
"name": "rondje stad",
|
||||
"name": "Evenementen Route",
|
||||
"locations": [
|
||||
{
|
||||
"name":"Escaping Breda: Escape Room Games Boschstraat 114",
|
||||
"coordinates":"51.59096518753322, 4.783727736123234",
|
||||
"description":"4811GK Breda",
|
||||
"imageUrl":"NULL"
|
||||
"coordinates":"51.59096518753322, 4.783727736123234"
|
||||
},
|
||||
{
|
||||
"name":"Prison Escape Kloosterlaan 168",
|
||||
"coordinates":"51.59058740778487, 4.784723144974098",
|
||||
"description":"4811EE Breda",
|
||||
"imageUrl":"NULL"
|
||||
"coordinates":"51.59058740778487, 4.784723144974098"
|
||||
},
|
||||
{
|
||||
"name":"De Koepel - FutureDome Events Nassausingel 26",
|
||||
"coordinates":"51.59025697138579, 4.787354025225596",
|
||||
"description":"4811HP Breda",
|
||||
"imageUrl":"NULL"
|
||||
"coordinates":"51.59025697138579, 4.787354025225596"
|
||||
},
|
||||
{
|
||||
"name":"MEZZ Breda Keizerstraat 101",
|
||||
"coordinates":"51.5837840024532, 4.779037836841554",
|
||||
"description":"4811HL Breda",
|
||||
"imageUrl":"NULL"
|
||||
"coordinates":"51.5837840024532, 4.779037836841554"
|
||||
},
|
||||
{
|
||||
"name":"Het Klooster Breda Schorsmolenstraat 13",
|
||||
"coordinates":"51.58765659148822, 4.764801414019652",
|
||||
"description":"4811VN Breda",
|
||||
"imageUrl":"NULL"
|
||||
"coordinates":"51.58765659148822, 4.764801414019652"
|
||||
}
|
||||
],
|
||||
"totalDistance": 1073.0,
|
||||
"totalTime": 342342
|
||||
"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"
|
||||
},
|
||||
{
|
||||
"name": "Obesi Route",
|
||||
"name": "Hongerige Route",
|
||||
"locations": [
|
||||
{
|
||||
"name": "McDonald's Breda Karnemelkstraat",
|
||||
@@ -71,6 +63,8 @@
|
||||
}
|
||||
],
|
||||
"totalDistance": 955.0,
|
||||
"totalTime": 342342
|
||||
"totalTime": 342342,
|
||||
"description": "Met deze route bezoekt u alle snackbars en restaurants in het centrum van Breda!",
|
||||
"imageURL": "kees_kroket"
|
||||
}
|
||||
]
|
||||
@@ -18,6 +18,7 @@ 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) {
|
||||
@@ -69,6 +70,10 @@ 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
|
||||
|
||||
@@ -28,10 +28,6 @@ public enum RouteHandler {
|
||||
this.routeFinishedListener = routeFinishedListener;
|
||||
}
|
||||
|
||||
public RouteFinishedListener getRouteFinishedListener() {
|
||||
return routeFinishedListener;
|
||||
}
|
||||
|
||||
public int getStepCount() {
|
||||
return stepCount;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.a1.nextlocation.data;
|
||||
|
||||
import org.osmdroid.views.overlay.Polyline;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -9,16 +11,7 @@ public enum StaticData {
|
||||
INSTANCE;
|
||||
private double distanceTraveled = 0;
|
||||
private int locationsVisited = 0;
|
||||
private long timeWalked = 0;
|
||||
private double zoom = 0;
|
||||
|
||||
public double getZoom() {
|
||||
return zoom;
|
||||
}
|
||||
|
||||
public void setZoom(double zoom) {
|
||||
this.zoom = zoom;
|
||||
}
|
||||
private long timeWalkedRoute = 0;
|
||||
|
||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||
|
||||
@@ -26,12 +19,12 @@ public enum StaticData {
|
||||
distanceTraveled += d;
|
||||
}
|
||||
|
||||
public long getTimeWalked() {
|
||||
return timeWalked;
|
||||
public long getTimeWalkedRoute() {
|
||||
return timeWalkedRoute;
|
||||
}
|
||||
|
||||
public void addTimeWalked(long time) {
|
||||
timeWalked += time;
|
||||
timeWalkedRoute += time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ 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;
|
||||
@@ -12,7 +11,6 @@ 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;
|
||||
@@ -36,7 +34,6 @@ 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;
|
||||
@@ -52,14 +49,13 @@ 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;
|
||||
@@ -96,14 +92,11 @@ 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;
|
||||
}
|
||||
@@ -112,7 +105,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
||||
* stops the current route
|
||||
*/
|
||||
private void stopRoute() {
|
||||
Log.d(TAG, "stopRoute: STOPPING ROUTE" );
|
||||
Log.e(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();
|
||||
@@ -135,7 +128,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!");
|
||||
|
||||
@@ -181,10 +174,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
||||
|
||||
// add the zoom controller
|
||||
IMapController mapController = mapView.getController();
|
||||
if (StaticData.INSTANCE.getZoom() == 0) {
|
||||
StaticData.INSTANCE.setZoom(15.0);
|
||||
}
|
||||
mapController.setZoom(StaticData.INSTANCE.getZoom());
|
||||
mapController.setZoom(15.0);
|
||||
|
||||
// add location manager and set the start point
|
||||
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||
@@ -355,18 +345,14 @@ public class HomeFragment extends Fragment implements LocationListener {
|
||||
}
|
||||
|
||||
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
|
||||
// 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) {
|
||||
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 10) {
|
||||
StaticData.INSTANCE.visitLocation(l);
|
||||
if (l.equals(last)) stopRoute();
|
||||
}
|
||||
}
|
||||
|
||||
StaticData.INSTANCE.setZoom(mapView.getZoomLevelDouble());
|
||||
});
|
||||
|
||||
t.start();
|
||||
|
||||
}
|
||||
|
||||
// empty override methods for the LocationListener
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.a1.nextlocation.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
@@ -11,6 +12,7 @@ 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;
|
||||
|
||||
@@ -26,10 +28,7 @@ import java.util.List;
|
||||
public class RouteDetailFragment extends Fragment {
|
||||
|
||||
private Route route;
|
||||
private TextView routeDetailText;
|
||||
private TextView routeName;
|
||||
private TextView totalDistance;
|
||||
private ImageButton imageButton;
|
||||
private ImageView imageView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -45,18 +44,23 @@ public class RouteDetailFragment extends Fragment {
|
||||
this.route = getArguments().getParcelable("route");
|
||||
}
|
||||
|
||||
this.routeName = view.findViewById(R.id.route_title);
|
||||
this.routeName.setText(this.route.getName());
|
||||
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.routeDetailText = view.findViewById(R.id.reoute_detail_tekst);
|
||||
this.routeDetailText.setText(this.route.getDescription());
|
||||
TextView routeName = view.findViewById(R.id.route_title);
|
||||
routeName.setText(this.route.getName());
|
||||
|
||||
this.totalDistance = view.findViewById(R.id.total_distance);
|
||||
TextView routeDetailText = view.findViewById(R.id.reoute_detail_tekst);
|
||||
routeDetailText.setText(this.route.getDescription());
|
||||
|
||||
TextView totalDistance = view.findViewById(R.id.total_distance);
|
||||
String distance_tekst = getResources().getString(R.string.total_distance_route);
|
||||
this.totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
|
||||
totalDistance.setText(distance_tekst + " " + calculateRoute(this.route.getLocations()) + "m");
|
||||
|
||||
this.imageButton = view.findViewById(R.id.route_detail_back_button);
|
||||
this.imageButton.setOnClickListener(v -> {
|
||||
ImageButton imageButton = view.findViewById(R.id.route_detail_back_button);
|
||||
imageButton.setOnClickListener(v -> {
|
||||
RouteFragment routeFragment = new RouteFragment();
|
||||
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, routeFragment).addToBackStack(null).commit();
|
||||
});
|
||||
|
||||
@@ -5,12 +5,15 @@ 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;
|
||||
@@ -43,7 +46,7 @@ public class StatisticFragment extends Fragment {
|
||||
distance.setText("" + String.format("%.1f",dist) + " km");
|
||||
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
|
||||
|
||||
long seconds = StaticData.INSTANCE.getTimeWalked() / 1000;
|
||||
long seconds = StaticData.INSTANCE.getTimeWalkedRoute() / 1000;
|
||||
long p1 = seconds % 60;
|
||||
long p2 = seconds / 60;
|
||||
long p3 = p2 % 60;
|
||||
|
||||
@@ -68,8 +68,8 @@ public class LocationTest {
|
||||
@Test
|
||||
public void coordinateDoublesTest(){
|
||||
double[] testDoubles = new double[2];
|
||||
testDoubles[0] = 27.5;
|
||||
testDoubles[1] = 15.4;
|
||||
testDoubles[0] = 15.4;
|
||||
testDoubles[1] = 27.5;
|
||||
|
||||
double [] expectedCoordAsDouble = testDoubles;
|
||||
String expectedStringFromDouble = "15.4,27.5";
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
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,13 +90,4 @@ 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
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