Merge branch 'follow-route' of https://github.com/SemvdH/Next-Location into follow-route

This commit is contained in:
Sem van der Hoeven
2021-01-06 16:57:08 +01:00
9 changed files with 131 additions and 43 deletions

View File

@@ -2,6 +2,12 @@
{
"name": "rondje stad",
"locations": [
{
"name":"Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates":"51.59096518753322, 4.783727736123234",
"description":"4811GK Breda",
"imageUrl":"NULL"
},
{
"name":"Prison Escape Kloosterlaan 168",
"coordinates":"51.59058740778487, 4.784723144974098",
@@ -14,13 +20,6 @@
"description":"4811HP Breda",
"imageUrl":"NULL"
},
{
"name":"Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates":"51.59096518753322, 4.783727736123234",
"description":"4811GK Breda",
"imageUrl":"NULL"
},
{
"name":"MEZZ Breda Keizerstraat 101",
"coordinates":"51.5837840024532, 4.779037836841554",
@@ -34,31 +33,31 @@
"imageUrl":"NULL"
}
],
"totalDistance": 2.3434,
"totalDistance": 1073.0,
"totalTime": 342342
},
{
"name": "Obesi Route",
"locations": [
{
"name": "Kees Kroket Houtmarkt 9",
"coordinates": "51.58628401688983, 4.77579695141302",
"description": "lekkere patatjes"
},
{
"name": "McDonald's Breda Karnemelkstraat",
"coordinates": "51.586062613842245, 4.777606887874218",
"description": "Wist je dat McDonalds de grootste restaurantketen ter wereld is? Hierdoor hebben we een indrukwekkende geschiedenis. Maar wij kijken liever naar onze toekomst. Nieuwe restaurants, betere producten en duurzaam ondernemen. Wil je meer weten over McDonalds? Lees verder op: https://www.mcdonalds.com/nl/nl-nl/over-ons.html!"
},
{
"name": "Kees Kroket Houtmarkt 9",
"coordinates": "51.58628401688983, 4.77579695141302",
"description": "lekkere patatjes"
},
{
"name": "Wok To Go Halstraat 40",
"coordinates": "51.586464146477574, 4.777606887874218",
"description": "Bij Wok To Go houden we van snelle, gezonde en smaakvolle maaltijden. Sinds 2003 ontwikkelen onze chef-koks de lekkerste wokgerechten met verse ingrediënten. We doen dit vól overgave onder het motto “Making people happy through food”. Door het roerbakken met een kleine hoeveelheid olie op grote hitte, blijven de smaak en gezonde voedingsstoffen bewaard. We kiezen voor gezonde en unieke ingrediënten en bereiden uitgebalanceerde gerechten in een Wokki box voor een gezonde levensstijl."
},
{
"name": "De Boterhal Grote Markt 19",
"coordinates": "51.58798747205394, 4.776265846483903",
"description": "De Boterhal in Breda is een internationaal tapasrestaurant, speciaalbiercafé en wijnbar. Men kan gezellig bij ons lunchen, borrelen en dineren. Wij hebben een uitgebreide menukaart met een hele hoop bieren, wijnen, zowel per glas als per fles te verkrijgen, lunch en tapasgerechtjes. Naast het eten wat wij serveren hebben we ook een hoop bieren en wijnen. Naast de bieren op de kaart hebben wij wisselende bieren; vijf ketelbieren en vijf seizoensbieren."
"name": "The Tosti Club Breda A4, Vlaszak 2",
"coordinates": "51.588922458012384, 4.7804923888638",
"description": "Je kunt bij al onze vestigingen de hele dag terecht, want bij The Tosti Club eet je het klokje rond. Dus kom gezellig ontbijten, lunchen of voor een snelle hap aan het einde van de dag (wat dacht je van onze The Tosti Slice, onze variant op pizza!). Even geen zin in brood? Dan kunnen we je ook verblijden met onder andere acaï smoothiebowls, pancakes, granolas / yoghurt of gewoon een lekkere warme drank met gebak. Mogen we je de Red Velvet fudge cake aanraden?"
},
{
"name": "Gauchos Grote Markt 33",
@@ -66,12 +65,12 @@
"description": "De middeleeuwse Grote Markt is een historische plek in het Bourgondische hart van Breda, ooit in handen van de Spaanse bezetter. Gauchos Grill-Restaurant combineert daar Brabantse gemoedelijkheid met professionele gastvrijheid. In onze Latijnse keuken bereiden wij op uw aanwijzing een malse Argentijnse steak of een smakelijk visgerecht van de grill."
},
{
"name": "The Tosti Club Breda A4, Vlaszak 2",
"coordinates": "51.588922458012384, 4.7804923888638",
"description": "Je kunt bij al onze vestigingen de hele dag terecht, want bij The Tosti Club eet je het klokje rond. Dus kom gezellig ontbijten, lunchen of voor een snelle hap aan het einde van de dag (wat dacht je van onze The Tosti Slice, onze variant op pizza!). Even geen zin in brood? Dan kunnen we je ook verblijden met onder andere acaï smoothiebowls, pancakes, granolas / yoghurt of gewoon een lekkere warme drank met gebak. Mogen we je de Red Velvet fudge cake aanraden?"
"name": "De Boterhal Grote Markt 19",
"coordinates": "51.58798747205394, 4.776265846483903",
"description": "De Boterhal in Breda is een internationaal tapasrestaurant, speciaalbiercafé en wijnbar. Men kan gezellig bij ons lunchen, borrelen en dineren. Wij hebben een uitgebreide menukaart met een hele hoop bieren, wijnen, zowel per glas als per fles te verkrijgen, lunch en tapasgerechtjes. Naast het eten wat wij serveren hebben we ook een hoop bieren en wijnen. Naast de bieren op de kaart hebben wij wisselende bieren; vijf ketelbieren en vijf seizoensbieren."
}
],
"totalDistance": 2.3434,
"totalDistance": 955.0,
"totalTime": 342342
}
]

