Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8d581b2cac
2 changed files with 26 additions and 9 deletions
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.RouteDataObject;
|
import net.osmand.binary.RouteDataObject;
|
||||||
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
import net.osmand.router.BinaryRoutePlanner.RouteSegment;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
|
@ -35,14 +36,14 @@ public class CurrentPositionHelper {
|
||||||
} else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
|
} else if (am.isDerivedRoutingFrom(ApplicationMode.CAR)) {
|
||||||
p = GeneralRouterProfile.CAR;
|
p = GeneralRouterProfile.CAR;
|
||||||
} else {
|
} else {
|
||||||
return;
|
p = GeneralRouterProfile.PEDESTRIAN;
|
||||||
}
|
}
|
||||||
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10,
|
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p.name().toLowerCase(), 10,
|
||||||
new HashMap<String, String>());
|
new HashMap<String, String>());
|
||||||
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles());
|
ctx = new RoutePlannerFrontEnd(false).buildRoutingContext(cfg, null, app.getResourceManager().getRoutingMapFiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized RouteDataObject runUpdateInThread(double lat, double lon) throws IOException {
|
public synchronized RouteDataObject runUpdateInThread(double lat, double lon, ResultMatcher<RouteDataObject> result) throws IOException {
|
||||||
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
|
RoutePlannerFrontEnd rp = new RoutePlannerFrontEnd(false);
|
||||||
if (ctx == null || am != app.getSettings().getApplicationMode()) {
|
if (ctx == null || am != app.getSettings().getApplicationMode()) {
|
||||||
initCtx(app);
|
initCtx(app);
|
||||||
|
@ -50,7 +51,14 @@ public class CurrentPositionHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RouteSegment sg = rp.findRouteSegment(lat, lon, ctx);
|
final RouteSegment sg = rp.findRouteSegment(lat, lon, ctx);
|
||||||
|
if(result != null) {
|
||||||
|
app.runInUIThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
result.publish(sg == null ? null : sg.getRoad());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
if (sg == null) {
|
if (sg == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -59,18 +67,18 @@ public class CurrentPositionHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void scheduleRouteSegmentFind(final Location loc) {
|
private void scheduleRouteSegmentFind(final Location loc, final ResultMatcher<RouteDataObject> result) {
|
||||||
Thread calcThread = calculatingThread;
|
Thread calcThread = calculatingThread;
|
||||||
if (calcThread == Thread.currentThread()) {
|
if (calcThread == Thread.currentThread()) {
|
||||||
lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude());
|
lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude(), result);
|
||||||
} else if (loc != null) {
|
} else if (loc != null) {
|
||||||
if (calcThread == null) {
|
if (calcThread == null) {
|
||||||
Runnable run = new Runnable() {
|
Runnable run = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude());
|
lastFound = runUpdateInThreadCatch(loc.getLatitude(), loc.getLongitude(), result);
|
||||||
if (lastAskedLocation != loc) {
|
if (lastAskedLocation != loc && result != null) {
|
||||||
// refresh and run new task if needed
|
// refresh and run new task if needed
|
||||||
getLastKnownRouteSegment(lastAskedLocation);
|
getLastKnownRouteSegment(lastAskedLocation);
|
||||||
}
|
}
|
||||||
|
@ -87,9 +95,9 @@ public class CurrentPositionHelper {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RouteDataObject runUpdateInThreadCatch(double latitude, double longitude) {
|
protected RouteDataObject runUpdateInThreadCatch(double latitude, double longitude, final ResultMatcher<RouteDataObject> result) {
|
||||||
try {
|
try {
|
||||||
return runUpdateInThread(latitude, longitude);
|
return runUpdateInThread(latitude, longitude, result);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
@ -115,6 +123,10 @@ public class CurrentPositionHelper {
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getLastKnownRouteSegment(Location loc, ResultMatcher<RouteDataObject> result) {
|
||||||
|
scheduleRouteSegmentFind(loc);
|
||||||
|
}
|
||||||
|
|
||||||
public RouteDataObject getLastKnownRouteSegment(Location loc) {
|
public RouteDataObject getLastKnownRouteSegment(Location loc) {
|
||||||
lastAskedLocation = loc;
|
lastAskedLocation = loc;
|
||||||
RouteDataObject r = lastFound;
|
RouteDataObject r = lastFound;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.List;
|
||||||
|
|
||||||
import net.osmand.GeoidAltitudeCorrection;
|
import net.osmand.GeoidAltitudeCorrection;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.access.NavigationInfo;
|
import net.osmand.access.NavigationInfo;
|
||||||
import net.osmand.binary.RouteDataObject;
|
import net.osmand.binary.RouteDataObject;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -847,6 +848,10 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
||||||
return currentPositionHelper.getLastKnownRouteSegment(getLastKnownLocation());
|
return currentPositionHelper.getLastKnownRouteSegment(getLastKnownLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getRouteSegment(net.osmand.Location loc, ResultMatcher<RouteDataObject> result) {
|
||||||
|
currentPositionHelper.getLastKnownRouteSegment(loc, result);
|
||||||
|
}
|
||||||
|
|
||||||
public net.osmand.Location getLastKnownLocation() {
|
public net.osmand.Location getLastKnownLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue