1 Commits

Author SHA1 Message Date
Robin Koedood
1db6d03da7 [ADD] Extra route and locations description 2021-01-06 14:07:19 +01:00
20 changed files with 123 additions and 305 deletions

View File

@@ -15,8 +15,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NextLocation"
android:hardwareAccelerated="false">
android:theme="@style/Theme.NextLocation">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -123,13 +123,13 @@
{
"name":"Belcrum Beach Veilingkade 12a",
"coordinates":"51.599434239284726,4.76632797992092",
"description":"Belcrum Beach is HET stadsstrand van Breda, gelegen op het Haveneiland in de wijk Belcrum. Wij zijn begonnen in 2013 op deze unieke lokatie in Breda. Het strand werkt met drie beheerders en een groot aantal vrijwilligers voor bar, onderhoud, programmering, sponsoring en tuin. Een plek om te relaxen met een drankje en een hapje, genietend van de zon, gezellig kletsen met je vrienden, luisterend naar muziek van een band of DJ, soms in een festival setting. Kinderen die kunnen spelen in het zand of mee kunnen doen aan speciale kinderactiviteiten. Belcrum Beach is ook een unieke lokatie voor een feestje of om je verjaardag te vieren, trouwen op het strand of een trouwfeest behoren ook tot de mogelijkheden.",
"description":"Belcrum Beach is HET stadsstrand van Breda, gelegen op het Haveneiland in de wijk Belcrum. Wij zijn begonnen in 2013 op deze unieke lokatie in Breda. Een plek om te relaxen met een drankje en een hapje, genietend van de zon, gezellig kletsen met je vrienden, luisterend naar muziek van een band of DJ, soms in een festival setting. Kinderen die kunnen spelen in het zand of mee kunnen doen aan speciale kinderactiviteiten.",
"imageUrl":"belcrum_beach"
},
{
"name":"De Belcrum Watertoren (1935) Speelhuislaan 158",
"coordinates":"51.60135351009892,4.7705765989322755",
"description":"De watertoren in de Belcrum in Breda is een industrieel monument uit het interbellum. De toren is de thuisbasis voor SOAB adviseurs voor woning en leefomgeving en onderstreept de missie van ons bureau. De toren hoort bij de Belcrum. Als landmark en als onderdak voor activiteiten. Zo vierden de Belcrummers hun 400 jaar bestaan in de toren en worden lunches met rondleiding op hoog niveau georganiseerd. Kijken en proeven.",
"description":"4815CJ Breda",
"imageUrl":"belcrum_watertoren"
}
]
]

View File

@@ -3,38 +3,76 @@
"name": "rondje stad",
"locations": [
{
"name":"Prison Escape Kloosterlaan 168",
"coordinates":"51.59073795635181,4.784917104321059",
"description":"4811EE Breda",
"imageUrl":"NULL"
"name": "Prison Escape Kloosterlaan 168",
"coordinates": "51.59073795635181,4.784917104321059",
"description": "4811EE Breda",
"imageUrl": "NULL"
},
{
"name":"De Koepel - FutureDome Events Nassausingel 26",
"coordinates":"51.590431588532105,4.786756741648511",
"description":"4811HP Breda",
"imageUrl":"NULL"
},
{
"name":"Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates":" 51.59110835530862,4.784147222780912",
"description":"4811GK Breda",
"imageUrl":"NULL"
"name": "De Koepel - FutureDome Events Nassausingel 26",
"coordinates": "51.590431588532105,4.786756741648511",
"description": "4811HP Breda",
"imageUrl": "NULL"
},
{
"name":"MEZZ Breda Keizerstraat 101",
"coordinates":"51.58394697737321,4.779757901349616",
"description":"4811HL Breda",
"imageUrl":"NULL"
"name": "Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates": " 51.59110835530862,4.784147222780912",
"description": "4811GK Breda",
"imageUrl": "NULL"
},
{
"name":"Het Klooster Breda Schorsmolenstraat 13",
"coordinates":"51.58775443759389,4.765568874365066",
"description":"4811VN Breda",
"imageUrl":"NULL"
"name": "MEZZ Breda Keizerstraat 101",
"coordinates": "51.58394697737321,4.779757901349616",
"description": "4811HL Breda",
"imageUrl": "NULL"
},
{
"name": "Het Klooster Breda Schorsmolenstraat 13",
"coordinates": "51.58775443759389,4.765568874365066",
"description": "4811VN Breda",
"imageUrl": "NULL"
}
],
"totalDistance": 2.3434,
"totalTime": 342342
},
{
"name": "Obesi Route",
"locations": [
{
"name": "KesCrOkÊt breeda",
"coordinates": "2.4654645,6.2342323",
"description": "lekkere patatjes"
},
{
"name": "McDonald's Breda Karnemelkstraat",
"coordinates": "51.58596318905295,4.77586651481887",
"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": "Wok To Go Halstraat 40",
"coordinates": "51.58650312572897,4.777467069592386",
"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.588069667604756,4.7762685632180695",
"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": "Gauchos Grote Markt 33",
"coordinates": "51.58859328857082,4.77601349563689",
"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.58905632735254,4.780729463841719",
"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?"
}
],
"totalDistance": 2.3434,
"totalTime": 342342
}
]
]

