This commit is contained in:
Victor Shcherb 2017-05-28 14:22:14 +02:00
parent a99b18460e
commit f6307d7c7d
3 changed files with 32 additions and 10 deletions

View file

@ -46,7 +46,7 @@ public class OsmAndLocationProvider implements SensorEventListener {
public static final int REQUEST_LOCATION_PERMISSION = 100; public static final int REQUEST_LOCATION_PERMISSION = 100;
private static final String SIMULATED_PROVIDER = "OsmAnd"; public static final String SIMULATED_PROVIDER = "OsmAnd";
public interface OsmAndLocationListener { public interface OsmAndLocationListener {

View file

@ -120,9 +120,13 @@ public class OsmAndLocationSimulation {
@Override @Override
public void run() { public void run() {
Location current = directions.isEmpty() ? null : new Location(directions.remove(0)); Location current = directions.isEmpty() ? null : new Location(directions.remove(0));
Location prev = current; Location prev = current;
long prevTime = current == null ? 0 : current.getTime(); long prevTime = current == null ? 0 : current.getTime();
float meters = metersToGoInFiveSteps(directions, current); float meters = metersToGoInFiveSteps(directions, current);
if(current != null) {
current.setProvider(OsmAndLocationProvider.SIMULATED_PROVIDER);
}
while (!directions.isEmpty() && routeAnimation != null) { while (!directions.isEmpty() && routeAnimation != null) {
int timeout = (int) (time * 1000); int timeout = (int) (time * 1000);
float intervalTime = time; float intervalTime = time;

View file

@ -1,6 +1,5 @@
package net.osmand.plus.monitoring; package net.osmand.plus.monitoring;
import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
@ -11,16 +10,17 @@ import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSession;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -32,6 +32,7 @@ public class LiveMonitoringHelper {
protected Context ctx; protected Context ctx;
private OsmandSettings settings; private OsmandSettings settings;
private long lastTimeUpdated; private long lastTimeUpdated;
private LatLon lastPoint;
private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class); private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class);
public LiveMonitoringHelper(Context ctx){ public LiveMonitoringHelper(Context ctx){
@ -44,18 +45,35 @@ public class LiveMonitoringHelper {
} }
public void updateLocation(net.osmand.Location location) { public void updateLocation(net.osmand.Location location) {
boolean record = false;
long locationTime = System.currentTimeMillis();
if (OsmAndLocationProvider.isPointAccurateForRouting(location) && isLiveMonitoringEnabled() if (OsmAndLocationProvider.isPointAccurateForRouting(location) && isLiveMonitoringEnabled()
&& OsmAndLocationProvider.isNotSimulatedLocation(location) && OsmAndLocationProvider.isNotSimulatedLocation(location)
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
long locationTime = System.currentTimeMillis();
if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) { if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) {
LiveMonitoringData data = new LiveMonitoringData((float)location.getLatitude(), (float)location.getLongitude(), record = true;
(float)location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getBearing(), locationTime); }
new LiveSender().execute(data); float minDistance = settings.SAVE_TRACK_MIN_DISTANCE.get();
lastTimeUpdated = locationTime; if(minDistance > 0 && lastPoint != null && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) <
minDistance) {
record = false;
}
float precision = settings.SAVE_TRACK_PRECISION.get();
if(precision > 0 && (!location.hasAccuracy() || location.getAccuracy() > precision)) {
record = false;
}
float minSpeed = settings.SAVE_TRACK_MIN_SPEED.get();
if(minSpeed > 0 && (!location.hasSpeed() || location.getSpeed() < minSpeed)) {
record = false;
} }
} }
if(record) {
LiveMonitoringData data = new LiveMonitoringData((float)location.getLatitude(), (float)location.getLongitude(),
(float)location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getBearing(), locationTime);
new LiveSender().execute(data);
lastPoint = new LatLon(location.getLatitude(), location.getLongitude());
lastTimeUpdated = locationTime;
}
} }