View File

@@ -112,15 +112,6 @@ public class Location implements Parcelable {
return long1 + "," + lat1;
}
/**
* calculates the distance to the other location.
* @param other the other location
* @return the distance between the locations in meters
*/
public double getDistance(Location other) {
return getDistance(this.getLat(),this.getLong(),other.getLat(),other.getLong());
}
/**
* calculates the distance between two coordinates
* @param lat1 the first latitude
@@ -145,8 +136,12 @@ public class Location implements Parcelable {
// Radius of earth in kilometers. Use 3956
// for miles
double r = 6371;
// if(miles) {
// double r = 3956;
// }
// else {
double r = 6371;
// }
// calculate the result
double distance = c * r;

View File

@@ -66,7 +66,6 @@ public class Route implements Parcelable {
}
public float getTotalDistance() {
//TODO calculate total distance according to all locations in list
return totalDistance;
}

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,5 +1,6 @@
package com.a1.nextlocation.fragments;
import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -27,6 +28,7 @@ public class RouteDetailFragment extends Fragment {
private Route route;
private TextView routeDetailText;
private TextView routeName;
private TextView totalDistance;
private ImageButton imageButton;
@Override
@@ -35,6 +37,7 @@ public class RouteDetailFragment extends Fragment {
}
@SuppressLint("SetTextI18n")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_route_detail, container, false);
@@ -48,6 +51,10 @@ public class RouteDetailFragment extends Fragment {
this.routeDetailText = view.findViewById(R.id.reoute_detail_tekst);
this.routeDetailText.setText(this.route.getDescription());
this.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");
this.imageButton = view.findViewById(R.id.route_detail_back_button);
this.imageButton.setOnClickListener(v -> {
RouteFragment routeFragment = new RouteFragment();
@@ -57,8 +64,6 @@ public class RouteDetailFragment extends Fragment {
Button startButton = view.findViewById(R.id.start_route_button);
startButton.setOnClickListener(this::startRoute);
calculateRoute(this.route.getLocations());
return view;
}
@@ -71,24 +76,28 @@ public class RouteDetailFragment extends Fragment {
RouteHandler.INSTANCE.followRoute(route);
Toast.makeText(requireContext(),"Route started!",Toast.LENGTH_SHORT).show();
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).addToBackStack(null).commit();
}
//Calculates the route total distance
/**
* Calculates the distance between points
* @param route the route that is calculated
* @return the total distance of a route
*/
public double calculateRoute(List<Location> route){
ArrayList<Location> routeArraylist = new ArrayList<>(route);
double totalDistance = 0;
Location firstLocation;
Location secondLocation;
System.out.println("Total locations: " + routeArraylist.size());
//Cycles through the arraylist
for(int i = 0; i < routeArraylist.size() - 1; i++) {
firstLocation = routeArraylist.get(i);
secondLocation = routeArraylist.get(i+1);
System.out.println("locations distance calculated: " + (i+1) + " and " + (i+2) + "\nThe added distance is: " + Location.getDistance(firstLocation.getLat(), firstLocation.getLong(), secondLocation.getLat(), secondLocation.getLong()));
//Calculates the distance between points
totalDistance += Location.getDistance(firstLocation.getLat(), firstLocation.getLong(), secondLocation.getLat(), secondLocation.getLong());
// totalDistance += firstLocation.getDistance(secondLocation);
System.out.println("Distance nu: " + totalDistance);
}
System.out.println("Total Distance: " + totalDistance);
return totalDistance;
}

View File

@@ -38,9 +38,7 @@
app:layout_constraintTop_toBottomOf="@id/route_detail_back_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/reoute_detail_tekst"
/>
app:layout_constraintBottom_toTopOf="@id/reoute_detail_tekst" />
<TextView
android:id="@+id/reoute_detail_tekst"
@@ -57,14 +55,29 @@
android:id="@+id/start_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_route"
android:layout_marginBottom="30dp"
android:backgroundTint="@color/secondaryColour"
android:text="@string/start_route"
android:textColor="@color/buttonColour"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/total_distance" />
<TextView
android:id="@+id/total_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="141dp"
android:layout_marginBottom="19dp"
android:text="@string/total_distance"
android:background="@color/secondaryColour"
android:textColor="@color/buttonColour"
app:layout_constraintBottom_toTopOf="@+id/start_route_button"
app:layout_constraintTop_toBottomOf="@+id/reoute_detail_tekst"
app:layout_constraintVertical_bias="0.671" />
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteX="169dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -19,6 +19,7 @@
<string name="activate_question">Weet je zeker dat je deze coupon wilt activeren?</string>
<string name="activate">activeren</string>
<string name="done">Klaar</string>
<string name="total_distance_route">De totale afstand van de route is: </string>
<string name="cancel">annuleren</string>
<string name="English">Engels</string>
<string name="Dutch">Nederlands</string>

View File

@@ -18,6 +18,7 @@
<string name="activate">activate</string>
<string name="done">Done</string>
<string name="cancel">cancel</string>
<string name="total_distance_route">The total distance of the route is:</string>
<string name="route_stop_toast">Route stopped!</string>
<string name="Dutch">Dutch</string>
<string name="English">English</string>

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