Search in sources :

Example 51 with ActionEvent

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

the class FloatingActionButton method released.

@Override
public void released(int x, int y) {
    super.released(x, y);
    if (current != null) {
        current.dispose();
        current = null;
    }
    // if this fab has sub fab's display them
    if (subMenu != null) {
        final Container con = createPopupContent(subMenu);
        Dialog d = new Dialog();
        d.setDialogUIID("Container");
        d.getContentPane().setUIID("Container");
        d.setLayout(new BorderLayout());
        d.add(BorderLayout.CENTER, con);
        for (FloatingActionButton next : subMenu) {
            next.current = d;
        }
        d.setTransitionInAnimator(CommonTransitions.createEmpty());
        d.setTransitionOutAnimator(CommonTransitions.createEmpty());
        for (Component c : con) {
            c.setVisible(false);
        }
        Form f = getComponentForm();
        int oldTint = f.getTintColor();
        f.setTintColor(0);
        d.setBlurBackgroundRadius(-1);
        d.addShowListener(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                for (Component c : con) {
                    c.setY(con.getHeight());
                    c.setVisible(true);
                }
                con.animateLayout(200);
            }
        });
        showPopupDialog(d);
        f.setTintColor(oldTint);
        for (FloatingActionButton next : subMenu) {
            next.remove();
        }
        con.removeAll();
    }
}
Also used : Container(com.codename1.ui.Container) BorderLayout(com.codename1.ui.layouts.BorderLayout) ActionListener(com.codename1.ui.events.ActionListener) Form(com.codename1.ui.Form) Dialog(com.codename1.ui.Dialog) ActionEvent(com.codename1.ui.events.ActionEvent) Component(com.codename1.ui.Component)

Example 52 with ActionEvent

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

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

Example 54 with ActionEvent

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

the class FaceBookAccess method getUserNotifications.

/**
 * Gets the user notifications (this method uses the legacy rest api see http://developers.facebook.com/docs/reference/rest/)
 *
 * @param userId the user id
 * @param startTime Indicates the earliest time to return a notification.
 * This equates to the updated_time field in the notification FQL table. If not specified, this call returns all available notifications.
 * @param includeRead Indicates whether to include notifications that have already been read.
 * By default, notifications a user has read are not included.
 * @param notifications store notifications results into the given model,
 * each entry is an Hashtable Object contaning the Object data
 * @param callback the callback that should be updated when the data arrives
 */
public void getUserNotifications(String userId, String startTime, boolean includeRead, DefaultListModel notifications, final ActionListener callback) throws IOException {
    checkAuthentication();
    final FacebookRESTService con = new FacebookRESTService(token, "https://api.facebook.com/method/notifications.getList", false);
    con.addArgument("start_time", startTime);
    con.addArgument("include_read", new Boolean(includeRead).toString());
    con.addArgument("format", "json");
    con.setResponseDestination(notifications);
    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);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Example 55 with ActionEvent

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

the class FaceBookAccess method getFaceBookObject.

/**
 * This method returns immediately and will call the callback when it returns with
 * the FaceBook Object data.
 *
 * @param faceBookId the object id that we would like to query
 * @param callback the callback that should be updated when the data arrives
 * @param needToken if true authentication is being checked
 */
public void getFaceBookObject(String faceBookId, final ActionListener callback, boolean needToken, boolean async) throws IOException {
    if (needToken) {
        checkAuthentication();
    }
    final FacebookRESTService con = new FacebookRESTService(token, faceBookId, "", false);
    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;
    if (async) {
        NetworkManager.getInstance().addToQueue(con);
    } else {
        NetworkManager.getInstance().addToQueueAndWait(con);
    }
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)98 ActionListener (com.codename1.ui.events.ActionListener)55 IOException (java.io.IOException)30 BorderLayout (com.codename1.ui.layouts.BorderLayout)28 Form (com.codename1.ui.Form)18 Hashtable (java.util.Hashtable)14 Vector (java.util.Vector)11 NetworkEvent (com.codename1.io.NetworkEvent)10 Container (com.codename1.ui.Container)9 ActionEvent (java.awt.event.ActionEvent)9 Command (com.codename1.ui.Command)8 ActionListener (java.awt.event.ActionListener)8 Button (com.codename1.ui.Button)7 Style (com.codename1.ui.plaf.Style)7 Rectangle (com.codename1.ui.geom.Rectangle)6 File (java.io.File)6 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)6 MediaException (javax.microedition.media.MediaException)6 RecordStoreException (javax.microedition.rms.RecordStoreException)6 BufferedOutputStream (com.codename1.io.BufferedOutputStream)5