Fix osmo settings
This commit is contained in:
parent
8d3319daa5
commit
882c45bdd6
6 changed files with 71 additions and 34 deletions
|
@ -9,10 +9,12 @@
|
|||
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
|
||||
-->
|
||||
<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_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>
|
||||
<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_locations_sent">Locations sent %1$d (in buffer %2$d) </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)
|
||||
</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_off">Start OsMo session</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_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>
|
||||
|
|
|
@ -828,6 +828,8 @@ public class OsmandSettings {
|
|||
|
||||
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();
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
|
|
|
@ -28,7 +28,9 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
public OsMoPlugin(final OsmandApplication app) {
|
||||
service = new OsMoService(app);
|
||||
tracker = new OsMoTracker(service);
|
||||
if(app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get()) {
|
||||
tracker.enableTracker();
|
||||
}
|
||||
groups = new OsMoGroups(service, tracker, app.getSettings());
|
||||
this.app = app;
|
||||
}
|
||||
|
@ -74,17 +76,23 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
|
|||
|
||||
@Override
|
||||
public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, final OsmandMapTileView view) {
|
||||
final boolean off = !service.isConnected();
|
||||
qa.item(off ? R.string.osmo_mode_off : R.string.osmo_mode_on)
|
||||
.icon(off ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big)
|
||||
//final boolean off = !service.isConnected();
|
||||
final boolean autosend = app.getSettings().OSMO_AUTO_SEND_LOCATIONS.get();
|
||||
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() {
|
||||
|
||||
@Override
|
||||
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
|
||||
if (off) {
|
||||
service.connect(true);
|
||||
if(autosend) {
|
||||
tracker.disableTracker();
|
||||
tracker.enableTracker();
|
||||
} else if (offTracker) {
|
||||
tracker.enableTracker();
|
||||
} else {
|
||||
service.disconnect();
|
||||
tracker.disableTracker();
|
||||
}
|
||||
}
|
||||
}).reg();
|
||||
|
|
|
@ -128,15 +128,13 @@ public class OsMoThread {
|
|||
protected void checkAsyncSocket() {
|
||||
long delay = HEARTBEAT_DELAY;
|
||||
try {
|
||||
if (selector == null) {
|
||||
stopThread = true;
|
||||
} else {
|
||||
// if (selector == null) {
|
||||
// stopThread = true;
|
||||
if(activeChannel == null || reconnect) {
|
||||
initConnection();
|
||||
} else {
|
||||
checkSelectedKeys();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("Exception selecting socket", e);
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.json.JSONObject;
|
|||
public class OsMoTracker implements OsMoSender, OsMoReactor {
|
||||
private ConcurrentLinkedQueue<Location> bufferOfLocations = new ConcurrentLinkedQueue<Location>();
|
||||
private Map<String, Location> otherLocations = new ConcurrentHashMap<String, Location>();
|
||||
private boolean trackerStarted;
|
||||
private boolean startSendingLocations;
|
||||
private OsmandMapTileView view;
|
||||
private OsMoService service;
|
||||
|
@ -24,12 +23,22 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
|
|||
service.registerReactor(this);
|
||||
}
|
||||
|
||||
public boolean isEnabledTracker() {
|
||||
return startSendingLocations;
|
||||
}
|
||||
|
||||
public void enableTracker() {
|
||||
if(!startSendingLocations) {
|
||||
startSendingLocations = true;
|
||||
service.pushCommand("TRACKER_SESSION_OPEN");
|
||||
}
|
||||
}
|
||||
|
||||
public void disableTracker() {
|
||||
if(startSendingLocations) {
|
||||
startSendingLocations = false;
|
||||
service.pushCommand("TRACKER_SESSION_CLOSE");
|
||||
}
|
||||
}
|
||||
|
||||
public void startTrackingId(String id) {
|
||||
|
@ -44,15 +53,6 @@ public class OsMoTracker implements OsMoSender, OsMoReactor {
|
|||
|
||||
@Override
|
||||
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()){
|
||||
Location loc = bufferOfLocations.poll();
|
||||
StringBuilder cmd = new StringBuilder("T|");
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.app.AlertDialog.Builder;
|
|||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.text.format.DateFormat;
|
||||
|
@ -25,6 +26,7 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
|
|||
public static final String DEFINE_EDIT = "DEFINE_EDIT";
|
||||
private Preference debugPref;
|
||||
private Preference trackerId;
|
||||
private CheckBoxPreference sendLocationsref;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +36,21 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
|
|||
PreferenceScreen grp = getPreferenceScreen();
|
||||
|
||||
|
||||
|
||||
trackerId = new Preference(this);
|
||||
trackerId.setTitle(R.string.osmo_tracker_id);
|
||||
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.setTitle(R.string.osmo_settings_debug);
|
||||
|
||||
debugPref.setOnPreferenceClickListener(this);
|
||||
updateDebugPref();
|
||||
grp.addPreference(debugPref);
|
||||
}
|
||||
|
@ -50,8 +60,6 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
|
|||
OsMoService service = plugin.getService();
|
||||
OsMoTracker tracker = plugin.getTracker();
|
||||
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()) {
|
||||
int seconds = (int) ((System.currentTimeMillis() - service.getConnectionTime()) / 1000);
|
||||
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");
|
||||
}
|
||||
} 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,
|
||||
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.setOnPreferenceClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -92,6 +105,19 @@ public class SettingsOsMoActivity extends SettingsBaseActivity {
|
|||
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() {
|
||||
super.updateAllSettings();
|
||||
|
|
Loading…
Reference in a new issue