Fix npe in parking plugin

This commit is contained in:
max-klaus 2019-11-05 12:30:42 +03:00
parent 075256f41b
commit 49e73ad305

View file

@ -440,34 +440,36 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override @Override
public boolean updateInfo(DrawSettings drawSettings) { public boolean updateInfo(DrawSettings drawSettings) {
LatLon parkingPoint = parkingLayer.getParkingPoint(); if (parkingLayer != null) {
if( parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) { LatLon parkingPoint = parkingLayer.getParkingPoint();
OsmandMapTileView view = map.getMapView(); if (parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) {
int d = 0; OsmandMapTileView view = map.getMapView();
if (d == 0) { int d = 0;
net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations); if (d == 0) {
d = (int) calculations[0]; net.osmand.Location.distanceBetween(view.getLatitude(), view.getLongitude(), parkingPoint.getLatitude(), parkingPoint.getLongitude(), calculations);
} d = (int) calculations[0];
if (distChanged(cachedMeters, d)) {
cachedMeters = d;
if (cachedMeters <= 20) {
cachedMeters = 0;
setText(null, null);
} else {
String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
} }
if (distChanged(cachedMeters, d)) {
cachedMeters = d;
if (cachedMeters <= 20) {
cachedMeters = 0;
setText(null, null);
} else {
String ds = OsmAndFormatter.getFormattedDistance(cachedMeters, map.getMyApplication());
int ls = ds.lastIndexOf(' ');
if (ls == -1) {
setText(ds, null);
} else {
setText(ds.substring(0, ls), ds.substring(ls + 1));
}
}
return true;
}
} else if (cachedMeters != 0) {
cachedMeters = 0;
setText(null, null);
return true; return true;
} }
} else if (cachedMeters != 0) {
cachedMeters = 0;
setText(null, null);
return true;
} }
return false; return false;
} }