Add live monitoring

This commit is contained in:
Victor Shcherb 2012-01-27 00:46:15 +01:00
parent 8a34338c05
commit 71dabcc563
7 changed files with 94 additions and 7 deletions

View file

@ -1,5 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources>
<string name="live_monitoring_descr">Enable sending HTTP requests to the specified web service</string>
<string name="live_monitoring">Enable Live Tracking</string>
<string name="live_monitoring_interval_descr">Specify Live Tracking inverval</string>
<string name="live_monitoring_interval">Live Tracking intervals</string>
<string name="live_monitoring_url_descr">Specify Live Tracking web address using following patterns : lat={0}, lon={1}, timestamp={2}, hdop={3}, altitude={5}, speed={6}</string>
<string name="live_monitoring_url">Live Tracking web address</string>
<string name="gpx_monitoring_disabled_warn">Please enable \'Log track to GPX\' Tracking settings</string>
<string name="show_current_gpx_title">Show current track</string>
<string name="tip_recent_changes_0_7_0_t">Changes in 0.7.0 :

View file

@ -56,6 +56,12 @@
<ListPreference android:summary="@string/save_track_interval_descr" android:title="@string/save_track_interval"
android:key="save_track_interval"></ListPreference>
<Preference android:summary="@string/save_current_track_descr" android:title="@string/save_current_track" android:key="save_current_track"></Preference>
<CheckBoxPreference android:summary="@string/live_monitoring_descr" android:title="@string/live_monitoring"
android:key="live_monitoring"></CheckBoxPreference>
<ListPreference android:summary="@string/live_monitoring_interval_descr" android:title="@string/live_monitoring_interval"
android:key="live_monitoring_interval"></ListPreference>
<EditTextPreference android:summary="@string/live_monitoring_url_descr" android:title="@string/live_monitoring_url"
android:key="live_monitoring_url"/>
</PreferenceScreen>

View file

@ -2,6 +2,7 @@ package net.osmand.plus;
import net.osmand.Version;
import net.osmand.plus.activities.LiveMonitoringHelper;
import net.osmand.plus.activities.OsmandApplication;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.routing.RoutingHelper;
@ -53,6 +54,7 @@ public class NavigationService extends Service implements LocationListener {
private static WakeLock lockStatic;
private PendingIntent pendingIntent;
private BroadcastReceiver broadcastReceiver;
private LiveMonitoringHelper liveMonitoringHelper;
@Override
public IBinder onBind(Intent intent) {
@ -94,6 +96,7 @@ public class NavigationService extends Service implements LocationListener {
serviceOffProvider = settings.SERVICE_OFF_PROVIDER.get();
serviceError = settings.SERVICE_OFF_WAIT_INTERVAL.get();
savingTrackHelper = new SavingTrackHelper(this);
liveMonitoringHelper = new LiveMonitoringHelper(this);
routingHelper = ((OsmandApplication)getApplication()).getRoutingHelper();
((OsmandApplication)getApplication()).setNavigationService(this);
@ -193,6 +196,8 @@ public class NavigationService extends Service implements LocationListener {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
liveMonitoringHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
if(routingHelper.isFollowingMode()){
routingHelper.setCurrentLocation(location);
}

View file

@ -480,6 +480,17 @@ public class OsmandSettings {
SAVE_TRACK_INTERVAL.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 20);
}
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false, false);
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5, false);
// 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}&timestamp={2}&hdop={3}&altitude={5}&speed={6}", false);
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> USE_OSMAND_ROUTING_SERVICE_ALWAYS =
new BooleanPreference("use_osmand_routing_service", true, false);

View file

@ -0,0 +1,48 @@
package net.osmand.plus.activities;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import org.apache.commons.logging.Log;
import net.osmand.LogUtil;
import net.osmand.plus.OsmandSettings;
import android.content.Context;
public class LiveMonitoringHelper {
protected Context ctx;
private OsmandSettings settings;
private long lastTimeUpdated;
private final static Log log = LogUtil.getLog(LiveMonitoringHelper.class);
public LiveMonitoringHelper(Context ctx){
this.ctx = ctx;
settings = OsmandSettings.getOsmandSettings(ctx);
}
public boolean isLiveMonitoringEnabled(){
return settings.LIVE_MONITORING.get();
}
public void insertData(double lat, double lon, double alt, double speed, double hdop, long time, OsmandSettings settings){
if (time - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get() * 1000) {
sendData((float)lat, (float)lon,(float) alt,(float) speed,(float) hdop, time );
lastTimeUpdated = time;
}
}
public void sendData(float lat, float lon, float alt, float speed, float hdop, long time) {
String url = MessageFormat.format(settings.LIVE_MONITORING_URL.get(), lat, lon, time, hdop, alt, speed);
try {
URL curl = new URL(url);
URLConnection conn = curl.openConnection();
conn.setDoInput(false);
conn.setDoOutput(false);
conn.connect();
} catch (Exception e) {
log.error("Failed connect to " + url, e);
}
}
}

View file

@ -106,6 +106,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
final private MapActivityLayers mapLayers = new MapActivityLayers(this);
private SavingTrackHelper savingTrackHelper;
private LiveMonitoringHelper liveMonitoringHelper;
private RoutingHelper routingHelper;
private boolean sensorRegistered = false;
@ -190,6 +191,7 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
savingTrackHelper = new SavingTrackHelper(this);
liveMonitoringHelper = new LiveMonitoringHelper(this);
LatLon pointToNavigate = settings.getPointToNavigate();
routingHelper = getMyApplication().getRoutingHelper();
@ -662,17 +664,23 @@ public class MapActivity extends TrackedActivity implements IMapLocationListener
if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
}
if(location != null && settings.SAVE_TRACK_TO_GPX.get()){
if(location != null ){
// write only with 50 meters accuracy
if (!location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getSpeed(),
location.getAccuracy(), location.getTime(), settings);
if (settings.SAVE_TRACK_TO_GPX.get()) {
savingTrackHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
if (settings.SHOW_CURRENT_GPX_TRACK.get()) {
WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), location.getTime(), location.getAltitude(), location.getSpeed(),
location.getAccuracy());
WptPt pt = new GPXUtilities.WptPt(location.getLatitude(), location.getLongitude(), location.getTime(),
location.getAltitude(), location.getSpeed(), location.getAccuracy());
mapLayers.getGpxLayer().addTrackPoint(pt);
}
}
if(settings.LIVE_MONITORING.get()){
liveMonitoringHelper.insertData(location.getLatitude(), location.getLongitude(), location.getAltitude(),
location.getSpeed(), location.getAccuracy(), location.getTime(), settings);
}
}
}

View file

@ -173,6 +173,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerBooleanPreference(osmandSettings.AUTO_ZOOM_MAP,screen);
registerBooleanPreference(osmandSettings.AUTO_FOLLOW_ROUTE_NAV,screen);
registerBooleanPreference(osmandSettings.SAVE_TRACK_TO_GPX,screen);
registerBooleanPreference(osmandSettings.LIVE_MONITORING,screen);
registerBooleanPreference(osmandSettings.DEBUG_RENDERING_INFO,screen);
registerBooleanPreference(osmandSettings.FAST_ROUTE_MODE,screen);
registerBooleanPreference(osmandSettings.USE_OSMAND_ROUTING_SERVICE_ALWAYS,screen);
@ -190,6 +191,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerEditTextPreference(osmandSettings.USER_NAME, screen);
registerEditTextPreference(osmandSettings.USER_PASSWORD, screen);
registerEditTextPreference(osmandSettings.LIVE_MONITORING_URL, screen);
registerSeekBarPreference(osmandSettings.MAP_OVERLAY_TRANSPARENCY, screen);
@ -285,6 +287,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerListPreference(osmandSettings.SERVICE_OFF_PROVIDER, screen, entries, entrieValues);
registerTimeListPreference(osmandSettings.SAVE_TRACK_INTERVAL, screen, new int[]{1, 2, 3, 5, 10, 15, 20, 30}, new int[]{1, 2, 3, 5}, 1);
registerTimeListPreference(osmandSettings.LIVE_MONITORING_INTERVAL, screen, new int[]{1, 2, 3, 5, 10, 15, 20, 30}, new int[]{1, 2, 3, 5}, 1);
registerTimeListPreference(osmandSettings.SERVICE_OFF_INTERVAL, screen,
new int[]{0, 30, 45, 60}, new int[]{2, 3, 5, 10, 15, 30, 45, 60, 90}, 1000);
registerTimeListPreference(osmandSettings.SERVICE_OFF_WAIT_INTERVAL, screen,