Search in sources :

Example 31 with Data

use of com.codename1.ui.util.xml.Data 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 32 with Data

use of com.codename1.ui.util.xml.Data 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 33 with Data

use of com.codename1.ui.util.xml.Data 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)

Example 34 with Data

use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.

the class FaceBookAccess method anonymousLogin.

/**
 * Some simple queries for public data can work just fine with anonymous login without requiring the whole
 * OAuth process, they still need a facebook application though
 * @param appid the id of the application
 * @param clientSecret the client secret for the application
 */
public static void anonymousLogin(String appid, String clientSecret) {
    ConnectionRequest req = new ConnectionRequest();
    req.setPost(false);
    req.setUrl("https://graph.facebook.com/oauth/access_token");
    req.addArgument("client_id", appid);
    req.addArgument("client_secret", clientSecret);
    req.addArgument("grant_type", "client_credentials");
    NetworkManager.getInstance().addToQueueAndWait(req);
    if (req.getResponseData() != null) {
        token = new String(req.getResponseData());
        token = token.substring(token.indexOf('=') + 1);
    }
}
Also used : ConnectionRequest(com.codename1.io.ConnectionRequest)

Example 35 with Data

use of com.codename1.ui.util.xml.Data 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
 */
public void getFaceBookObject(String faceBookId, final ActionListener callback) throws IOException {
    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;
    NetworkManager.getInstance().addToQueue(con);
}
Also used : ActionListener(com.codename1.ui.events.ActionListener) ActionEvent(com.codename1.ui.events.ActionEvent)

Aggregations

IOException (java.io.IOException)18 EncodedImage (com.codename1.ui.EncodedImage)12 Hashtable (java.util.Hashtable)12 Image (com.codename1.ui.Image)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)9 FileInputStream (java.io.FileInputStream)8 ActionEvent (com.codename1.ui.events.ActionEvent)7 ActionListener (com.codename1.ui.events.ActionListener)7 FileEncodedImage (com.codename1.components.FileEncodedImage)6 ConnectionRequest (com.codename1.io.ConnectionRequest)6 File (java.io.File)6 Intent (android.content.Intent)5 StorageImage (com.codename1.components.StorageImage)5 IntentResultListener (com.codename1.impl.android.IntentResultListener)5 EditableResources (com.codename1.ui.util.EditableResources)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DataInputStream (java.io.DataInputStream)5 Vector (java.util.Vector)5 CodenameOneActivity (com.codename1.impl.android.CodenameOneActivity)4