Search in sources :

Example 6 with EventDispatcher

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

the class IOSImplementation method openGallery.

@Override
public void openGallery(ActionListener response, int type) {
    if (!nativeInstance.checkPhotoLibraryUsage()) {
        throw new RuntimeException("Please add the ios.NSPhotoLibraryUsageDescription build hint");
    }
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    nativeInstance.openGallery(type);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 7 with EventDispatcher

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

the class BlackBerryOS5Implementation method captureVideo.

public void captureVideo(ActionListener response) {
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    UiApplication.getUiApplication().addFileSystemJournalListener(new FileSystemJournalListener() {

        private long lastUSN;

        private String videoPath;

        public void fileJournalChanged() {
            // next sequence number file system will use
            long USN = FileSystemJournal.getNextUSN();
            for (long i = USN - 1; i >= lastUSN && i < USN; --i) {
                FileSystemJournalEntry entry = FileSystemJournal.getEntry(i);
                if (entry == null) {
                    break;
                }
                String path = entry.getPath();
                if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED && videoPath == null) {
                    int index = path.indexOf(".3GP");
                    if (index != -1) {
                        videoPath = path;
                    }
                } else if (entry.getEvent() == FileSystemJournalEntry.FILE_RENAMED) {
                    if (path != null && path.equals(videoPath)) {
                        // close the camera
                        UiApplication.getUiApplication().removeFileSystemJournalListener(this);
                        try {
                            EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, Characters.ESCAPE, 0, 200);
                            inject.post();
                            inject.post();
                        } catch (Exception e) {
                        // try to close the camera
                        }
                        captureCallback.fireActionEvent(new ActionEvent("file://" + path));
                        captureCallback = null;
                        videoPath = null;
                        break;
                    }
                }
            }
            lastUSN = USN;
        }
    });
    app.setWaitingForReply(true);
    synchronized (UiApplication.getEventLock()) {
        Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments(CameraArguments.ARG_VIDEO_RECORDER));
    }
}
Also used : FileSystemJournalEntry(net.rim.device.api.io.file.FileSystemJournalEntry) CameraArguments(net.rim.blackberry.api.invoke.CameraArguments) EventDispatcher(com.codename1.ui.util.EventDispatcher) FileSystemJournalListener(net.rim.device.api.io.file.FileSystemJournalListener) ActionEvent(com.codename1.ui.events.ActionEvent) DatabaseIOException(net.rim.device.api.database.DatabaseIOException) DatabasePathException(net.rim.device.api.database.DatabasePathException) IOException(java.io.IOException) EventInjector(net.rim.device.api.system.EventInjector)

Example 8 with EventDispatcher

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

the class BrowserComponent method fireWebEvent.

/**
 * Used internally by the implementation to fire an event from the native browser widget
 *
 * @param type the type of the event
 * @param ev the event
 */
public void fireWebEvent(String type, ActionEvent ev) {
    if (onLoad.equals(type)) {
        synchronized (readyLock) {
            ready = true;
            readyLock.notifyAll();
        }
    }
    EventDispatcher e = getEventDispatcher(type, false);
    if (e != null) {
        e.fireActionEvent(ev);
    }
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 9 with EventDispatcher

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

the class ConnectionRequest method addResponseCodeListener.

/**
 * Adds a listener that would be notified on the CodenameOne thread of a response code that
 * is not a 200 (OK) or 301/2 (redirect) response code.
 *
 * @param a listener
 */
public void addResponseCodeListener(ActionListener<NetworkEvent> a) {
    if (responseCodeListeners == null) {
        responseCodeListeners = new EventDispatcher();
        responseCodeListeners.setBlocking(false);
    }
    responseCodeListeners.addListener(a);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher)

Example 10 with EventDispatcher

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

Aggregations

EventDispatcher (com.codename1.ui.util.EventDispatcher)19 IOException (java.io.IOException)4 ActionEvent (com.codename1.ui.events.ActionEvent)3 FileSystemJournalEntry (net.rim.device.api.io.file.FileSystemJournalEntry)3 FileSystemJournalListener (net.rim.device.api.io.file.FileSystemJournalListener)3 Uri (android.net.Uri)2 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)2 MediaException (javax.microedition.media.MediaException)2 RecordStoreException (javax.microedition.rms.RecordStoreException)2 CameraArguments (net.rim.blackberry.api.invoke.CameraArguments)2 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Form (com.codename1.ui.Form)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 Hashtable (java.util.Hashtable)1 DatabaseIOException (net.rim.device.api.database.DatabaseIOException)1 DatabasePathException (net.rim.device.api.database.DatabasePathException)1 EventInjector (net.rim.device.api.system.EventInjector)1