Send trail over XMPP.
This commit is contained in:
parent
f1ad139832
commit
35d9b8ccfb
|
|
@ -167,6 +167,18 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
changeStatusTrace();
|
changeStatusTrace();
|
||||||
|
try {
|
||||||
|
if (serviceGps.isTraceurActivated()) {
|
||||||
|
serviceXmpp.sendCommandStartTrail();
|
||||||
|
} else {
|
||||||
|
serviceXmpp.sendCommandStopTrail();
|
||||||
|
}
|
||||||
|
} catch (XmppStringprepException ex) {
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
} catch (SmackException.NoResponseException e) {
|
||||||
|
} catch (SmackException.NotConnectedException e) {
|
||||||
|
} catch (XMPPException.XMPPErrorException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
||||||
|
|
@ -186,6 +198,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||||
addMarker(gp, loc.isFound());
|
addMarker(gp, loc.isFound());
|
||||||
|
try {
|
||||||
|
serviceXmpp.sendCommandObjectTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (serviceGps.isDogActivated()) {
|
} else if (serviceGps.isDogActivated()) {
|
||||||
markAsFound();
|
markAsFound();
|
||||||
|
|
@ -618,6 +634,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
if (o instanceof String && o.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
if (o instanceof String && o.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
||||||
MyLocation loc = serviceGps.getCurrentLocation();
|
MyLocation loc = serviceGps.getCurrentLocation();
|
||||||
onNewLocation(loc);
|
onNewLocation(loc);
|
||||||
|
try {
|
||||||
|
serviceXmpp.sendCommandLocationTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public class ObjectGeolocCommand extends LocalCommand {
|
||||||
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||||
|
|
||||||
double latitude = 0, longitude = 0;
|
double latitude = 0, longitude = 0;
|
||||||
int time = 0;
|
long time = 0;
|
||||||
for (String latitudeStr : latitudeStrs) {
|
for (String latitudeStr : latitudeStrs) {
|
||||||
try {
|
try {
|
||||||
latitude = Double.parseDouble(latitudeStr);
|
latitude = Double.parseDouble(latitudeStr);
|
||||||
|
|
@ -90,7 +90,7 @@ public class ObjectGeolocCommand extends LocalCommand {
|
||||||
}
|
}
|
||||||
for (String timeStr : timeStrs) {
|
for (String timeStr : timeStrs) {
|
||||||
try {
|
try {
|
||||||
time = Integer.parseInt(timeStr);
|
time = Long.parseLong(timeStr);
|
||||||
break;
|
break;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ public class TrailGeolocCommand extends LocalCommand {
|
||||||
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||||
|
|
||||||
double latitude = 0, longitude = 0;
|
double latitude = 0, longitude = 0;
|
||||||
int time = 0;
|
long time = 0;
|
||||||
for (String latitudeStr : latitudeStrs) {
|
for (String latitudeStr : latitudeStrs) {
|
||||||
try {
|
try {
|
||||||
latitude = Double.parseDouble(latitudeStr);
|
latitude = Double.parseDouble(latitudeStr);
|
||||||
|
|
@ -90,7 +90,7 @@ public class TrailGeolocCommand extends LocalCommand {
|
||||||
}
|
}
|
||||||
for (String timeStr : timeStrs) {
|
for (String timeStr : timeStrs) {
|
||||||
try {
|
try {
|
||||||
time = Integer.parseInt(timeStr);
|
time = Long.parseLong(timeStr);
|
||||||
break;
|
break;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@ import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||||
import org.jivesoftware.smackx.commands.AdHocCommandManager;
|
import org.jivesoftware.smackx.commands.AdHocCommandManager;
|
||||||
import org.jivesoftware.smackx.commands.LocalCommand;
|
import org.jivesoftware.smackx.commands.LocalCommand;
|
||||||
import org.jivesoftware.smackx.commands.LocalCommandFactory;
|
import org.jivesoftware.smackx.commands.LocalCommandFactory;
|
||||||
|
import org.jivesoftware.smackx.commands.RemoteCommand;
|
||||||
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
import org.jxmpp.jid.BareJid;
|
import org.jxmpp.jid.BareJid;
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
import org.jxmpp.jid.Jid;
|
import org.jxmpp.jid.Jid;
|
||||||
|
|
@ -119,7 +121,7 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
|
|
||||||
isConnected = connection.isConnected();
|
isConnected = connection.isConnected();
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
jid = connection.getUser().asEntityBareJidString();
|
jid = connection.getUser().asFullJidIfPossible().toString();
|
||||||
Log.i(TAG, "JID: "+jid);
|
Log.i(TAG, "JID: "+jid);
|
||||||
}
|
}
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
|
|
@ -153,16 +155,16 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
//<editor-fold defaultstate="collapsed" desc="Presence">
|
//<editor-fold defaultstate="collapsed" desc="Presence">
|
||||||
public void sendPresenceAvailable() throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
public void sendPresenceAvailable() throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
||||||
if (otherJid != null) {
|
if (otherJid != null) {
|
||||||
sendPresence(JidCreate.bareFrom(otherJid), Presence.Type.available);
|
sendPresence(JidCreate.fullFrom(otherJid), Presence.Type.available);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPresenceAvailable(String to) throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
public void sendPresenceAvailable(String to) throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
||||||
sendPresence(JidCreate.bareFrom(to), Presence.Type.available);
|
sendPresence(JidCreate.fullFrom(to), Presence.Type.available);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPresenceUnavailable(String to) throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
public void sendPresenceUnavailable(String to) throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
||||||
sendPresence(JidCreate.bareFrom(to), Presence.Type.unavailable);
|
sendPresence(JidCreate.fullFrom(to), Presence.Type.unavailable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPresence(Jid to, Presence.Type type) throws SmackException.NotConnectedException, InterruptedException {
|
private void sendPresence(Jid to, Presence.Type type) throws SmackException.NotConnectedException, InterruptedException {
|
||||||
|
|
@ -175,12 +177,12 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void presenceAvailable(FullJid address, Presence availablePresence) {
|
public void presenceAvailable(FullJid address, Presence availablePresence) {
|
||||||
String bareJid = address.asBareJid().toString();
|
String fullJid = address.asFullJidIfPossible().toString();
|
||||||
if (!bareJid.equals(jid) && (otherJid == null || !bareJid.equals(otherJid))) {
|
if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) {
|
||||||
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+bareJid);
|
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+fullJid);
|
||||||
otherJid = bareJid;
|
otherJid = fullJid;
|
||||||
try {
|
try {
|
||||||
sendPresenceAvailable(bareJid);
|
sendPresenceAvailable(fullJid);
|
||||||
} catch (SmackException.NotConnectedException e) {
|
} catch (SmackException.NotConnectedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
|
@ -221,13 +223,13 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_STOP_TRAIL);
|
notifyObservers(NOTIF_STOP_TRAIL);
|
||||||
}
|
}
|
||||||
public void addTrailGeoloc(double lat, double lon, int time) {
|
public void addTrailGeoloc(double lat, double lon, long time) {
|
||||||
Log.i(TAG, "Add location");
|
Log.i(TAG, "Add location");
|
||||||
currentXmppLocation = new MyLocation(lat, lon, time);
|
currentXmppLocation = new MyLocation(lat, lon, time);
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_NEW_LOCATION);
|
notifyObservers(NOTIF_NEW_LOCATION);
|
||||||
}
|
}
|
||||||
public void addObjectGeoloc(double lat, double lon, int time) {
|
public void addObjectGeoloc(double lat, double lon, long time) {
|
||||||
Log.i(TAG, "Add object");
|
Log.i(TAG, "Add object");
|
||||||
lastObjectXmppLocation = new MyLocation(lat, lon, time);
|
lastObjectXmppLocation = new MyLocation(lat, lon, time);
|
||||||
setChanged();
|
setChanged();
|
||||||
|
|
@ -239,6 +241,54 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
public MyLocation getLastObjectXmppLocation() {
|
public MyLocation getLastObjectXmppLocation() {
|
||||||
return lastObjectXmppLocation;
|
return lastObjectXmppLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
|
if (isOtherJidSet()) {
|
||||||
|
Log.i(TAG, "Send command start");
|
||||||
|
RemoteCommand command = commandManager.getRemoteCommand(JidCreate.fullFrom(otherJid), XMPP_NODE_START_TRAIL_GEOLOC);
|
||||||
|
command.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
|
if (isOtherJidSet()) {
|
||||||
|
Log.i(TAG, "Send command stop");
|
||||||
|
RemoteCommand command = commandManager.getRemoteCommand(JidCreate.fullFrom(otherJid), XMPP_NODE_STOP_TRAIL_GEOLOC);
|
||||||
|
command.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCommandObjectTrail(double lat, double lon, long time) throws Exception {
|
||||||
|
if (isOtherJidSet()) {
|
||||||
|
Log.i(TAG, "Send command object");
|
||||||
|
RemoteCommand command = commandManager.getRemoteCommand(JidCreate.fullFrom(otherJid), XMPP_NODE_OBJECT_GEOLOC);
|
||||||
|
command.execute();
|
||||||
|
if (command.getForm() == null) {
|
||||||
|
throw new Exception("Didn't get form back");
|
||||||
|
}
|
||||||
|
Form form = command.getForm().createAnswerForm();
|
||||||
|
form.setAnswer(ObjectGeolocCommand.FIELD_PARAM_LATITUDE, lat);
|
||||||
|
form.setAnswer(ObjectGeolocCommand.FIELD_PARAM_LONGITUDE, lon);
|
||||||
|
form.setAnswer(ObjectGeolocCommand.FIELD_PARAM_TIME, time);
|
||||||
|
command.next(form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCommandLocationTrail(double lat, double lon, long time) throws Exception {
|
||||||
|
if (isOtherJidSet()) {
|
||||||
|
Log.i(TAG, "Send command location");
|
||||||
|
RemoteCommand command = commandManager.getRemoteCommand(JidCreate.fullFrom(otherJid), XMPP_NODE_TRAIL_GEOLOC);
|
||||||
|
command.execute();
|
||||||
|
if (command.getForm() == null) {
|
||||||
|
throw new Exception("Didn't get form back");
|
||||||
|
}
|
||||||
|
Form form = command.getForm().createAnswerForm();
|
||||||
|
form.setAnswer(TrailGeolocCommand.FIELD_PARAM_LATITUDE, lat);
|
||||||
|
form.setAnswer(TrailGeolocCommand.FIELD_PARAM_LONGITUDE, lon);
|
||||||
|
form.setAnswer(TrailGeolocCommand.FIELD_PARAM_TIME, time);
|
||||||
|
command.next(form);
|
||||||
|
}
|
||||||
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
public void setOtherJid(String otherJid) {
|
public void setOtherJid(String otherJid) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue