Fix osmo settings

This commit is contained in:
vshcherb 2014-05-21 20:37:10 +02:00
parent 8d3319daa5
commit 882c45bdd6
6 changed files with 71 additions and 34 deletions

View file

@ -9,10 +9,12 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="osmo_auto_send_locations_descr">Automatically start tracker session and send locations after application startup</string>
<string name="osmo_auto_send_locations">Automatically start tracker session</string>
<string name="osmo_tracker_id">Personal tracker id</string> <string name="osmo_tracker_id">Personal tracker id</string>
<string name="osmo_tracker_id_descr">Click to view or share tracker id. <string name="osmo_tracker_id_descr">Click to view or share tracker id.
Using tracker id connected devices will be able to monitor all movements of this device! To disconnect select Regenerate option.</string> Using tracker id connected devices will be able to monitor all movements of this device! To disconnect select Regenerate option.</string>
<string name="osmo_session_token">Session token %1$s</string> <string name="osmo_session_token">Session token : %1$s</string>
<string name="osmo_auth_pending">Waiting for authorization...</string> <string name="osmo_auth_pending">Waiting for authorization...</string>
<string name="osmo_locations_sent">Locations sent %1$d (in buffer %2$d) </string> <string name="osmo_locations_sent">Locations sent %1$d (in buffer %2$d) </string>
<string name="osmo_conn_successfull">Connection established : %1$s </string> <string name="osmo_conn_successfull">Connection established : %1$s </string>
@ -23,10 +25,11 @@
* Changed layout of countries for downloads (support local names search) * Changed layout of countries for downloads (support local names search)
</string> </string>
<string name="use_points_as_intermediates">Calculate route between points</string> <string name="use_points_as_intermediates">Calculate route between points</string>
<string name="osmo_mode_restart">Restart OsMo session</string>
<string name="osmo_mode_on">Stop OsMo session</string> <string name="osmo_mode_on">Stop OsMo session</string>
<string name="osmo_mode_off">Start OsMo session</string> <string name="osmo_mode_off">Start OsMo session</string>
<string name="osmo_settings_debug">Debug information</string> <string name="osmo_settings_debug">Debug information</string>
<string name="osmo_settings_descr">Configure monitoring settings and setup personal monitoring channel</string>
<string name="osmo_settings">OsMo (OpenStreetMap-Monitoring)</string> <string name="osmo_settings">OsMo (OpenStreetMap-Monitoring)</string>
<string name="osmo_plugin_description">OpenStreetMap-Monitoring - Advanced Live Monitoring with lots of features for remote control http://osmo.mobi</string> <string name="osmo_plugin_description">OpenStreetMap-Monitoring - Advanced Live Monitoring with lots of features for remote control http://osmo.mobi</string>
<string name="osmo_plugin_name">OsMo (Advanced Live Monitoring)</string> <string name="osmo_plugin_name">OsMo (Advanced Live Monitoring)</string>

View file

@ -828,6 +828,8 @@ public class OsmandSettings {
public final OsmandPreference<String> OSMO_DEVICE_KEY = new StringPreference("osmo_device_token", "").makeGlobal(); public final OsmandPreference<String> OSMO_DEVICE_KEY = new StringPreference("osmo_device_token", "").makeGlobal();
public final OsmandPreference<Boolean> OSMO_AUTO_SEND_LOCATIONS = new BooleanPreference("osmo_automatically_send_locations", false).makeGlobal();
public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal(); public final OsmandPreference<String> OSMO_GROUPS = new StringPreference("osmo_groups", "{}").makeGlobal();
// this value string is synchronized with settings_pref.xml preference name // this value string is synchronized with settings_pref.xml preference name

View file

@ -28,7 +28,9 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
public OsMoPlugin(final OsmandApplication app) { public OsMoPlugin(final OsmandApplication app) {
service = new OsMoService(app); service = new OsMoService(app);
tracker = new OsMoTracker(service); tracker = new OsMoTracker(service);
if(app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get()) {
tracker.enableTracker(); tracker.enableTracker();
}
groups = new OsMoGroups(service, tracker, app.getSettings()); groups = new OsMoGroups(service, tracker, app.getSettings());
this.app = app; this.app = app;
} }
@ -74,17 +76,23 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
@Override @Override
public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, final OsmandMapTileView view) { public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, final OsmandMapTileView view) {
final boolean off = !service.isConnected(); //final boolean off = !service.isConnected();
qa.item(off ? R.string.osmo_mode_off : R.string.osmo_mode_on) final boolean autosend = app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get();
.icon(off ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big) final boolean offTracker = tracker.isEnabledTracker();
qa.item(autosend ? R.string.osmo_mode_restart :
( offTracker ? R.string.osmo_mode_off : R.string.osmo_mode_on))
.icon(offTracker ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big)
.listen(new OnContextMenuClick() { .listen(new OnContextMenuClick() {
@Override @Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) { public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
if (off) { if(autosend) {
service.connect(true); tracker.disableTracker();
tracker.enableTracker();
} else if (offTracker) {
tracker.enableTracker();
} else { } else {
service.disconnect(); tracker.disableTracker();
} }
} }
}).reg(); }).reg();

