Receive start, stop and location on XMPP.
This commit is contained in:
parent
e41c3e9948
commit
367c72bf8c
|
|
@ -620,42 +620,72 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
public void updateServiceGps(Object o) {
|
||||
if (o instanceof String && o.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
||||
MyLocation loc = serviceGps.getCurrentLocation();
|
||||
if (loc != null) {
|
||||
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
if (mLocationOverlay.isFollowLocationEnabled()) {
|
||||
map.getController().setCenter(currentPoint);
|
||||
}
|
||||
if (serviceGps.isTraceurActivated()) {
|
||||
updateTrailTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += loc.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
lastLocation = loc;
|
||||
} else if (serviceGps.isDogActivated()) {
|
||||
updateDogTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += loc.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
lastLocation = loc;
|
||||
}
|
||||
|
||||
float orientation = serviceGps.getOrientation(deviceOrientation);
|
||||
if (orientation >= 0) {
|
||||
map.setMapOrientation(orientation);
|
||||
}
|
||||
|
||||
if (!zoomed) {
|
||||
IMapController mapController = map.getController();
|
||||
mapController.setZoom(20.0);
|
||||
zoomed = true;
|
||||
}
|
||||
}
|
||||
onNewGeoloc(loc);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateServiceXmpp(Object o) {
|
||||
if (o instanceof String) {
|
||||
if (o.equals(ServiceXmpp.NOTIF_NEW_LOCATION)) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MyLocation loc = serviceXmpp.getCurrentLocation();
|
||||
onNewGeoloc(loc);
|
||||
}
|
||||
});
|
||||
} else if (o.equals(ServiceXmpp.NOTIF_START_TRAIL)){
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
changeStatusTrace();
|
||||
}
|
||||
});
|
||||
} else if (o.equals(ServiceXmpp.NOTIF_STOP_TRAIL)){
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
changeStatusTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onNewGeoloc(MyLocation loc) {
|
||||
if (loc != null) {
|
||||
serviceGps.addPoint(loc);
|
||||
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
if (mLocationOverlay.isFollowLocationEnabled()) {
|
||||
map.getController().setCenter(currentPoint);
|
||||
}
|
||||
if (serviceGps.isTraceurActivated()) {
|
||||
updateTrailTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += loc.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
lastLocation = loc;
|
||||
} else if (serviceGps.isDogActivated()) {
|
||||
updateDogTrace();
|
||||
if (lastLocation != null) {
|
||||
distance += loc.distanceTo(lastLocation);
|
||||
updateDistance();
|
||||
}
|
||||
lastLocation = loc;
|
||||
}
|
||||
|
||||
float orientation = serviceGps.getOrientation(deviceOrientation);
|
||||
if (orientation >= 0) {
|
||||
map.setMapOrientation(orientation);
|
||||
}
|
||||
|
||||
if (!zoomed) {
|
||||
IMapController mapController = map.getController();
|
||||
mapController.setZoom(20.0);
|
||||
zoomed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<GeoPoint> convertListLocation(MyLocationArray list) {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public class QRCodeGeneratorActivity extends Activity {
|
|||
|
||||
private ImageView imageView;
|
||||
private static Bitmap image = null;
|
||||
private static boolean generating = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -26,12 +27,19 @@ public class QRCodeGeneratorActivity extends Activity {
|
|||
setContentView(R.layout.qr_code_generator);
|
||||
|
||||
imageView = findViewById(R.id.qr_code_image);
|
||||
while (generating) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
if (image != null) {
|
||||
imageView.setImageBitmap(image);
|
||||
}
|
||||
}
|
||||
|
||||
public static void textToImageEncode(String value, Resources resources) throws WriterException {
|
||||
generating = true;
|
||||
Log.i(TAG, "QR CODE "+value);
|
||||
BitMatrix bitMatrix;
|
||||
try {
|
||||
|
|
@ -56,5 +64,6 @@ public class QRCodeGeneratorActivity extends Activity {
|
|||
image = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
|
||||
image.setPixels(pixels, 0, 500, 0, 0, bitMatrixWidth, bitMatrixHeight);
|
||||
Log.i(TAG, "FIN GENERATION QR CODE");
|
||||
generating = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,16 +20,24 @@ public class Traces {
|
|||
|
||||
|
||||
public void addPointTraceur(MyLocation point) {
|
||||
listPointTraceur.add(point);
|
||||
if (point != null) {
|
||||
listPointTraceur.add(point);
|
||||
}
|
||||
}
|
||||
public void addPointDog(MyLocation point) {
|
||||
listPointDog.add(point);
|
||||
if (point != null) {
|
||||
listPointDog.add(point);
|
||||
}
|
||||
}
|
||||
public void addPointObjectTrail(WayPointLocation point) {
|
||||
listPointObjectsTrail.add(point);
|
||||
if (point != null) {
|
||||
listPointObjectsTrail.add(point);
|
||||
}
|
||||
}
|
||||
public void addPointObjectDog(WayPointLocation point) {
|
||||
listPointObjectsDog.add(point);
|
||||
if (point != null) {
|
||||
listPointObjectsDog.add(point);
|
||||
}
|
||||
}
|
||||
public WayPointLocation getPointObjectTrail(double lat, double lon) {
|
||||
WayPointLocation ret = null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
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.jxmpp.jid.Jid;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.services.ServiceXmpp;
|
||||
|
||||
public class StartTrailGeolocCommand extends LocalCommand {
|
||||
|
||||
private final ServiceXmpp serviceXmpp;
|
||||
|
||||
public StartTrailGeolocCommand(ServiceXmpp serviceXmpp) {
|
||||
this.serviceXmpp = serviceXmpp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLastStage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Jid jid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.startTrailGeoloc();
|
||||
}
|
||||
this.addNote(new AdHocCommandNote(AdHocCommandNote.Type.info, "SUCCESS"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||
}
|
||||
|
||||
@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 {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
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.jxmpp.jid.Jid;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.services.ServiceXmpp;
|
||||
|
||||
public class StopTrailGeolocCommand extends LocalCommand {
|
||||
|
||||
private final ServiceXmpp serviceXmpp;
|
||||
|
||||
public StopTrailGeolocCommand(ServiceXmpp serviceXmpp) {
|
||||
this.serviceXmpp = serviceXmpp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLastStage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Jid jid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.stopTrailGeoloc();
|
||||
}
|
||||
this.addNote(new AdHocCommandNote(AdHocCommandNote.Type.info, "SUCCESS"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next(Form response) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException {
|
||||
}
|
||||
|
||||
@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,5 +1,6 @@
|
|||
package fr.chteufleur.mytrackingdog.models.xmpp.commands;
|
||||
|
||||
import android.app.Service;
|
||||
import android.util.Log;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
|
|
@ -13,6 +14,8 @@ import org.jxmpp.jid.Jid;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.services.ServiceXmpp;
|
||||
|
||||
public class TrailGeolocCommand extends LocalCommand {
|
||||
|
||||
public static final String TAG = TrailGeolocCommand.class.getName();
|
||||
|
|
@ -21,10 +24,11 @@ public class TrailGeolocCommand extends LocalCommand {
|
|||
public static final String FIELD_PARAM_LONGITUDE = "longitude";
|
||||
public static final String FIELD_PARAM_TIME = "time";
|
||||
|
||||
private long latitude;
|
||||
private long longitude;
|
||||
private int time;
|
||||
private final ServiceXmpp serviceXmpp;
|
||||
|
||||
public TrailGeolocCommand(ServiceXmpp serviceXmpp) {
|
||||
this.serviceXmpp = serviceXmpp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLastStage() {
|
||||
|
|
@ -33,7 +37,6 @@ public class TrailGeolocCommand extends LocalCommand {
|
|||
|
||||
@Override
|
||||
public boolean hasPermission(Jid jid) {
|
||||
// TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -72,16 +75,33 @@ public class TrailGeolocCommand extends LocalCommand {
|
|||
List<String> longitudeStrs = response.getField(FIELD_PARAM_LONGITUDE).getValues();
|
||||
List<String> timeStrs = response.getField(FIELD_PARAM_TIME).getValues();
|
||||
|
||||
long latitude = 0, longitude = 0;
|
||||
int time = 0;
|
||||
for (String latitudeStr : latitudeStrs) {
|
||||
Log.i(TAG, "Next latitude: " + latitudeStr);
|
||||
try {
|
||||
latitude = Long.parseLong(latitudeStr);
|
||||
break;
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
for (String longitudeStr : longitudeStrs) {
|
||||
Log.i(TAG, "Next longitude: " + longitudeStr);
|
||||
try {
|
||||
longitude = Long.parseLong(longitudeStr);
|
||||
break;
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
for (String timeStr : timeStrs) {
|
||||
Log.i(TAG, "Next time: " + timeStr);
|
||||
try {
|
||||
time = Integer.parseInt(timeStr);
|
||||
break;
|
||||
} catch (NumberFormatException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
if (serviceXmpp != null && latitude != 0 && longitude != 0 && time != 0) {
|
||||
serviceXmpp.addTrailGeoloc(latitude, longitude, time);
|
||||
}
|
||||
this.addNote(new AdHocCommandNote(AdHocCommandNote.Type.info, "SUCCESS"));
|
||||
} else {
|
||||
this.addNote((new AdHocCommandNote(AdHocCommandNote.Type.error, "FAIL")));
|
||||
|
|
|
|||
|
|
@ -123,11 +123,13 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
return this.vibrationNearObjectEnabled;
|
||||
}
|
||||
|
||||
public void addPoint(MyLocation location) {
|
||||
traces.addCurrentPoint(location);
|
||||
}
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.i(TAG, "onLocationChanged");
|
||||
currentLocation = new MyLocation(location);
|
||||
traces.addCurrentPoint(currentLocation);
|
||||
setChanged();
|
||||
notifyObservers(NOTIF_NEW_LOCATION);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,12 +17,11 @@ import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|||
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.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.jid.impl.LocalAndDomainpartJid;
|
||||
import org.jxmpp.jid.impl.LocalDomainAndResourcepartJid;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -31,15 +30,25 @@ import java.net.UnknownHostException;
|
|||
import java.util.Observable;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.QRCodeGeneratorActivity;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StartTrailGeolocCommand;
|
||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StopTrailGeolocCommand;
|
||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.TrailGeolocCommand;
|
||||
|
||||
public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||
|
||||
public static final String TAG = ServiceXmpp.class.getName();
|
||||
|
||||
public static final String NOTIF_NEW_LOCATION = ServiceXmpp.class.getName()+".newlocation";
|
||||
public static final String NOTIF_START_TRAIL = ServiceXmpp.class.getName()+".starttrail";
|
||||
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_START_TRAIL_GEOLOC = "start_trail_geoloc";
|
||||
private static final String XMPP_NODE_STOP_TRAIL_GEOLOC = "stop_trail_geoloc";
|
||||
|
||||
private static final String XMPP_IP_SERVER = "51.254.205.203";
|
||||
private static final String XMPP_DOMAIN_SERVER = "anon.xmpp.kingpenguin.tk";
|
||||
//private static final String XMPP_DOMAIN_SERVER = "kingpenguin.tk";
|
||||
private static final int XMPP_PORT = 5222;
|
||||
|
||||
private final Resources resources;
|
||||
|
|
@ -47,10 +56,9 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
private AdHocCommandManager commandManager;
|
||||
private AbstractXMPPConnection connection;
|
||||
private String jid;
|
||||
|
||||
private String otherJid;
|
||||
|
||||
private Roster roster;
|
||||
private final ServiceXmpp thsi;
|
||||
|
||||
public ServiceXmpp(Resources resources) throws UnknownHostException, XmppStringprepException {
|
||||
this.resources = resources;
|
||||
|
|
@ -63,6 +71,7 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
.performSaslAnonymousAuthentication()
|
||||
.setKeystoreType(null)
|
||||
.build();
|
||||
this.thsi = this;
|
||||
}
|
||||
|
||||
public boolean connect() throws InterruptedException, XMPPException, SmackException, IOException {
|
||||
|
|
@ -77,7 +86,24 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
connection.connect();
|
||||
connection.login();
|
||||
|
||||
commandManager.registerCommand(XMPP_NODE_TRAIL_GEOLOC, XMPP_NODE_TRAIL_GEOLOC, TrailGeolocCommand.class);
|
||||
commandManager.registerCommand(XMPP_NODE_TRAIL_GEOLOC, XMPP_NODE_TRAIL_GEOLOC, new LocalCommandFactory() {
|
||||
@Override
|
||||
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
||||
return new TrailGeolocCommand(thsi);
|
||||
}
|
||||
});
|
||||
commandManager.registerCommand(XMPP_NODE_START_TRAIL_GEOLOC, XMPP_NODE_START_TRAIL_GEOLOC, new LocalCommandFactory() {
|
||||
@Override
|
||||
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
||||
return new StartTrailGeolocCommand(thsi);
|
||||
}
|
||||
});
|
||||
commandManager.registerCommand(XMPP_NODE_STOP_TRAIL_GEOLOC, XMPP_NODE_STOP_TRAIL_GEOLOC, new LocalCommandFactory() {
|
||||
@Override
|
||||
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
|
||||
return new StopTrailGeolocCommand(thsi);
|
||||
}
|
||||
});
|
||||
|
||||
roster = Roster.getInstanceFor(connection);
|
||||
roster.addPresenceEventListener(this);
|
||||
|
|
@ -86,12 +112,18 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
if (isConnected) {
|
||||
jid = connection.getUser().asEntityBareJidString();
|
||||
Log.i(TAG, "JID: "+jid);
|
||||
try {
|
||||
QRCodeGeneratorActivity.textToImageEncode(jid, resources);
|
||||
} catch (WriterException ex) {
|
||||
Log.e(TAG, "Failed to generate QR Code");
|
||||
}
|
||||
}
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
QRCodeGeneratorActivity.textToImageEncode(jid, resources);
|
||||
} catch (WriterException ex) {
|
||||
Log.e(TAG, "Failed to generate QR Code");
|
||||
}
|
||||
}
|
||||
};
|
||||
new Thread(r).start();
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
|
|
@ -167,6 +199,26 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
|||
}
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||
private MyLocation currentXmppLocation = null;
|
||||
public void startTrailGeoloc() {
|
||||
setChanged();
|
||||
notifyObservers(NOTIF_START_TRAIL);
|
||||
}
|
||||
public void stopTrailGeoloc() {
|
||||
setChanged();
|
||||
notifyObservers(NOTIF_STOP_TRAIL);
|
||||
}
|
||||
public void addTrailGeoloc(long lat, long lon, int time) {
|
||||
currentXmppLocation = new MyLocation(lat, lon, time);
|
||||
setChanged();
|
||||
notifyObservers(NOTIF_NEW_LOCATION);
|
||||
}
|
||||
public MyLocation getCurrentLocation() {
|
||||
return currentXmppLocation;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
public void setOtherJid(String otherJid) {
|
||||
this.otherJid = otherJid;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue