Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a97ced823f
5 changed files with 36 additions and 9 deletions
|
@ -1936,6 +1936,8 @@
|
|||
<string name="live_monitoring_interval">Online tracking interval</string>
|
||||
<string name="live_monitoring_url_descr">Specify the web address with parameter syntax: lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={4}, speed={5}, bearing={6}</string>
|
||||
<string name="live_monitoring_url">Online tracking web address</string>
|
||||
<string name="live_monitoring_max_interval_to_send">Time buffer for online tracking</string>
|
||||
<string name="live_monitoring_max_interval_to_send_desrc">Specify a time buffer to keep locations to send without connection</string>
|
||||
<string name="gpx_monitoring_disabled_warn">Log track using GPX widget or via \'Trip recording\' settings.</string>
|
||||
<string name="show_current_gpx_title">Show current track</string>
|
||||
<string name="free_version_message">This free OsmAnd version is limited to %1$s downloads and does not support offline Wikipedia articles.</string>
|
||||
|
|
|
@ -1123,6 +1123,9 @@ public class OsmandSettings {
|
|||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeGlobal();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
|
||||
"http://example.com?lat={0}&lon={1}×tamp={2}&hdop={3}&altitude={4}&speed={5}").makeGlobal();
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.net.URL;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
@ -33,17 +34,20 @@ public class LiveMonitoringHelper {
|
|||
private OsmandSettings settings;
|
||||
private long lastTimeUpdated;
|
||||
private LatLon lastPoint;
|
||||
private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class);
|
||||
private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class);
|
||||
private ConcurrentLinkedQueue<LiveMonitoringData> queue;
|
||||
private boolean started = false;
|
||||
|
||||
public LiveMonitoringHelper(Context ctx){
|
||||
this.ctx = ctx;
|
||||
settings = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
|
||||
queue = new ConcurrentLinkedQueue<>();
|
||||
}
|
||||
|
||||
public boolean isLiveMonitoringEnabled(){
|
||||
return settings.LIVE_MONITORING.get() && (settings.SAVE_TRACK_TO_GPX.get() || settings.SAVE_GLOBAL_TRACK_TO_GPX.get());
|
||||
}
|
||||
|
||||
|
||||
public void updateLocation(net.osmand.Location location) {
|
||||
boolean record = false;
|
||||
long locationTime = System.currentTimeMillis();
|
||||
|
@ -67,10 +71,18 @@ public class LiveMonitoringHelper {
|
|||
record = false;
|
||||
}
|
||||
}
|
||||
if (isLiveMonitoringEnabled()) {
|
||||
if (!started) {
|
||||
new LiveSender().execute(queue);
|
||||
started = true;
|
||||
}
|
||||
} else {
|
||||
started = 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);
|
||||
queue.add(data);
|
||||
lastPoint = new LatLon(location.getLatitude(), location.getLongitude());
|
||||
lastTimeUpdated = locationTime;
|
||||
}
|
||||
|
@ -99,16 +111,22 @@ public class LiveMonitoringHelper {
|
|||
|
||||
}
|
||||
|
||||
private class LiveSender extends AsyncTask<LiveMonitoringData, Void, Void> {
|
||||
private class LiveSender extends AsyncTask<ConcurrentLinkedQueue<LiveMonitoringData>, Void, Void> {
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(LiveMonitoringData... params) {
|
||||
for(LiveMonitoringData d : params){
|
||||
sendData(d);
|
||||
protected Void doInBackground(ConcurrentLinkedQueue<LiveMonitoringData>... concurrentLinkedQueues) {
|
||||
while (isLiveMonitoringEnabled()) {
|
||||
for (ConcurrentLinkedQueue queue : concurrentLinkedQueues) {
|
||||
if (!queue.isEmpty()) {
|
||||
LiveMonitoringData data = (LiveMonitoringData) queue.poll();
|
||||
if (!(System.currentTimeMillis() - data.time > settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND.get())) {
|
||||
sendData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendData(LiveMonitoringData data) {
|
||||
|
|
|
@ -131,6 +131,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
|
||||
public static final int[] SECONDS = new int[] {0, 1, 2, 3, 5, 10, 15, 30, 60, 90};
|
||||
public static final int[] MINUTES = new int[] {2, 3, 5};
|
||||
public static final int[] MAX_INTERVAL_TO_SEND_MINUTES = new int[] {1, 2, 5, 10, 15, 20, 30, 60};
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -513,4 +514,4 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
return DashTrackFragment.FRAGMENT_DATA;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
public static final int[] BG_MINUTES = new int[]{2, 3, 5, 10, 15, 30, 60, 90};
|
||||
private static final int[] SECONDS = OsmandMonitoringPlugin.SECONDS;
|
||||
private static final int[] MINUTES = OsmandMonitoringPlugin.MINUTES;
|
||||
private static final int[] MAX_INTERVAL_TO_SEND_MINUTES = OsmandMonitoringPlugin.MAX_INTERVAL_TO_SEND_MINUTES;
|
||||
|
||||
public SettingsMonitoringActivity() {
|
||||
super(true);
|
||||
|
@ -136,6 +137,8 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
|
|||
cat.addPreference(liveMonitoring);
|
||||
cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_INTERVAL, SECONDS,
|
||||
MINUTES, 1000, R.string.live_monitoring_interval, R.string.live_monitoring_interval_descr));
|
||||
cat.addPreference(createTimeListPreference(settings.LIVE_MONITORING_MAX_INTERVAL_TO_SEND, null,
|
||||
MAX_INTERVAL_TO_SEND_MINUTES, 1000, R.string.live_monitoring_max_interval_to_send, R.string.live_monitoring_max_interval_to_send_desrc));
|
||||
}
|
||||
|
||||
private void createNotificationSection(PreferenceScreen grp) {
|
||||
|
|
Loading…
Reference in a new issue