View file

@ -128,15 +128,13 @@ public class OsMoThread {
protected void checkAsyncSocket() { protected void checkAsyncSocket() {
long delay = HEARTBEAT_DELAY; long delay = HEARTBEAT_DELAY;
try { try {
if (selector == null) { // if (selector == null) {
stopThread = true; // stopThread = true;
} else {
if(activeChannel == null || reconnect) { if(activeChannel == null || reconnect) {
initConnection(); initConnection();
} else { } else {
checkSelectedKeys(); checkSelectedKeys();
} }
}
} catch (Exception e) { } catch (Exception e) {
log.info("Exception selecting socket", e); log.info("Exception selecting socket", e);
e.printStackTrace(); e.printStackTrace();

View file

@ -12,7 +12,6 @@ import org.json.JSONObject;
public class OsMoTracker implements OsMoSender, OsMoReactor { public class OsMoTracker implements OsMoSender, OsMoReactor {
private ConcurrentLinkedQueue<Location> bufferOfLocations = new ConcurrentLinkedQueue<Location>(); private ConcurrentLinkedQueue<Location> bufferOfLocations = new ConcurrentLinkedQueue<Location>();
private Map<String, Location> otherLocations = new ConcurrentHashMap<String, Location>(); private Map<String, Location> otherLocations = new ConcurrentHashMap<String, Location>();
private boolean trackerStarted;
private boolean startSendingLocations; private boolean startSendingLocations;
private OsmandMapTileView view; private OsmandMapTileView view;
private OsMoService service; private OsMoService service;
@ -24,12 +23,22 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
service.registerReactor(this); service.registerReactor(this);
} }
public boolean isEnabledTracker() {
return startSendingLocations;
}
public void enableTracker() { public void enableTracker() {
if(!startSendingLocations) {
startSendingLocations = true; startSendingLocations = true;
service.pushCommand("TRACKER_SESSION_OPEN");
}
} }
public void disableTracker() { public void disableTracker() {
if(startSendingLocations) {
startSendingLocations = false; startSendingLocations = false;
service.pushCommand("TRACKER_SESSION_CLOSE");
}
} }
public void startTrackingId(String id) { public void startTrackingId(String id) {
@ -44,15 +53,6 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
@Override @Override
public String nextSendCommand(OsMoThread thread) { public String nextSendCommand(OsMoThread thread) {
if (trackerStarted != startSendingLocations) {
if (!trackerStarted) {
trackerStarted = true;
return "TRACKER_SESSION_OPEN";
} else {
trackerStarted = false;
return "TRACKER_SESSION_CLOSE";
}
}
if(!bufferOfLocations.isEmpty()){ if(!bufferOfLocations.isEmpty()){
Location loc = bufferOfLocations.poll(); Location loc = bufferOfLocations.poll();
StringBuilder cmd = new StringBuilder("T|"); StringBuilder cmd = new StringBuilder("T|");

View file

@ -12,6 +12,7 @@ import android.app.AlertDialog.Builder;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.text.format.DateFormat; import android.text.format.DateFormat;
@ -25,6 +26,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
public static final String DEFINE_EDIT = "DEFINE_EDIT"; public static final String DEFINE_EDIT = "DEFINE_EDIT";
private Preference debugPref; private Preference debugPref;
private Preference trackerId; private Preference trackerId;
private CheckBoxPreference sendLocationsref;
@Override @Override
@ -34,13 +36,21 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
PreferenceScreen grp = getPreferenceScreen(); PreferenceScreen grp = getPreferenceScreen();
trackerId = new Preference(this); trackerId = new Preference(this);
trackerId.setTitle(R.string.osmo_tracker_id); trackerId.setTitle(R.string.osmo_tracker_id);
trackerId.setSummary(R.string.osmo_tracker_id_descr); trackerId.setSummary(R.string.osmo_tracker_id_descr);
trackerId.setOnPreferenceClickListener(this);
grp.addPreference(trackerId);
sendLocationsref = createCheckBoxPreference(settings.OSMO_AUTO_SEND_LOCATIONS);
sendLocationsref.setTitle(R.string.osmo_auto_send_locations);
sendLocationsref.setSummary(R.string.osmo_auto_send_locations_descr);
grp.addPreference(sendLocationsref);
debugPref = new Preference(this); debugPref = new Preference(this);
debugPref.setTitle(R.string.osmo_settings_debug); debugPref.setTitle(R.string.osmo_settings_debug);
debugPref.setOnPreferenceClickListener(this);
updateDebugPref(); updateDebugPref();
grp.addPreference(debugPref); grp.addPreference(debugPref);
} }
@ -50,8 +60,6 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
OsMoService service = plugin.getService(); OsMoService service = plugin.getService();
OsMoTracker tracker = plugin.getTracker(); OsMoTracker tracker = plugin.getTracker();
StringBuilder s = new StringBuilder(); StringBuilder s = new StringBuilder();
s.append(getString(R.string.osmo_settings_uuid)).append(" : ")
.append(getMyApplication().getSettings().OSMO_DEVICE_KEY.get().toUpperCase()).append("\n");
if(service.isConnected()) { if(service.isConnected()) {
int seconds = (int) ((System.currentTimeMillis() - service.getConnectionTime()) / 1000); int seconds = (int) ((System.currentTimeMillis() - service.getConnectionTime()) / 1000);
s.append(getString(R.string.osmo_conn_successfull, Algorithms.formatDuration(seconds))).append("\n"); s.append(getString(R.string.osmo_conn_successfull, Algorithms.formatDuration(seconds))).append("\n");
@ -62,13 +70,18 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
s.append(getString(R.string.osmo_session_token, si.token)).append("\n"); s.append(getString(R.string.osmo_session_token, si.token)).append("\n");
} }
} else { } else {
s.append(getString(R.string.osmo_io_error) + service.getLastRegistrationError()).append("\n"); String err = service.getLastRegistrationError();
if(err == null) {
err = "...";
}
s.append(getString(R.string.osmo_io_error) + err).append("\n");
} }
s.append(getString(R.string.osmo_locations_sent, s.append(getString(R.string.osmo_locations_sent,
tracker.getLocationsSent(), tracker.getLocationsSent(),
tracker.getBufferLocationsSize())); tracker.getBufferLocationsSize())).append("\n");
s.append(getString(R.string.osmo_settings_uuid)).append(" : ")
.append(getMyApplication().getSettings().OSMO_DEVICE_KEY.get().toUpperCase()).append("\n");
debugPref.setSummary(s.toString().trim()); debugPref.setSummary(s.toString().trim());
debugPref.setOnPreferenceClickListener(this);
} }
@Override @Override
@ -92,6 +105,19 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
return super.onPreferenceClick(preference); return super.onPreferenceClick(preference);
} }
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean p = super.onPreferenceChange(preference, newValue);
String id = preference.getKey();
if (id.equals(settings.OSMO_AUTO_SEND_LOCATIONS.getId())) {
if ((Boolean) newValue) {
final OsMoPlugin plugin = OsMoPlugin.getEnabledPlugin(OsMoPlugin.class);
plugin.getTracker().enableTracker();
}
}
return p;
}
public void updateAllSettings() { public void updateAllSettings() {
super.updateAllSettings(); super.updateAllSettings();