added keeping zoom level

This commit is contained in:
Sem van der Hoeven
2021-01-06 16:56:57 +01:00
parent fb2f7e8a66
commit 7c9dc07c3d
2 changed files with 21 additions and 2 deletions

View File

@@ -12,6 +12,15 @@ public enum StaticData {
private double distanceTraveled = 0;
private int locationsVisited = 0;
private long timeWalkedRoute = 0;
private double zoom = 0;
public double getZoom() {
return zoom;
}
public void setZoom(double zoom) {
this.zoom = zoom;
}
private ArrayList<String> visitedNames = new ArrayList<>();

View File

@@ -2,6 +2,7 @@ package com.a1.nextlocation.fragments;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
@@ -11,6 +12,7 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
@@ -34,6 +36,7 @@ import com.a1.nextlocation.recyclerview.LocationListManager;
import org.osmdroid.api.IMapController;
import org.osmdroid.config.Configuration;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.CustomZoomButtonsController;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.Overlay;
@@ -174,7 +177,10 @@ public class HomeFragment extends Fragment implements LocationListener {
// add the zoom controller
IMapController mapController = mapView.getController();
mapController.setZoom(15.0);
if (StaticData.INSTANCE.getZoom() == 0) {
StaticData.INSTANCE.setZoom(15.0);
}
mapController.setZoom(StaticData.INSTANCE.getZoom());
// add location manager and set the start point
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
@@ -345,14 +351,18 @@ public class HomeFragment extends Fragment implements LocationListener {
}
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) {
// mark the location visited if we are less than 20 meters away
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 20) {
StaticData.INSTANCE.visitLocation(l);
if (l.equals(last)) stopRoute();
}
}
StaticData.INSTANCE.setZoom(mapView.getZoomLevelDouble());
});
t.start();
}
// empty override methods for the LocationListener