use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getPage.
/**
* Gets a Page from a pageId/name
* This is a sync method it will block until a response it returned
* @param pageId the pageId
* @return the Page requested
*/
public Page getPage(String pageId) throws IOException {
final Page page = new Page();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(pageId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
page.copy(t);
}
}, false, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return page;
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class Progress method actionPerformed.
/**
* {@inheritDoc}
*/
public void actionPerformed(ActionEvent evt) {
NetworkEvent ev = (NetworkEvent) evt;
if (ev.getConnectionRequest() == request) {
if (disposeOnCompletion && ev.getProgressType() == NetworkEvent.PROGRESS_TYPE_COMPLETED) {
dispose();
return;
}
if (autoShow && !showing) {
showing = true;
showModeless();
}
}
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getPhoto.
/**
* Gets a Photo from a photoId
* This is a sync method it will block until a response it returned
* @param the photoId
* @param needAuth if this object is public needAuth can be false and no
* authentication will be performed
* @return the Photo requested
*/
public Photo getPhoto(String photoId, boolean needAuth) throws IOException {
final Photo photo = new Photo();
final Vector err = new Vector();
addResponseCodeListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
NetworkEvent ne = (NetworkEvent) evt;
err.addElement(ne);
removeResponseCodeListener(this);
}
});
getFaceBookObject(photoId, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Vector v = (Vector) ((NetworkEvent) evt).getMetaData();
Hashtable t = (Hashtable) v.elementAt(0);
photo.copy(t);
}
}, needAuth, false);
if (err.size() > 0) {
throw new IOException(((NetworkEvent) err.elementAt(0)).getResponseCode() + ": " + ((NetworkEvent) err.elementAt(0)).getMessage());
}
return photo;
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FaceBookAccess method getUsersDetails.
/**
* Gets users requested details ((this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/))
*
* @param usersIds the users to query
* @param fields which fields to query on the users see http://developers.facebook.com/docs/reference/rest/users.getInfo/
* @param callback the result will call the callback with the result
* to extrct the data preform the following:
* public void actionPerformed(ActionEvent evt) {
* Vector data = (Vector) ((NetworkEvent) evt).getMetaData();
* Vector users = (Vector) data.elementAt(0);
* }
*/
public void getUsersDetails(String[] usersIds, String[] fields, final ActionListener callback) throws IOException {
checkAuthentication();
final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/users.getInfo", false);
String ids = usersIds[0];
int ulen = usersIds.length;
for (int i = 1; i < ulen; i++) {
ids += "," + usersIds[i];
}
con.addArgumentNoEncoding("uids", ids);
String fieldsStr = fields[0];
int flen = fields.length;
for (int i = 1; i < flen; i++) {
fieldsStr += "," + fields[i];
}
con.addArgumentNoEncoding("fields", fieldsStr);
con.addArgument("format", "json");
con.addResponseListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (!con.isAlive()) {
return;
}
if (callback != null) {
callback.actionPerformed(evt);
}
}
});
if (slider != null) {
SliderBridge.bindProgress(con, slider);
}
for (int i = 0; i < responseCodeListeners.size(); i++) {
con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
}
current = con;
NetworkManager.getInstance().addToQueue(con);
}
use of com.codename1.io.NetworkEvent in project CodenameOne by codenameone.
the class FacebookRESTService method readResponse.
protected void readResponse(InputStream input) throws IOException {
// BufferedInputStream i = new BufferedInputStream(new InputStreamReader(input, ));
BufferedInputStream i;
if (input instanceof BufferedInputStream) {
i = (BufferedInputStream) input;
} else {
i = new BufferedInputStream(input);
}
i.setYield(-1);
InputStreamReader reader = new InputStreamReader(i, "UTF-8");
JSONParser.parse(reader, this);
Util.cleanup(reader);
if (stack.size() > 0) {
fireResponseListener(new NetworkEvent(this, stack.elementAt(0)));
}
}
Aggregations