mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-22 10:37:59 +01:00
Add pubsub publishing and altaccuracy parameter to geoloc
This commit is contained in:
parent
f8f70bc5fb
commit
632c172f6d
5 changed files with 78 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2016 Ishan Khanna
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -21,12 +21,18 @@ import java.util.WeakHashMap;
|
|||
|
||||
import org.jivesoftware.smack.ConnectionCreationListener;
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPConnectionRegistry;
|
||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
|
||||
import org.jivesoftware.smackx.geoloc.packet.GeoLocation;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PayloadItem;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubException.NotALeafNodeException;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
|
@ -86,4 +92,39 @@ public final class GeoLocationManager extends Manager {
|
|||
return GeoLocation.from(message) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send geolocation through the PubSub node.
|
||||
*
|
||||
* @param geoLocation
|
||||
* @throws InterruptedException
|
||||
* @throws NotConnectedException
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws NotALeafNodeException
|
||||
*/
|
||||
public void sendGeolocation(GeoLocation geoLocation)
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException {
|
||||
getNode().publish(new PayloadItem<GeoLocation>(geoLocation));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send empty geolocation through the PubSub node.
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* @throws NotConnectedException
|
||||
* @throws XMPPErrorException
|
||||
* @throws NoResponseException
|
||||
* @throws NotALeafNodeException
|
||||
*/
|
||||
public void stopPublishingGeolocation()
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException {
|
||||
GeoLocation emptyGeolocation = new GeoLocation.Builder().build();
|
||||
getNode().publish(new PayloadItem<GeoLocation>(emptyGeolocation));
|
||||
}
|
||||
|
||||
private LeafNode getNode()
|
||||
throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotALeafNodeException {
|
||||
return PubSubManager.getInstance(connection()).getOrCreateLeafNode(GeoLocation.NAMESPACE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2016 Ishan Khanna
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -43,6 +43,7 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
|
||||
private final Double accuracy;
|
||||
private final Double alt;
|
||||
private final Double altAccuracy;
|
||||
private final String area;
|
||||
private final Double bearing;
|
||||
private final String building;
|
||||
|
@ -65,12 +66,13 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
private final String tzo;
|
||||
private final URI uri;
|
||||
|
||||
private GeoLocation(Double accuracy, Double alt, String area, Double bearing, String building, String country,
|
||||
private GeoLocation(Double accuracy, Double alt, Double altAccuracy, String area, Double bearing, String building, String country,
|
||||
String countryCode, String datum, String description, Double error, String floor, Double lat,
|
||||
String locality, Double lon, String postalcode, String region, String room, Double speed,
|
||||
String street, String text, Date timestamp, String tzo, URI uri) {
|
||||
this.accuracy = accuracy;
|
||||
this.alt = alt;
|
||||
this.altAccuracy = altAccuracy;
|
||||
this.area = area;
|
||||
this.bearing = bearing;
|
||||
this.building = building;
|
||||
|
@ -118,6 +120,10 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
return alt;
|
||||
}
|
||||
|
||||
public Double getAltAccuracy() {
|
||||
return altAccuracy;
|
||||
}
|
||||
|
||||
public String getArea() {
|
||||
return area;
|
||||
}
|
||||
|
@ -213,6 +219,7 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
xml.rightAngleBracket();
|
||||
xml.optElement("accuracy", accuracy);
|
||||
xml.optElement("alt", alt);
|
||||
xml.optElement("altaccuracy", altAccuracy);
|
||||
xml.optElement("area", area);
|
||||
xml.optElement("bearing", bearing);
|
||||
xml.optElement("building", building);
|
||||
|
@ -255,6 +262,7 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
|
||||
private Double accuracy;
|
||||
private Double alt;
|
||||
private Double altAccuracy;
|
||||
private String area;
|
||||
private Double bearing;
|
||||
private String building;
|
||||
|
@ -287,6 +295,11 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder setAltAccuracy(Double altAccuracy) {
|
||||
this.altAccuracy = altAccuracy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setArea(String area) {
|
||||
this.area = area;
|
||||
return this;
|
||||
|
@ -394,7 +407,7 @@ public final class GeoLocation implements Serializable, ExtensionElement {
|
|||
|
||||
public GeoLocation build() {
|
||||
|
||||
return new GeoLocation(accuracy, alt, area, bearing, building, country, countryCode, datum, description,
|
||||
return new GeoLocation(accuracy, alt, altAccuracy, area, bearing, building, country, countryCode, datum, description,
|
||||
error, floor, lat, locality, lon, postalcode, region, room, speed, street, text, timestamp,
|
||||
tzo, uri);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2016 Ishan Khanna
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -48,6 +48,9 @@ public class GeoLocationProvider extends ExtensionElementProvider<GeoLocation> {
|
|||
case "alt":
|
||||
builder.setAlt(ParserUtils.getDoubleFromNextText(parser));
|
||||
break;
|
||||
case "altaccuracy":
|
||||
builder.setAltAccuracy(ParserUtils.getDoubleFromNextText(parser));
|
||||
break;
|
||||
case "area":
|
||||
builder.setArea(parser.nextText());
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2016 Ishan Khanna
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -72,6 +72,14 @@ public class GeoLocationTest extends InitExtensions {
|
|||
assertEquals((Double) 1.34, geoLocation.getAccuracy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void altAccuracyTest() {
|
||||
|
||||
GeoLocation geoLocation = new GeoLocation.Builder().setAltAccuracy(1.52d).build();
|
||||
|
||||
assertEquals((Double) 1.52, geoLocation.getAltAccuracy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toXMLMethodTest() throws Exception {
|
||||
|
||||
|
@ -81,6 +89,7 @@ public class GeoLocationTest extends InitExtensions {
|
|||
+ "<geoloc xmlns='http://jabber.org/protocol/geoloc'>"
|
||||
+ "<accuracy>23</accuracy>"
|
||||
+ "<alt>1000</alt>"
|
||||
+ "<altaccuracy>10</altaccuracy>"
|
||||
+ "<area>Delhi</area>"
|
||||
+ "<bearing>10</bearing>"
|
||||
+ "<building>Small Building</building>"
|
||||
|
@ -113,7 +122,7 @@ public class GeoLocationTest extends InitExtensions {
|
|||
assertNotNull(geoLocation);
|
||||
assertNotNull(geoLocation.toXML());
|
||||
|
||||
GeoLocation constructedGeoLocation = GeoLocation.builder().setAccuracy(23d).setAlt(1000d).setArea("Delhi").setBearing(
|
||||
GeoLocation constructedGeoLocation = GeoLocation.builder().setAccuracy(23d).setAlt(1000d).setAltAccuracy(10d).setArea("Delhi").setBearing(
|
||||
10d).setBuilding("Small Building").setCountry("India").setCountryCode("IN").setDescription(
|
||||
"My Description").setError(90d).setFloor("top").setLat(25.098345d).setLocality("awesome").setLon(
|
||||
77.992034).setPostalcode("110085").setRegion("North").setRoom("small").setSpeed(250.0d).setStreet(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015-2016 Ishan Khanna
|
||||
* Copyright 2015-2017 Ishan Khanna, Fernando Ramirez
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -41,6 +41,7 @@ public class GeoLocationProviderTest extends InitExtensions {
|
|||
+ "<geoloc xmlns='http://jabber.org/protocol/geoloc'>"
|
||||
+ "<accuracy>23</accuracy>"
|
||||
+ "<alt>1000</alt>"
|
||||
+ "<altaccuracy>10</altaccuracy>"
|
||||
+ "<area>Delhi</area>"
|
||||
+ "<bearing>10</bearing>"
|
||||
+ "<building>Small Building</building>"
|
||||
|
@ -74,6 +75,7 @@ public class GeoLocationProviderTest extends InitExtensions {
|
|||
|
||||
assertEquals((Double) 23d, geoLocation.getAccuracy());
|
||||
assertEquals((Double) 1000d, geoLocation.getAlt());
|
||||
assertEquals((Double) 10d, geoLocation.getAltAccuracy());
|
||||
assertEquals("Delhi", geoLocation.getArea());
|
||||
assertEquals((Double) 10d, geoLocation.getBearing());
|
||||
assertEquals("Small Building", geoLocation.getBuilding());
|
||||
|
@ -107,6 +109,7 @@ public class GeoLocationProviderTest extends InitExtensions {
|
|||
+ "<geoloc xmlns='http://jabber.org/protocol/geoloc'>"
|
||||
+ "<accuracy>23</accuracy>"
|
||||
+ "<alt>1000</alt>"
|
||||
+ "<altaccuracy>10</altaccuracy>"
|
||||
+ "<area>Delhi</area>"
|
||||
+ "<bearing>10</bearing>"
|
||||
+ "<building>Small Building</building>"
|
||||
|
@ -141,6 +144,7 @@ public class GeoLocationProviderTest extends InitExtensions {
|
|||
|
||||
assertEquals((Double) 23d, geoLocation.getAccuracy());
|
||||
assertEquals((Double) 1000d, geoLocation.getAlt());
|
||||
assertEquals((Double) 10d, geoLocation.getAltAccuracy());
|
||||
assertEquals("Delhi", geoLocation.getArea());
|
||||
assertEquals((Double) 10d, geoLocation.getBearing());
|
||||
assertEquals("Small Building", geoLocation.getBuilding());
|
||||
|
|
Loading…
Reference in a new issue