From a980e4016b5670e2cf24a96989fe1edbb11084db Mon Sep 17 00:00:00 2001 From: cepprice Date: Tue, 19 Jan 2021 20:57:34 +0500 Subject: [PATCH 1/9] Possible sulution --- .../osmand/aidlapi/IOsmAndAidlInterface.aidl | 3 + .../osmand/aidlapi/map/SetLocationParams.aidl | 3 + .../osmand/aidlapi/map/SetLocationParams.java | 61 +++++++++++++++++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 65 +++++++++++++++++++ .../net/osmand/aidl/OsmandAidlServiceV2.java | 15 +++++ .../osmand/plus/OsmAndLocationProvider.java | 26 +++++++- 6 files changed, 171 insertions(+), 2 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl index 92115f873b..0b0466ff21 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl +++ b/OsmAnd-api/src/net/osmand/aidlapi/IOsmAndAidlInterface.aidl @@ -2,6 +2,7 @@ package net.osmand.aidlapi; import net.osmand.aidlapi.map.ALatLon; import net.osmand.aidlapi.map.SetMapLocationParams; +import net.osmand.aidlapi.map.SetLocationParams; import net.osmand.aidlapi.favorite.group.AFavoriteGroup; import net.osmand.aidlapi.favorite.group.AddFavoriteGroupParams; @@ -901,4 +902,6 @@ interface IOsmAndAidlInterface { boolean addRoadBlock(in AddBlockedRoadParams params); boolean removeRoadBlock(in RemoveBlockedRoadParams params); + + boolean setLocation(in SetLocationParams params); } \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl new file mode 100644 index 0000000000..e39726efd0 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable SetLocationParams; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java new file mode 100644 index 0000000000..167ae1d3a4 --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java @@ -0,0 +1,61 @@ +package net.osmand.aidlapi.map; + +import android.os.Bundle; +import android.os.Parcel; + +import net.osmand.aidlapi.AidlParams; + +public class SetLocationParams extends AidlParams { + + private double latitude; + private double longitude; + private long timeToNotUseOtherGPS; + + public SetLocationParams(double latitude, double longitude, long timeToNotUseOtherGPS) { + this.latitude = latitude; + this.longitude = longitude; + this.timeToNotUseOtherGPS = timeToNotUseOtherGPS; + } + + public SetLocationParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public SetLocationParams createFromParcel(Parcel in) { + return new SetLocationParams(in); + } + + @Override + public SetLocationParams[] newArray(int size) { + return new SetLocationParams[size]; + } + }; + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + public long getTimeToNotUseOtherGPS() { + return timeToNotUseOtherGPS; + } + + @Override + public void writeToBundle(Bundle bundle) { + bundle.putDouble("latitude", latitude); + bundle.putDouble("longitude", longitude); + bundle.putLong("aidl_time_to_not_use_other_gps", timeToNotUseOtherGPS); + } + + @Override + protected void readFromBundle(Bundle bundle) { + latitude = bundle.getDouble("latitude"); + longitude = bundle.getDouble("longitude"); + timeToNotUseOtherGPS = bundle.getLong("aidl_time_to_not_use_other_gps"); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 88307a259e..3a480856fe 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -57,6 +57,7 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; @@ -122,6 +123,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; @@ -167,11 +170,13 @@ public class OsmandAidlApi { private static final String AIDL_REFRESH_MAP = "aidl_refresh_map"; private static final String AIDL_SET_MAP_LOCATION = "aidl_set_map_location"; + private static final String AIDL_SET_LOCATION = "aidl_set_location"; private static final String AIDL_LATITUDE = "aidl_latitude"; private static final String AIDL_LONGITUDE = "aidl_longitude"; 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_TIME_TO_NOT_USE_OTHER_GPS = "aidl_time_to_not_use_other_gps"; private static final String AIDL_START_NAME = "aidl_start_name"; private static final String AIDL_START_LAT = "aidl_start_lat"; @@ -232,6 +237,7 @@ public class OsmandAidlApi { private MapActivity mapActivity; private boolean mapActivityActive = false; + private boolean hasCustomLocation = false; public OsmandAidlApi(OsmandApplication app) { this.app = app; @@ -263,6 +269,7 @@ public class OsmandAidlApi { registerHideSqliteDbFileReceiver(mapActivity); registerExecuteQuickActionReceiver(mapActivity); registerLockStateReceiver(mapActivity); + registerSetLocationReceiver(mapActivity); initOsmandTelegram(); app.getAppCustomization().addListener(mapActivity); this.mapActivity = mapActivity; @@ -903,6 +910,50 @@ public class OsmandAidlApi { registerReceiver(lockStateReceiver, mapActivity, AIDL_LOCK_STATE); } + private void registerSetLocationReceiver(MapActivity mapActivity) { + final WeakReference 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); + 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); + 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() { + @Override + public void run() { + if (app.getLocationProvider() != null) { + hasCustomLocation = false; + app.getLocationProvider().addLocationListener(listener); + } + } + }, timeToNotUseOtherGPS); + } + }; + registerReceiver(setLocationReceiver, mapActivity, AIDL_SET_LOCATION); + } + public void registerMapLayers(@NonNull MapActivity mapActivity) { for (ConnectedApp connectedApp : connectedApps.values()) { connectedApp.registerMapLayers(mapActivity); @@ -2405,6 +2456,20 @@ public class OsmandAidlApi { return true; } + public boolean setLocation(double latitude, double longitude, long timeToNotUseOtherGPS) { + Intent intent = new Intent(); + intent.setAction(AIDL_SET_LOCATION); + intent.putExtra(AIDL_LATITUDE, latitude); + intent.putExtra(AIDL_LONGITUDE, longitude); + 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; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 5fa2f75421..4384a8ac85 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -53,6 +53,7 @@ import net.osmand.aidlapi.gpx.StopGpxRecordingParams; import net.osmand.aidlapi.info.AppInfoParams; import net.osmand.aidlapi.lock.SetLockStateParams; import net.osmand.aidlapi.map.ALatLon; +import net.osmand.aidlapi.map.SetLocationParams; import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.maplayer.AddMapLayerParams; import net.osmand.aidlapi.maplayer.RemoveMapLayerParams; @@ -1443,6 +1444,20 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener } return false; } + + @Override + public boolean setLocation(SetLocationParams params) { + try { + if (params != null) { + OsmandAidlApi api = getApi("setLocation"); + return api != null && api.setLocation(params.getLatitude(), + params.getLongitude(), params.getTimeToNotUseOtherGPS()); + } + } catch (Exception e) { + handleException(e); + } + return false; + } }; private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index a19ebd3023..32f2b4ee8b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -796,6 +796,9 @@ public class OsmAndLocationProvider implements SensorEventListener { if (locationSimulation.isRouteAnimating()) { return; } + if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + return; + } if (location != null) { notifyGpsLocationRecovered(); } @@ -812,10 +815,13 @@ public class OsmAndLocationProvider implements SensorEventListener { setLocation(location); } - private void setLocation(net.osmand.Location location) { if (location == null) { + private void setLocation(net.osmand.Location location) { + if (location == null) { updateGPSInfo(null); } - + if (app.getAidlApi().hasCustomLocation() && isNotSimulatedLocation(location)) { + return; + } if (location != null) { // // use because there is a bug on some devices with location.getTime() lastTimeLocationFixed = System.currentTimeMillis(); @@ -850,6 +856,22 @@ 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; From 319ed417007d773d5b5e6413a9e4829b27e6ef93 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 20 Jan 2021 22:55:51 +0500 Subject: [PATCH 2/9] Adjust logic and add addition params to location (in addition to latitute & longitude) --- .../src/net/osmand/aidlapi/map/ALocation.aidl | 3 + .../src/net/osmand/aidlapi/map/ALocation.java | 209 ++++++++++++++++++ .../osmand/aidlapi/map/SetLocationParams.java | 23 +- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 69 +++--- .../net/osmand/aidl/OsmandAidlServiceV2.java | 3 +- .../osmand/plus/OsmAndLocationProvider.java | 30 +-- 6 files changed, 264 insertions(+), 73 deletions(-) create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl create mode 100644 OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl new file mode 100644 index 0000000000..88c65b5e0c --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidlapi.map; + +parcelable ALocation; \ No newline at end of file diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java new file mode 100644 index 0000000000..243e8e89fa --- /dev/null +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/ALocation.java @@ -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 CREATOR = new Parcelable.Creator() { + @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; + } + } +} diff --git a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java index 167ae1d3a4..61531125fe 100644 --- a/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java +++ b/OsmAnd-api/src/net/osmand/aidlapi/map/SetLocationParams.java @@ -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"); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 3a480856fe..108e52c558 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -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,44 +912,41 @@ public class OsmandAidlApi { } private void registerSetLocationReceiver(MapActivity mapActivity) { - final WeakReference 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() { - @Override - public void run() { - if (app.getLocationProvider() != null) { - hasCustomLocation = false; - app.getLocationProvider().addLocationListener(listener); + app.runInUIThread(new Runnable() { + @Override + public void run() { + app.getLocationProvider().setCustomLocation(null); } - } - }, timeToNotUseOtherGPS); + }, 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; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java index 4384a8ac85..60a8d8acd6 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlServiceV2.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 32f2b4ee8b..9f043a78c3 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -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) { @@ -810,6 +811,15 @@ public class OsmAndLocationProvider implements SensorEventListener { app.getRoutingHelper().updateLocation(location); 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; From bc6afe286e09b45aec255fd2c1acfaf9879bf40b Mon Sep 17 00:00:00 2001 From: WaldiS Date: Thu, 21 Jan 2021 16:30:03 +0000 Subject: [PATCH 3/9] Translated using Weblate (Polish) Currently translated at 99.2% (3618 of 3645 strings) --- OsmAnd/res/values-pl/strings.xml | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index 840fa52189..4be69e1a63 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3963,4 +3963,37 @@ Wybierz folder Wybierz folder lub dodaj nowy Opróżnij + Analiza według przedziałów (przedział podziału) + Prześlij do OpenStreetMap + Edytuj trasę + Zmień nazwę trasy + Zmień folder + sek + Omijanie + Podejście + Długie przygotowanie + Przygotuj + Poza trasą + Przyjedź do miejsca docelowego + Zakręt + Odstępy czasowe i odległościowe + Czas ogłaszania różnych komunikatów głosowych zależy od rodzaju komunikatu, aktualnej prędkości nawigacji i domyślnej prędkości nawigacji. + Czas ogłoszenia + Rozpocznij nagrywanie + Pokaż trasę na mapie + Wózek inwalidzki + Wędrówki + Pieszo + Jazda na rowerze elektrycznym + Kolarstwo górskie + Kolarstwo szosowe + Regularna jazda na rowerze + HGV + Mała ciężarówka + Ciężarówka + Skuter + Rower wyścigowy + MTB + Błąd serwera: %1$s + Taka nazwa już istnieje \ No newline at end of file From dd5056737ef48e643a14b79a5b29ec84ad56e068 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 22 Jan 2021 14:08:51 +0300 Subject: [PATCH 4/9] Hide travel purchase button temporarily --- OsmAnd/res/values-ar/strings.xml | 2 +- OsmAnd/res/values-b+ast/strings.xml | 2 +- OsmAnd/res/values-b+be+Latn/strings.xml | 2 +- OsmAnd/res/values-be/strings.xml | 2 +- OsmAnd/res/values-ca/strings.xml | 2 +- OsmAnd/res/values-cs/strings.xml | 2 +- OsmAnd/res/values-da/strings.xml | 2 +- OsmAnd/res/values-de/strings.xml | 2 +- OsmAnd/res/values-el/strings.xml | 2 +- OsmAnd/res/values-eo/strings.xml | 2 +- OsmAnd/res/values-es-rAR/strings.xml | 2 +- OsmAnd/res/values-es-rUS/strings.xml | 2 +- OsmAnd/res/values-es/strings.xml | 2 +- OsmAnd/res/values-et/strings.xml | 2 +- OsmAnd/res/values-eu/strings.xml | 2 +- OsmAnd/res/values-fa/strings.xml | 2 +- OsmAnd/res/values-fr/strings.xml | 2 +- OsmAnd/res/values-gl/strings.xml | 2 +- OsmAnd/res/values-hu/strings.xml | 2 +- OsmAnd/res/values-hy/strings.xml | 2 +- OsmAnd/res/values-id/strings.xml | 2 +- OsmAnd/res/values-is/strings.xml | 2 +- OsmAnd/res/values-it/strings.xml | 2 +- OsmAnd/res/values-iw/strings.xml | 2 +- OsmAnd/res/values-ja/strings.xml | 2 +- OsmAnd/res/values-lv/strings.xml | 2 +- OsmAnd/res/values-ml/strings.xml | 2 +- OsmAnd/res/values-nb/strings.xml | 2 +- OsmAnd/res/values-nl/strings.xml | 2 +- OsmAnd/res/values-pl/strings.xml | 2 +- OsmAnd/res/values-pt-rBR/strings.xml | 2 +- OsmAnd/res/values-pt/strings.xml | 2 +- OsmAnd/res/values-ru/strings.xml | 2 +- OsmAnd/res/values-sc/strings.xml | 2 +- OsmAnd/res/values-sk/strings.xml | 2 +- OsmAnd/res/values-sl/strings.xml | 2 +- OsmAnd/res/values-sr/strings.xml | 2 +- OsmAnd/res/values-sv/strings.xml | 2 +- OsmAnd/res/values-tr/strings.xml | 2 +- OsmAnd/res/values-uk/strings.xml | 2 +- OsmAnd/res/values-zh-rTW/strings.xml | 2 +- OsmAnd/res/values/strings.xml | 2 +- .../ChoosePlanWikivoyageDialogFragment.java | 26 +++- .../explore/ExploreTabFragment.java | 119 ++++++++---------- .../explore/travelcards/BaseTravelCard.java | 2 +- .../travelcards/OpenBetaTravelCard.java | 25 ++-- .../travelcards/StartEditingTravelCard.java | 13 +- 47 files changed, 144 insertions(+), 125 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index ef68e3055c..8929bd6f4d 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -2826,7 +2826,7 @@ أسلوب الملاحة مع التباين العالي والحد الأعلى من التفاصيل. يتضمن كل خيارات النمط الافتراضي أوسماند، مع عرض أكبر قدر ممكن من التفاصيل ، ولا سيما الطرق والمسارات وطرق السفر الأخرى. التمييز الواضح بين \"جولة الأطلس\" بين أنواع الطرق. مناسبة للاستخدام النهاري والليلي وفي الهواء الطلق. أسلوب الغرض العام. تقديم نظافة مبسطة في المدن المكتظة بالسكان. الملامح الرئيسية: خطوط الكنتور ، والطرق ، وجودة السطح ، والقيود المفروضة على الوصول ، ودروع الطريق ، والمسارات التي تظهر وفقاً لمقياس SAC ، وميزات رياضة الماء الأبيض. قم بتنزيل أدلة السفر هذه من ويكي الرحلات لعرض مقالات حول الأماكن في العالم بدون إنترنت. - دليل السفر حاليا على أساس Wikivoyage. اختبار كافة الميزات أثناء اختبار بيتا المفتوحة مجانا.بعد ذلك، وأدلة السفر ستكون متاحة للمشتركين في أوسماند غير المحدود و اصحاب +أوسماند. + دليل السفر حاليا على أساس Wikivoyage. اختبار كافة الميزات أثناء اختبار بيتا المفتوحة مجانا. ملف GPX مع الإحداثيات والبيانات من الملاحظات المحددة. ملف GPX مع الإحداثيات والبيانات من كافة الملاحظات.