View File

@@ -1,35 +1,35 @@
package com.a1.nextlocation;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.util.Log;
import android.view.MenuItem;
import com.a1.nextlocation.fragments.HelpPopup;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.data.FileIO;
import com.a1.nextlocation.data.Route;
import com.a1.nextlocation.fragments.HomeFragment;
import com.a1.nextlocation.fragments.Refreshable;
import com.a1.nextlocation.fragments.RouteFragment;
import com.a1.nextlocation.fragments.SettingsFragment;
import com.a1.nextlocation.fragments.StatisticFragment;
import com.a1.nextlocation.network.ApiHandler;
import com.a1.nextlocation.recyclerview.CouponListManager;
import com.a1.nextlocation.recyclerview.LocationListManager;
import com.a1.nextlocation.recyclerview.RouteListManager;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.io.File;
import java.util.Arrays;
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements Refreshable {
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getName();
private BottomNavigationView bottomNav;
private ImageButton infoButton;
/**
* onCreate method that creates the main activity
@@ -38,15 +38,11 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// initialize saved language from sharedPreferences
setLocale(loadLocale());
setContentView(R.layout.activity_main);
bottomNav = findViewById(R.id.navigation_bar);
BottomNavigationView bottomNav = findViewById(R.id.navigation_bar);
bottomNav.setOnNavigationItemSelectedListener(navListener);
infoButton = findViewById(R.id.info_button);
infoButton.setOnClickListener(onInfoClickListener);
/*System.out.println(Arrays.toString(getFilesDir().listFiles()));
FileIO<Route> fileIO = new FileIO<>();
@@ -60,9 +56,10 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
RouteListManager.INSTANCE.setContext(this);
RouteListManager.INSTANCE.load();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
}
// initialize saved language from sharedPreferences
setLocale(loadLocale());
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
}
/**
@@ -108,33 +105,4 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, selectedFragment).commit();
return true;
};
/**
* refreshes bottom navigation
*/
@Override
public void refresh() {
bottomNav.getMenu().clear();
bottomNav.inflateMenu(R.menu.navmenu);
bottomNav.setSelectedItemId(R.id.settings);
}
private View.OnClickListener onInfoClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
// AlertDialog.Builder infoBuilder = new AlertDialog.Builder(getBaseContext());
// infoBuilder.setCancelable(true);
//// infoBuilder.setPositiveButton(R.string.activate, (dialog, which) -> {
//// dialog.cancel();
//// });
// infoBuilder.setView(getLayoutInflater().inflate(R.layout.help_popup, null));
// AlertDialog infoPopup = infoBuilder.create();
// infoPopup.show();
FragmentManager fragment = getSupportFragmentManager();
DialogFragment helpPopupFragment = new HelpPopup();
helpPopupFragment.show(fragment, "YEET");
}
};
}

