Add object location received on XMPP.
This commit is contained in:
parent
367c72bf8c
commit
f1ad139832
|
|
@ -182,7 +182,11 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (serviceGps.isTraceurActivated()) {
|
if (serviceGps.isTraceurActivated()) {
|
||||||
addMarker();
|
WayPointLocation loc = serviceGps.addPointObjectTrail();
|
||||||
|
if (loc != null) {
|
||||||
|
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||||
|
addMarker(gp, loc.isFound());
|
||||||
|
}
|
||||||
} else if (serviceGps.isDogActivated()) {
|
} else if (serviceGps.isDogActivated()) {
|
||||||
markAsFound();
|
markAsFound();
|
||||||
}
|
}
|
||||||
|
|
@ -248,13 +252,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addMarker() {
|
|
||||||
WayPointLocation loc = serviceGps.addPointObjectTrail();
|
|
||||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
|
||||||
addMarker(gp, loc.isFound());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addMarker(GeoPoint gp, boolean isFound) {
|
private void addMarker(GeoPoint gp, boolean isFound) {
|
||||||
Marker marker = new Marker(map);
|
Marker marker = new Marker(map);
|
||||||
marker.setIcon(getResources().getDrawable(isFound ? R.drawable.ic_marker_blue : R.drawable.ic_marker_red));
|
marker.setIcon(getResources().getDrawable(isFound ? R.drawable.ic_marker_blue : R.drawable.ic_marker_red));
|
||||||
|
|
@ -620,7 +617,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
public void updateServiceGps(Object o) {
|
public void updateServiceGps(Object o) {
|
||||||
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();
|
||||||
onNewGeoloc(loc);
|
onNewLocation(loc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -631,7 +628,17 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MyLocation loc = serviceXmpp.getCurrentLocation();
|
MyLocation loc = serviceXmpp.getCurrentLocation();
|
||||||
onNewGeoloc(loc);
|
onNewLocation(loc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (o.equals(ServiceXmpp.NOTIF_NEW_OBJECT)){
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
MyLocation locObj = serviceXmpp.getLastObjectXmppLocation();
|
||||||
|
WayPointLocation loc = serviceGps.addPointObjectTrail(locObj);
|
||||||
|
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||||
|
addMarker(gp, loc.isFound());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (o.equals(ServiceXmpp.NOTIF_START_TRAIL)){
|
} else if (o.equals(ServiceXmpp.NOTIF_START_TRAIL)){
|
||||||
|
|
@ -652,7 +659,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNewGeoloc(MyLocation loc) {
|
private void onNewLocation(MyLocation loc) {
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
serviceGps.addPoint(loc);
|
serviceGps.addPoint(loc);
|
||||||
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
package fr.chteufleur.mytrackingdog.models.xmpp.commands;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smackx.commands.AdHocCommandNote;
|
||||||
|
import org.jivesoftware.smackx.commands.LocalCommand;
|
||||||
|
import org.jivesoftware.smackx.xdata.Form;
|
||||||
|
import org.jivesoftware.smackx.xdata.FormField;
|
||||||
|
import org.jivesoftware.smackx.xdata.packet.DataForm;
|
||||||
|
import org.jxmpp.jid.Jid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.chteufleur.mytrackingdog.services.ServiceXmpp;
|
||||||
|
|
||||||
|
public class ObjectGeolocCommand extends LocalCommand {
|
||||||
|
|
||||||
|
public static final String TAG = ObjectGeolocCommand.class.getName();
|
||||||
|
|
||||||
|
public static final String FIELD_PARAM_LATITUDE = "latitude";
|
||||||
|
public static final String FIELD_PARAM_LONGITUDE = "longitude";
|
||||||
|
public static final String FIELD_PARAM_TIME = "time";
|
||||||
|
|
||||||
|
private final ServiceXmpp serviceXmpp;
|
||||||
|
|
||||||
|
public ObjectGeolocCommand(ServiceXmpp serviceXmpp) {
|
||||||
|
this.serviceXmpp = serviceXmpp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLastStage() {
|
||||||
|
return getCurrentStage() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasPermission(Jid jid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||||
|
Form result = new Form(DataForm.Type.form);
|
||||||
|
setExecuteAction(Action.next);
|
||||||
|
|
||||||
|
FormField resultFieldLatitude = new FormField(FIELD_PARAM_LATITUDE);
|
||||||
|
resultFieldLatitude.setLabel(FIELD_PARAM_LATITUDE);
|
||||||
|
resultFieldLatitude.setType(FormField.Type.text_single);
|
||||||
|
result.addField(resultFieldLatitude);
|
||||||
|
|
||||||
|
FormField resultFieldLongitude = new FormField(FIELD_PARAM_LONGITUDE);
|
||||||
|
resultFieldLongitude.setLabel(FIELD_PARAM_LONGITUDE);
|
||||||
|
resultFieldLongitude.setType(FormField.Type.text_single);
|
||||||
|
result.addField(resultFieldLongitude);
|
||||||
|
|
||||||
|
FormField resultFieldTime = new FormField(FIELD_PARAM_TIME);
|
||||||
|
resultFieldTime.setLabel(FIELD_PARAM_TIME);
|
||||||
|
resultFieldTime.setType(FormField.Type.text_single);
|
||||||
|
result.addField(resultFieldTime);
|
||||||
|
|
||||||
|
this.addActionAvailable(Action.next);
|
||||||
|
setForm(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void next(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||||
|
FormField formLatitude = response.getField(FIELD_PARAM_LATITUDE);
|
||||||
|
FormField formLongitude = response.getField(FIELD_PARAM_LONGITUDE);
|
||||||
|
FormField formTime = response.getField(FIELD_PARAM_TIME);
|
||||||
|
|
||||||
|
if (formLatitude != null && formLongitude != null && formTime != null) {
|
||||||
|
List<String> latitudeStrs = formLatitude.getValues();
|
||||||
|
List<String> longitudeStrs = response.getField(FIELD_PARAM_LONGITUDE).getValues();
|
||||||
|
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||||
|
|
||||||
|
double latitude = 0, longitude = 0;
|
||||||
|
int time = 0;
|
||||||
|
for (String latitudeStr : latitudeStrs) {
|
||||||
|
try {
|
||||||
|
latitude = Double.parseDouble(latitudeStr);
|
||||||
|
break;
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String longitudeStr : longitudeStrs) {
|
||||||
|
try {
|
||||||
|
longitude = Double.parseDouble(longitudeStr);
|
||||||
|
break;
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String timeStr : timeStrs) {
|
||||||
|
try {
|
||||||
|
time = Integer.parseInt(timeStr);
|
||||||
|
break;
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serviceXmpp != null && latitude != 0 && longitude != 0 && time != 0) {
|
||||||
|
serviceXmpp.addObjectGeoloc(latitude, longitude, time);
|
||||||
|
}
|
||||||
|
this.addNote(new AdHocCommandNote(AdHocCommandNote.Type.info, "SUCCESS"));
|
||||||
|
} else {
|
||||||
|
this.addNote((new AdHocCommandNote(AdHocCommandNote.Type.error, "FAIL")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void complete(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prev() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancel() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
package fr.chteufleur.mytrackingdog.models.xmpp.commands;
|
package fr.chteufleur.mytrackingdog.models.xmpp.commands;
|
||||||
|
|
||||||
import android.app.Service;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smackx.commands.AdHocCommandNote;
|
import org.jivesoftware.smackx.commands.AdHocCommandNote;
|
||||||
|
|
@ -75,18 +72,18 @@ public class TrailGeolocCommand extends LocalCommand {
|
||||||
List<String> longitudeStrs = response.getField(FIELD_PARAM_LONGITUDE).getValues();
|
List<String> longitudeStrs = response.getField(FIELD_PARAM_LONGITUDE).getValues();
|
||||||
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||||
|
|
||||||
long latitude = 0, longitude = 0;
|
double latitude = 0, longitude = 0;
|
||||||
int time = 0;
|
int time = 0;
|
||||||
for (String latitudeStr : latitudeStrs) {
|
for (String latitudeStr : latitudeStrs) {
|
||||||
try {
|
try {
|
||||||
latitude = Long.parseLong(latitudeStr);
|
latitude = Double.parseDouble(latitudeStr);
|
||||||
break;
|
break;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String longitudeStr : longitudeStrs) {
|
for (String longitudeStr : longitudeStrs) {
|
||||||
try {
|
try {
|
||||||
longitude = Long.parseLong(longitudeStr);
|
longitude = Double.parseDouble(longitudeStr);
|
||||||
break;
|
break;
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -205,9 +205,13 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
||||||
}
|
}
|
||||||
|
|
||||||
public WayPointLocation addPointObjectTrail() {
|
public WayPointLocation addPointObjectTrail() {
|
||||||
|
return addPointObjectTrail(currentLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WayPointLocation addPointObjectTrail(MyLocation location) {
|
||||||
WayPointLocation wpl = null;
|
WayPointLocation wpl = null;
|
||||||
if (currentLocation != null) {
|
if (location != null) {
|
||||||
wpl = new WayPointLocation(currentLocation);
|
wpl = new WayPointLocation(location);
|
||||||
traces.addPointObjectTrail(wpl);
|
traces.addPointObjectTrail(wpl);
|
||||||
}
|
}
|
||||||
return wpl;
|
return wpl;
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import java.util.Observable;
|
||||||
|
|
||||||
import fr.chteufleur.mytrackingdog.QRCodeGeneratorActivity;
|
import fr.chteufleur.mytrackingdog.QRCodeGeneratorActivity;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.ObjectGeolocCommand;
|
||||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StartTrailGeolocCommand;
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StartTrailGeolocCommand;
|
||||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StopTrailGeolocCommand;
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StopTrailGeolocCommand;
|
||||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.TrailGeolocCommand;
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.TrailGeolocCommand;
|
||||||
|
|
@ -40,10 +41,12 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
public static final String TAG = ServiceXmpp.class.getName();
|
public static final String TAG = ServiceXmpp.class.getName();
|
||||||
|
|
||||||
public static final String NOTIF_NEW_LOCATION = ServiceXmpp.class.getName()+".newlocation";
|
public static final String NOTIF_NEW_LOCATION = ServiceXmpp.class.getName()+".newlocation";
|
||||||
|
public static final String NOTIF_NEW_OBJECT = ServiceXmpp.class.getName()+".newobject";
|
||||||
public static final String NOTIF_START_TRAIL = ServiceXmpp.class.getName()+".starttrail";
|
public static final String NOTIF_START_TRAIL = ServiceXmpp.class.getName()+".starttrail";
|
||||||
public static final String NOTIF_STOP_TRAIL = ServiceXmpp.class.getName()+".stoptrail";
|
public static final String NOTIF_STOP_TRAIL = ServiceXmpp.class.getName()+".stoptrail";
|
||||||
|
|
||||||
private static final String XMPP_NODE_TRAIL_GEOLOC = "trail_geoloc";
|
private static final String XMPP_NODE_TRAIL_GEOLOC = "trail_geoloc";
|
||||||
|
private static final String XMPP_NODE_OBJECT_GEOLOC = "object_geoloc";
|
||||||
private static final String XMPP_NODE_START_TRAIL_GEOLOC = "start_trail_geoloc";
|
private static final String XMPP_NODE_START_TRAIL_GEOLOC = "start_trail_geoloc";
|
||||||
private static final String XMPP_NODE_STOP_TRAIL_GEOLOC = "stop_trail_geoloc";
|
private static final String XMPP_NODE_STOP_TRAIL_GEOLOC = "stop_trail_geoloc";
|
||||||
|
|
||||||
|
|
@ -92,6 +95,12 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
return new TrailGeolocCommand(thsi);
|
return new TrailGeolocCommand(thsi);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
commandManager.registerCommand(XMPP_NODE_OBJECT_GEOLOC, XMPP_NODE_OBJECT_GEOLOC, new LocalCommandFactory() {
|
||||||
|
@Override
|
||||||
|
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
||||||
|
return new ObjectGeolocCommand(thsi);
|
||||||
|
}
|
||||||
|
});
|
||||||
commandManager.registerCommand(XMPP_NODE_START_TRAIL_GEOLOC, XMPP_NODE_START_TRAIL_GEOLOC, new LocalCommandFactory() {
|
commandManager.registerCommand(XMPP_NODE_START_TRAIL_GEOLOC, XMPP_NODE_START_TRAIL_GEOLOC, new LocalCommandFactory() {
|
||||||
@Override
|
@Override
|
||||||
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
||||||
|
|
@ -201,22 +210,35 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||||
private MyLocation currentXmppLocation = null;
|
private MyLocation currentXmppLocation = null;
|
||||||
|
private MyLocation lastObjectXmppLocation = null;
|
||||||
public void startTrailGeoloc() {
|
public void startTrailGeoloc() {
|
||||||
|
Log.i(TAG, "Start trail");
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_START_TRAIL);
|
notifyObservers(NOTIF_START_TRAIL);
|
||||||
}
|
}
|
||||||
public void stopTrailGeoloc() {
|
public void stopTrailGeoloc() {
|
||||||
|
Log.i(TAG, "Stop trail");
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_STOP_TRAIL);
|
notifyObservers(NOTIF_STOP_TRAIL);
|
||||||
}
|
}
|
||||||
public void addTrailGeoloc(long lat, long lon, int time) {
|
public void addTrailGeoloc(double lat, double lon, int time) {
|
||||||
|
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) {
|
||||||
|
Log.i(TAG, "Add object");
|
||||||
|
lastObjectXmppLocation = new MyLocation(lat, lon, time);
|
||||||
|
setChanged();
|
||||||
|
notifyObservers(NOTIF_NEW_OBJECT);
|
||||||
|
}
|
||||||
public MyLocation getCurrentLocation() {
|
public MyLocation getCurrentLocation() {
|
||||||
return currentXmppLocation;
|
return currentXmppLocation;
|
||||||
}
|
}
|
||||||
|
public MyLocation getLastObjectXmppLocation() {
|
||||||
|
return lastObjectXmppLocation;
|
||||||
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
public void setOtherJid(String otherJid) {
|
public void setOtherJid(String otherJid) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue