diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 6837bdf855f..a2dc032d6ae 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -53,6 +53,7 @@ import net.osmand.plus.utils.AndroidUtils; import net.osmand.router.RouteSegmentResult; import net.osmand.util.Algorithms; +import net.osmand.util.CollectionUtils; import net.osmand.util.MapUtils; import java.util.ArrayList; @@ -140,8 +141,8 @@ public interface OsmAndCompassListener { private final GPSInfo gpsInfo = new GPSInfo(); - private final List locationListeners = new ArrayList<>(); - private final List compassListeners = new ArrayList<>(); + private List locationListeners = new ArrayList<>(); + private List compassListeners = new ArrayList<>(); private GnssStatus.Callback gpsStatusListener; private final float[] mRotationM = new float[9]; @@ -246,22 +247,22 @@ public void updateScreenOrientation(int orientation) { public void addLocationListener(@NonNull OsmAndLocationListener listener) { if (!locationListeners.contains(listener)) { - locationListeners.add(listener); + locationListeners = CollectionUtils.addToList(locationListeners, listener); } } public void removeLocationListener(@NonNull OsmAndLocationListener listener) { - locationListeners.remove(listener); + locationListeners = CollectionUtils.removeFromList(locationListeners, listener); } public void addCompassListener(@NonNull OsmAndCompassListener listener) { if (!compassListeners.contains(listener)) { - compassListeners.add(listener); + compassListeners = CollectionUtils.addToList(compassListeners, listener); } } public void removeCompassListener(@NonNull OsmAndCompassListener listener) { - compassListeners.remove(listener); + compassListeners = CollectionUtils.removeFromList(compassListeners, listener); } private void addLocationSourceListener() { @@ -488,9 +489,9 @@ private float getAngle(float sinA, float cosA) { return MapUtils.unifyRotationTo360((float) (Math.atan2(sinA, cosA) * 180 / Math.PI)); } - private void updateLocation(net.osmand.Location loc) { - for (OsmAndLocationListener l : locationListeners) { - l.updateLocation(loc); + private void updateLocation(net.osmand.Location location) { + for (OsmAndLocationListener listener : locationListeners) { + listener.updateLocation(location); } }