}
});
xmppSession.getExtensionManager(EntityCapabilitiesManager.class).setEnabled(true);
GeoLocationManager geoLocationManager = xmppSession.getExtensionManager(GeoLocationManager.class);
geoLocationManager.addGeoLocationListener(new GeoLocationListener() {
@Override
public void geoLocationUpdated(GeoLocationEvent e) {
int i = 0;
}
});
SoftwareVersionManager softwareVersionManager = xmppSession.getExtensionManager(SoftwareVersionManager.class);
softwareVersionManager.setSoftwareVersion(new SoftwareVersion("Babbler", "0.1"));
final FileTransferManager fileTransferManager = xmppSession.getExtensionManager(FileTransferManager.class);
fileTransferManager.addFileTransferOfferListener(new FileTransferOfferListener() {
@Override
public void fileTransferOffered(FileTransferOfferEvent e) {
try {
OutputStream outputStream = new FileOutputStream("test222.png");
//e.reject();
final FileTransfer fileTransfer = e.accept(outputStream);
fileTransfer.transfer();
AnimationTimer animationTimer = new AnimationTimer() {
@Override
public void handle(long now) {
System.out.println(fileTransfer.getProgress());
if (fileTransfer.isDone()) {
stop();
}
}
};
animationTimer.start();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
try {
xmppSession.connect();
xmppSession.login(txtUser.getText(), txtPassword.getText(), "test");
//xmppSession.loginAnonymously();
Presence presence = new Presence();
xmppSession.send(presence);
//xmppSession.getRosterManager().requestRoster();
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
});
ListView<ContactItem> listView = new ListView<>();
listView.setCellFactory(new Callback<ListView<ContactItem>, ListCell<ContactItem>>() {
@Override
public ListCell<ContactItem> call(ListView<ContactItem> contactListView) {
final ListCell<ContactItem> listCell = new ListCell<ContactItem>() {
@Override
protected void updateItem(final ContactItem item, boolean empty) {
super.updateItem(item, empty);
setGraphic(null);
setContextMenu(null);
if (item != null) {
final Jid user = item.contact.get().getJid();
if (item.avatar.get() == null) {
final Task<byte[]> task = new Task<byte[]>() {
@Override
protected byte[] call() throws Exception {
AvatarManager avatarManager = xmppSession.getExtensionManager(AvatarManager.class);
return avatarManager.getAvatar(user);
}
};
task.stateProperty().addListener(new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends Worker.State> observableValue, Worker.State state, Worker.State state2) {
switch (state2) {
case SUCCEEDED:
byte[] avatar = task.getValue();
if (avatar != null) {
item.avatar.set(avatar);
}
}
}
});
new Thread(task).start();
}
setGraphic(new ContactItemView(item));
ContextMenu contextMenu = new ContextMenu();
MenuItem lastActivityMenuItem = new MenuItem("Get last activity");
lastActivityMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
LastActivityManager lastActivityManager = xmppSession.getExtensionManager(LastActivityManager.class);
try {
lastActivityManager.getLastActivity(item.contact.get().getJid().withResource("test"));
} catch (XmppException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
});
MenuItem pingMenuItem = new MenuItem("Ping");
pingMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
PingManager pingManager = xmppSession.getExtensionManager(PingManager.class);
try {
pingManager.pingServer();
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem searchMenuItem = new MenuItem("Search");
searchMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
SearchManager searchManager = xmppSession.getExtensionManager(SearchManager.class);
try {
Search search = new Search("22*", null, null, null);
searchManager.discoverSearchFields(new Jid("search.dev"));
Search result = searchManager.search(search, new Jid("search.dev"));
for (Search.Item item : result.getItems()) {
System.out.println(item.getJid());
}
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem softwareVersionItem = new MenuItem("Get Software Version");
softwareVersionItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
SoftwareVersionManager softwareVersionManager = xmppSession.getExtensionManager(SoftwareVersionManager.class);
try {
SoftwareVersion softwareVersion = softwareVersionManager.getSoftwareVersion(item.contact.get().getJid());
if (softwareVersion != null)
System.out.println(softwareVersion.getName());
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem serviceDiscoveryMenuItem = new MenuItem("Discover Info");
serviceDiscoveryMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
ServiceDiscoveryManager serviceDiscoveryManager = xmppSession.getExtensionManager(ServiceDiscoveryManager.class);
try {
Jid jid = new Jid(item.contact.get().getJid().getLocal(), item.contact.get().getJid().getDomain());
InfoNode infoNode = serviceDiscoveryManager.discoverInformation(null);
int i = 0;
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem vCardItem = new MenuItem("Get VCard");
vCardItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
VCardManager vCardManager = xmppSession.getExtensionManager(VCardManager.class);
try {
Jid jid = new Jid(item.contact.get().getJid().getLocal(), item.contact.get().getJid().getDomain());
VCard vCard = vCardManager.getVCard(jid);
int i = 0;
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem storeAnnotationsItems = new MenuItem("Store annotations");
storeAnnotationsItems.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
PrivateDataManager privateDataManager = xmppSession.getExtensionManager(PrivateDataManager.class);
try {
List<Annotation.Note> notes = new ArrayList<>();
notes.add(new Annotation.Note("Hallo", item.contact.get().getJid()));
privateDataManager.storeData(new Annotation(notes));
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem getAnnotationsItems = new MenuItem("Get annotations");
getAnnotationsItems.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
PrivateDataManager privateDataManager = xmppSession.getExtensionManager(PrivateDataManager.class);
try {
Annotation annotations = privateDataManager.getData(Annotation.class);
int i = 0;
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem pubSubItem = new MenuItem("PubSub");
pubSubItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
PubSubManager pubSubManager = xmppSession.getExtensionManager(PubSubManager.class);
ServiceDiscoveryManager serviceDiscoveryManager = xmppSession.getExtensionManager(ServiceDiscoveryManager.class);
try {
ItemNode infoNode = serviceDiscoveryManager.discoverItems(null);
int i = 0;
} catch (XmppException e) {
e.printStackTrace();
}
}
});
MenuItem pepItem = new MenuItem("PEP");
pepItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
try {
GeoLocationManager geoLocationManager = xmppSession.getExtensionManager(GeoLocationManager.class);
geoLocationManager.publish(new GeoLocation(45.44, 12.33));
} catch (XmppException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}