Search in sources :

Example 26 with Callback

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

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

the class FaceBookAccess method postLike.

/**
 * Post like on a given post
 *
 * @param postId the post Id
 */
public void postLike(String postId, ActionListener callback) throws IOException {
    checkAuthentication();
    FacebookRESTService con = new FacebookRESTService(token, postId, FacebookRESTService.LIKES, true);
    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 28 with Callback

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

Example 29 with Callback

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

the class IOSImplementation method capturePhoto.

/**
 * Captures a photo and notifies with the image data when available
 * @param response callback for the resulting image
 */
public void capturePhoto(ActionListener response) {
    if (!nativeInstance.checkCameraUsage()) {
        throw new RuntimeException("Please add the ios.NSCameraUsageDescription build hint");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.captureCamera(false);
    dropEvents = true;
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 30 with Callback

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

the class IOSImplementation method captureVideo.

/**
 * Captures a video and notifies with the data when available
 * @param response callback for the resulting video
 */
public void captureVideo(ActionListener response) {
    if (!nativeInstance.checkCameraUsage() || !nativeInstance.checkMicrophoneUsage()) {
        throw new RuntimeException("Please add the ios.NSCameraUsageDescription and ios.NSMicrophoneUsageDescription build hints");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.captureCamera(true);
    dropEvents = true;
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

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