added displaying all locations upon stopping the route
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.a1.nextlocation.data;
|
package com.a1.nextlocation.data;
|
||||||
|
|
||||||
|
import org.osmdroid.views.overlay.Polyline;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* singleton to track the current route that is being followed
|
* singleton to track the current route that is being followed
|
||||||
*/
|
*/
|
||||||
@@ -9,6 +11,21 @@ public enum RouteHandler {
|
|||||||
private boolean isFollowingRoute = false;
|
private boolean isFollowingRoute = false;
|
||||||
private Route currentRoute;
|
private Route currentRoute;
|
||||||
private int stepCount = 0;
|
private int stepCount = 0;
|
||||||
|
private RouteFinishedListener routeFinishedListener;
|
||||||
|
|
||||||
|
private Polyline currentRouteLine;
|
||||||
|
|
||||||
|
public void setCurrentRouteLine(Polyline currentRouteLine) {
|
||||||
|
this.currentRouteLine = currentRouteLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Polyline getCurrentRouteLine() {
|
||||||
|
return currentRouteLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRouteFinishedListener(RouteFinishedListener routeFinishedListener) {
|
||||||
|
this.routeFinishedListener = routeFinishedListener;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStepCount() {
|
public int getStepCount() {
|
||||||
return stepCount;
|
return stepCount;
|
||||||
@@ -22,6 +39,7 @@ public enum RouteHandler {
|
|||||||
stepCount = 0;
|
stepCount = 0;
|
||||||
isFollowingRoute = false;
|
isFollowingRoute = false;
|
||||||
currentRoute = null;
|
currentRoute = null;
|
||||||
|
currentRouteLine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void followRoute(Route route) {
|
public void followRoute(Route route) {
|
||||||
@@ -39,4 +57,13 @@ public enum RouteHandler {
|
|||||||
public boolean isFollowingRoute() {
|
public boolean isFollowingRoute() {
|
||||||
return isFollowingRoute;
|
return isFollowingRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Route getCurrentRoute() {
|
||||||
|
return currentRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface RouteFinishedListener {
|
||||||
|
void onRouteFinish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,14 +34,6 @@ public enum StaticData {
|
|||||||
return locationsVisited;
|
return locationsVisited;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Polyline currentRoute;
|
|
||||||
|
|
||||||
public void setCurrentRoute(Polyline currentRoute) {
|
|
||||||
this.currentRoute = currentRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Polyline getCurrentRoute() {
|
|
||||||
return currentRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.a1.nextlocation.fragments;
|
package com.a1.nextlocation.fragments;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@@ -25,6 +24,7 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
|
import com.a1.nextlocation.data.RouteHandler;
|
||||||
import com.a1.nextlocation.data.StaticData;
|
import com.a1.nextlocation.data.StaticData;
|
||||||
import com.a1.nextlocation.json.DirectionsResult;
|
import com.a1.nextlocation.json.DirectionsResult;
|
||||||
import com.a1.nextlocation.network.ApiHandler;
|
import com.a1.nextlocation.network.ApiHandler;
|
||||||
@@ -46,17 +46,19 @@ import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HomeFragment extends Fragment implements LocationListener{
|
public class HomeFragment extends Fragment implements LocationListener {
|
||||||
private final String userAgent = "com.ai.nextlocation.fragments";
|
private final String userAgent = "com.ai.nextlocation.fragments";
|
||||||
public final static String MAPQUEST_API_KEY = "vuyXjqnAADpjeL9QwtgWGleIk95e36My";
|
public final static String MAPQUEST_API_KEY = "vuyXjqnAADpjeL9QwtgWGleIk95e36My";
|
||||||
private ImageButton imageButton;
|
private ImageButton imageButton;
|
||||||
|
private ImageButton stopButton;
|
||||||
private MapView mapView;
|
private MapView mapView;
|
||||||
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
|
private final int REQUEST_PERMISSIONS_REQUEST_CODE = 1;
|
||||||
private final String TAG = HomeFragment.class.getCanonicalName();
|
private final String TAG = HomeFragment.class.getCanonicalName();
|
||||||
// private RoadManager roadManager;
|
// private RoadManager roadManager;
|
||||||
private Polyline roadOverlay;
|
private Polyline roadOverlay;
|
||||||
private int color;
|
private int color;
|
||||||
private Location currentLocation;
|
private Location currentLocation;
|
||||||
|
private Overlay allLocationsOverlay;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -84,6 +86,23 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
|
((FragmentActivity) view.getContext()).getSupportFragmentManager().beginTransaction().replace(R.id.fragment_layout, locationFragment).addToBackStack(null).commit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
stopButton = view.findViewById(R.id.home_stop_route_button);
|
||||||
|
stopButton.setOnClickListener(v -> {
|
||||||
|
RouteHandler.INSTANCE.finishRoute();
|
||||||
|
stopButton.setVisibility(View.GONE);
|
||||||
|
Toast.makeText(requireContext(),getResources().getString(R.string.route_stop_toast),Toast.LENGTH_SHORT).show();
|
||||||
|
mapView.getOverlays().remove(roadOverlay);
|
||||||
|
mapView.getOverlays().remove(allLocationsOverlay);
|
||||||
|
addLocations();
|
||||||
|
mapView.invalidate();
|
||||||
|
roadOverlay = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (RouteHandler.INSTANCE.isFollowingRoute()) {
|
||||||
|
stopButton.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
stopButton.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable);
|
ApiHandler.INSTANCE.addListener(this::onDirectionsAvailable);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
@@ -103,7 +122,7 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
roadOverlay.setColor(color);
|
roadOverlay.setColor(color);
|
||||||
|
|
||||||
|
|
||||||
StaticData.INSTANCE.setCurrentRoute(roadOverlay);
|
RouteHandler.INSTANCE.setCurrentRouteLine(roadOverlay);
|
||||||
Log.d(TAG, "onDirectionsAvailable: successfully added road!");
|
Log.d(TAG, "onDirectionsAvailable: successfully added road!");
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -117,6 +136,7 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method initializes the map and all the things it needs
|
* This method initializes the map and all the things it needs
|
||||||
|
*
|
||||||
* @param view the view the map is on
|
* @param view the view the map is on
|
||||||
*/
|
*/
|
||||||
private void initMap(@NonNull View view) {
|
private void initMap(@NonNull View view) {
|
||||||
@@ -133,7 +153,7 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(this.requireContext());
|
GpsMyLocationProvider gpsMyLocationProvider = new GpsMyLocationProvider(this.requireContext());
|
||||||
|
|
||||||
// add the compass overlay
|
// add the compass overlay
|
||||||
CompassOverlay compassOverlay = new CompassOverlay(requireContext(),new InternalCompassOrientationProvider(requireContext()),mapView);
|
CompassOverlay compassOverlay = new CompassOverlay(requireContext(), new InternalCompassOrientationProvider(requireContext()), mapView);
|
||||||
compassOverlay.enableCompass();
|
compassOverlay.enableCompass();
|
||||||
mapView.getOverlays().add(compassOverlay);
|
mapView.getOverlays().add(compassOverlay);
|
||||||
|
|
||||||
@@ -153,19 +173,17 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);
|
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
||||||
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,this);
|
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
|
||||||
|
|
||||||
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
if (currentLocation == null) {
|
if (currentLocation == null) {
|
||||||
currentLocation = location;
|
currentLocation = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( location != null ) {
|
if (location != null) {
|
||||||
GeoPoint start = new GeoPoint(location.getLatitude(), location.getLongitude());
|
GeoPoint start = new GeoPoint(location.getLatitude(), location.getLongitude());
|
||||||
mapController.setCenter(start);
|
mapController.setCenter(start);
|
||||||
}
|
}
|
||||||
@@ -188,32 +206,34 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
|
|
||||||
private void displayRoute() {
|
private void displayRoute() {
|
||||||
|
|
||||||
if (roadOverlay == null) {
|
if (RouteHandler.INSTANCE.isFollowingRoute()) {
|
||||||
if (StaticData.INSTANCE.getCurrentRoute() != null) {
|
if (roadOverlay == null) {
|
||||||
roadOverlay = StaticData.INSTANCE.getCurrentRoute();
|
if (RouteHandler.INSTANCE.getCurrentRouteLine() != null) {
|
||||||
|
roadOverlay = RouteHandler.INSTANCE.getCurrentRouteLine();
|
||||||
|
mapView.getOverlays().add(roadOverlay);
|
||||||
|
mapView.invalidate();
|
||||||
|
Log.d(TAG, "initMap: successfully added road!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
mapView.getOverlays().add(roadOverlay);
|
mapView.getOverlays().add(roadOverlay);
|
||||||
mapView.invalidate();
|
mapView.invalidate();
|
||||||
Log.d(TAG, "initMap: successfully added road!");
|
Log.d(TAG, "initMap: successfully added road!");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
mapView.getOverlays().add(roadOverlay);
|
|
||||||
mapView.invalidate();
|
|
||||||
Log.d(TAG, "initMap: successfully added road!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLocations() {
|
private void addLocations() {
|
||||||
List<com.a1.nextlocation.data.Location> locations = LocationListManager.INSTANCE.getLocationList();
|
List<com.a1.nextlocation.data.Location> locations = RouteHandler.INSTANCE.isFollowingRoute() ? RouteHandler.INSTANCE.getCurrentRoute().getLocations() : LocationListManager.INSTANCE.getLocationList();
|
||||||
final ArrayList<OverlayItem> items = new ArrayList<>(locations.size());
|
final ArrayList<OverlayItem> items = new ArrayList<>(locations.size());
|
||||||
Drawable marker = ContextCompat.getDrawable(requireContext(),R.drawable.ic_baseline_location_on_24);
|
Drawable marker = ContextCompat.getDrawable(requireContext(), R.drawable.ic_baseline_location_on_24);
|
||||||
marker.setAlpha(255);
|
marker.setAlpha(255);
|
||||||
marker.setTint(getResources().getColor(R.color.primaryColour));
|
marker.setTint(getResources().getColor(R.color.primaryColour));
|
||||||
for (com.a1.nextlocation.data.Location location : locations) {
|
for (com.a1.nextlocation.data.Location location : locations) {
|
||||||
OverlayItem item = new OverlayItem(location.getName(),location.getDescription(),location.convertToGeoPoint());
|
OverlayItem item = new OverlayItem(location.getName(), location.getDescription(), location.convertToGeoPoint());
|
||||||
item.setMarker(marker);
|
item.setMarker(marker);
|
||||||
items.add(item);
|
items.add(item);
|
||||||
}
|
}
|
||||||
Overlay allLocationsOverlay = new ItemizedIconOverlay<OverlayItem>(items,
|
allLocationsOverlay = new ItemizedIconOverlay<OverlayItem>(items,
|
||||||
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
|
new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onItemSingleTapUp(int index, OverlayItem item) {
|
public boolean onItemSingleTapUp(int index, OverlayItem item) {
|
||||||
@@ -225,14 +245,14 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
@Override
|
@Override
|
||||||
public boolean onItemLongPress(int index, OverlayItem item) {
|
public boolean onItemLongPress(int index, OverlayItem item) {
|
||||||
com.a1.nextlocation.data.Location clicked = locations.get(index);
|
com.a1.nextlocation.data.Location clicked = locations.get(index);
|
||||||
Toast.makeText(requireContext(), clicked.getName(),Toast.LENGTH_SHORT).show();
|
Toast.makeText(requireContext(), clicked.getName(), Toast.LENGTH_SHORT).show();
|
||||||
// Route route = new Route("Route to " + clicked.getName());
|
// Route route = new Route("Route to " + clicked.getName());
|
||||||
// route.addLocation(new com.a1.nextlocation.data.Location("Current location",currentLocation.getLatitude(),currentLocation.getLongitude(),"your location",null));
|
// route.addLocation(new com.a1.nextlocation.data.Location("Current location",currentLocation.getLatitude(),currentLocation.getLongitude(),"your location",null));
|
||||||
// route.addLocation(clicked);
|
// route.addLocation(clicked);
|
||||||
// ApiHandler.INSTANCE.getDirections(route);
|
// ApiHandler.INSTANCE.getDirections(route);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},requireContext());
|
}, requireContext());
|
||||||
|
|
||||||
mapView.getOverlays().add(allLocationsOverlay);
|
mapView.getOverlays().add(allLocationsOverlay);
|
||||||
Log.d(TAG, "addLocations: successfully added locations");
|
Log.d(TAG, "addLocations: successfully added locations");
|
||||||
@@ -266,7 +286,7 @@ public class HomeFragment extends Fragment implements LocationListener{
|
|||||||
//new thread because we don't want the main thread to hang
|
//new thread because we don't want the main thread to hang
|
||||||
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()) {
|
||||||
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(),currentLocation.getLongitude(),l.getLat(),l.getLong()) < 10) {
|
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 10) {
|
||||||
StaticData.INSTANCE.visitLocation(l);
|
StaticData.INSTANCE.visitLocation(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
app/src/main/res/drawable-anydpi/ic_stop_icon.xml
Normal file
12
app/src/main/res/drawable-anydpi/ic_stop_icon.xml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="#333333"
|
||||||
|
android:alpha="0.6">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M8,16h8V8H8V16zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2L12,2z"
|
||||||
|
android:fillType="evenOdd"/>
|
||||||
|
</vector>
|
||||||
BIN
app/src/main/res/drawable-hdpi/ic_stop_icon.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_stop_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 318 B |
BIN
app/src/main/res/drawable-mdpi/ic_stop_icon.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_stop_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 213 B |
BIN
app/src/main/res/drawable-xhdpi/ic_stop_icon.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_stop_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 416 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_stop_icon.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_stop_icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 552 B |
@@ -27,6 +27,17 @@
|
|||||||
android:src="@drawable/ic_baseline_outlined_flag_24"
|
android:src="@drawable/ic_baseline_outlined_flag_24"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/home_stop_route_button"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/location_list_button"
|
||||||
|
android:backgroundTint="@color/secondaryColour"
|
||||||
|
android:src="@drawable/ic_stop_icon"/>
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -17,4 +17,5 @@
|
|||||||
<string name="coupons_gespaard">Coupons gespaard:</string>
|
<string name="coupons_gespaard">Coupons gespaard:</string>
|
||||||
<string name="coupons">Coupons</string>
|
<string name="coupons">Coupons</string>
|
||||||
<string name="start_route">Start Route</string>
|
<string name="start_route">Start Route</string>
|
||||||
|
<string name="route_stop_toast">Route stopped!</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user