Search in sources :

Example 16 with ActionListener

use of com.codename1.ui.events.ActionListener 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;
}
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 17 with ActionListener

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

the class FaceBookAccess method getFaceBookObjectItems.

/**
 * Get a list of FaceBook objects for a given id
 *
 * @param faceBookId the id to preform the query upon
 * @param itemsConnection the type of the query
 * @param feed
 * @param params
 * @param callback the callback that should be updated when the data arrives
 */
public void getFaceBookObjectItems(String faceBookId, String itemsConnection, final DefaultListModel feed, Hashtable params, final ActionListener callback) throws IOException {
    checkAuthentication();
    final FacebookRESTService con = new FacebookRESTService(token, faceBookId, itemsConnection, false);
    con.setResponseDestination(feed);
    con.addResponseListener(new Listener(con, callback));
    if (params != null) {
        Enumeration keys = params.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            con.addArgument(key, (String) params.get(key));
        }
    }
    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);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) Enumeration(java.util.Enumeration)

Example 18 with ActionListener

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

the class FaceBookAccess method postComment.

/**
 * Post a comment on a given post
 *
 * @param postId the post id
 * @param message the message to post
 */
public void postComment(String postId, String message, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, postId, FacebookRESTService.COMMENTS, true);
    con.addResponseListener(new Listener(con, callback));
    con.addArgument("message", "" + message);
    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 19 with ActionListener

use of com.codename1.ui.events.ActionListener 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;
}
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 20 with ActionListener

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

the class FaceBookAccess method createNote.

/**
 * Post a note onto the users wall
 *
 * @param userId the userId
 * @param message the message to post
 */
public void createNote(String userId, String subject, String message, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, userId, FacebookRESTService.NOTES, true);
    con.addResponseListener(new Listener(con, callback));
    con.addArgument("subject", "" + subject);
    con.addArgument("message", "" + message);
    if (slider != null) {
        SliderBridge.bindProgress(con, slider);
    }
    for (int i = 0; i < responseCodeListeners.size(); i++) {
        con.addResponseCodeListener((ActionListener) responseCodeListeners.elementAt(i));
    }
    current = con;
    System.out.println(con.getUrl());
    NetworkManager.getInstance().addToQueueAndWait(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener)

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