Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -860,4 +861,34 @@ interface IOsmAndAidlInterface {
* @params keyEventList (List<Integer>) - list of requested key events
*/
long registerForKeyEvents(in AKeyEventsParams params, IOsmAndAidlCallback callback);
}

/**
* Method to get position of various objects
*
* @params positionType (int) - type of position to get
*/
boolean getPosition(in int positionType, out APosition position);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New aidl methods must be added to the end of the file or following methods will be broken.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, acknowledged )


/**
* Method to get index of the current route segment
*/
int getCurrentRouteSegmentIndex();

/**
* Method to get creation time of current route
*
*/
long getRouteCreationTime();

/**
* Method to get current route points
*
*/
boolean getRoutePoints(out List<ALatLon> route);

/**
* Method to get application mode
*
*/
String getApplicationMode();
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be refactored into 3 differnet methods:

  1. getCalculatedRoute - information about calculated routes, geometry, appmode, time, etc
  2. getApplicationMode - current app mode
  3. getNavigationStatus - progress, currentSegment, leftDistance, leftTime, etc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in latest commit

3 changes: 3 additions & 0 deletions OsmAnd-api/src/net/osmand/aidlapi/map/APosition.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package net.osmand.aidlapi.map;

parcelable APosition;
138 changes: 138 additions & 0 deletions OsmAnd-api/src/net/osmand/aidlapi/map/APosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package net.osmand.aidlapi.map;

import android.os.Parcel;
import android.os.Parcelable;

public class APosition implements Parcelable {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. APosition > ALocation
  2. ALocation immutable
  3. ALocation extends AidlParams
  4. positionType > locationType and it should be explained in the method's description

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in latest commit


public double getLatitude() {
return latitude;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public double getLongitude() {
return longitude;
}

public void setLongitude(double longitude) {
this.longitude = longitude;
}

public double getAltitude() {
return altitude;
}

public void setAltitude(double altitude) {
this.altitude = altitude;
}

public double getSpeed() {
return speed;
}

public void setSpeed(double speed) {
this.speed = speed;
}

public double getBearing() {
return bearing;
}

public void setBearing(double bearing) {
this.bearing = bearing;
}

private double latitude;
private double longitude;
private double altitude;
private double speed;
private double bearing;

public 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 = bearing;
}

public APosition(Parcel in) {
readFromParcel(in);
}

public static final Creator<APosition> CREATOR = new
Creator<APosition>() {
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;
}
}
32 changes: 32 additions & 0 deletions OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -861,4 +862,35 @@ interface IOsmAndAidlInterface {
* Toggle Lock/Unlock screen.
*/
boolean setLockState(in SetLockStateParams 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 index of current route segment
*
*/
int getCurrentRouteSegmentIndex();

/**
* Method to get creation time current route
*
*/
long getRouteCreationTime();

/**
* Method to get current route points
*
*/
boolean getRoutePoints(out List<ALatLon> route);

/**
* Method to get application mode
*
*/
String getApplicationMode();
}
42 changes: 42 additions & 0 deletions OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -30,10 +31,12 @@
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;
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;
Expand All @@ -44,6 +47,9 @@
import net.osmand.plus.AppInitializer;
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;
import net.osmand.plus.FavouritesDbHelper;
Expand Down Expand Up @@ -1031,6 +1037,42 @@ boolean removeAllActiveMapMarkers() {
return true;
}

public APosition getPosition(int positionType) {
switch (positionType) {
case 0: {
RoutingHelper rh = app.getRoutingHelper();
Location location = rh.getLastFixedLocation();
return new APosition(
location.getLatitude(),
location.getLongitude(),
location.getAltitude(),
location.getSpeed(),
location.getBearing()
);
}
}
return null;
}

public int getCurrentRouteSegmentIndex() {
RouteCalculationResult route = getRoute();
return route != null ? route.getCurrentRoute() : -1;
}

public long getRouteCreationTime() {
RouteCalculationResult route = getRoute();
return route != null ? route.getCreationTime() : -1;
}

public RouteCalculationResult getRoute() {
RoutingHelper rh = app.getRoutingHelper();
return rh.getRoute();
}

public ApplicationMode getApplicationMode() {
RoutingHelper rh = app.getRoutingHelper();
return rh.getAppMode();
}

boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) {
LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude());
Expand Down
Loading