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
|
||||
public void onClick(View view) {
|
||||
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);
|
||||
|
|
@ -186,6 +198,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
if (loc != null) {
|
||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
addMarker(gp, loc.isFound());
|
||||
try {
|
||||
serviceXmpp.sendCommandObjectTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} else if (serviceGps.isDogActivated()) {
|
||||
markAsFound();
|
||||
|
|
@ -618,6 +634,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
if (o instanceof String && o.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
||||
MyLocation loc = serviceGps.getCurrentLocation();
|
||||
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();
|
||||
|
||||
double latitude = 0, longitude = 0;
|
||||
int time = 0;
|
||||
long time = 0;
|
||||
for (String latitudeStr : latitudeStrs) {
|
||||
try {
|
||||
latitude = Double.parseDouble(latitudeStr);
|
||||
|
|
@ -90,7 +90,7 @@ public class ObjectGeolocCommand extends LocalCommand {
|
|||
}
|
||||
for (String timeStr : timeStrs) {
|
||||
try {
|
||||
time = Integer.parseInt(timeStr);
|
||||
time = Long.parseLong(timeStr);
|
||||
break;
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class TrailGeolocCommand extends LocalCommand {
|
|||
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||
|
||||
double latitude = 0, longitude = 0;
|
||||
int time = 0;
|
||||
long time = 0;
|
||||
for (String latitudeStr : latitudeStrs) {
|
||||
try {
|
||||
latitude = Double.parseDouble(latitudeStr);
|
||||
|
|
@ -90,7 +90,7 @@ public class TrailGeolocCommand extends LocalCommand {
|
|||
}
|
||||
for (String timeStr : timeStrs) {
|
||||
try {
|
||||
time = Integer.parseInt(timeStr);
|
||||
time = Long.parseLong(timeStr);
|
||||
break;
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
|||
import org.jivesoftware.smackx.commands.AdHocCommandManager;
|
||||
import org.jivesoftware.smackx.commands.LocalCommand;
|
||||
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.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
|
@ -119,7 +121,7 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
|
||||
isConnected = connection.isConnected();
|
||||
if (isConnected) {
|
||||
jid = connection.getUser().asEntityBareJidString();
|
||||
jid = connection.getUser().asFullJidIfPossible().toString();
|
||||
Log.i(TAG, "JID: "+jid);
|
||||
}
|
||||
Runnable r = new Runnable() {
|
||||
|
|
@ -153,16 +155,16 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
//<editor-fold defaultstate="collapsed" desc="Presence">
|
||||
public void sendPresenceAvailable() throws SmackException.NotConnectedException, InterruptedException, XmppStringprepException {
|
||||
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 {
|
||||
sendPresence(JidCreate.bareFrom(to), Presence.Type.available);
|
||||
sendPresence(JidCreate.fullFrom(to), Presence.Type.available);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -175,12 +177,12 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
|
||||
@Override
|
||||
public void presenceAvailable(FullJid address, Presence availablePresence) {
|
||||
String bareJid = address.asBareJid().toString();
|
||||
if (!bareJid.equals(jid) && (otherJid == null || !bareJid.equals(otherJid))) {
|
||||
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+bareJid);
|
||||
otherJid = bareJid;
|
||||
String fullJid = address.asFullJidIfPossible().toString();
|
||||
if (!fullJid.equals(jid) && (otherJid == null || !fullJid.equals(otherJid))) {
|
||||
Log.i(TAG, "PRESENCE AVAILABLE RECEIVED FROM "+fullJid);
|
||||
otherJid = fullJid;
|
||||
try {
|
||||
sendPresenceAvailable(bareJid);
|
||||
sendPresenceAvailable(fullJid);
|
||||
} catch (SmackException.NotConnectedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
|
|
@ -221,13 +223,13 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
setChanged();
|
||||
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");
|
||||
currentXmppLocation = new MyLocation(lat, lon, time);
|
||||
setChanged();
|
||||
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");
|
||||
lastObjectXmppLocation = new MyLocation(lat, lon, time);
|
||||
setChanged();
|
||||
|
|
@ -239,6 +241,54 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
public MyLocation getLastObjectXmppLocation() {
|
||||
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>
|
||||
|
||||
public void setOtherJid(String otherJid) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue