Search in sources :

Example 6 with Callback

use of com.codename1.util.Callback 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 7 with Callback

use of com.codename1.util.Callback 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 8 with Callback

use of com.codename1.util.Callback 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 9 with Callback

use of com.codename1.util.Callback 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)

Example 10 with Callback

use of com.codename1.util.Callback in project CodenameOne by codenameone.

the class AndroidImplementation method startBackgroundFetchService.

/**
 * Starts the background fetch service.
 */
public void startBackgroundFetchService() {
    LocalNotification n = new LocalNotification();
    n.setId(BACKGROUND_FETCH_NOTIFICATION_ID);
    cancelLocalNotification(BACKGROUND_FETCH_NOTIFICATION_ID);
    // We schedule a local notification
    // First callback will be at the repeat interval
    // We don't specify a repeat interval because the scheduleLocalNotification will
    // set that for us using the getPreferredBackgroundFetchInterval method.
    scheduleLocalNotification(n, System.currentTimeMillis() + getPreferredBackgroundFetchInterval() * 1000, 0);
}
Also used : LocalNotification(com.codename1.notifications.LocalNotification)

Aggregations

ActionListener (com.codename1.ui.events.ActionListener)14 ActionEvent (com.codename1.ui.events.ActionEvent)12 IOException (java.io.IOException)11 ConnectionRequest (com.codename1.io.ConnectionRequest)10 EventDispatcher (com.codename1.ui.util.EventDispatcher)8 NetworkEvent (com.codename1.io.NetworkEvent)6 InputStream (java.io.InputStream)5 Intent (android.content.Intent)4 ComponentAnimation (com.codename1.ui.animations.ComponentAnimation)4 ArrayList (java.util.ArrayList)4 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 Uri (android.net.Uri)3 IntentResultListener (com.codename1.impl.android.IntentResultListener)3 AccessToken (com.codename1.io.AccessToken)3 GZConnectionRequest (com.codename1.io.gzip.GZConnectionRequest)3 EncodedImage (com.codename1.ui.EncodedImage)3 Image (com.codename1.ui.Image)3 File (java.io.File)3 OutputStream (java.io.OutputStream)3 RandomAccessFile (java.io.RandomAccessFile)3