Remember state of latest osmo position

This commit is contained in:
Victor Shcherb 2014-12-06 22:26:01 +01:00
parent 6e440eb0f5
commit 6379cf64fc
3 changed files with 20 additions and 10 deletions

View file

@ -888,6 +888,8 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> OSMO_AUTO_SEND_LOCATIONS = new BooleanPreference("osmo_automatically_send_locations", false).makeGlobal();
public final OsmandPreference<Boolean> OSMO_SEND_LOCATIONS_STATE = new BooleanPreference("osmo_send_locations", false).cache().makeGlobal();
public final OsmandPreference<Boolean> OSMO_SHOW_GROUP_NOTIFICATIONS = new BooleanPreference("osmo_show_toast_notifications", true).makeGlobal();
public final CommonPreference<Integer> OSMO_SAVE_TRACK_INTERVAL = new IntPreference("osmo_save_track_interval", 5000).makeGlobal().cache();

View file

@ -71,7 +71,8 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
this.app = app;
service = new OsMoService(app, this);
tracker = new OsMoTracker(service, app.getSettings().OSMO_SAVE_TRACK_INTERVAL,
app.getSettings().OSMO_AUTO_SEND_LOCATIONS);
app.getSettings().OSMO_AUTO_SEND_LOCATIONS,
app.getSettings().OSMO_SEND_LOCATIONS_STATE);
deviceControl = new OsMoControlDevice(app, this, service, tracker);
groups = new OsMoGroups(this, service, tracker, app);
ApplicationMode.regWidget("osmo_control", (ApplicationMode[])null);

View file

@ -13,7 +13,6 @@ import org.json.JSONObject;
public class OsMoTracker implements OsMoReactor {
private ConcurrentLinkedQueue<Location> bufferOfLocations = new ConcurrentLinkedQueue<Location>();
private boolean startSendingLocations;
private OsMoService service;
private int locationsSent = 0;
private OsmoTrackerListener trackerListener = null;
@ -23,6 +22,7 @@ public class OsMoTracker implements OsMoReactor {
private String sessionURL;
private Map<String, OsMoDevice> trackingDevices = new java.util.concurrent.ConcurrentHashMap<String, OsMoGroupsStorage.OsMoDevice>();
private OsmandPreference<Boolean> autoStart;
private OsmandPreference<Boolean> stateSendLocation;
public interface OsmoTrackerListener {
@ -31,10 +31,11 @@ public class OsMoTracker implements OsMoReactor {
public OsMoTracker(OsMoService service, OsmandPreference<Integer> interval,
OsmandPreference<Boolean> autoStart) {
OsmandPreference<Boolean> autoStart, OsmandPreference<Boolean> stateSendLocation) {
this.service = service;
this.pref = interval;
this.autoStart = autoStart;
this.stateSendLocation = stateSendLocation;
service.registerReactor(this);
}
@ -46,19 +47,22 @@ public class OsMoTracker implements OsMoReactor {
}
public boolean isEnabledTracker() {
return startSendingLocations;
return stateSendLocation.get();
}
public void enableTracker() {
if(!startSendingLocations) {
startSendingLocations = true;
if(!isEnabledTracker()) {
stateSendLocation.set(true);
service.pushCommand("TRACKER_SESSION_OPEN");
}
}
public void disableTracker() {
if(startSendingLocations) {
startSendingLocations = false;
if(isEnabledTracker()) {
if(autoStart.get()) {
autoStart.set(false);
}
stateSendLocation.set(false);
service.pushCommand("TRACKER_SESSION_CLOSE");
}
}
@ -110,7 +114,7 @@ public class OsMoTracker implements OsMoReactor {
}
public void sendCoordinate(Location location) {
if(startSendingLocations && location != null) {
if(stateSendLocation.set(true) && location != null) {
long ltime = lastBufferLocation == null ? 0 : lastBufferLocation.getTime();
if (location.getTime() - ltime > pref.get()) {
@ -214,7 +218,10 @@ public class OsMoTracker implements OsMoReactor {
@Override
public void onConnected() {
if(autoStart.get() || startSendingLocations) {
if(autoStart.get() || stateSendLocation.get()) {
if(autoStart.get() && !stateSendLocation.get()) {
stateSendLocation.set(true);
}
enableTracker();
}
}