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

View File

@@ -123,13 +123,13 @@
{ {
"name":"Belcrum Beach Veilingkade 12a", "name":"Belcrum Beach Veilingkade 12a",
"coordinates":"51.599434239284726,4.76632797992092", "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" "imageUrl":"belcrum_beach"
}, },
{ {
"name":"De Belcrum Watertoren (1935) Speelhuislaan 158", "name":"De Belcrum Watertoren (1935) Speelhuislaan 158",
"coordinates":"51.60135351009892,4.7705765989322755", "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" "imageUrl":"belcrum_watertoren"
} }
] ]

View File

@@ -14,7 +14,6 @@
"description": "4811HP Breda", "description": "4811HP Breda",
"imageUrl": "NULL" "imageUrl": "NULL"
}, },
{ {
"name": "Escaping Breda: Escape Room Games Boschstraat 114", "name": "Escaping Breda: Escape Room Games Boschstraat 114",
"coordinates": " 51.59110835530862,4.784147222780912", "coordinates": " 51.59110835530862,4.784147222780912",
@@ -36,5 +35,44 @@
], ],
"totalDistance": 2.3434, "totalDistance": 2.3434,
"totalTime": 342342 "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; package com.a1.nextlocation;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.util.Log;
import android.widget.ImageButton; 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.HomeFragment;
import com.a1.nextlocation.fragments.Refreshable;
import com.a1.nextlocation.fragments.RouteFragment; import com.a1.nextlocation.fragments.RouteFragment;
import com.a1.nextlocation.fragments.SettingsFragment; import com.a1.nextlocation.fragments.SettingsFragment;
import com.a1.nextlocation.fragments.StatisticFragment; import com.a1.nextlocation.fragments.StatisticFragment;
import com.a1.nextlocation.network.ApiHandler;
import com.a1.nextlocation.recyclerview.CouponListManager; import com.a1.nextlocation.recyclerview.CouponListManager;
import com.a1.nextlocation.recyclerview.LocationListManager; import com.a1.nextlocation.recyclerview.LocationListManager;
import com.a1.nextlocation.recyclerview.RouteListManager; import com.a1.nextlocation.recyclerview.RouteListManager;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.io.File;
import java.util.Arrays;
import java.util.Locale; 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 static final String TAG = MainActivity.class.getName();
private BottomNavigationView bottomNav;
private ImageButton infoButton;
/** /**
* onCreate method that creates the main activity * onCreate method that creates the main activity
@@ -38,15 +38,11 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// initialize saved language from sharedPreferences
setLocale(loadLocale());
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
bottomNav = findViewById(R.id.navigation_bar);
BottomNavigationView bottomNav = findViewById(R.id.navigation_bar);
bottomNav.setOnNavigationItemSelectedListener(navListener); bottomNav.setOnNavigationItemSelectedListener(navListener);
infoButton = findViewById(R.id.info_button);
infoButton.setOnClickListener(onInfoClickListener);
/*System.out.println(Arrays.toString(getFilesDir().listFiles())); /*System.out.println(Arrays.toString(getFilesDir().listFiles()));
FileIO<Route> fileIO = new FileIO<>(); FileIO<Route> fileIO = new FileIO<>();
@@ -60,10 +56,11 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
RouteListManager.INSTANCE.setContext(this); RouteListManager.INSTANCE.setContext(this);
RouteListManager.INSTANCE.load(); RouteListManager.INSTANCE.load();
if (savedInstanceState == null) { // initialize saved language from sharedPreferences
setLocale(loadLocale());
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, new HomeFragment()).commit();
} }
}
/** /**
* loads the saved language from SharedPreferences * loads the saved language from SharedPreferences
@@ -108,33 +105,4 @@ public class MainActivity extends AppCompatActivity implements Refreshable {
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, selectedFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, selectedFragment).commit();
return true; 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; 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) { 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) { public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
double dlon = lon2 - lon1; double dlon = lon2 - lon1;
double dlat = lat2 - lat1; double dlat = lat2 - lat1;

View File

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

View File

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

View File

@@ -1,20 +1,4 @@
package com.a1.nextlocation.fragments; package com.a1.nextlocation.fragments;
import android.os.Bundle; public class HelpPopup {
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;
}
} }

View File

@@ -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. * 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 * @param directionsResult the directions received from the api
*/ */
private void onDirectionsAvailable(DirectionsResult directionsResult) { private void onDirectionsAvailable(DirectionsResult directionsResult) {
@@ -209,7 +208,6 @@ public class HomeFragment extends Fragment implements LocationListener {
private void displayRoute() { private void displayRoute() {
if (RouteHandler.INSTANCE.isFollowingRoute()) { if (RouteHandler.INSTANCE.isFollowingRoute()) {
Log.d(TAG, "displayRoute: WE ARE FOLLOWING A ROUTE");
if (roadOverlay == null) { if (roadOverlay == null) {
if (RouteHandler.INSTANCE.getCurrentRouteLine() != null) { if (RouteHandler.INSTANCE.getCurrentRouteLine() != null) {
roadOverlay = RouteHandler.INSTANCE.getCurrentRouteLine(); 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 * @author Ricky
* request the permissions needed for location and network, made by 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) { private void requestPermissionsIfNecessary(String... permissions) {
ArrayList<String> permissionsToRequest = new ArrayList<>(); 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 * 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 * @param location the new location
*/ */
@Override @Override
public void onLocationChanged(@NonNull Location location) { public void onLocationChanged(@NonNull Location location) {
// calculate the distance walked // calculate the distance walked
if (currentLocation != null) {
double distance = currentLocation.distanceTo(location); // in meters double distance = currentLocation.distanceTo(location); // in meters
// can't walk 100 meters in a few seconds
if (distance < 100)
StaticData.INSTANCE.addDistance(distance); StaticData.INSTANCE.addDistance(distance);
}
currentLocation = location; currentLocation = location;
//new thread because we don't want the main thread to hang, this method gets called a lot //new thread because we don't want the main thread to hang, this method gets called a lot
Thread t = new Thread(() -> { Thread t = new Thread(() -> {
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) { for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {

View File

@@ -1,6 +1,5 @@
package com.a1.nextlocation.fragments; package com.a1.nextlocation.fragments;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@@ -12,8 +11,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.a1.nextlocation.R; import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Location; import com.a1.nextlocation.data.Location;
@@ -23,9 +20,6 @@ public class LocationDetailFragment extends Fragment {
private ImageButton imageButton; private ImageButton imageButton;
private Location location; private Location location;
private TextView titelText;
private TextView detailText;
private ImageView locationImage;
public LocationDetailFragment() { public LocationDetailFragment() {
@@ -44,13 +38,6 @@ public class LocationDetailFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_location_detail, container, false); 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 = view.findViewById(R.id.detail_location_back_button);
this.imageButton.setOnClickListener(v -> { this.imageButton.setOnClickListener(v -> {
LocationFragment locationFragment = new LocationFragment(); LocationFragment locationFragment = new LocationFragment();
@@ -60,12 +47,6 @@ public class LocationDetailFragment extends Fragment {
if (location != null) { if (location != null) {
Log.d(TAG, "onCreateView: the location has a name of: " + location.getName()); 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; 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; return view;
} }
/**
* Button onclick method that starts the route that is being viewed.
* @param view the button
*/
public void startRoute(View view) { public void startRoute(View view) {
ApiHandler.INSTANCE.getDirections(route); ApiHandler.INSTANCE.getDirections(route);
RouteHandler.INSTANCE.followRoute(route); RouteHandler.INSTANCE.followRoute(route);

View File

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

View File

@@ -40,11 +40,9 @@ public class StatisticFragment extends Fragment {
TextView distance = view.findViewById(R.id.statistics_km); TextView distance = view.findViewById(R.id.statistics_km);
TextView locs = view.findViewById(R.id.statistics_locations_visited); TextView locs = view.findViewById(R.id.statistics_locations_visited);
TextView timeText = view.findViewById(R.id.statistics_time_value);
double dist = StaticData.INSTANCE.getDistanceTraveled()/1000; double dist = StaticData.INSTANCE.getDistanceTraveled()/1000;
distance.setText("" + String.format("%.1f",dist) + " km"); distance.setText("" + String.format("%.1f",dist) + " km");
locs.setText("" + StaticData.INSTANCE.getLocationsVisited()); locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
timeText.setText("" + StaticData.INSTANCE.getTimeWalkedRoute());
this.couponList = CouponListManager.INSTANCE.getCouponList(); 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) { public void parseRoute(String json) {
Gson gson = new GsonBuilder().setPrettyPrinting().create(); Gson gson = new GsonBuilder().setPrettyPrinting().create();

View File

@@ -20,72 +20,43 @@ import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
/**
* Singleton that handles all API calls
*/
public enum ApiHandler { public enum ApiHandler {
INSTANCE; INSTANCE;
private static String TAG = ApiHandler.class.getCanonicalName(); private static String TAG = ApiHandler.class.getCanonicalName();
public static final MediaType JSON = MediaType.get("application/json; charset=utf-8"); 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 BASE_URL = "https://api.openrouteservice.org/v2/directions/";
private final String API_KEY = "5b3ce3597851110001cf6248d4eee2099f724255918adc71cc502b2a"; private final String API_KEY = "5b3ce3597851110001cf6248d4eee2099f724255918adc71cc502b2a";
private final String DIRECTIONS_MODE = "foot-walking"; private final String DIRECTIONS_MODE = "foot-walking";
private List<DirectionsListener> listeners = new ArrayList<>(); private List<DirectionsListener> listeners = new ArrayList<>();
private OkHttpClient client = new OkHttpClient(); 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) { public void getDirections(Location startLocation, Location endLocation) {
getDirections(startLocation.getCoordinates(),endLocation.getCoordinates()); 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) { public void getDirections(double startLat, double startLong, double endLat, double endLong) {
getDirections(startLong + "," + startLat, endLong + "," + endLat); 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) { public void getDirections(String startLocation, String endLocation) {
// build the url
String requestUrl = BASE_URL + DIRECTIONS_MODE + "?api_key=" + API_KEY + "&start=" +startLocation + "&end=" + endLocation; 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(() -> { Thread t = new Thread(() -> {
// build a request from the url
Request request = new Request.Builder().url(requestUrl).build(); Request request = new Request.Builder().url(requestUrl).build();
// try to get the response
try (Response response = client.newCall(request).execute()) { try (Response response = client.newCall(request).execute()) {
if (response.body() != null) { if (response.body() != null) {
String responseString = Objects.requireNonNull(response.body()).string(); String responseString = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "getDirections: got response: " + responseString); Log.d(TAG, "getDirections: got response: " + responseString);
System.out.println(responseString);
// convert the response into a result object
DirectionsResult result = new DirectionsResult(); DirectionsResult result = new DirectionsResult();
result.parse(responseString); result.parse(responseString);
Log.d(TAG, "getDirections: " + result.getSteps().size()); Log.d(TAG, "getDirections: " + result.getSteps().size());
// notify the listeners
for (DirectionsListener listener : listeners) { for (DirectionsListener listener : listeners) {
listener.onDirectionsAvailable(result); 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) { public void addListener(DirectionsListener listener) {
this.listeners.add(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) { 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<>(); ArrayList<double[]> allCoords = new ArrayList<>();
for (Location location : route.getLocations()) { for (Location location : route.getLocations()) {
allCoords.add(location.getCoordinatesAsDoubles()); allCoords.add(location.getCoordinatesAsDoubles());
} }
// convert it to a json string
String body = "{\"coordinates\":" + new Gson().toJson(allCoords) + "}"; String body = "{\"coordinates\":" + new Gson().toJson(allCoords) + "}";
String requestUrl = BASE_URL + DIRECTIONS_MODE + "?api_key=" + API_KEY; 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(() -> { Thread t = new Thread(() -> {
// add the body to the request
RequestBody requestBody = RequestBody.create(body,JSON); RequestBody requestBody = RequestBody.create(body,JSON);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(requestUrl) .url(requestUrl)
@@ -145,19 +110,15 @@ public enum ApiHandler {
if (response.body() != null) { if (response.body() != null) {
String responseString = Objects.requireNonNull(response.body()).string(); String responseString = Objects.requireNonNull(response.body()).string();
Log.d(TAG, "getDirections: got response: " + responseString); Log.d(TAG, "getDirections: got response: " + responseString);
// kinda lazy, but we had time pressure
if (responseString.startsWith("{\"error")) { if (responseString.startsWith("{\"error")) {
Log.e(TAG, "getDirections: ERROR IN REQUEST!"); Log.e(TAG, "getDirections: ERROR IN REQUEST!");
return; return;
} }
// convert the result into a DirectionsResult
DirectionsResult result = new DirectionsResult(); DirectionsResult result = new DirectionsResult();
result.parseRoute(responseString); result.parseRoute(responseString);
Log.d(TAG, "getDirections: " + result.getSteps().size()); Log.d(TAG, "getDirections: " + result.getSteps().size());
//notify the listeners
for (DirectionsListener listener : listeners) { for (DirectionsListener listener : listeners) {
listener.onDirectionsAvailable(result); listener.onDirectionsAvailable(result);
} }
@@ -171,7 +132,6 @@ public enum ApiHandler {
t.start(); 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 { try {
t.join(); t.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {

View File

@@ -151,7 +151,6 @@
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/statistics_time_value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="" 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="activate">activeren</string>
<string name="done">Klaar</string> <string name="done">Klaar</string>
<string name="cancel">annuleren</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> </resources>

View File

@@ -19,9 +19,4 @@
<string name="done">Done</string> <string name="done">Done</string>
<string name="cancel">cancel</string> <string name="cancel">cancel</string>
<string name="route_stop_toast">Route stopped!</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> </resources>