Add turnInfo for aidl
This commit is contained in:
parent
5b4420eb42
commit
7b7e3fc6fe
2 changed files with 65 additions and 20 deletions
|
@ -10,17 +10,20 @@ public class AppInfoParams extends AidlParams {
|
|||
|
||||
private ALatLon lastKnownLocation;
|
||||
private ALatLon mapLocation;
|
||||
private int time;
|
||||
private long eta;
|
||||
|
||||
private Bundle turnInfo;
|
||||
private int leftTime;
|
||||
private int leftDistance;
|
||||
private long arrivalTime;
|
||||
private boolean mapVisible;
|
||||
|
||||
public AppInfoParams(ALatLon lastKnownLocation, ALatLon mapLocation, int time, long eta, int leftDistance, boolean mapVisible) {
|
||||
public AppInfoParams(ALatLon lastKnownLocation, ALatLon mapLocation, Bundle turnInfo, int leftTime, int leftDistance, long arrivalTime, boolean mapVisible) {
|
||||
this.lastKnownLocation = lastKnownLocation;
|
||||
this.mapLocation = mapLocation;
|
||||
this.time = time;
|
||||
this.eta = eta;
|
||||
this.leftTime = leftTime;
|
||||
this.leftDistance = leftDistance;
|
||||
this.arrivalTime = arrivalTime;
|
||||
this.turnInfo = turnInfo;
|
||||
this.mapVisible = mapVisible;
|
||||
}
|
||||
|
||||
|
@ -48,12 +51,12 @@ public class AppInfoParams extends AidlParams {
|
|||
return mapLocation;
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
public int getLeftTime() {
|
||||
return leftTime;
|
||||
}
|
||||
|
||||
public long getEta() {
|
||||
return eta;
|
||||
public long getArrivalTime() {
|
||||
return arrivalTime;
|
||||
}
|
||||
|
||||
public int getLeftDistance() {
|
||||
|
@ -64,23 +67,29 @@ public class AppInfoParams extends AidlParams {
|
|||
return mapVisible;
|
||||
}
|
||||
|
||||
public Bundle getTurnInfo() {
|
||||
return turnInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToBundle(Bundle bundle) {
|
||||
bundle.putParcelable("location", lastKnownLocation);
|
||||
bundle.putParcelable("lastKnownLocation", lastKnownLocation);
|
||||
bundle.putParcelable("mapLocation", mapLocation);
|
||||
bundle.putInt("time", time);
|
||||
bundle.putLong("eta", eta);
|
||||
bundle.putInt("leftTime", leftTime);
|
||||
bundle.putLong("arrivalTime", arrivalTime);
|
||||
bundle.putInt("leftDistance", leftDistance);
|
||||
bundle.putBundle("turnInfo", turnInfo);
|
||||
bundle.putBoolean("mapVisible", mapVisible);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromBundle(Bundle bundle) {
|
||||
lastKnownLocation = bundle.getParcelable("location");
|
||||
lastKnownLocation = bundle.getParcelable("lastKnownLocation");
|
||||
mapLocation = bundle.getParcelable("mapLocation");
|
||||
time = bundle.getInt("time");
|
||||
eta = bundle.getLong("eta");
|
||||
leftTime = bundle.getInt("leftTime");
|
||||
arrivalTime = bundle.getLong("arrivalTime");
|
||||
leftDistance = bundle.getInt("leftDistance");
|
||||
turnInfo = bundle.getBundle("turnInfo");
|
||||
mapVisible = bundle.getBoolean("mapVisible");
|
||||
}
|
||||
}
|
|
@ -73,6 +73,7 @@ import net.osmand.plus.quickaction.QuickActionRegistry;
|
|||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.routing.IRoutingDataUpdateListener;
|
||||
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
|
||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.VoiceRouter;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
|
@ -103,6 +104,7 @@ import java.io.InputStream;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -127,6 +129,11 @@ import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PART_SIZE_LIMIT_E
|
|||
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_UNSUPPORTED_FILE_TYPE_ERROR;
|
||||
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_WRITE_LOCK_ERROR;
|
||||
import static net.osmand.aidlapi.OsmandAidlConstants.OK_RESPONSE;
|
||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_LANES;
|
||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_NAME;
|
||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN;
|
||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE;
|
||||
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT;
|
||||
|
||||
public class OsmandAidlApi {
|
||||
|
||||
|
@ -1734,17 +1741,46 @@ public class OsmandAidlApi {
|
|||
mapVisible = mapActivity.isMapVisible();
|
||||
}
|
||||
|
||||
int time = 0;
|
||||
long eta = 0;
|
||||
int leftTime = 0;
|
||||
long arrivalTime = 0;
|
||||
int leftDistance = 0;
|
||||
Bundle turnInfo = null;
|
||||
|
||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
if (routingHelper.isRouteCalculated()) {
|
||||
time = routingHelper.getLeftTime();
|
||||
eta = time + System.currentTimeMillis() / 1000;
|
||||
leftTime = routingHelper.getLeftTime();
|
||||
arrivalTime = leftTime + System.currentTimeMillis() / 1000;
|
||||
leftDistance = routingHelper.getLeftDistance();
|
||||
|
||||
NextDirectionInfo directionInfo = routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), true);
|
||||
turnInfo = new Bundle();
|
||||
if (directionInfo.distanceTo > 0) {
|
||||
updateTurnInfo("next_", turnInfo, directionInfo);
|
||||
directionInfo = routingHelper.getNextRouteDirectionInfoAfter(directionInfo, new NextDirectionInfo(), true);
|
||||
if (directionInfo.distanceTo > 0) {
|
||||
updateTurnInfo("after_next", turnInfo, directionInfo);
|
||||
}
|
||||
}
|
||||
routingHelper.getNextRouteDirectionInfo(new NextDirectionInfo(), false);
|
||||
if (directionInfo.distanceTo > 0) {
|
||||
updateTurnInfo("no_speak_next_", turnInfo, directionInfo);
|
||||
}
|
||||
}
|
||||
return new AppInfoParams(lastKnownLocation, mapLocation, turnInfo, leftTime, leftDistance, arrivalTime, mapVisible);
|
||||
}
|
||||
|
||||
private void updateTurnInfo(String prefix, Bundle bundle, NextDirectionInfo ni) {
|
||||
bundle.putInt(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
|
||||
bundle.putInt(prefix + PARAM_NT_IMMINENT, ni.imminent);
|
||||
if (ni.directionInfo != null && ni.directionInfo.getTurnType() != null) {
|
||||
TurnType tt = ni.directionInfo.getTurnType();
|
||||
RouteDirectionInfo a = ni.directionInfo;
|
||||
bundle.putString(prefix + PARAM_NT_DIRECTION_NAME, RoutingHelper.formatStreetName(a.getStreetName(), a.getRef(), a.getDestinationName(), ""));
|
||||
bundle.putString(prefix + PARAM_NT_DIRECTION_TURN, tt.toXmlString());
|
||||
if (tt.getLanes() != null) {
|
||||
bundle.putString(prefix + PARAM_NT_DIRECTION_LANES, Arrays.toString(tt.getLanes()));
|
||||
}
|
||||
}
|
||||
return new AppInfoParams(lastKnownLocation, mapLocation, time, eta, leftDistance, mapVisible);
|
||||
}
|
||||
|
||||
boolean search(final String searchQuery, final int searchType, final double latitude, final double longitude,
|
||||
|
|
Loading…
Reference in a new issue