Fix region detection

This commit is contained in:
Alexey Kulish 2017-07-29 18:01:00 +03:00
parent 565c9ede3c
commit 7576fbc7ca

View file

@ -1,6 +1,7 @@
package net.osmand.plus.base; package net.osmand.plus.base;
import android.content.Context; import android.content.Context;
import android.os.AsyncTask;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
import android.view.WindowManager; import android.view.WindowManager;
@ -150,16 +151,24 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
return movingToMyLocation; return movingToMyLocation;
} }
private void detectDrivingRegion(final LatLon latLon) {
new AsyncTask<LatLon, Void, BinaryMapDataObject>() {
@Override @Override
public void updateLocation(Location location) { protected BinaryMapDataObject doInBackground(LatLon... latLons) {
myLocation = location;
showViewAngle = false;
if (location != null) {
locationProvider = location.getProvider();
if (settings.DRIVING_REGION_AUTOMATIC.get() && !drivingRegionUpdated) {
try { try {
BinaryMapDataObject o = app.getRegions().findBinaryMapDataObject( if (latLons != null && latLons.length > 0) {
new LatLon(location.getLatitude(), location.getLongitude())); return app.getRegions().findBinaryMapDataObject(latLons[0]);
}
} catch (IOException e) {
// ignore
}
return null;
}
@Override
protected void onPostExecute(BinaryMapDataObject o) {
if (o != null) { if (o != null) {
String fullName = app.getRegions().getFullName(o); String fullName = app.getRegions().getFullName(o);
WorldRegion worldRegion = app.getRegions().getRegionData(fullName); WorldRegion worldRegion = app.getRegions().getRegionData(fullName);
@ -167,11 +176,20 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
app.setupDrivingRegion(worldRegion); app.setupDrivingRegion(worldRegion);
} }
} }
drivingRegionUpdated = true;
} catch (IOException e) {
// ignore
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, latLon);
}
@Override
public void updateLocation(Location location) {
myLocation = location;
showViewAngle = false;
if (location != null) {
locationProvider = location.getProvider();
if (settings.DRIVING_REGION_AUTOMATIC.get() && !drivingRegionUpdated && !app.isApplicationInitializing()) {
drivingRegionUpdated = true;
detectDrivingRegion(new LatLon(location.getLatitude(), location.getLongitude()));
} }
} }
if (mapView != null) { if (mapView != null) {