use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class ImageDownloadService method postResponse.
/**
* {@inheritDoc}
*/
protected void postResponse() {
// trigger an exception in case of an invalid image
result.getWidth();
Image image = result;
if (toScale != null && toScale.getWidth() != image.getWidth() && toScale.getHeight() != image.getHeight()) {
image = scaleImage(image, toScale, maintainAspectRatio);
}
final Image i = image;
if (parentLabel != null) {
final Dimension pref = parentLabel.getPreferredSize();
if (parentLabel.getComponentForm() != null) {
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (isDownloadToStyles()) {
parentLabel.getUnselectedStyle().setBgImage(i);
parentLabel.getSelectedStyle().setBgImage(i);
parentLabel.getPressedStyle().setBgImage(i);
} else {
parentLabel.setIcon(i);
}
Dimension newPref = parentLabel.getPreferredSize();
// sized image in place or has a hardcoded preferred size.
if (pref.getWidth() != newPref.getWidth() || pref.getHeight() != newPref.getHeight()) {
parentLabel.getComponentForm().revalidate();
}
}
});
} else {
Display.getInstance().callSerially(new Runnable() {
public void run() {
if (isDownloadToStyles()) {
parentLabel.getUnselectedStyle().setBgImage(i);
parentLabel.getSelectedStyle().setBgImage(i);
parentLabel.getPressedStyle().setBgImage(i);
} else {
parentLabel.setIcon(i);
}
}
});
}
parentLabel.repaint();
return;
} else {
if (targetList != null) {
setEntryInListModel(targetOffset, image);
// revalidate only once to avoid multiple revalidate refreshes during scroll
if (targetList.getParent() != null) {
if (alwaysRevalidate) {
targetList.getParent().revalidate();
} else {
if (targetList.getClientProperty("$imgDSReval") == null) {
targetList.putClientProperty("$imgDSReval", Boolean.TRUE);
targetList.getParent().revalidate();
} else {
targetList.repaint();
}
}
}
}
}
// if this is a list cell renderer component
fireResponseListener(new NetworkEvent(this, result));
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getUser.
/**
* Gets a User from a user id
* This is a sync method it will block until a response it returned
* @param userId the user id or null to get details on the authenticated user
* @return the User requested
*/
public User getUser(String userId) throws IOException {
String id = userId;
if (id == null) {
id = "me";
}
final User user = new User();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(id, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
user.copy(t);
}
}, true, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return user;
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getUser.
/**
* Gets a user from a user id
*
* @param userId the user id or null to get detaild on the authenticated user
* @param user an object to fill with the user details
* @param callback the callback that should be updated when the data arrives
*/
public void getUser(String userId, final User user, final ActionListener callback) throws IOException {
String id = userId;
if (id == null) {
id = "me";
}
getFaceBookObject(id, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
if (user != null) {
user.copy(t);
}
if (callback != null) {
callback.actionPerformed(evt);
}
}
});
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getPost.
/**
* Gets a Post from a postId
* This is a sync method it will block until a response it returned
* @param postId the post id
* @param needAuth if this object is public needAuth can be false and no
* authentication will be performed
* @return the Post requested
*/
public Post getPost(String postId, boolean needAuth) throws IOException {
final Post post = new Post();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(postId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
post.copy(t);
}
}, needAuth, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return post;
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getAlbum.
/**
* Gets a Album from a albumId
* This is a sync method it will block until a response it returned
* @param the albumId
* @param needAuth if this object is public needAuth can be false and no
* authentication will be performed
*
* @return the Album requested
*/
public Album getAlbum(String albumId, boolean needAuth) throws IOException {
final Album album = new Album();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(albumId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
album.copy(t);
}
}, needAuth, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return album;
}
Aggregations