Adjust logic and add addition params to location (in addition to latitute & longitude)
This commit is contained in:
parent
a980e4016b
commit
319ed41700
6 changed files with 264 additions and 73 deletions
3
OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl
Normal file
3
OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl
Normal file
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidlapi.map;
|
||||
|
||||
parcelable ALocation;
|
209
OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java
Normal file
209
OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java
Normal file
|
@ -0,0 +1,209 @@
|
|||
package net.osmand.aidlapi.map;
|
||||
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import net.osmand.aidlapi.AidlParams;
|
||||
|
||||
public class ALocation extends AidlParams {
|
||||
|
||||
private double latitude = 0.0;
|
||||
private double longitude = 0.0;
|
||||
private long time = 0;
|
||||
private boolean hasAltitude = false;
|
||||
private double altitude = 0.0f;
|
||||
private boolean hasSpeed = false;
|
||||
private float speed = 0.0f;
|
||||
private boolean hasBearing = false;
|
||||
private float bearing = 0.0f;
|
||||
private boolean hasAccuracy = false;
|
||||
private float accuracy = 0.0f;
|
||||
private boolean hasVerticalAccuracy = false;
|
||||
private float verticalAccuracy = 0.0f;
|
||||
|
||||
private ALocation() {
|
||||
}
|
||||
|
||||
public ALocation(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<ALocation> CREATOR = new Parcelable.Creator<ALocation>() {
|
||||
@Override
|
||||
public ALocation createFromParcel(Parcel in) {
|
||||
return new ALocation(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ALocation[] newArray(int size) {
|
||||
return new ALocation[size];
|
||||
}
|
||||
};
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public boolean hasAltitude() {
|
||||
return hasAltitude;
|
||||
}
|
||||
|
||||
public double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public boolean hasSpeed() {
|
||||
return hasSpeed;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public boolean hasBearing() {
|
||||
return hasBearing;
|
||||
}
|
||||
|
||||
public float getBearing() {
|
||||
return bearing;
|
||||
}
|
||||
|
||||
public boolean hasAccuracy() {
|
||||
return hasAccuracy;
|
||||
}
|
||||
|
||||
public float getAccuracy() {
|
||||
return accuracy;
|
||||
}
|
||||
|
||||
public boolean hasVerticalAccuracy() {
|
||||
return hasVerticalAccuracy;
|
||||
}
|
||||
|
||||
public float getVerticalAccuracy() {
|
||||
return verticalAccuracy;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeToBundle(Bundle bundle) {
|
||||
bundle.putDouble("latitude", latitude);
|
||||
bundle.putDouble("longitude", longitude);
|
||||
bundle.putLong("time", time);
|
||||
bundle.putBoolean("hasAltitude", hasAltitude);
|
||||
bundle.putDouble("altitude", altitude);
|
||||
bundle.putBoolean("hasSpeed", hasSpeed);
|
||||
bundle.putFloat("speed", speed);
|
||||
bundle.putBoolean("hasBearing", hasBearing);
|
||||
bundle.putFloat("bearing", bearing);
|
||||
bundle.putBoolean("hasAccuracy", hasAccuracy);
|
||||
bundle.putFloat("accuracy", accuracy);
|
||||
bundle.putBoolean("hasVerticalAccuracy", hasVerticalAccuracy);
|
||||
bundle.putFloat("verticalAccuracy", verticalAccuracy);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromBundle(Bundle bundle) {
|
||||
latitude = bundle.getDouble("latitude");
|
||||
longitude = bundle.getDouble("longitude");
|
||||
time = bundle.getLong("time");
|
||||
hasAltitude = bundle.getBoolean("hasAltitude");
|
||||
altitude = bundle.getDouble("altitude");
|
||||
hasSpeed = bundle.getBoolean("hasSpeed");
|
||||
speed = bundle.getFloat("speed");
|
||||
hasBearing = bundle.getBoolean("hasBearing");
|
||||
bearing = bundle.getFloat("bearing");
|
||||
hasAccuracy = bundle.getBoolean("hasAccuracy");
|
||||
accuracy = bundle.getFloat("accuracy");
|
||||
hasVerticalAccuracy = bundle.getBoolean("hasVerticalAccuracy");
|
||||
verticalAccuracy = bundle.getFloat("verticalAccuracy");
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new ALocation().new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder setLatitude(double latitude) {
|
||||
ALocation.this.latitude = latitude;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLongitude(double longitude) {
|
||||
ALocation.this.longitude = longitude;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTime(long time) {
|
||||
ALocation.this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasAltitude(boolean hasAltitude) {
|
||||
ALocation.this.hasAltitude = hasAltitude;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAltitude(float altitude) {
|
||||
ALocation.this.altitude = altitude;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasSpeed(boolean hasSpeed) {
|
||||
ALocation.this.hasSpeed = hasSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSpeed(float speed) {
|
||||
ALocation.this.speed = speed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasBearing(boolean hasBearing) {
|
||||
ALocation.this.hasBearing = hasBearing;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBearing(float bearing) {
|
||||
ALocation.this.bearing = bearing;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasAccuracy(boolean hasAccuracy) {
|
||||
ALocation.this.hasAccuracy = hasAccuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAccuracy(float accuracy) {
|
||||
ALocation.this.accuracy = accuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder hasVerticalAccuracy(boolean hasVerticalAccuracy) {
|
||||
ALocation.this.hasVerticalAccuracy = hasVerticalAccuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setVerticalAccuracy(float verticalAccuracy) {
|
||||
ALocation.this.verticalAccuracy = verticalAccuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ALocation build() {
|
||||
return ALocation.this;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,13 +7,11 @@ import net.osmand.aidlapi.AidlParams;
|
|||
|
||||
public class SetLocationParams extends AidlParams {
|
||||
|
||||
private double latitude;
|
||||
private double longitude;
|
||||
private ALocation location;
|
||||
private long timeToNotUseOtherGPS;
|
||||
|
||||
public SetLocationParams(double latitude, double longitude, long timeToNotUseOtherGPS) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
public SetLocationParams(ALocation location, long timeToNotUseOtherGPS) {
|
||||
this.location = location;
|
||||
this.timeToNotUseOtherGPS = timeToNotUseOtherGPS;
|
||||
}
|
||||
|
||||
|
@ -33,12 +31,8 @@ public class SetLocationParams extends AidlParams {
|
|||
}
|
||||
};
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
public ALocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public long getTimeToNotUseOtherGPS() {
|
||||
|
@ -47,15 +41,14 @@ public class SetLocationParams extends AidlParams {
|
|||
|
||||
@Override
|
||||
public void writeToBundle(Bundle bundle) {
|
||||
bundle.putDouble("latitude", latitude);
|
||||
bundle.putDouble("longitude", longitude);
|
||||
bundle.putParcelable("location", location);
|
||||
bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromBundle(Bundle bundle) {
|
||||
latitude = bundle.getDouble("latitude");
|
||||
longitude = bundle.getDouble("longitude");
|
||||
bundle.setClassLoader(ALocation.class.getClassLoader());
|
||||
location = bundle.getParcelable("location");
|
||||
timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps");
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ import net.osmand.aidl.tiles.ASqliteDbFile;
|
|||
import net.osmand.aidlapi.customization.AProfile;
|
||||
import net.osmand.aidlapi.info.AppInfoParams;
|
||||
import net.osmand.aidlapi.map.ALatLon;
|
||||
import net.osmand.aidlapi.map.ALocation;
|
||||
import net.osmand.aidlapi.navigation.ABlockedRoad;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -176,6 +177,7 @@ public class OsmandAidlApi {
|
|||
private static final String AIDL_ZOOM = "aidl_zoom";
|
||||
private static final String AIDL_ROTATION = "aidl_rotation";
|
||||
private static final String AIDL_ANIMATED = "aidl_animated";
|
||||
private static final String AIDL_LOCATION = "aidl_location";
|
||||
private static final String AIDL_TIME_TO_NOT_USE_OTHER_GPS = "aidl_time_to_not_use_other_gps";
|
||||
|
||||
private static final String AIDL_START_NAME = "aidl_start_name";
|
||||
|
@ -237,7 +239,6 @@ public class OsmandAidlApi {
|
|||
private MapActivity mapActivity;
|
||||
|
||||
private boolean mapActivityActive = false;
|
||||
private boolean hasCustomLocation = false;
|
||||
|
||||
public OsmandAidlApi(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -911,45 +912,42 @@ public class OsmandAidlApi {
|
|||
}
|
||||
|
||||
private void registerSetLocationReceiver(MapActivity mapActivity) {
|
||||
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||
BroadcastReceiver setLocationReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
double lat = intent.getDoubleExtra(AIDL_LATITUDE, Double.NaN);
|
||||
double lon = intent.getDoubleExtra(AIDL_LONGITUDE, Double.NaN);
|
||||
ALocation aLocation = intent.getParcelableExtra(AIDL_LOCATION);
|
||||
long timeToNotUseOtherGPS = intent.getLongExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, 0);
|
||||
|
||||
if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
|
||||
mapActivity.setMapLocation(lat, lon);
|
||||
mapActivity.refreshMap();
|
||||
hasCustomLocation = true;
|
||||
net.osmand.Location location = new net.osmand.Location("OsmAnd", lat, lon);
|
||||
if (aLocation != null && !Double.isNaN(aLocation.getLatitude()) && !Double.isNaN(aLocation.getLongitude())) {
|
||||
Location location = new Location(app.getPackageName());
|
||||
location.setLatitude(aLocation.getLatitude());
|
||||
location.setLongitude(aLocation.getLongitude());
|
||||
location.setTime(aLocation.getTime());
|
||||
if (aLocation.hasAltitude()) {
|
||||
location.setAltitude(aLocation.getAltitude());
|
||||
}
|
||||
if (aLocation.hasSpeed()) {
|
||||
location.setSpeed(aLocation.getSpeed());
|
||||
}
|
||||
if (aLocation.hasBearing()) {
|
||||
location.setBearing(aLocation.getBearing());
|
||||
}
|
||||
if (aLocation.hasAccuracy()) {
|
||||
location.setAccuracy(aLocation.getAccuracy());
|
||||
}
|
||||
if (aLocation.hasVerticalAccuracy()) {
|
||||
location.setVerticalAccuracy(aLocation.getVerticalAccuracy());
|
||||
}
|
||||
app.getLocationProvider().setCustomLocation(location);
|
||||
}
|
||||
|
||||
final OsmAndLocationProvider.OsmAndLocationListener listener = new OsmAndLocationProvider.OsmAndLocationListener() {
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
mapActivity.setMapLocation(location.getLatitude(), location.getLongitude());
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
};
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
app.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (app.getLocationProvider() != null) {
|
||||
hasCustomLocation = false;
|
||||
app.getLocationProvider().addLocationListener(listener);
|
||||
}
|
||||
app.getLocationProvider().setCustomLocation(null);
|
||||
}
|
||||
}, timeToNotUseOtherGPS);
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(setLocationReceiver, mapActivity, AIDL_SET_LOCATION);
|
||||
}
|
||||
|
@ -2456,20 +2454,15 @@ public class OsmandAidlApi {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean setLocation(double latitude, double longitude, long timeToNotUseOtherGPS) {
|
||||
public boolean setLocation(ALocation location, long timeToNotUseOtherGPS) {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(AIDL_SET_LOCATION);
|
||||
intent.putExtra(AIDL_LATITUDE, latitude);
|
||||
intent.putExtra(AIDL_LONGITUDE, longitude);
|
||||
intent.putExtra(AIDL_LOCATION, location);
|
||||
intent.putExtra(AIDL_TIME_TO_NOT_USE_OTHER_GPS, timeToNotUseOtherGPS);
|
||||
app.sendBroadcast(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasCustomLocation() {
|
||||
return hasCustomLocation;
|
||||
}
|
||||
|
||||
private static class FileCopyInfo {
|
||||
long startTime;
|
||||
long lastAccessTime;
|
||||
|
|
|
@ -1450,8 +1450,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
|
|||
try {
|
||||
if (params != null) {
|
||||
OsmandAidlApi api = getApi("setLocation");
|
||||
return api != null && api.setLocation(params.getLatitude(),
|
||||
params.getLongitude(), params.getTimeToNotUseOtherGPS());
|
||||
return api != null && api.setLocation(params.getLocation(), params.getTimeToNotUseOtherGPS());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
|
|
|
@ -97,6 +97,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
|
||||
private long cachedLocationTimeFix = 0;
|
||||
private net.osmand.Location cachedLocation;
|
||||
private net.osmand.Location customLocation;
|
||||
|
||||
private boolean sensorRegistered = false;
|
||||
private float[] mGravs = new float[3];
|
||||
|
@ -796,7 +797,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
if (locationSimulation.isRouteAnimating()) {
|
||||
return;
|
||||
}
|
||||
if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) {
|
||||
if (hasCustomLocation() && isNotSimulatedLocation(location)) {
|
||||
return;
|
||||
}
|
||||
if (location != null) {
|
||||
|
@ -811,6 +812,15 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
app.getWaypointHelper().locationChanged(location);
|
||||
}
|
||||
|
||||
public void setCustomLocation(net.osmand.Location location) {
|
||||
customLocation = location;
|
||||
setLocation(location);
|
||||
}
|
||||
|
||||
private boolean hasCustomLocation() {
|
||||
return customLocation != null;
|
||||
}
|
||||
|
||||
public void setLocationFromSimulation(net.osmand.Location location) {
|
||||
setLocation(location);
|
||||
}
|
||||
|
@ -819,7 +829,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
if (location == null) {
|
||||
updateGPSInfo(null);
|
||||
}
|
||||
if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) {
|
||||
if (hasCustomLocation() && isNotSimulatedLocation(location)) {
|
||||
return;
|
||||
}
|
||||
if (location != null) {
|
||||
|
@ -856,22 +866,6 @@ public class OsmAndLocationProvider implements SensorEventListener {
|
|||
updateLocation(this.location);
|
||||
}
|
||||
|
||||
public void setCustomLocation(net.osmand.Location location) {
|
||||
if (locationSimulation.isRouteAnimating()) {
|
||||
return;
|
||||
}
|
||||
if (location != null) {
|
||||
notifyGpsLocationRecovered();
|
||||
}
|
||||
// notify about lost location
|
||||
scheduleCheckIfGpsLost(location);
|
||||
|
||||
app.getSavingTrackHelper().updateLocation(location, heading);
|
||||
OsmandPlugin.updateLocationPlugins(location);
|
||||
app.getRoutingHelper().updateLocation(location);
|
||||
app.getWaypointHelper().locationChanged(location);
|
||||
}
|
||||
|
||||
private void notifyGpsLocationRecovered() {
|
||||
if (gpsSignalLost) {
|
||||
gpsSignalLost = false;
|
||||
|
|
Loading…
Reference in a new issue