View File

@@ -112,23 +112,25 @@ 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());
double dlon = other.getLong() - getLong();
double dlat = other.getLat() - getLong();
double a = Math.pow(Math.sin(dlat / 2), 2)
+ Math.cos(getLat()) * Math.cos(other.getLong())
* Math.pow(Math.sin(dlon / 2),2);
double c = 2 * Math.asin(Math.sqrt(a));
// Radius of earth in kilometers. Use 3956
// for miles
double r = 6371;
// calculate the result
double distance = c * r;
return Math.floor(distance);
}
/**
* calculates the distance between two coordinates
* @param lat1 the first latitude
* @param lon1 the first longitude
* @param lat2 the second latitude
* @param lon2 the second longitude
* @return the distance between the coordinates in meters
*/
public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
double dlon = lon2 - lon1;
double dlat = lat2 - lat1;

View File

@@ -12,7 +12,6 @@ public enum RouteHandler {
private Route currentRoute;
private int stepCount = 0;
private RouteFinishedListener routeFinishedListener;
private long startedTime;
private Polyline currentRouteLine;
@@ -41,14 +40,11 @@ public enum RouteHandler {
isFollowingRoute = false;
currentRoute = null;
currentRouteLine = null;
StaticData.INSTANCE.addTimeWalked(System.currentTimeMillis()-startedTime);
startedTime = 0;
}
public void followRoute(Route route) {
this.currentRoute = route;
setFollowingRoute(true);
startedTime = System.currentTimeMillis();
}
public boolean isFollowingRoute(Route route) {

View File

@@ -11,7 +11,6 @@ public enum StaticData {
INSTANCE;
private double distanceTraveled = 0;
private int locationsVisited = 0;
private long timeWalkedRoute = 0;
private ArrayList<String> visitedNames = new ArrayList<>();
@@ -19,14 +18,6 @@ public enum StaticData {
distanceTraveled += d;
}
public long getTimeWalkedRoute() {
return timeWalkedRoute;
}
public void addTimeWalked(long time) {
timeWalkedRoute += time;
}
public double getDistanceTraveled() {
return distanceTraveled;

View File

@@ -1,20 +1,4 @@
package com.a1.nextlocation.fragments;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.DialogFragment;
import com.a1.nextlocation.R;
public class HelpPopup extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.help_popup, container, false);
getDialog().setTitle("Simple Dialog");
return rootView;
}
public class HelpPopup {
}

View File

@@ -91,7 +91,7 @@ public class HomeFragment extends Fragment implements LocationListener {
stopButton.setOnClickListener(v -> {
RouteHandler.INSTANCE.finishRoute();
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();
mapView.getOverlays().remove(roadOverlay);
mapView.getOverlays().remove(allLocationsOverlay);
addLocations();
@@ -110,7 +110,6 @@ public class HomeFragment extends Fragment implements LocationListener {
/**
* callback method that gets called when there are new directions available in the form of a {@link DirectionsResult} object.
*
* @param directionsResult the directions received from the api
*/
private void onDirectionsAvailable(DirectionsResult directionsResult) {
@@ -209,7 +208,6 @@ public class HomeFragment extends Fragment implements LocationListener {
private void displayRoute() {
if (RouteHandler.INSTANCE.isFollowingRoute()) {
Log.d(TAG, "displayRoute: WE ARE FOLLOWING A ROUTE");
if (roadOverlay == null) {
if (RouteHandler.INSTANCE.getCurrentRouteLine() != null) {
roadOverlay = RouteHandler.INSTANCE.getCurrentRouteLine();
@@ -288,9 +286,9 @@ public class HomeFragment extends Fragment implements LocationListener {
}
/**
* @param permissions tbe permissions we want to ask
* @author Ricky
* request the permissions needed for location and network, made by Ricky
* @param permissions tbe permissions we want to ask
*/
private void requestPermissionsIfNecessary(String... permissions) {
ArrayList<String> permissionsToRequest = new ArrayList<>();
@@ -312,22 +310,15 @@ public class HomeFragment extends Fragment implements LocationListener {
/**
* location callback that gets called each time the location is updated. It is used for updating the distance walked and checking if there are locations you have visited
*
* @param location the new location
*/
@Override
public void onLocationChanged(@NonNull Location location) {
// calculate the distance walked
if (currentLocation != null) {
double distance = currentLocation.distanceTo(location); // in meters
// can't walk 100 meters in a few seconds
if (distance < 100)
StaticData.INSTANCE.addDistance(distance);
}
double distance = currentLocation.distanceTo(location); // in meters
StaticData.INSTANCE.addDistance(distance);
currentLocation = location;
//new thread because we don't want the main thread to hang, this method gets called a lot
Thread t = new Thread(() -> {
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {

View File

@@ -1,6 +1,5 @@
package com.a1.nextlocation.fragments;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -12,8 +11,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Location;
@@ -23,9 +20,6 @@ public class LocationDetailFragment extends Fragment {
private ImageButton imageButton;
private Location location;
private TextView titelText;
private TextView detailText;
private ImageView locationImage;
public LocationDetailFragment() {
@@ -44,13 +38,6 @@ public class LocationDetailFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_location_detail, container, false);
this.titelText = view.findViewById(R.id.detail_location_name);
this.titelText.setText(location.getName());
this.detailText = view.findViewById(R.id.detail_location_text);
this.detailText.setText(location.getDescription());
this.imageButton = view.findViewById(R.id.detail_location_back_button);
this.imageButton.setOnClickListener(v -> {
LocationFragment locationFragment = new LocationFragment();
@@ -60,12 +47,6 @@ public class LocationDetailFragment extends Fragment {
if (location != null) {
Log.d(TAG, "onCreateView: the location has a name of: " + location.getName());
}
this.locationImage = view.findViewById(R.id.detail_location_image);
Context context = this.locationImage.getContext();
int id = context.getResources().getIdentifier(this.location.getImageUrl(), "drawable", context.getPackageName());
this.locationImage.setImageResource(id);
return view;
}

View File

@@ -1,5 +0,0 @@
package com.a1.nextlocation.fragments;
public interface Refreshable {
void refresh();
}

View File

@@ -57,10 +57,6 @@ public class RouteDetailFragment extends Fragment {
return view;
}
/**
* Button onclick method that starts the route that is being viewed.
* @param view the button
*/
public void startRoute(View view) {
ApiHandler.INSTANCE.getDirections(route);
RouteHandler.INSTANCE.followRoute(route);

View File

@@ -5,6 +5,8 @@ import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -18,24 +20,18 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import com.a1.nextlocation.MainActivity;
import com.a1.nextlocation.R;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
public class SettingsFragment extends Fragment {
private SharedPreferences.Editor editor;
private ImageView imageButton;
SwitchCompat fontChanger;
private Refreshable refreshable;
@Override
public void onAttach(@NotNull Context context) {
super.onAttach(context);
refreshable = (Refreshable) context;
}
SwitchCompat fontChanger;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -91,7 +87,7 @@ public class SettingsFragment extends Fragment {
private void initializeLanguageDropdown(View view) {
Spinner languageDropdown = view.findViewById(R.id.dropdown_menu_Settings);
String[] items = new String[]{getResources().getString(R.string.Dutch), getResources().getString(R.string.English), getResources().getString(R.string.Chinese)};
String[] items = new String[]{"Nederlands", "Engels", "Chinees"};
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, items);
languageDropdown.setAdapter(arrayAdapter);
@@ -103,11 +99,15 @@ public class SettingsFragment extends Fragment {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
setLocale(dropdownPositionToLanguage(id));
// refresh fragment on language change
if (id != previousID) {
refresh();
Fragment currentFragment = getActivity().getSupportFragmentManager().findFragmentById(R.id.fragment_layout);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.detach(currentFragment);
fragmentTransaction.attach(currentFragment);
fragmentTransaction.commit();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
@@ -157,8 +157,6 @@ public class SettingsFragment extends Fragment {
fragmentTransaction.detach(currentFragment);
fragmentTransaction.attach(currentFragment);
fragmentTransaction.commit();
refreshable.refresh();
}
/**

View File

@@ -40,11 +40,9 @@ public class StatisticFragment extends Fragment {
TextView distance = view.findViewById(R.id.statistics_km);
TextView locs = view.findViewById(R.id.statistics_locations_visited);
TextView timeText = view.findViewById(R.id.statistics_time_value);
double dist = StaticData.INSTANCE.getDistanceTraveled()/1000;
distance.setText("" + String.format("%.1f",dist) + " km");
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
timeText.setText("" + StaticData.INSTANCE.getTimeWalkedRoute());
this.couponList = CouponListManager.INSTANCE.getCouponList();

View File

@@ -132,10 +132,6 @@ public class DirectionsResult {
}
/**
* parses the given json string into this object. This method is used for when you want to
* @param json
*/
public void parseRoute(String json) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

View File

@@ -20,72 +20,43 @@ import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* Singleton that handles all API calls
*/
public enum ApiHandler {
INSTANCE;
private static String TAG = ApiHandler.class.getCanonicalName();
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8");
private final String BASE_URL = "https://api.openrouteservice.org/v2/directions/";
private final String API_KEY = "5b3ce3597851110001cf6248d4eee2099f724255918adc71cc502b2a";
private final String DIRECTIONS_MODE = "foot-walking";
private List<DirectionsListener> listeners = new ArrayList<>();
private OkHttpClient client = new OkHttpClient();
/**
* gets directions from the start location to the end location
* @param startLocation the start location
* @param endLocation the end location
*/
public void getDirections(Location startLocation, Location endLocation) {
getDirections(startLocation.getCoordinates(),endLocation.getCoordinates());
}
/**
* gets directions from the start location latitude and longitude and the end location latitude and longitude
* @param startLat the start latitude
* @param startLong the start longitude
* @param endLat the end latitude
* @param endLong the end longitude
*/
public void getDirections(double startLat, double startLong, double endLat, double endLong) {
getDirections(startLong + "," + startLat, endLong + "," + endLat);
}
/**
* Gets the directions from the start location to the end location. An example location would be "3.543543,5.7675765"
* @param startLocation the start location represented as <i>startlat,startlong</i>
* @param endLocation the end location represented as <i>endlat,endlong</i>
*/
public void getDirections(String startLocation, String endLocation) {
// build the url
String requestUrl = BASE_URL + DIRECTIONS_MODE + "?api_key=" + API_KEY + "&start=" +startLocation + "&end=" + endLocation;
// start a new thread to do the request, because we don't want to be networking on our main thread
Thread t = new Thread(() -> {
// build a request from the url
Request request = new Request.Builder().url(requestUrl).build();
// try to get the response
try (Response response = client.newCall(request).execute()) {
if (response.body() != null) {
String responseString = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "getDirections: got response: " + responseString);
// convert the response into a result object
System.out.println(responseString);
DirectionsResult result = new DirectionsResult();
result.parse(responseString);
Log.d(TAG, "getDirections: " + result.getSteps().size());
// notify the listeners
for (DirectionsListener listener : listeners) {
listener.onDirectionsAvailable(result);
}
@@ -106,35 +77,29 @@ public enum ApiHandler {
}
/**
* adds a listener for when a result of an api call is available
* @param listener the new listener
*/
public void addListener(DirectionsListener listener) {
this.listeners.add(listener);
}
/**
* gets directions for the given {@link Route}
* @param route the route to get directions for
*/
public void getDirections(Route route) {
// for (int i = 0; i < route.getLocations().size()-1; i+= 2) {
// Location start = route.getLocations().get(i);
// Location end = route.getLocations().get(i+1);
// getDirections(start,end);
// }
// add the coordinates to the list
ArrayList<double[]> allCoords = new ArrayList<>();
for (Location location : route.getLocations()) {
allCoords.add(location.getCoordinatesAsDoubles());
}
// convert it to a json string
String body = "{\"coordinates\":" + new Gson().toJson(allCoords) + "}";
String requestUrl = BASE_URL + DIRECTIONS_MODE + "?api_key=" + API_KEY;
// new thread, because we don't want to be networking on our main thread
Thread t = new Thread(() -> {
// add the body to the request
RequestBody requestBody = RequestBody.create(body,JSON);
Request request = new Request.Builder()
.url(requestUrl)
@@ -145,19 +110,15 @@ public enum ApiHandler {
if (response.body() != null) {
String responseString = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "getDirections: got response: " + responseString);
// kinda lazy, but we had time pressure
if (responseString.startsWith("{\"error")) {
Log.e(TAG, "getDirections: ERROR IN REQUEST!");
return;
}
// convert the result into a DirectionsResult
DirectionsResult result = new DirectionsResult();
result.parseRoute(responseString);
Log.d(TAG, "getDirections: " + result.getSteps().size());
//notify the listeners
for (DirectionsListener listener : listeners) {
listener.onDirectionsAvailable(result);
}
@@ -171,7 +132,6 @@ public enum ApiHandler {
t.start();
// wait for when we have a result from the api until we can continue, otherwise the route will be drawn before we get the result
try {
t.join();
} catch (InterruptedException e) {

View File

@@ -151,7 +151,6 @@
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/statistics_time_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""

View File

@@ -1,64 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--<androidx.appcompat.widget.LinearLayoutCompat-->
<!-- xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_gravity="center"-->
<!-- android:orientation="vertical">-->
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@string/help"-->
<!-- android:textAlignment="center"-->
<!-- android:background="@color/secondaryColour"-->
<!-- android:paddingVertical="10dp"/>-->
<!-- -->
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="400dp"-->
<!-- android:text="@string/help_discription"-->
<!-- android:background="@color/primaryColour"/>-->
<!-- -->
<!--</androidx.appcompat.widget.LinearLayoutCompat>-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/helpPopConst"
android:layout_height="500dp"
android:layout_width="300dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:background="@color/primaryColour">
<TextView
android:id="@+id/helpPopTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="300dp"
android:layout_height="50dp"
android:text="@string/help"
android:textColor="@color/black"
android:textAlignment="center"
android:background="@color/secondaryColour"
android:paddingVertical="10dp"/>
<TextView
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/helpPopTitle"
android:layout_width="280dp"
android:layout_height="380dp"
android:text="@string/help_discription"
android:textColor="@color/white"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -20,9 +20,4 @@
<string name="activate">activeren</string>
<string name="done">Klaar</string>
<string name="cancel">annuleren</string>
<string name="English">Engels</string>
<string name="Dutch">Nederlands</string>
<string name="Chinese">Chinees</string>
<string name="help">HELP</string>
<string name="help_discription">Onderaan het scherm zijn verschillende knoppen te zien. Deze knoppen hebben de volgende functies: \nLocaties: toont een lijst met alle locaties die bezocht kunnen worden. Elke locatie wordt kort beschreven. \nRoutes: Toont een lijst met alle routes die gelopen kunnen worden. Van elke route wordt een omschrijving gegeven. \nStatistieken: Toont persoonlijke statistieken. \nInstellingen: Hier kunnen app-instellingen worden aangepast naar eigen voorkeur. \n\nEen locatie ingedrukt houden laat extra informatie zien over de gekozen locatie</string>
</resources>

View File

@@ -19,9 +19,4 @@
<string name="done">Done</string>
<string name="cancel">cancel</string>
<string name="route_stop_toast">Route stopped!</string>
<string name="Dutch">Dutch</string>
<string name="English">English</string>
<string name="Chinese">Chinese</string>
<string name="help">HELP</string>
<string name="help_discription">Hasn\'t been translated yet</string>
</resources>