Search in sources :

Example 11 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class FaceBookAccess method postOnWall.

/**
 * Post a message on the users wall
 *
 * @param userId the userId
 * @param message the message to post
 * @param name
 * @param link
 * @param description
 * @param picture
 * @param caption
 */
public void postOnWall(String userId, String message, String name, String link, String description, String picture, String caption, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, userId, FacebookRESTService.FEED, true);
    if (message != null) {
        con.addArgument("message", message);
    }
    if (name != null) {
        con.addArgument("name", name);
    }
    if (link != null) {
        con.addArgument("link", link);
    }
    if (description != null) {
        con.addArgument("description", description);
    }
    if (picture != null) {
        con.addArgument("picture", picture);
    }
    if (caption != null) {
        con.addArgument("caption", caption);
    }
    con.addResponseListener(new Listener(con, callback));
    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().addToQueueAndWait(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener)

Example 12 with ActionListener

use of com.codename1.ui.events.ActionListener 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;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) IOException(java.io.IOException) Vector(java.util.Vector)

Example 13 with ActionListener

use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.

the class FaceBookAccess method getPictureAndWait.

/**
 * Gets the picture of the given facebook object id
 *
 * @param id the object id to query
 * @param toScale picture dimension or null
 * @return the picture
 */
public EncodedImage getPictureAndWait(String id, Dimension toScale) {
    ImageDownloadService im = new ImageDownloadService(getImageURL(id, toScale), (ActionListener) null);
    NetworkManager.getInstance().addToQueueAndWait(im);
    return im.getResult();
}
Also used : ImageDownloadService(com.codename1.io.services.ImageDownloadService)

Example 14 with ActionListener

use of com.codename1.ui.events.ActionListener 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);
            }
        }
    });
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) Vector(java.util.Vector)

Example 15 with ActionListener

use of com.codename1.ui.events.ActionListener 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;
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) NetworkEvent(com.codename1.io.NetworkEvent) IOException(java.io.IOException) Vector(java.util.Vector)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)61 ActionListener (com.codename1.ui.events.ActionListener)61 IOException (java.io.IOException)25 BorderLayout (com.codename1.ui.layouts.BorderLayout)20 EventDispatcher (com.codename1.ui.util.EventDispatcher)16 Hashtable (java.util.Hashtable)14 NetworkEvent (com.codename1.io.NetworkEvent)13 Form (com.codename1.ui.Form)13 Vector (java.util.Vector)11 Container (com.codename1.ui.Container)10 Button (com.codename1.ui.Button)8 ActionEvent (java.awt.event.ActionEvent)8 ActionListener (java.awt.event.ActionListener)8 Dialog (com.codename1.ui.Dialog)7 EncodedImage (com.codename1.ui.EncodedImage)6 Image (com.codename1.ui.Image)6 Label (com.codename1.ui.Label)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6