diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 4cbf907f0f7d..fce23f8fce28 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -1,6 +1,8 @@ package net.osmand.aidlapi; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.ALocation; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.map.SetLocationParams; @@ -20,6 +22,7 @@ import net.osmand.aidlapi.mapmarker.RemoveMapMarkerParams; import net.osmand.aidlapi.mapmarker.UpdateMapMarkerParams; import net.osmand.aidlapi.calculateroute.CalculateRouteParams; +import net.osmand.aidlapi.calculateroute.CalculatedRoute; import net.osmand.aidlapi.profile.ExportProfileParams; @@ -46,6 +49,7 @@ import net.osmand.aidlapi.maplayer.UpdateMapLayerParams; import net.osmand.aidlapi.navigation.NavigateParams; import net.osmand.aidlapi.navigation.NavigateGpxParams; +import net.osmand.aidlapi.navigation.NavigationStatus; import net.osmand.aidlapi.note.TakePhotoNoteParams; import net.osmand.aidlapi.note.StartVideoRecordingParams; @@ -938,4 +942,35 @@ interface IOsmAndAidlInterface { long registerForLogcatMessages(in ALogcatListenerParams params, IOsmAndAidlCallback callback); boolean setZoomLimits(in ZoomLimitsParams params); -} \ No newline at end of file + + /** + * Method to get current route points + * + */ + boolean getRoutePoints(out List route); + + /** + * Method to get position of various objects + * + * @params locationType (ALocationType) - type of position to get (CURRENT - last fixed, PROJECTION - last projection, ROUTE_END end of the route) + */ + boolean getLocation(in ALocationType locationType, out ALocation location); + + /** + * Method to get application mode + * + */ + String getApplicationMode(); + + /** + * Method to get current navigation status + * + */ + boolean getNavigationStatus(out NavigationStatus status); + + /** + * Method to get calculated route + * + */ + boolean getCalculatedRoute(out CalculatedRoute route); +} diff --git a/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.aidl b/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.aidl new file mode 100644 index 000000000000..33553a4accdb --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.calculateroute; + +parcelable CalculatedRoute; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.java b/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.java new file mode 100644 index 000000000000..29c73661c54b --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.java @@ -0,0 +1,133 @@ +package net.osmand.aidlapi.calculateroute; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; +import net.osmand.aidlapi.map.ALatLon; + +import java.util.ArrayList; + +public class CalculatedRoute extends AidlParams { + + private boolean isRouteCalculated; + + private String appMode; + + private ArrayList routePoints; + private int routeDistance; + + private float routingTime; + private long creationTime; + + private float calculationTime; + + public CalculatedRoute() { + + } + + public CalculatedRoute(boolean isRouteCalculated, String appMode, ArrayList routePoints, int routeDistance, float routingTime, long creationTime, float calculationTime) { + this.isRouteCalculated = isRouteCalculated; + this.appMode = appMode; + this.routePoints = routePoints; + this.routeDistance = routeDistance; + this.routingTime = routingTime; + this.creationTime = creationTime; + this.calculationTime = calculationTime; + } + + protected CalculatedRoute(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public CalculatedRoute createFromParcel(Parcel in) { + return new CalculatedRoute(in); + } + + @Override + public CalculatedRoute[] newArray(int size) { + return new CalculatedRoute[size]; + } + }; + + public boolean isRouteCalculated() { + return isRouteCalculated; + } + + public String getAppMode() { + return appMode; + } + + public ArrayList getRoutePoints() { + return routePoints; + } + + public int getRouteDistance() { + return routeDistance; + } + + public float getRoutingTime() { + return routingTime; + } + + public long getCreationTime() { + return creationTime; + } + + public float getCalculationTime() { + return calculationTime; + } + + public void setRouteCalculated(boolean routeCalculated) { + isRouteCalculated = routeCalculated; + } + + public void setAppMode(String appMode) { + this.appMode = appMode; + } + + public void setRoutePoints(ArrayList routePoints) { + this.routePoints = routePoints; + } + + public void setRouteDistance(int routeDistance) { + this.routeDistance = routeDistance; + } + + public void setRoutingTime(float routingTime) { + this.routingTime = routingTime; + } + + public void setCreationTime(long creationTime) { + this.creationTime = creationTime; + } + + public void setCalculationTime(float calculationTime) { + this.calculationTime = calculationTime; + } + + @Override + protected void readFromBundle(Bundle bundle) { + bundle.setClassLoader(ALatLon.class.getClassLoader()); + isRouteCalculated = bundle.getBoolean("isRouteCalculated"); + appMode = bundle.getString("appMode"); + routePoints = bundle.getParcelableArrayList("routePoints"); + routeDistance = bundle.getInt("routeDistance"); + routingTime = bundle.getFloat("routingTime"); + creationTime = bundle.getLong("creationTime"); + calculationTime = bundle.getFloat("calculationTime"); + } + + @Override + protected void writeToBundle(Bundle bundle) { + bundle.putBoolean("isRouteCalculated", isRouteCalculated); + bundle.putString("appMode", appMode); + bundle.putParcelableArrayList("routePoints", routePoints); + bundle.putInt("routeDistance", routeDistance); + bundle.putFloat("routingTime", routingTime); + bundle.putLong("creationTime", creationTime); + bundle.putFloat("calculationTime", calculationTime); + } +} diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.aidl new file mode 100644 index 000000000000..1c0113934ac2 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable ALocationType; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.java b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.java new file mode 100644 index 000000000000..e9de4e75431d --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.java @@ -0,0 +1,43 @@ +package net.osmand.aidlapi.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public enum ALocationType implements Parcelable { + CURRENT(0), + PROJECTION(1), + ROUTE_END(2), + ; + + final int value; + + ALocationType(int value) { + this.value = value; + } + + public static final Creator CREATOR = new Creator() { + @Override + public ALocationType createFromParcel(Parcel in) { + return ALocationType.valueOf(in.readString()); + } + + @Override + public ALocationType[] newArray(int size) { + return new ALocationType[size]; + } + }; + + public int getValue() { + return value; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(name()); + } +} diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.aidl b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.aidl new file mode 100644 index 000000000000..d473a2892b0d --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.navigation; + +parcelable NavigationStatus; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.java b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.java new file mode 100644 index 000000000000..10684a8fe21a --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.java @@ -0,0 +1,166 @@ +package net.osmand.aidlapi.navigation; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class NavigationStatus extends AidlParams { + + private int currentRouteSegmentIndex; + + private float currentMaxSpeed; + + private int leftDistance; + private int leftTime; + + private int leftDistanceToNextIntermediate; + private int leftTimeToNextIntermediate; + + private boolean isRouteCalculated; + private boolean isRouteFinished; + + private boolean isPauseNavigation; + private boolean isDeviatedFromRoute; + + public NavigationStatus() { + + } + + public NavigationStatus(int currentRouteSegmentIndex, float currentMaxSpeed, int leftDistance, int leftTime, int leftDistanceToNextIntermediate, int leftTimeToNextIntermediate, boolean isRouteCalculated, boolean isRouteFinished, boolean isPauseNavigation, boolean isDeviatedFromRoute) { + this.currentRouteSegmentIndex = currentRouteSegmentIndex; + this.currentMaxSpeed = currentMaxSpeed; + this.leftDistance = leftDistance; + this.leftTime = leftTime; + this.leftDistanceToNextIntermediate = leftDistanceToNextIntermediate; + this.leftTimeToNextIntermediate = leftTimeToNextIntermediate; + this.isRouteCalculated = isRouteCalculated; + this.isRouteFinished = isRouteFinished; + this.isPauseNavigation = isPauseNavigation; + this.isDeviatedFromRoute = isDeviatedFromRoute; + } + + protected NavigationStatus(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public NavigationStatus createFromParcel(Parcel in) { + return new NavigationStatus(in); + } + + @Override + public NavigationStatus[] newArray(int size) { + return new NavigationStatus[size]; + } + }; + + public int getCurrentRouteSegmentIndex() { + return currentRouteSegmentIndex; + } + + public float getCurrentMaxSpeed() { + return currentMaxSpeed; + } + + public int getLeftDistance() { + return leftDistance; + } + + public int getLeftTime() { + return leftTime; + } + + public int getLeftDistanceToNextIntermediate() { + return leftDistanceToNextIntermediate; + } + + public int getLeftTimeToNextIntermediate() { + return leftTimeToNextIntermediate; + } + + public boolean isRouteCalculated() { + return isRouteCalculated; + } + + public boolean isRouteFinished() { + return isRouteFinished; + } + + public boolean isPauseNavigation() { + return isPauseNavigation; + } + + public boolean isDeviatedFromRoute() { + return isDeviatedFromRoute; + } + + public void setCurrentRouteSegmentIndex(int currentRouteSegmentIndex) { + this.currentRouteSegmentIndex = currentRouteSegmentIndex; + } + + public void setCurrentMaxSpeed(float currentMaxSpeed) { + this.currentMaxSpeed = currentMaxSpeed; + } + + public void setLeftDistance(int leftDistance) { + this.leftDistance = leftDistance; + } + + public void setLeftTime(int leftTime) { + this.leftTime = leftTime; + } + + public void setLeftDistanceToNextIntermediate(int leftDistanceToNextIntermediate) { + this.leftDistanceToNextIntermediate = leftDistanceToNextIntermediate; + } + + public void setLeftTimeToNextIntermediate(int leftTimeToNextIntermediate) { + this.leftTimeToNextIntermediate = leftTimeToNextIntermediate; + } + + public void setRouteCalculated(boolean routeCalculated) { + isRouteCalculated = routeCalculated; + } + + public void setRouteFinished(boolean routeFinished) { + isRouteFinished = routeFinished; + } + + public void setPauseNavigation(boolean pauseNavigation) { + isPauseNavigation = pauseNavigation; + } + + public void setDeviatedFromRoute(boolean deviatedFromRoute) { + isDeviatedFromRoute = deviatedFromRoute; + } + + @Override + protected void readFromBundle(Bundle bundle) { + currentRouteSegmentIndex = bundle.getInt("currentRouteSegmentIndex"); + currentMaxSpeed = bundle.getFloat("currentMaxSpeed"); + leftDistance = bundle.getInt("leftDistance"); + leftTime = bundle.getInt("leftTime"); + leftDistanceToNextIntermediate = bundle.getInt("leftDistanceToNextIntermediate"); + leftTimeToNextIntermediate = bundle.getInt("leftTimeToNextIntermediate"); + isRouteCalculated = bundle.getBoolean("isRouteCalculated"); + isRouteFinished = bundle.getBoolean("isRouteFinished"); + isPauseNavigation = bundle.getBoolean("isPauseNavigation"); + isDeviatedFromRoute = bundle.getBoolean("isDeviatedFromRoute"); + } + + @Override + protected void writeToBundle(Bundle bundle) { + bundle.putInt("currentRouteSegmentIndex", currentRouteSegmentIndex); + bundle.putFloat("currentMaxSpeed", currentMaxSpeed); + bundle.putInt("leftDistance", leftDistance); + bundle.putInt("leftTime", leftTime); + bundle.putInt("leftDistanceToNextIntermediate", leftDistanceToNextIntermediate); + bundle.putInt("leftTimeToNextIntermediate", leftTimeToNextIntermediate); + bundle.putBoolean("isRouteCalculated", isRouteCalculated); + bundle.putBoolean("isRouteFinished", isRouteFinished); + bundle.putBoolean("isPauseNavigation", isPauseNavigation); + bundle.putBoolean("isDeviatedFromRoute", isDeviatedFromRoute); + } +} diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 153c0591cd98..e4a01534d7bf 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -1,6 +1,8 @@ package net.osmand.aidl; import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.ALocation; +import net.osmand.aidl.map.ALocationType; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.favorite.group.AFavoriteGroup; @@ -19,6 +21,7 @@ import net.osmand.aidl.mapmarker.RemoveMapMarkerParams; import net.osmand.aidl.mapmarker.UpdateMapMarkerParams; import net.osmand.aidl.calculateroute.CalculateRouteParams; +import net.osmand.aidl.calculateroute.CalculatedRoute; import net.osmand.aidl.gpx.ImportGpxParams; import net.osmand.aidl.gpx.ShowGpxParams; @@ -43,6 +46,7 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams; import net.osmand.aidl.navigation.NavigateParams; import net.osmand.aidl.navigation.NavigateGpxParams; +import net.osmand.aidl.navigation.NavigationStatus; import net.osmand.aidl.note.TakePhotoNoteParams; import net.osmand.aidl.note.StartVideoRecordingParams; @@ -861,4 +865,29 @@ interface IOsmAndAidlInterface { * Toggle Lock/Unlock screen. */ boolean setLockState(in SetLockStateParams params); + + /** + * Method to get position of various objects + * + * @params locationType (ALocationType) - type of position to get (CURRENT - last fixed, PROJECTION - last projection, ROUTE_END end of the route) + */ + boolean getLocation(in ALocationType locationType, out ALocation location); + + /** + * Method to get application mode + * + */ + String getApplicationMode(); + + /** + * Method to get current navigation status + * + */ + boolean getNavigationStatus(out NavigationStatus status); + + /** + * Method to get calculated route + * + */ + boolean getCalculatedRoute(out CalculatedRoute route); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index dce03bc0d5b2..7d9620cf08c9 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -49,10 +49,12 @@ import net.osmand.IndexConstants; import net.osmand.Location; import net.osmand.PlatformUtil; +import net.osmand.aidl.calculateroute.CalculatedRoute; import net.osmand.aidl.gpx.AGpxFile; import net.osmand.aidl.gpx.AGpxFileDetails; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.navigation.ADirectionInfo; +import net.osmand.aidl.navigation.NavigationStatus; import net.osmand.aidl.navigation.OnVoiceNavigationParams; import net.osmand.aidl.quickaction.QuickActionInfoParams; import net.osmand.aidl.tiles.ASqliteDbFile; @@ -64,6 +66,7 @@ import net.osmand.aidlapi.logcat.OnLogcatMessageParams; import net.osmand.aidlapi.map.ALatLon; import net.osmand.aidlapi.map.ALocation; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.aidlapi.navigation.ABlockedRoad; import net.osmand.aidlapi.navigation.NavigateGpxParams; import net.osmand.data.FavouritePoint; @@ -72,8 +75,8 @@ import net.osmand.gpx.GPXFile; import net.osmand.gpx.GPXTrackAnalysis; import net.osmand.gpx.GPXUtilities; -import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializeListener; +import net.osmand.plus.AppInitializer; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -105,6 +108,7 @@ import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.resources.SQLiteTileSource; import net.osmand.plus.routing.IRoutingDataUpdateListener; +import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.VoiceRouter; @@ -1110,6 +1114,201 @@ boolean removeAllActiveMapMarkers() { return true; } + public ALocation getLocation(net.osmand.aidl.map.ALocationType locationType) { + RoutingHelper rh = app.getRoutingHelper(); + switch (locationType) { + case CURRENT: + Location location = rh.getLastFixedLocation(); + return new ALocation( + location.getLatitude(), + location.getLongitude(), + location.getTime(), + location.hasAltitude(), + location.getAltitude(), + location.hasSpeed(), + location.getSpeed(), + location.hasBearing(), + location.getBearing(), + location.hasAccuracy(), + location.getAccuracy(), + location.hasVerticalAccuracy(), + location.getVerticalAccuracy() + ); + case PROJECTION: + Location projection = rh.getLastProjection(); + return new ALocation( + projection.getLatitude(), + projection.getLongitude(), + projection.getTime(), + projection.hasAltitude(), + projection.getAltitude(), + projection.hasSpeed(), + projection.getSpeed(), + projection.hasBearing(), + projection.getBearing(), + projection.hasAccuracy(), + projection.getAccuracy(), + projection.hasVerticalAccuracy(), + projection.getVerticalAccuracy() + ); + case ROUTE_END: + LatLon finalLocation = rh.getFinalLocation(); + return new ALocation( + finalLocation.getLatitude(), + finalLocation.getLongitude(), + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0 + ); + } + return null; + } + + public ALocation getLocationV2(ALocationType locationType) { + RoutingHelper rh = app.getRoutingHelper(); + switch (locationType) { + case CURRENT: + Location location = rh.getLastFixedLocation(); + return new ALocation( + location.getLatitude(), + location.getLongitude(), + location.getTime(), + location.hasAltitude(), + location.getAltitude(), + location.hasSpeed(), + location.getSpeed(), + location.hasBearing(), + location.getBearing(), + location.hasAccuracy(), + location.getAccuracy(), + location.hasVerticalAccuracy(), + location.getVerticalAccuracy() + ); + case PROJECTION: + Location projection = rh.getLastProjection(); + return new ALocation( + projection.getLatitude(), + projection.getLongitude(), + projection.getTime(), + projection.hasAltitude(), + projection.getAltitude(), + projection.hasSpeed(), + projection.getSpeed(), + projection.hasBearing(), + projection.getBearing(), + projection.hasAccuracy(), + projection.getAccuracy(), + projection.hasVerticalAccuracy(), + projection.getVerticalAccuracy() + ); + case ROUTE_END: + LatLon finalLocation = rh.getFinalLocation(); + return new ALocation( + finalLocation.getLatitude(), + finalLocation.getLongitude(), + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0, + false, + 0 + ); + } + return null; + } + + public NavigationStatus getNavigationStatus() { + RoutingHelper routingHelper = app.getRoutingHelper(); + RouteCalculationResult route = routingHelper.getRoute(); + + return new NavigationStatus( + route.getCurrentRoute(), + route.getCurrentMaxSpeed(), + routingHelper.getLeftDistance(), + routingHelper.getLeftTime(), + routingHelper.getLeftDistanceNextIntermediate(), + routingHelper.getLeftTimeNextIntermediate(), + routingHelper.isRouteCalculated(), + routingHelper.isRouteWasFinished(), + routingHelper.isPauseNavigation(), + routingHelper.isDeviatedFromRoute() + ); + } + + public CalculatedRoute getCalculatedRoute() { + RoutingHelper routingHelper = app.getRoutingHelper(); + boolean isRouteCalculated = routingHelper.isRouteCalculated(); + CalculatedRoute calculatedRoute = new CalculatedRoute(); + + calculatedRoute.setRouteCalculated(isRouteCalculated); + calculatedRoute.setAppMode(routingHelper.getAppMode().getStringKey()); + + if (isRouteCalculated) { + RouteCalculationResult route = routingHelper.getRoute(); + + List locations = route.getImmutableAllLocations(); + ArrayList routePoints = new ArrayList<>(locations.size()); + for (Location location : locations) { + routePoints.add(new ALatLon(location)); + } + + calculatedRoute.setRoutePoints(routePoints); + calculatedRoute.setRouteDistance(route.getWholeDistance()); + calculatedRoute.setRoutingTime(route.getRoutingTime()); + calculatedRoute.setCreationTime(route.getCreationTime()); + calculatedRoute.setCalculationTime(route.getCalculateTime()); + } + return calculatedRoute; + } + + public net.osmand.aidlapi.calculateroute.CalculatedRoute getCalculatedRouteV2(){ + RoutingHelper routingHelper = app.getRoutingHelper(); + boolean isRouteCalculated = routingHelper.isRouteCalculated(); + net.osmand.aidlapi.calculateroute.CalculatedRoute calculatedRoute = new net.osmand.aidlapi.calculateroute.CalculatedRoute(); + + calculatedRoute.setRouteCalculated(isRouteCalculated); + calculatedRoute.setAppMode(routingHelper.getAppMode().getStringKey()); + + if (isRouteCalculated) { + RouteCalculationResult route = routingHelper.getRoute(); + + List locations = route.getImmutableAllLocations(); + ArrayList routePoints = new ArrayList<>(locations.size()); + for (Location location : locations) { + routePoints.add(new net.osmand.aidlapi.map.ALatLon(location.getLatitude(), location.getLongitude())); + } + + calculatedRoute.setRoutePoints(routePoints); + calculatedRoute.setRouteDistance(route.getWholeDistance()); + calculatedRoute.setRoutingTime(route.getRoutingTime()); + calculatedRoute.setCreationTime(route.getCreationTime()); + calculatedRoute.setCalculationTime(route.getCalculateTime()); + } + return calculatedRoute; + } + + public RouteCalculationResult getRoute() { + RoutingHelper rh = app.getRoutingHelper(); + return rh.getRoute(); + } + + public ApplicationMode getApplicationMode() { + RoutingHelper rh = app.getRoutingHelper(); + return rh.getAppMode(); + } boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) { LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude()); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 9f68dd02a0b9..154269c83ff0 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -20,11 +20,13 @@ import androidx.annotation.Nullable; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; import net.osmand.aidl.calculateroute.CalculateRouteParams; +import net.osmand.aidl.calculateroute.CalculatedRoute; import net.osmand.aidl.contextmenu.ContextMenuButtonsParams; import net.osmand.aidl.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidl.contextmenu.UpdateContextMenuButtonsParams; @@ -55,6 +57,8 @@ import net.osmand.aidl.gpx.StopGpxRecordingParams; import net.osmand.aidl.lock.SetLockStateParams; import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.ALocation; +import net.osmand.aidl.map.ALocationType; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; @@ -81,6 +85,7 @@ import net.osmand.aidl.navigation.NavigateGpxParams; import net.osmand.aidl.navigation.NavigateParams; import net.osmand.aidl.navigation.NavigateSearchParams; +import net.osmand.aidl.navigation.NavigationStatus; import net.osmand.aidl.navigation.PauseNavigationParams; import net.osmand.aidl.navigation.ResumeNavigationParams; import net.osmand.aidl.navigation.StopNavigationParams; @@ -1273,6 +1278,83 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } } + @Override + public boolean getLocation(ALocationType locationType, ALocation location) { + try { + OsmandAidlApi api = getApi("getLocation"); + if (api != null) { + ALocation p = api.getLocation(locationType); + location.setLatitude(p.getLatitude()); + location.setLongitude(p.getLongitude()); + location.setAltitude(p.getAltitude()); + location.setSpeed(p.getSpeed()); + location.setBearing(p.getBearing()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public String getApplicationMode() { + try { + OsmandAidlApi api = getApi("getApplicationMode"); + if (api != null) { + return api.getApplicationMode().getStringKey(); + } + } catch (Exception e) { + handleException(e); + } + return null; + } + + @Override + public boolean getNavigationStatus(NavigationStatus navigationStatus){ + try { + OsmandAidlApi api = getApi("getNavigationStatus"); + if (api != null) { + NavigationStatus status = api.getNavigationStatus(); + navigationStatus.setCurrentRouteSegmentIndex(status.getCurrentRouteSegmentIndex()); + navigationStatus.setCurrentMaxSpeed(status.getCurrentMaxSpeed()); + navigationStatus.setLeftDistance(status.getLeftDistance()); + navigationStatus.setLeftTime(status.getLeftTime()); + navigationStatus.setLeftDistanceToNextIntermediate(status.getLeftDistanceToNextIntermediate()); + navigationStatus.setLeftTimeToNextIntermediate(status.getLeftTimeToNextIntermediate()); + navigationStatus.setRouteCalculated(status.isRouteCalculated()); + navigationStatus.setRouteFinished(status.isRouteFinished()); + navigationStatus.setPauseNavigation(status.isPauseNavigation()); + navigationStatus.setDeviatedFromRoute(status.isDeviatedFromRoute()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public boolean getCalculatedRoute(CalculatedRoute calculatedRoute){ + try { + OsmandAidlApi api = getApi("getCalculatedRoute"); + if (api != null) { + CalculatedRoute route = api.getCalculatedRoute(); + calculatedRoute.setRouteCalculated(route.isRouteCalculated()); + calculatedRoute.setAppMode(route.getAppMode()); + calculatedRoute.setRoutePoints(route.getRoutePoints()); + calculatedRoute.setRouteDistance(route.getRouteDistance()); + calculatedRoute.setRoutingTime(route.getRoutingTime()); + calculatedRoute.setCreationTime(route.getCreationTime()); + calculatedRoute.setCalculationTime(route.getCalculationTime()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + @Override public boolean getGpxColor(GpxColorParams params) { try { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 753b6a945d6d..d8655a6cf36a 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -22,13 +22,16 @@ import androidx.annotation.Nullable; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; +import net.osmand.aidlapi.map.ALocation; import net.osmand.aidlapi.IOsmAndAidlCallback; import net.osmand.aidlapi.IOsmAndAidlInterface; import net.osmand.aidlapi.calculateroute.CalculateRouteParams; +import net.osmand.aidlapi.calculateroute.CalculatedRoute; import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams; @@ -70,6 +73,7 @@ import net.osmand.aidlapi.logcat.ALogcatListenerParams; import net.osmand.aidlapi.map.ALatLon; import net.osmand.aidlapi.map.SetLocationParams; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.maplayer.AddMapLayerParams; import net.osmand.aidlapi.maplayer.RemoveMapLayerParams; @@ -103,6 +107,7 @@ import net.osmand.aidlapi.navigation.ResumeNavigationParams; import net.osmand.aidlapi.navigation.StopNavigationParams; import net.osmand.aidlapi.navigation.UnmuteNavigationParams; +import net.osmand.aidlapi.navigation.NavigationStatus; import net.osmand.aidlapi.note.StartAudioRecordingParams; import net.osmand.aidlapi.note.StartVideoRecordingParams; import net.osmand.aidlapi.note.StopRecordingParams; @@ -115,6 +120,9 @@ import net.osmand.aidlapi.search.SearchResult; import net.osmand.aidlapi.tiles.ASqliteDbFile; import net.osmand.data.LatLon; +import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.util.Algorithms; @@ -1267,6 +1275,83 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } } + @Override + public boolean getLocation(ALocationType locationType, ALocation location) { + try { + OsmandAidlApi api = getApi("getLocation"); + if (api != null) { + net.osmand.aidl.map.ALocation p = api.getLocationV2(locationType); + location.setLatitude(p.getLatitude()); + location.setLongitude(p.getLongitude()); + location.setAltitude(p.getAltitude()); + location.setSpeed(p.getSpeed()); + location.setBearing(p.getBearing()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public String getApplicationMode() { + try { + OsmandAidlApi api = getApi("getApplicationMode"); + if (api != null) { + return api.getApplicationMode().getStringKey(); + } + } catch (Exception e) { + handleException(e); + } + return null; + } + + @Override + public boolean getNavigationStatus(NavigationStatus navigationStatus){ + try { + OsmandAidlApi api = getApi("getNavigationStatus"); + if (api != null) { + net.osmand.aidl.navigation.NavigationStatus status = api.getNavigationStatus(); + navigationStatus.setCurrentRouteSegmentIndex(status.getCurrentRouteSegmentIndex()); + navigationStatus.setCurrentMaxSpeed(status.getCurrentMaxSpeed()); + navigationStatus.setLeftDistance(status.getLeftDistance()); + navigationStatus.setLeftTime(status.getLeftTime()); + navigationStatus.setLeftDistanceToNextIntermediate(status.getLeftDistanceToNextIntermediate()); + navigationStatus.setLeftTimeToNextIntermediate(status.getLeftTimeToNextIntermediate()); + navigationStatus.setRouteCalculated(status.isRouteCalculated()); + navigationStatus.setRouteFinished(status.isRouteFinished()); + navigationStatus.setPauseNavigation(status.isPauseNavigation()); + navigationStatus.setDeviatedFromRoute(status.isDeviatedFromRoute()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + + @Override + public boolean getCalculatedRoute(CalculatedRoute calculatedRoute){ + try { + OsmandAidlApi api = getApi("getCalculatedRoute"); + if (api != null) { + CalculatedRoute route = api.getCalculatedRouteV2(); + calculatedRoute.setRouteCalculated(route.isRouteCalculated()); + calculatedRoute.setAppMode(route.getAppMode()); + calculatedRoute.setRoutePoints(route.getRoutePoints()); + calculatedRoute.setRouteDistance(route.getRouteDistance()); + calculatedRoute.setRoutingTime(route.getRoutingTime()); + calculatedRoute.setCreationTime(route.getCreationTime()); + calculatedRoute.setCalculationTime(route.getCalculationTime()); + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + @Override public boolean importProfile(ProfileSettingsParams params) { try { diff --git a/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.aidl b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.aidl new file mode 100644 index 000000000000..fd4c359be23b --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.calculateroute; + +parcelable CalculatedRoute; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.java b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.java new file mode 100644 index 000000000000..06db39ba2152 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.java @@ -0,0 +1,135 @@ +package net.osmand.aidl.calculateroute; + +import android.os.Parcel; +import android.os.Parcelable; + +import net.osmand.aidl.map.ALatLon; + +import java.util.ArrayList; + +public class CalculatedRoute implements Parcelable { + + private boolean isRouteCalculated; + + private String appMode; + + private ArrayList routePoints; + private int routeDistance; + + private float routingTime; + private long creationTime; + + private float calculationTime; + + public CalculatedRoute() { + + } + + public CalculatedRoute(boolean isRouteCalculated, String appMode, ArrayList routePoints, int routeDistance, float routingTime, long creationTime, float calculationTime) { + this.isRouteCalculated = isRouteCalculated; + this.appMode = appMode; + this.routePoints = routePoints; + this.routeDistance = routeDistance; + this.routingTime = routingTime; + this.creationTime = creationTime; + this.calculationTime = calculationTime; + } + + protected CalculatedRoute(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public CalculatedRoute createFromParcel(Parcel in) { + return new CalculatedRoute(in); + } + + @Override + public CalculatedRoute[] newArray(int size) { + return new CalculatedRoute[size]; + } + }; + + public boolean isRouteCalculated() { + return isRouteCalculated; + } + + public String getAppMode() { + return appMode; + } + + public ArrayList getRoutePoints() { + return routePoints; + } + + public int getRouteDistance() { + return routeDistance; + } + + public float getRoutingTime() { + return routingTime; + } + + public long getCreationTime() { + return creationTime; + } + + public float getCalculationTime() { + return calculationTime; + } + + public void setRouteCalculated(boolean routeCalculated) { + isRouteCalculated = routeCalculated; + } + + public void setAppMode(String appMode) { + this.appMode = appMode; + } + + public void setRoutePoints(ArrayList routePoints) { + this.routePoints = routePoints; + } + + public void setRouteDistance(int routeDistance) { + this.routeDistance = routeDistance; + } + + public void setRoutingTime(float routingTime) { + this.routingTime = routingTime; + } + + public void setCreationTime(long creationTime) { + this.creationTime = creationTime; + } + + public void setCalculationTime(float calculationTime) { + this.calculationTime = calculationTime; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeByte((byte) (isRouteCalculated ? 1 : 0)); + dest.writeString(appMode); + dest.writeTypedList(routePoints); + dest.writeInt(routeDistance); + dest.writeFloat(routingTime); + dest.writeLong(creationTime); + dest.writeFloat(calculationTime); + } + + public void readFromParcel(Parcel in) { + isRouteCalculated = in.readByte() != 0; + appMode = in.readString(); + routePoints = in.createTypedArrayList(ALatLon.CREATOR); + routeDistance = in.readInt(); + routingTime = in.readFloat(); + creationTime = in.readLong(); + calculationTime = in.readFloat(); + } +} diff --git a/OsmAnd/src/net/osmand/aidl/map/ALatLon.java b/OsmAnd/src/net/osmand/aidl/map/ALatLon.java index 377344fd6ab1..4676a805c6b4 100644 --- a/OsmAnd/src/net/osmand/aidl/map/ALatLon.java +++ b/OsmAnd/src/net/osmand/aidl/map/ALatLon.java @@ -3,6 +3,8 @@ import android.os.Parcel; import android.os.Parcelable; +import net.osmand.Location; + public class ALatLon implements Parcelable { private double longitude; @@ -13,6 +15,10 @@ public ALatLon(double latitude, double longitude) { this.longitude = longitude; } + public ALatLon(Location location) { + this(location.getLatitude(), location.getLongitude()); + } + public ALatLon(Parcel in) { readFromParcel(in); } diff --git a/OsmAnd/src/net/osmand/aidl/map/ALocation.aidl b/OsmAnd/src/net/osmand/aidl/map/ALocation.aidl new file mode 100644 index 000000000000..3e799988684e --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/ALocation.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.map; + +parcelable ALocation; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/map/ALocation.java b/OsmAnd/src/net/osmand/aidl/map/ALocation.java new file mode 100644 index 000000000000..856872cca390 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/ALocation.java @@ -0,0 +1,138 @@ +package net.osmand.aidl.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public class ALocation implements Parcelable { + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getAltitude() { + return altitude; + } + + public void setAltitude(double altitude) { + this.altitude = altitude; + } + + public double getSpeed() { + return speed; + } + + public void setSpeed(double speed) { + this.speed = speed; + } + + public double getBearing() { + return bearing; + } + + public void setBearing(double bearing) { + this.bearing = bearing; + } + + private double latitude; + private double longitude; + private double altitude; + private double speed; + private double bearing; + + public ALocation(double latitude, double longitude, double altitude, double speed, double bearing) { + this.latitude = latitude; + this.longitude = longitude; + this.altitude = altitude; + this.speed = speed; + this.bearing = bearing; + } + + public ALocation(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public ALocation createFromParcel(Parcel in) { + return new ALocation(in); + } + + public ALocation[] newArray(int size) { + return new ALocation[size]; + } + }; + + public ALocation() { + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + int temp; + temp = (int)Math.floor(latitude * 10000); + result = prime * result + temp; + temp = (int)Math.floor(longitude * 10000); + result = prime * result + temp; + temp = (int)Math.floor(altitude * 10000); + result = prime * result + temp; + temp = (int)Math.floor(speed * 10000); + result = prime * result + temp; + temp = (int)Math.floor(bearing * 10000); + result = prime * result + temp; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + + ALocation other = (ALocation) obj; + return Math.abs(latitude - other.latitude) < 0.00001 + && Math.abs(longitude - other.longitude) < 0.00001 + && Math.abs(altitude - other.altitude) < 1 + && Math.abs(speed - other.speed) < 1; + } + + @Override + public String toString() { + return "Lat " + ((float)latitude) + " Lon " + ((float)longitude) + " Alt " + ((float)altitude); + } + + public void writeToParcel(Parcel out, int flags) { + out.writeDouble(latitude); + out.writeDouble(longitude); + out.writeDouble(altitude); + out.writeDouble(speed); + out.writeDouble(bearing); + } + + public void readFromParcel(Parcel in) { + latitude = in.readDouble(); + longitude = in.readDouble(); + altitude = in.readDouble(); + speed = in.readDouble(); + bearing = in.readDouble(); + } + + public int describeContents() { + return 0; + } +} diff --git a/OsmAnd/src/net/osmand/aidl/map/ALocationType.aidl b/OsmAnd/src/net/osmand/aidl/map/ALocationType.aidl new file mode 100644 index 000000000000..581266f0e3f5 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/ALocationType.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.map; + +parcelable ALocationType; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/map/ALocationType.java b/OsmAnd/src/net/osmand/aidl/map/ALocationType.java new file mode 100644 index 000000000000..b80fe2c52351 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/ALocationType.java @@ -0,0 +1,44 @@ +package net.osmand.aidl.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public enum ALocationType implements Parcelable { + CURRENT(0), + PROJECTION(1), + ROUTE_END(2), + ; + + public final int value; + + ALocationType(int value) { + this.value = value; + } + + + public static final Creator CREATOR = new Creator() { + @Override + public ALocationType createFromParcel(Parcel in) { + return ALocationType.valueOf(in.readString()); + } + + @Override + public ALocationType[] newArray(int size) { + return new ALocationType[size]; + } + }; + + public int getValue() { + return value; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(name()); + } +} diff --git a/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.aidl b/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.aidl new file mode 100644 index 000000000000..6ff5086a7971 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.navigation; + +parcelable NavigationStatus; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.java b/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.java new file mode 100644 index 000000000000..b69aa1a92bb5 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.java @@ -0,0 +1,168 @@ +package net.osmand.aidl.navigation; + +import android.os.Parcel; +import android.os.Parcelable; + +public class NavigationStatus implements Parcelable { + + private int currentRouteSegmentIndex; + + private float currentMaxSpeed; + + private int leftDistance; + private int leftTime; + + private int leftDistanceToNextIntermediate; + private int leftTimeToNextIntermediate; + + private boolean isRouteCalculated; + private boolean isRouteFinished; + + private boolean isPauseNavigation; + private boolean isDeviatedFromRoute; + + public NavigationStatus() { + + } + + public NavigationStatus(int currentRouteSegmentIndex, float currentMaxSpeed, int leftDistance, int leftTime, int leftDistanceToNextIntermediate, int leftTimeToNextIntermediate, boolean isRouteCalculated, boolean isRouteFinished, boolean isPauseNavigation, boolean isDeviatedFromRoute) { + this.currentRouteSegmentIndex = currentRouteSegmentIndex; + this.currentMaxSpeed = currentMaxSpeed; + this.leftDistance = leftDistance; + this.leftTime = leftTime; + this.leftDistanceToNextIntermediate = leftDistanceToNextIntermediate; + this.leftTimeToNextIntermediate = leftTimeToNextIntermediate; + this.isRouteCalculated = isRouteCalculated; + this.isRouteFinished = isRouteFinished; + this.isPauseNavigation = isPauseNavigation; + this.isDeviatedFromRoute = isDeviatedFromRoute; + } + + protected NavigationStatus(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public NavigationStatus createFromParcel(Parcel in) { + return new NavigationStatus(in); + } + + @Override + public NavigationStatus[] newArray(int size) { + return new NavigationStatus[size]; + } + }; + + public int getCurrentRouteSegmentIndex() { + return currentRouteSegmentIndex; + } + + public float getCurrentMaxSpeed() { + return currentMaxSpeed; + } + + public int getLeftDistance() { + return leftDistance; + } + + public int getLeftTime() { + return leftTime; + } + + public int getLeftDistanceToNextIntermediate() { + return leftDistanceToNextIntermediate; + } + + public int getLeftTimeToNextIntermediate() { + return leftTimeToNextIntermediate; + } + + public boolean isRouteCalculated() { + return isRouteCalculated; + } + + public boolean isRouteFinished() { + return isRouteFinished; + } + + public boolean isPauseNavigation() { + return isPauseNavigation; + } + + public boolean isDeviatedFromRoute() { + return isDeviatedFromRoute; + } + + public void setCurrentRouteSegmentIndex(int currentRouteSegmentIndex) { + this.currentRouteSegmentIndex = currentRouteSegmentIndex; + } + + public void setCurrentMaxSpeed(float currentMaxSpeed) { + this.currentMaxSpeed = currentMaxSpeed; + } + + public void setLeftDistance(int leftDistance) { + this.leftDistance = leftDistance; + } + + public void setLeftTime(int leftTime) { + this.leftTime = leftTime; + } + + public void setLeftDistanceToNextIntermediate(int leftDistanceToNextIntermediate) { + this.leftDistanceToNextIntermediate = leftDistanceToNextIntermediate; + } + + public void setLeftTimeToNextIntermediate(int leftTimeToNextIntermediate) { + this.leftTimeToNextIntermediate = leftTimeToNextIntermediate; + } + + public void setRouteCalculated(boolean routeCalculated) { + isRouteCalculated = routeCalculated; + } + + public void setRouteFinished(boolean routeFinished) { + isRouteFinished = routeFinished; + } + + public void setPauseNavigation(boolean pauseNavigation) { + isPauseNavigation = pauseNavigation; + } + + public void setDeviatedFromRoute(boolean deviatedFromRoute) { + isDeviatedFromRoute = deviatedFromRoute; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(currentRouteSegmentIndex); + dest.writeFloat(currentMaxSpeed); + dest.writeInt(leftDistance); + dest.writeInt(leftTime); + dest.writeInt(leftDistanceToNextIntermediate); + dest.writeInt(leftTimeToNextIntermediate); + dest.writeByte((byte) (isRouteCalculated ? 1 : 0)); + dest.writeByte((byte) (isRouteFinished ? 1 : 0)); + dest.writeByte((byte) (isPauseNavigation ? 1 : 0)); + dest.writeByte((byte) (isDeviatedFromRoute ? 1 : 0)); + } + + public void readFromParcel(Parcel in) { + currentRouteSegmentIndex = in.readInt(); + currentMaxSpeed = in.readFloat(); + leftDistance = in.readInt(); + leftTime = in.readInt(); + leftDistanceToNextIntermediate = in.readInt(); + leftTimeToNextIntermediate = in.readInt(); + isRouteCalculated = in.readByte() != 0; + isRouteFinished = in.readByte() != 0; + isPauseNavigation = in.readByte() != 0; + isDeviatedFromRoute = in.readByte() != 0; + } +} diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 254204f07cc6..3cfdc1bde23e 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -30,12 +30,20 @@ import net.osmand.PlatformUtil; import net.osmand.aidl.AidlSearchResultWrapper; import net.osmand.aidl.OsmandAidlApi; +import net.osmand.aidl.map.ALatLon; import net.osmand.aidl.search.SearchParams; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.gpx.GPXFile; import net.osmand.gpx.GPXUtilities; +import net.osmand.plus.routing.RouteCalculationResult; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -97,6 +105,7 @@ public class ExternalApiHelper { public static final String API_CMD_STOP_AV_REC = "stop_av_rec"; public static final String API_CMD_GET_INFO = "get_info"; + public static final String API_CMD_GET_ROUTE = "get_route"; public static final String API_CMD_ADD_FAVORITE = "add_favorite"; public static final String API_CMD_ADD_MAP_MARKER = "add_map_marker"; @@ -169,6 +178,13 @@ public class ExternalApiHelper { public static final String PARAM_PLUGINS_VERSIONS = "plugins_versions"; public static final String PARAM_PROFILES_VERSIONS = "profiles_versions"; + public static final String PARAM_HAS_ROUTE = "has_route"; + public static final String PARAM_ROUTE_POINTS = "route_points"; + private static final String PARAM_DIRECTION_POINTS = "direction_points"; + private static final String PARAM_ROUTE_TIME = "route_time"; + private static final String PARAM_CREATION_TIME = "route_id"; + private static final String PARAM_MODE = "mode"; + // RESULT_OK == -1 // RESULT_CANCELED == 0 // RESULT_FIRST_USER == 1 @@ -468,7 +484,35 @@ public void onDismiss(DialogInterface dialog) { finish = true; resultCode = Activity.RESULT_OK; + } else if (API_CMD_GET_ROUTE.equals(cmd)) { + final RoutingHelper routingHelper = app.getRoutingHelper(); + final boolean has_route = routingHelper.isRouteCalculated(); + if (has_route) { + RouteCalculationResult route = routingHelper.getRoute(); + // export waypoints of the route + List locations = route.getImmutableAllLocations(); + ArrayList route_points = new ArrayList<>(locations.size()); + for (Location location : locations) { + route_points.add(new ALatLon(location)); + } + result.putParcelableArrayListExtra(PARAM_ROUTE_POINTS, route_points); + // export indexes of waypoints of the route which have routing directions + List directions = route.getRouteDirections(); + ArrayList direction_points = new ArrayList<>(directions.size()); + for (RouteDirectionInfo direction : directions) { + direction_points.add(direction.routePointOffset); + } + result.putExtra(PARAM_DIRECTION_POINTS, direction_points); + // export miscellaneous info of the route + result.putExtra(PARAM_ROUTE_TIME, route.getRoutingTime()); + result.putExtra(PARAM_MODE, routingHelper.getAppMode().getStringKey()); + long routeCreationTime = route.getCreationTime(); + result.putExtra(PARAM_CREATION_TIME, routeCreationTime); + } + result.putExtra(PARAM_HAS_ROUTE, has_route); + finish = true; + resultCode = Activity.RESULT_OK; } else if (API_CMD_ADD_FAVORITE.equals(cmd)) { String name = uri.getQueryParameter(PARAM_NAME); String desc = uri.getQueryParameter(PARAM_DESC); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index f2c206d45dd5..6bd49612274e 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -54,6 +54,7 @@ public class RouteCalculationResult { private final int visitedSegments; private final int loadedTiles; private final float calculateTime; + private final long creationTime; protected int cacheCurrentTextDirectionInfo = -1; protected List cacheAgreggatedDirections; @@ -94,6 +95,7 @@ public RouteCalculationResult(String errorMessage) { this.routeRecalcDistance = 0; this.routeVisibleAngle = 0; this.initialCalculation = false; + this.creationTime = System.currentTimeMillis(); } public RouteCalculationResult(List list, List directions, @@ -138,6 +140,7 @@ public RouteCalculationResult(List list, List dire this.routeVisibleAngle = 0; } this.initialCalculation = params.initialCalculation; + this.creationTime = System.currentTimeMillis(); } public RouteCalculationResult(List list, Location start, LatLon end, @@ -186,6 +189,7 @@ public RouteCalculationResult(List list, Location start, Lat this.routeVisibleAngle = routeService == RouteService.STRAIGHT ? ctx.getSettings().ROUTE_STRAIGHT_ANGLE.getModeValue(mode) : 0; this.initialCalculation = initialCalculation; + this.creationTime = System.currentTimeMillis(); } public ApplicationMode getAppMode() { @@ -1092,6 +1096,10 @@ public float getCalculateTime() { return calculateTime; } + public long getCreationTime() { + return creationTime; + } + public int getLoadedTiles() { return loadedTiles; }