From f47eaf8845608245c144f4cc045af5ec04602ef2 Mon Sep 17 00:00:00 2001 From: atmi Date: Tue, 16 Jun 2020 20:12:50 +0300 Subject: [PATCH 1/8] get_route api function --- .../src/net/osmand/data/LatLonParcelable.java | 41 +++++++++++++++++++ .../plus/helpers/ExternalApiHelper.java | 35 ++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 OsmAnd/src/net/osmand/data/LatLonParcelable.java diff --git a/OsmAnd/src/net/osmand/data/LatLonParcelable.java b/OsmAnd/src/net/osmand/data/LatLonParcelable.java new file mode 100644 index 00000000000..26a9b6a5c91 --- /dev/null +++ b/OsmAnd/src/net/osmand/data/LatLonParcelable.java @@ -0,0 +1,41 @@ +package net.osmand.data; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.Parcelable.Creator; + +public class LatLonParcelable extends LatLon implements Parcelable { + public LatLonParcelable(double latitude, double longitude) { + super(latitude, longitude); + } + + public LatLonParcelable(LatLon latlon) { + super(latlon.getLatitude(), latlon.getLongitude()); + } + + public LatLonParcelable(Parcel in) { + super(in.readDouble(), in.readDouble()); + } + + public static final Creator CREATOR = new Creator() { + @Override + public LatLonParcelable createFromParcel(Parcel in) { + return new LatLonParcelable(in); + } + + @Override + public LatLonParcelable[] newArray(int size) { + return new LatLonParcelable[size]; + } + }; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel parcel, int i) { + parcel.writeDouble(getLatitude()); + parcel.writeDouble(getLongitude()); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 4cb07d65431..2d400045c96 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -25,7 +25,9 @@ import net.osmand.aidl.search.SearchParams; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.LatLonParcelable; import net.osmand.data.PointDescription; +import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.MapMarkersHelper; @@ -92,6 +94,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"; @@ -154,6 +157,12 @@ public class ExternalApiHelper { public static final String PARAM_QUICK_ACTION_PARAMS = "quick_action_params"; public static final String PARAM_QUICK_ACTION_NUMBER = "quick_action_number"; + 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_MODE = "mode"; + public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ ApplicationMode.CAR, ApplicationMode.BICYCLE, @@ -493,7 +502,33 @@ 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.getRouteLocations(); + ArrayList route_points = new ArrayList<>(locations.size()); + for (Location location : locations) { + route_points.add(new LatLonParcelable(location.getLatitude(), location.getLongitude())); + } + 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()); + } + 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); From d16d530d981dde91257439bca0d99f523b3bcd34 Mon Sep 17 00:00:00 2001 From: atmi Date: Thu, 18 Jun 2020 17:27:04 +0300 Subject: [PATCH 2/8] aidl method stub to get location --- .../net/osmand/aidlapi/IOsmAndAidlInterface.aidl | 7 +++++++ .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 7 +++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 16 ++++++++++++++++ .../src/net/osmand/aidl/OsmandAidlService.java | 11 +++++++++++ .../src/net/osmand/aidl/OsmandAidlServiceV2.java | 11 +++++++++++ 5 files changed, 52 insertions(+) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 45bf3907f76..cb8528e2c1d 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -836,6 +836,13 @@ interface IOsmAndAidlInterface { */ boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); + /** + * Method to get location of various objects + * + * @params locationType (int) - type of location to get + */ + double[] getLocation(in int locationType); + boolean importProfile(in ProfileSettingsParams params); boolean executeQuickAction(in QuickActionParams params); diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 91410a35c76..e67b633bf0b 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -837,6 +837,13 @@ interface IOsmAndAidlInterface { */ boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); + /** + * Method to get location of various objects + * + * @params locationType (int) - type of location to get + */ + double[] getLocation(in int locationType); + /** * Method to get color name for gpx. * diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 582d6972ee5..bc86d95546c 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -29,6 +29,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.gpx.AGpxFile; import net.osmand.aidl.gpx.AGpxFileDetails; @@ -1003,6 +1004,21 @@ boolean removeAllActiveMapMarkers() { return true; } + double[] getLocation(int locationType) { + double lat, lon, alt = 0, speed = 0, bearing = 0; + switch (locationType) { + default: { + RoutingHelper rh = app.getRoutingHelper(); + Location location = rh.getLastFixedLocation(); + lat = location.getLatitude(); + lon = location.getLongitude(); + alt = location.getAltitude(); + speed = location.getSpeed(); + bearing = location.getBearing(); + } + } + return new double[]{ lat, lon, alt, speed, bearing }; + } 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 8763156abe5..13849acc2bb 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1278,6 +1278,17 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } } + @Override + public double[] getLocation(int locationType) { + try { + OsmandAidlApi api = getApi("getLocation"); + return api != null ? api.getLocation(locationType) : null; + } catch (Exception e) { + handleException(e); + return null; + } + } + @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 1953e185fd6..d17c9ffc0bc 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1227,6 +1227,17 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } } + @Override + public double[] getLocation(int locationType) { + try { + OsmandAidlApi api = getApi("getLocation"); + return api != null ? api.getLocation(locationType) : null; + } catch (Exception e) { + handleException(e); + return null; + } + } + @Override public boolean importProfile(ProfileSettingsParams params) { try { From b899b04a8740086b2481bd3c48d5fbc612498050 Mon Sep 17 00:00:00 2001 From: atmi Date: Thu, 18 Jun 2020 22:38:05 +0300 Subject: [PATCH 3/8] aidl output parameter as parcelable --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 7 +- .../src/net/osmand/aidlapi/map/APosition.aidl | 3 + .../src/net/osmand/aidlapi/map/APosition.java | 138 ++++++++++++++++++ .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 7 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 22 +-- .../net/osmand/aidl/OsmandAidlService.java | 17 ++- .../net/osmand/aidl/OsmandAidlServiceV2.java | 17 ++- OsmAnd/src/net/osmand/aidl/map/APosition.aidl | 3 + OsmAnd/src/net/osmand/aidl/map/APosition.java | 138 ++++++++++++++++++ 9 files changed, 328 insertions(+), 24 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java create mode 100644 OsmAnd/src/net/osmand/aidl/map/APosition.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/map/APosition.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index cb8528e2c1d..4e64ae32c88 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -1,6 +1,7 @@ package net.osmand.aidlapi; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.APosition; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.favorite.group.AFavoriteGroup; @@ -837,11 +838,11 @@ interface IOsmAndAidlInterface { boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); /** - * Method to get location of various objects + * Method to get position of various objects * - * @params locationType (int) - type of location to get + * @params positionType (int) - type of position to get */ - double[] getLocation(in int locationType); + boolean getPosition(in int positionType, out APosition position); boolean importProfile(in ProfileSettingsParams params); diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl new file mode 100644 index 00000000000..5f1329af4c7 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable APosition; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java new file mode 100644 index 00000000000..b238a1a509a --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java @@ -0,0 +1,138 @@ +package net.osmand.aidlapi.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public class APosition implements Parcelable { + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + 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 longitude; + private double latitude; + private double altitude; + private double speed; + private double bearing; + + public APosition(double longitude, double latitude, double altitude, double speed, double bearer) { + this.longitude = longitude; + this.latitude = latitude; + this.altitude = altitude; + this.speed = speed; + this.bearing = bearer; + } + + public APosition(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public APosition createFromParcel(Parcel in) { + return new APosition(in); + } + + public APosition[] newArray(int size) { + return new APosition[size]; + } + }; + + public APosition() { + } + + @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; + + APosition other = (APosition) 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/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index e67b633bf0b..89876166de0 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -1,6 +1,7 @@ package net.osmand.aidl; import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.APosition; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.favorite.group.AFavoriteGroup; @@ -838,11 +839,11 @@ interface IOsmAndAidlInterface { boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); /** - * Method to get location of various objects + * Method to get position of various objects * - * @params locationType (int) - type of location to get + * @params positionType (int) - type of position to get */ - double[] getLocation(in int locationType); + boolean getPosition(in int positionType, out APosition position); /** * Method to get color name for gpx. diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index bc86d95546c..019f1da5907 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -34,6 +34,7 @@ import net.osmand.aidl.gpx.AGpxFile; import net.osmand.aidl.gpx.AGpxFileDetails; import net.osmand.aidl.gpx.ASelectedGpxFile; +import net.osmand.aidl.map.APosition; import net.osmand.aidl.navigation.ADirectionInfo; import net.osmand.aidl.navigation.OnVoiceNavigationParams; import net.osmand.aidl.quickaction.QuickActionInfoParams; @@ -1004,20 +1005,21 @@ boolean removeAllActiveMapMarkers() { return true; } - double[] getLocation(int locationType) { - double lat, lon, alt = 0, speed = 0, bearing = 0; - switch (locationType) { - default: { + public APosition getPosition(int positionType) { + switch (positionType) { + case 0: { RoutingHelper rh = app.getRoutingHelper(); Location location = rh.getLastFixedLocation(); - lat = location.getLatitude(); - lon = location.getLongitude(); - alt = location.getAltitude(); - speed = location.getSpeed(); - bearing = location.getBearing(); + return new APosition( + location.getLatitude(), + location.getLongitude(), + location.getAltitude(), + location.getSpeed(), + location.getBearing() + ); } } - return new double[]{ lat, lon, alt, speed, bearing }; + return null; } boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 13849acc2bb..0718e6a14f3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -45,6 +45,7 @@ import net.osmand.aidl.gpx.StartGpxRecordingParams; import net.osmand.aidl.gpx.StopGpxRecordingParams; import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.APosition; import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.maplayer.AddMapLayerParams; import net.osmand.aidl.maplayer.RemoveMapLayerParams; @@ -1279,14 +1280,22 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } @Override - public double[] getLocation(int locationType) { + public boolean getPosition(int positionType, APosition position) { try { - OsmandAidlApi api = getApi("getLocation"); - return api != null ? api.getLocation(locationType) : null; + OsmandAidlApi api = getApi("getPosition"); + if (api != null) { + APosition p = api.getPosition(positionType); + position.setLatitude(p.getLatitude()); + position.setLongitude(p.getLongitude()); + position.setAltitude(p.getAltitude()); + position.setSpeed(p.getSpeed()); + position.setBearing(p.getBearing()); + return true; + } } catch (Exception e) { handleException(e); - return null; } + return false; } @Override diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index d17c9ffc0bc..cc1ba2aeee6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -15,6 +15,7 @@ import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; +import net.osmand.aidlapi.map.APosition; import net.osmand.aidlapi.IOsmAndAidlCallback; import net.osmand.aidlapi.IOsmAndAidlInterface; import net.osmand.aidlapi.calculateroute.CalculateRouteParams; @@ -1228,14 +1229,22 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } @Override - public double[] getLocation(int locationType) { + public boolean getPosition(int positionType, APosition position) { try { - OsmandAidlApi api = getApi("getLocation"); - return api != null ? api.getLocation(locationType) : null; + OsmandAidlApi api = getApi("getPosition"); + if (api != null) { + net.osmand.aidl.map.APosition p = api.getPosition(positionType); + position.setLatitude(p.getLatitude()); + position.setLongitude(p.getLongitude()); + position.setAltitude(p.getAltitude()); + position.setSpeed(p.getSpeed()); + position.setBearing(p.getBearing()); + return true; + } } catch (Exception e) { handleException(e); - return null; } + return false; } @Override diff --git a/OsmAnd/src/net/osmand/aidl/map/APosition.aidl b/OsmAnd/src/net/osmand/aidl/map/APosition.aidl new file mode 100644 index 00000000000..67927a046f5 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/APosition.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.map; + +parcelable APosition; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/map/APosition.java b/OsmAnd/src/net/osmand/aidl/map/APosition.java new file mode 100644 index 00000000000..88f302421d1 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/map/APosition.java @@ -0,0 +1,138 @@ +package net.osmand.aidl.map; + +import android.os.Parcel; +import android.os.Parcelable; + +public class APosition implements Parcelable { + + public double getLongitude() { + return longitude; + } + + public void setLongitude(double longitude) { + this.longitude = longitude; + } + + public double getLatitude() { + return latitude; + } + + public void setLatitude(double latitude) { + this.latitude = latitude; + } + + 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 longitude; + private double latitude; + private double altitude; + private double speed; + private double bearing; + + public APosition(double longitude, double latitude, double altitude, double speed, double bearer) { + this.longitude = longitude; + this.latitude = latitude; + this.altitude = altitude; + this.speed = speed; + this.bearing = bearer; + } + + public APosition(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new + Creator() { + public APosition createFromParcel(Parcel in) { + return new APosition(in); + } + + public APosition[] newArray(int size) { + return new APosition[size]; + } + }; + + public APosition() { + } + + @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; + + APosition other = (APosition) 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; + } +} From 34261cac6a8c0e61edd75f8e23b183a5e20d35ac Mon Sep 17 00:00:00 2001 From: atmi Date: Fri, 19 Jun 2020 14:21:32 +0300 Subject: [PATCH 4/8] APosition constructor params order fixed --- .../src/net/osmand/aidlapi/map/APosition.java | 24 +++++++++---------- OsmAnd/src/net/osmand/aidl/map/APosition.java | 24 +++++++++---------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java index b238a1a509a..a32c44f589a 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java @@ -5,14 +5,6 @@ public class APosition implements Parcelable { - public double getLongitude() { - return longitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - public double getLatitude() { return latitude; } @@ -21,6 +13,14 @@ 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; } @@ -45,18 +45,18 @@ public void setBearing(double bearing) { this.bearing = bearing; } - private double longitude; private double latitude; + private double longitude; private double altitude; private double speed; private double bearing; - public APosition(double longitude, double latitude, double altitude, double speed, double bearer) { - this.longitude = longitude; + public APosition(double latitude, double longitude, double altitude, double speed, double bearing) { this.latitude = latitude; + this.longitude = longitude; this.altitude = altitude; this.speed = speed; - this.bearing = bearer; + this.bearing = bearing; } public APosition(Parcel in) { diff --git a/OsmAnd/src/net/osmand/aidl/map/APosition.java b/OsmAnd/src/net/osmand/aidl/map/APosition.java index 88f302421d1..c743f31151d 100644 --- a/OsmAnd/src/net/osmand/aidl/map/APosition.java +++ b/OsmAnd/src/net/osmand/aidl/map/APosition.java @@ -5,14 +5,6 @@ public class APosition implements Parcelable { - public double getLongitude() { - return longitude; - } - - public void setLongitude(double longitude) { - this.longitude = longitude; - } - public double getLatitude() { return latitude; } @@ -21,6 +13,14 @@ 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; } @@ -45,18 +45,18 @@ public void setBearing(double bearing) { this.bearing = bearing; } - private double longitude; private double latitude; + private double longitude; private double altitude; private double speed; private double bearing; - public APosition(double longitude, double latitude, double altitude, double speed, double bearer) { - this.longitude = longitude; + public APosition(double latitude, double longitude, double altitude, double speed, double bearing) { this.latitude = latitude; + this.longitude = longitude; this.altitude = altitude; this.speed = speed; - this.bearing = bearer; + this.bearing = bearing; } public APosition(Parcel in) { From a219ef276dbcd245d4947482e059a1bd1b6180f3 Mon Sep 17 00:00:00 2001 From: atmi Date: Sat, 18 Jul 2020 11:22:19 +0300 Subject: [PATCH 5/8] Order of AIDL methods rearranged; Added getCurrentRouteSegmentIndex() & getRouteCreationTime(); --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 19 ++++++++++--- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 26 +++++++++++++----- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 10 +++++++ .../net/osmand/aidl/OsmandAidlService.java | 26 ++++++++++++++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 27 +++++++++++++++++++ .../plus/helpers/ExternalApiHelper.java | 5 +++- .../plus/routing/RouteCalculationResult.java | 8 ++++++ 7 files changed, 109 insertions(+), 12 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 4e64ae32c88..fda602539c2 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -837,6 +837,12 @@ interface IOsmAndAidlInterface { */ boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); + boolean importProfile(in ProfileSettingsParams params); + + boolean executeQuickAction(in QuickActionParams params); + + boolean getQuickActionsInfo(out List quickActions); + /** * Method to get position of various objects * @@ -844,9 +850,14 @@ interface IOsmAndAidlInterface { */ boolean getPosition(in int positionType, out APosition position); - boolean importProfile(in ProfileSettingsParams params); - - boolean executeQuickAction(in QuickActionParams params); + /** + * Method to get index of the current route segment + */ + int getCurrentRouteSegmentIndex(); - boolean getQuickActionsInfo(out List quickActions); + /** + * Method to get creation time of current route + * + */ + long getRouteCreationTime(); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 89876166de0..6585787bf0a 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -838,13 +838,6 @@ interface IOsmAndAidlInterface { */ boolean removeAllActiveMapMarkers(in RemoveMapMarkersParams params); - /** - * Method to get position of various objects - * - * @params positionType (int) - type of position to get - */ - boolean getPosition(in int positionType, out APosition position); - /** * Method to get color name for gpx. * @@ -864,4 +857,23 @@ interface IOsmAndAidlInterface { boolean executeQuickAction(in QuickActionParams params); boolean getQuickActionsInfo(out List quickActions); + + /** + * Method to get position of various objects + * + * @params positionType (int) - type of position to get + */ + boolean getPosition(in int positionType, out APosition position); + + /** + * Method to get index of current route segment + * + */ + int getCurrentRouteSegmentIndex(); + + /** + * Method to get creation time current route + * + */ + long getRouteCreationTime(); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 019f1da5907..728a1d1db88 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1022,6 +1022,16 @@ public APosition getPosition(int positionType) { return null; } + public int getCurrentRouteSegmentIndex() { + RoutingHelper rh = app.getRoutingHelper(); + return rh.getRoute().getCurrentRoute(); + } + + public long getRouteCreationTime(){ + RoutingHelper rh = app.getRoutingHelper(); + return rh.getRoute().getCreationTime(); + } + boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) { LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude()); LatLon latLonNew = new LatLon(newLatLon.getLatitude(), newLatLon.getLongitude()); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 0718e6a14f3..e72989626f9 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1298,6 +1298,32 @@ public boolean getPosition(int positionType, APosition position) { return false; } + @Override + public int getCurrentRouteSegmentIndex() { + try { + OsmandAidlApi api = getApi("getCurrentRouteSegmentIndex"); + if (api != null) { + return api.getCurrentRouteSegmentIndex(); + } + } catch (Exception e) { + handleException(e); + } + return -1; + } + + @Override + public long getRouteCreationTime() { + try { + OsmandAidlApi api = getApi("getRouteCreationTime"); + if (api != null) { + return api.getRouteCreationTime(); + } + } catch (Exception e) { + handleException(e); + } + return -1; + } + @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 cc1ba2aeee6..0f140796b70 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -88,6 +88,7 @@ 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.settings.backend.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; import net.osmand.util.Algorithms; @@ -1247,6 +1248,32 @@ public boolean getPosition(int positionType, APosition position) { return false; } + @Override + public int getCurrentRouteSegmentIndex() { + try { + OsmandAidlApi api = getApi("getCurrentRouteSegmentIndex"); + if (api != null) { + return api.getCurrentRouteSegmentIndex(); + } + } catch (Exception e) { + handleException(e); + } + return -1; + } + + @Override + public long getRouteCreationTime() { + try { + OsmandAidlApi api = getApi("getRouteCreationTime"); + if (api != null) { + return api.getRouteCreationTime(); + } + } catch (Exception e) { + handleException(e); + } + return -1; + } + @Override public boolean importProfile(ProfileSettingsParams params) { try { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index 2d400045c96..f1bef4bee13 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -161,6 +161,7 @@ public class ExternalApiHelper { 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"; public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{ @@ -508,7 +509,7 @@ public void onDismiss(DialogInterface dialog) { if (has_route) { RouteCalculationResult route = routingHelper.getRoute(); // export waypoints of the route - List locations = route.getRouteLocations(); + List locations = route.getImmutableAllLocations(); ArrayList route_points = new ArrayList<>(locations.size()); for (Location location : locations) { route_points.add(new LatLonParcelable(location.getLatitude(), location.getLongitude())); @@ -524,6 +525,8 @@ public void onDismiss(DialogInterface dialog) { // 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); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 6ac55e75920..5daf02ef6b4 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; @@ -92,6 +93,7 @@ public RouteCalculationResult(String errorMessage) { this.appMode = null; this.routeRecalcDistance = 0; this.routeVisibleAngle = 0; + this.creationTime = System.currentTimeMillis(); } public RouteCalculationResult(List list, List directions, RouteCalculationParams params, List waypoints, boolean addMissingTurns) { @@ -134,6 +136,7 @@ public RouteCalculationResult(List list, List dire this.routeRecalcDistance = 0; this.routeVisibleAngle = 0; } + this.creationTime = System.currentTimeMillis(); } public RouteCalculationResult(List list, Location start, LatLon end, List intermediates, @@ -174,6 +177,7 @@ public RouteCalculationResult(List list, Location start, Lat this.routeRecalcDistance = ctx.getSettings().ROUTE_RECALCULATION_DISTANCE.getModeValue(mode); this.routeVisibleAngle = routeService == RouteProvider.RouteService.STRAIGHT ? ctx.getSettings().ROUTE_STRAIGHT_ANGLE.getModeValue(mode) : 0; + this.creationTime = System.currentTimeMillis(); } public ApplicationMode getAppMode() { @@ -983,6 +987,10 @@ public float getCalculateTime() { return calculateTime; } + public long getCreationTime() { + return creationTime; + } + public int getLoadedTiles() { return loadedTiles; } From 93c590145ce0433b0d9d27508eb9fb2945296b5f Mon Sep 17 00:00:00 2001 From: ATMI_LAPTOP Date: Wed, 22 Jul 2020 14:11:12 +0300 Subject: [PATCH 6/8] get rid of duplicate class LatLonParcelable, use ALatLon instead; added getRoute() aidl api method; added getRoutePoints() aidl method --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 8 +++- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 6 +++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 9 ++++ .../net/osmand/aidl/OsmandAidlService.java | 19 +++++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 19 +++++++++ OsmAnd/src/net/osmand/aidl/map/ALatLon.java | 6 +++ .../src/net/osmand/data/LatLonParcelable.java | 41 ------------------- .../plus/helpers/ExternalApiHelper.java | 6 +-- 8 files changed, 69 insertions(+), 45 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/data/LatLonParcelable.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index fda602539c2..d6390a33548 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -860,4 +860,10 @@ interface IOsmAndAidlInterface { * */ long getRouteCreationTime(); -} \ No newline at end of file + + /** + * Method to get current route points + * + */ + boolean getRoutePoints(out List route); +} diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 6585787bf0a..1731353aa49 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -876,4 +876,10 @@ interface IOsmAndAidlInterface { * */ long getRouteCreationTime(); + + /** + * Method to get current route points + * + */ + boolean getRoutePoints(out List route); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 0fd01f07ae0..0ae5f7b4d79 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -46,6 +46,7 @@ import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.dialogs.GpxAppearanceAdapter; +import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; @@ -1032,6 +1033,14 @@ public long getRouteCreationTime(){ return rh.getRoute().getCreationTime(); } + public RouteCalculationResult getRoute() { + RoutingHelper rh = app.getRoutingHelper(); + if(rh.isRouteCalculated()) { + return rh.getRoute(); + } + return null; + } + boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) { LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude()); LatLon latLonNew = new LatLon(newLatLon.getLatitude(), newLatLon.getLongitude()); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index e72989626f9..3c1feb9d268 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -11,6 +11,7 @@ import androidx.annotation.Nullable; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; @@ -1324,6 +1325,24 @@ public long getRouteCreationTime() { return -1; } + @Override + public boolean getRoutePoints(List route) { + try { + OsmandAidlApi api = getApi("getRoutePoints"); + if (api != null) { + route.clear(); + List locations = api.getRoute().getImmutableAllLocations(); + for (Location location : locations) { + route.add(new ALatLon(location)); + } + 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 0f140796b70..d0e4c0be0f9 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -11,6 +11,7 @@ import androidx.annotation.Nullable; +import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; @@ -1274,6 +1275,24 @@ public long getRouteCreationTime() { return -1; } + @Override + public boolean getRoutePoints(List route) { + try { + OsmandAidlApi api = getApi("getRoutePoints"); + if (api != null) { + route.clear(); + List locations = api.getRoute().getImmutableAllLocations(); + for (Location location : locations) { + route.add(new ALatLon(location.getLatitude(), location.getLongitude())); + } + return true; + } + } catch (Exception e) { + handleException(e); + } + return false; + } + @Override public boolean importProfile(ProfileSettingsParams params) { try { diff --git a/OsmAnd/src/net/osmand/aidl/map/ALatLon.java b/OsmAnd/src/net/osmand/aidl/map/ALatLon.java index 377344fd6ab..4676a805c6b 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/data/LatLonParcelable.java b/OsmAnd/src/net/osmand/data/LatLonParcelable.java deleted file mode 100644 index 26a9b6a5c91..00000000000 --- a/OsmAnd/src/net/osmand/data/LatLonParcelable.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.osmand.data; -import android.os.Parcel; -import android.os.Parcelable; -import android.os.Parcelable.Creator; - -public class LatLonParcelable extends LatLon implements Parcelable { - public LatLonParcelable(double latitude, double longitude) { - super(latitude, longitude); - } - - public LatLonParcelable(LatLon latlon) { - super(latlon.getLatitude(), latlon.getLongitude()); - } - - public LatLonParcelable(Parcel in) { - super(in.readDouble(), in.readDouble()); - } - - public static final Creator CREATOR = new Creator() { - @Override - public LatLonParcelable createFromParcel(Parcel in) { - return new LatLonParcelable(in); - } - - @Override - public LatLonParcelable[] newArray(int size) { - return new LatLonParcelable[size]; - } - }; - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeDouble(getLatitude()); - parcel.writeDouble(getLongitude()); - } -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index f1bef4bee13..58cc16aaff8 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -22,10 +22,10 @@ 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.LatLonParcelable; import net.osmand.data.PointDescription; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.settings.backend.ApplicationMode; @@ -510,9 +510,9 @@ public void onDismiss(DialogInterface dialog) { RouteCalculationResult route = routingHelper.getRoute(); // export waypoints of the route List locations = route.getImmutableAllLocations(); - ArrayList route_points = new ArrayList<>(locations.size()); + ArrayList route_points = new ArrayList<>(locations.size()); for (Location location : locations) { - route_points.add(new LatLonParcelable(location.getLatitude(), location.getLongitude())); + route_points.add(new ALatLon(location)); } result.putParcelableArrayListExtra(PARAM_ROUTE_POINTS, route_points); // export indexes of waypoints of the route which have routing directions From 04c73270d99bd360022a41b7218cb5421bd17cc1 Mon Sep 17 00:00:00 2001 From: ATMI_LAPTOP Date: Wed, 22 Jul 2020 17:02:21 +0300 Subject: [PATCH 7/8] getApplicationMode() aidl method added --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 7 ++++++- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 6 ++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 21 +++++++++++-------- .../net/osmand/aidl/OsmandAidlService.java | 14 +++++++++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 13 ++++++++++++ 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index a7ade88f784..b5eee878c34 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -861,7 +861,6 @@ interface IOsmAndAidlInterface { * @params keyEventList (List) - list of requested key events */ long registerForKeyEvents(in AKeyEventsParams params, IOsmAndAidlCallback callback); -} /** * Method to get position of various objects @@ -886,4 +885,10 @@ interface IOsmAndAidlInterface { * */ boolean getRoutePoints(out List route); + + /** + * Method to get application mode + * + */ + String getApplicationMode(); } diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index c7a21c99e50..d5d4119f404 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -887,4 +887,10 @@ interface IOsmAndAidlInterface { * */ boolean getRoutePoints(out List route); + + /** + * Method to get application mode + * + */ + String getApplicationMode(); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index a51a08590d2..51d9bbf81d5 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.app.Activity; +import android.app.Application; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -1054,21 +1055,23 @@ public APosition getPosition(int positionType) { } public int getCurrentRouteSegmentIndex() { - RoutingHelper rh = app.getRoutingHelper(); - return rh.getRoute().getCurrentRoute(); + RouteCalculationResult route = getRoute(); + return route != null ? route.getCurrentRoute() : -1; } - public long getRouteCreationTime(){ - RoutingHelper rh = app.getRoutingHelper(); - return rh.getRoute().getCreationTime(); + public long getRouteCreationTime() { + RouteCalculationResult route = getRoute(); + return route != null ? route.getCreationTime() : -1; } public RouteCalculationResult getRoute() { RoutingHelper rh = app.getRoutingHelper(); - if(rh.isRouteCalculated()) { - return rh.getRoute(); - } - return null; + 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) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 1963e6356b2..cacc7f84478 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -1344,6 +1344,19 @@ public boolean getRoutePoints(List route) { 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 getGpxColor(GpxColorParams params) { try { @@ -1392,6 +1405,7 @@ public boolean getQuickActionsInfo(List quickActions) { return false; } } + @Override public boolean setLockState(SetLockStateParams params) { try { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 1bad400443c..2d1dcb963e6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -1318,6 +1318,19 @@ public boolean getRoutePoints(List route) { 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 importProfile(ProfileSettingsParams params) { try { From 9c75003be11de09ec9598a58c7873541e61b7f08 Mon Sep 17 00:00:00 2001 From: ATMI_LAPTOP Date: Sun, 9 Aug 2020 11:22:46 +0300 Subject: [PATCH 8/8] Refactored due to https://github.com/osmandapp/OsmAnd/pull/9304#discussion_r462920058 && https://github.com/osmandapp/OsmAnd/pull/9304#discussion_r462930388 --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 26 ++- .../calculateroute/CalculatedRoute.aidl | 3 + .../calculateroute/CalculatedRoute.java | 133 ++++++++++++++ .../map/{APosition.aidl => ALocation.aidl} | 2 +- .../map/{APosition.java => ALocation.java} | 55 +++--- .../net/osmand/aidlapi/map/ALocationType.aidl | 3 + .../net/osmand/aidlapi/map/ALocationType.java | 43 +++++ .../aidlapi/navigation/NavigationStatus.aidl | 3 + .../aidlapi/navigation/NavigationStatus.java | 166 +++++++++++++++++ .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 27 ++- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 144 +++++++++++++-- .../net/osmand/aidl/OsmandAidlService.java | 78 ++++---- .../net/osmand/aidl/OsmandAidlServiceV2.java | 79 ++++---- .../aidl/calculateroute/CalculatedRoute.aidl | 3 + .../aidl/calculateroute/CalculatedRoute.java | 135 ++++++++++++++ .../map/{APosition.aidl => ALocation.aidl} | 2 +- .../map/{APosition.java => ALocation.java} | 22 +-- .../net/osmand/aidl/map/ALocationType.aidl | 3 + .../net/osmand/aidl/map/ALocationType.java | 44 +++++ .../aidl/navigation/NavigationStatus.aidl | 3 + .../aidl/navigation/NavigationStatus.java | 168 ++++++++++++++++++ 21 files changed, 982 insertions(+), 160 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/calculateroute/CalculatedRoute.java rename OsmAnd-api/src/net/osmand/aidlapi/map/{APosition.aidl => ALocation.aidl} (61%) rename OsmAnd-api/src/net/osmand/aidlapi/map/{APosition.java => ALocation.java} (65%) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocationType.java create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/navigation/NavigationStatus.java create mode 100644 OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/calculateroute/CalculatedRoute.java rename OsmAnd/src/net/osmand/aidl/map/{APosition.aidl => ALocation.aidl} (58%) rename OsmAnd/src/net/osmand/aidl/map/{APosition.java => ALocation.java} (85%) create mode 100644 OsmAnd/src/net/osmand/aidl/map/ALocationType.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/map/ALocationType.java create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/navigation/NavigationStatus.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index b5eee878c34..30eb92cc7c5 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -1,7 +1,8 @@ package net.osmand.aidlapi; import net.osmand.aidlapi.map.ALatLon; -import net.osmand.aidlapi.map.APosition; +import net.osmand.aidlapi.map.ALocation; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.favorite.group.AFavoriteGroup; @@ -20,6 +21,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.gpx.ImportGpxParams; import net.osmand.aidlapi.gpx.ShowGpxParams; @@ -44,6 +46,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; @@ -865,30 +868,25 @@ interface IOsmAndAidlInterface { /** * Method to get position of various objects * - * @params positionType (int) - type of position to get + * @params locationType (ALocationType) - type of position to get (CURRENT - last fixed, PROJECTION - last projection, ROUTE_END end of the route) */ - boolean getPosition(in int positionType, out APosition position); + boolean getLocation(in ALocationType locationType, out ALocation location); /** - * Method to get index of the current route segment - */ - int getCurrentRouteSegmentIndex(); - - /** - * Method to get creation time of current route + * Method to get application mode * */ - long getRouteCreationTime(); + String getApplicationMode(); /** - * Method to get current route points + * Method to get current navigation status * */ - boolean getRoutePoints(out List route); + boolean getNavigationStatus(out NavigationStatus status); /** - * Method to get application mode + * Method to get calculated route * */ - String getApplicationMode(); + 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 00000000000..33553a4accd --- /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 00000000000..29c73661c54 --- /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/APosition.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl similarity index 61% rename from OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl rename to OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl index 5f1329af4c7..88c65b5e0cb 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl @@ -1,3 +1,3 @@ package net.osmand.aidlapi.map; -parcelable APosition; \ No newline at end of file +parcelable ALocation; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java similarity index 65% rename from OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java rename to OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java index a32c44f589a..827f20f15fb 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java @@ -1,9 +1,11 @@ package net.osmand.aidlapi.map; +import android.os.Bundle; import android.os.Parcel; -import android.os.Parcelable; -public class APosition implements Parcelable { +import net.osmand.aidlapi.AidlParams; + +public class ALocation extends AidlParams { public double getLatitude() { return latitude; @@ -51,7 +53,7 @@ public void setBearing(double bearing) { private double speed; private double bearing; - public APosition(double latitude, double longitude, double altitude, double speed, double bearing) { + public ALocation(double latitude, double longitude, double altitude, double speed, double bearing) { this.latitude = latitude; this.longitude = longitude; this.altitude = altitude; @@ -59,22 +61,22 @@ public APosition(double latitude, double longitude, double altitude, double spee this.bearing = bearing; } - public APosition(Parcel in) { + public ALocation(Parcel in) { readFromParcel(in); } - public static final Creator CREATOR = new - Creator() { - public APosition createFromParcel(Parcel in) { - return new APosition(in); + public static final Creator CREATOR = new + Creator() { + public ALocation createFromParcel(Parcel in) { + return new ALocation(in); } - public APosition[] newArray(int size) { - return new APosition[size]; + public ALocation[] newArray(int size) { + return new ALocation[size]; } }; - public APosition() { + public ALocation() { } @Override @@ -104,7 +106,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; - APosition other = (APosition) obj; + 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 @@ -116,23 +118,22 @@ 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(); + @Override + protected void readFromBundle(Bundle bundle) { + latitude = bundle.getDouble("latitude", latitude); + longitude = bundle.getDouble("longitude", longitude); + altitude = bundle.getDouble("altitude", altitude); + speed = bundle.getDouble("speed", speed); + bearing = bundle.getDouble("bearing", bearing); } - public int describeContents() { - return 0; + @Override + protected void writeToBundle(Bundle bundle) { + bundle.putDouble("latitude", latitude); + bundle.putDouble("longitude", longitude); + bundle.putDouble("altitude", altitude); + bundle.putDouble("speed", speed); + bundle.putDouble("bearing", bearing); } } 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 00000000000..1c0113934ac --- /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 00000000000..e9de4e75431 --- /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 00000000000..d473a2892b0 --- /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 00000000000..10684a8fe21 --- /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 d5d4119f404..e4a01534d7b 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -1,7 +1,8 @@ package net.osmand.aidl; import net.osmand.aidl.map.ALatLon; -import net.osmand.aidl.map.APosition; +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; @@ -20,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; @@ -44,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; @@ -866,31 +869,25 @@ interface IOsmAndAidlInterface { /** * Method to get position of various objects * - * @params positionType (int) - type of position to get + * @params locationType (ALocationType) - type of position to get (CURRENT - last fixed, PROJECTION - last projection, ROUTE_END end of the route) */ - boolean getPosition(in int positionType, out APosition position); + boolean getLocation(in ALocationType locationType, out ALocation location); /** - * Method to get index of current route segment - * - */ - int getCurrentRouteSegmentIndex(); - - /** - * Method to get creation time current route + * Method to get application mode * */ - long getRouteCreationTime(); + String getApplicationMode(); /** - * Method to get current route points + * Method to get current navigation status * */ - boolean getRoutePoints(out List route); + boolean getNavigationStatus(out NavigationStatus status); /** - * Method to get application mode + * Method to get calculated route * */ - String getApplicationMode(); + boolean getCalculatedRoute(out CalculatedRoute route); } diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 51d9bbf81d5..ec643852522 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -2,7 +2,6 @@ import android.annotation.SuppressLint; import android.app.Activity; -import android.app.Application; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -33,14 +32,18 @@ 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.map.APosition; +import net.osmand.aidl.map.ALatLon; +import net.osmand.aidl.map.ALocation; 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; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -63,7 +66,6 @@ import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; -import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.helpers.LockHelper; @@ -78,7 +80,6 @@ import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.VoiceRouter; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.SettingsHelper; @@ -1037,31 +1038,142 @@ boolean removeAllActiveMapMarkers() { return true; } - public APosition getPosition(int positionType) { - switch (positionType) { - case 0: { - RoutingHelper rh = app.getRoutingHelper(); + public ALocation getLocation(net.osmand.aidl.map.ALocationType locationType) { + RoutingHelper rh = app.getRoutingHelper(); + switch (locationType) { + case CURRENT: Location location = rh.getLastFixedLocation(); - return new APosition( + return new ALocation( location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(), location.getBearing() ); - } + case PROJECTION: + Location projection = rh.getLastProjection(); + return new ALocation( + projection.getLatitude(), + projection.getLongitude(), + projection.getAltitude(), + projection.getSpeed(), + projection.getBearing() + ); + case ROUTE_END: + LatLon finalLocation = rh.getFinalLocation(); + return new ALocation( + finalLocation.getLatitude(), + finalLocation.getLongitude(), + 0, + 0, + 0 + ); } return null; } - public int getCurrentRouteSegmentIndex() { - RouteCalculationResult route = getRoute(); - return route != null ? route.getCurrentRoute() : -1; + 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.getAltitude(), + location.getSpeed(), + location.getBearing() + ); + case PROJECTION: + Location projection = rh.getLastProjection(); + return new ALocation( + projection.getLatitude(), + projection.getLongitude(), + projection.getAltitude(), + projection.getSpeed(), + projection.getBearing() + ); + case ROUTE_END: + LatLon finalLocation = rh.getFinalLocation(); + return new ALocation( + finalLocation.getLatitude(), + finalLocation.getLongitude(), + 0, + 0, + 0 + ); + } + return null; } - public long getRouteCreationTime() { - RouteCalculationResult route = getRoute(); - return route != null ? route.getCreationTime() : -1; + 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() { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index cacc7f84478..d81248515a8 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -17,6 +17,7 @@ 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; @@ -46,7 +47,8 @@ import net.osmand.aidl.gpx.StartGpxRecordingParams; import net.osmand.aidl.gpx.StopGpxRecordingParams; import net.osmand.aidl.map.ALatLon; -import net.osmand.aidl.map.APosition; +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; @@ -73,6 +75,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; @@ -1282,16 +1285,16 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } @Override - public boolean getPosition(int positionType, APosition position) { + public boolean getLocation(ALocationType locationType, ALocation location) { try { - OsmandAidlApi api = getApi("getPosition"); + OsmandAidlApi api = getApi("getLocation"); if (api != null) { - APosition p = api.getPosition(positionType); - position.setLatitude(p.getLatitude()); - position.setLongitude(p.getLongitude()); - position.setAltitude(p.getAltitude()); - position.setSpeed(p.getSpeed()); - position.setBearing(p.getBearing()); + 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) { @@ -1301,41 +1304,34 @@ public boolean getPosition(int positionType, APosition position) { } @Override - public int getCurrentRouteSegmentIndex() { - try { - OsmandAidlApi api = getApi("getCurrentRouteSegmentIndex"); - if (api != null) { - return api.getCurrentRouteSegmentIndex(); - } - } catch (Exception e) { - handleException(e); - } - return -1; - } - - @Override - public long getRouteCreationTime() { + public String getApplicationMode() { try { - OsmandAidlApi api = getApi("getRouteCreationTime"); + OsmandAidlApi api = getApi("getApplicationMode"); if (api != null) { - return api.getRouteCreationTime(); + return api.getApplicationMode().getStringKey(); } } catch (Exception e) { handleException(e); } - return -1; + return null; } @Override - public boolean getRoutePoints(List route) { + public boolean getNavigationStatus(NavigationStatus navigationStatus){ try { - OsmandAidlApi api = getApi("getRoutePoints"); + OsmandAidlApi api = getApi("getNavigationStatus"); if (api != null) { - route.clear(); - List locations = api.getRoute().getImmutableAllLocations(); - for (Location location : locations) { - route.add(new ALatLon(location)); - } + 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) { @@ -1345,16 +1341,24 @@ public boolean getRoutePoints(List route) { } @Override - public String getApplicationMode() { + public boolean getCalculatedRoute(CalculatedRoute calculatedRoute){ try { - OsmandAidlApi api = getApi("getApplicationMode"); + OsmandAidlApi api = getApi("getCalculatedRoute"); if (api != null) { - return api.getApplicationMode().getStringKey(); + 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 null; + return false; } @Override diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 2d1dcb963e6..593c2ec4783 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -16,10 +16,11 @@ import net.osmand.aidl.OsmandAidlApi.GpxBitmapCreatedCallback; import net.osmand.aidl.OsmandAidlApi.OsmandAppInitCallback; import net.osmand.aidl.OsmandAidlApi.SearchCompleteCallback; -import net.osmand.aidlapi.map.APosition; +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; @@ -50,6 +51,7 @@ import net.osmand.aidlapi.gpx.StopGpxRecordingParams; import net.osmand.aidlapi.lock.SetLockStateParams; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.ALocationType; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.maplayer.AddMapLayerParams; import net.osmand.aidlapi.maplayer.RemoveMapLayerParams; @@ -80,6 +82,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; @@ -92,7 +95,6 @@ import net.osmand.aidlapi.tiles.ASqliteDbFile; import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.util.Algorithms; @@ -1256,16 +1258,16 @@ public boolean removeAllActiveMapMarkers(RemoveMapMarkersParams params) { } @Override - public boolean getPosition(int positionType, APosition position) { + public boolean getLocation(ALocationType locationType, ALocation location) { try { - OsmandAidlApi api = getApi("getPosition"); + OsmandAidlApi api = getApi("getLocation"); if (api != null) { - net.osmand.aidl.map.APosition p = api.getPosition(positionType); - position.setLatitude(p.getLatitude()); - position.setLongitude(p.getLongitude()); - position.setAltitude(p.getAltitude()); - position.setSpeed(p.getSpeed()); - position.setBearing(p.getBearing()); + 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) { @@ -1275,41 +1277,34 @@ public boolean getPosition(int positionType, APosition position) { } @Override - public int getCurrentRouteSegmentIndex() { - try { - OsmandAidlApi api = getApi("getCurrentRouteSegmentIndex"); - if (api != null) { - return api.getCurrentRouteSegmentIndex(); - } - } catch (Exception e) { - handleException(e); - } - return -1; - } - - @Override - public long getRouteCreationTime() { + public String getApplicationMode() { try { - OsmandAidlApi api = getApi("getRouteCreationTime"); + OsmandAidlApi api = getApi("getApplicationMode"); if (api != null) { - return api.getRouteCreationTime(); + return api.getApplicationMode().getStringKey(); } } catch (Exception e) { handleException(e); } - return -1; + return null; } @Override - public boolean getRoutePoints(List route) { + public boolean getNavigationStatus(NavigationStatus navigationStatus){ try { - OsmandAidlApi api = getApi("getRoutePoints"); + OsmandAidlApi api = getApi("getNavigationStatus"); if (api != null) { - route.clear(); - List locations = api.getRoute().getImmutableAllLocations(); - for (Location location : locations) { - route.add(new ALatLon(location.getLatitude(), location.getLongitude())); - } + 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) { @@ -1319,16 +1314,24 @@ public boolean getRoutePoints(List route) { } @Override - public String getApplicationMode() { + public boolean getCalculatedRoute(CalculatedRoute calculatedRoute){ try { - OsmandAidlApi api = getApi("getApplicationMode"); + OsmandAidlApi api = getApi("getCalculatedRoute"); if (api != null) { - return api.getApplicationMode().getStringKey(); + 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 null; + return false; } @Override 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 00000000000..fd4c359be23 --- /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 00000000000..06db39ba215 --- /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/APosition.aidl b/OsmAnd/src/net/osmand/aidl/map/ALocation.aidl similarity index 58% rename from OsmAnd/src/net/osmand/aidl/map/APosition.aidl rename to OsmAnd/src/net/osmand/aidl/map/ALocation.aidl index 67927a046f5..3e799988684 100644 --- a/OsmAnd/src/net/osmand/aidl/map/APosition.aidl +++ b/OsmAnd/src/net/osmand/aidl/map/ALocation.aidl @@ -1,3 +1,3 @@ package net.osmand.aidl.map; -parcelable APosition; \ No newline at end of file +parcelable ALocation; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/map/APosition.java b/OsmAnd/src/net/osmand/aidl/map/ALocation.java similarity index 85% rename from OsmAnd/src/net/osmand/aidl/map/APosition.java rename to OsmAnd/src/net/osmand/aidl/map/ALocation.java index c743f31151d..856872cca39 100644 --- a/OsmAnd/src/net/osmand/aidl/map/APosition.java +++ b/OsmAnd/src/net/osmand/aidl/map/ALocation.java @@ -3,7 +3,7 @@ import android.os.Parcel; import android.os.Parcelable; -public class APosition implements Parcelable { +public class ALocation implements Parcelable { public double getLatitude() { return latitude; @@ -51,7 +51,7 @@ public void setBearing(double bearing) { private double speed; private double bearing; - public APosition(double latitude, double longitude, double altitude, double speed, double bearing) { + public ALocation(double latitude, double longitude, double altitude, double speed, double bearing) { this.latitude = latitude; this.longitude = longitude; this.altitude = altitude; @@ -59,22 +59,22 @@ public APosition(double latitude, double longitude, double altitude, double spee this.bearing = bearing; } - public APosition(Parcel in) { + public ALocation(Parcel in) { readFromParcel(in); } - public static final Creator CREATOR = new - Creator() { - public APosition createFromParcel(Parcel in) { - return new APosition(in); + public static final Creator CREATOR = new + Creator() { + public ALocation createFromParcel(Parcel in) { + return new ALocation(in); } - public APosition[] newArray(int size) { - return new APosition[size]; + public ALocation[] newArray(int size) { + return new ALocation[size]; } }; - public APosition() { + public ALocation() { } @Override @@ -104,7 +104,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; - APosition other = (APosition) obj; + 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 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 00000000000..581266f0e3f --- /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 00000000000..b80fe2c5235 --- /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 00000000000..6ff5086a797 --- /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 00000000000..b69aa1a92bb --- /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; + } +}