Fix osmo plugin

This commit is contained in:
vshcherb 2014-05-05 01:06:21 +02:00
parent 02774b1c1f
commit 1deeef93c9
2 changed files with 21 additions and 7 deletions

View file

@ -27,7 +27,7 @@ import android.provider.Settings;
public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlServices {
private OsmandApplication app;
public static final String ID = "osmand.osmodroid.v2";
public static final String ID = "osmand.osmo";
private static final Log log = PlatformUtil.getLog(OsMoPlugin.class);
private OsMoService service;
@ -68,10 +68,9 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
}
@Override
public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, OsmandMapTileView view) {
public void addMonitorActions(ContextMenuAdapter qa, MonitoringInfoControl li, final OsmandMapTileView view) {
final boolean off = service.isActive();
qa.item(off ? R.string.osmodroid_mode_off : R.string.osmodroid_mode_on
)
qa.item(off ? R.string.osmodroid_mode_off : R.string.osmodroid_mode_on)
.icon(off ? R.drawable.monitoring_rec_inactive : R.drawable.monitoring_rec_big)
.listen(new OnContextMenuClick() {
@ -91,6 +90,21 @@ public class OsMoPlugin extends OsmandPlugin implements MonitoringInfoControlSer
}
}).reg();
qa.item("Test (send)").
icons(R.drawable.ic_action_grefresh_dark, R.drawable.ic_action_grefresh_light). listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
try {
String response = service.sendCoordinate(view.getLatitude(), view.getLongitude(), 0, 0, 0, 0);
app.showToastMessage(response);
} catch (Exception e) {
app.showToastMessage(app.getString(R.string.error_io_error) + ": " + e.getMessage());
}
}
}).reg();
}

View file

@ -8,7 +8,7 @@ import java.net.URL;
import java.net.URLConnection;
public class OsMoService {
private static String TRACKER_URL = "ws://srv.osmo.mobi";
private static String TRACKER_URL = "ws://srv.osmo.mobi:4242";
private URLConnection conn;
private OutputStreamWriter out;
private BufferedReader in;
@ -37,8 +37,8 @@ public class OsMoService {
return in.readLine();
}
public void sendCoordinate(double lat, double lon, float hdop, float alt, float speed, float bearing) throws IOException {
sendCommand("p|"+lat+":"+lon+":"+hdop+":"+alt+":"+speed+":"+bearing);
public String sendCoordinate(double lat, double lon, float hdop, float alt, float speed, float bearing) throws IOException {
return sendCommand("p|"+lat+":"+lon+":"+hdop+":"+alt+":"+speed+":"+bearing);
}
public String deactivate() throws IOException {