Search in sources :

Example 1 with CameraArguments

use of net.rim.blackberry.api.invoke.CameraArguments 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 2 with CameraArguments

use of net.rim.blackberry.api.invoke.CameraArguments in project CodenameOne by codenameone.

the class BlackBerryImplementation method capturePhoto.

public void capturePhoto(ActionListener response) {
    EventLog.getInstance().logInformationEvent("capturePhoto");
    captureCallback = new EventDispatcher();
    captureCallback.addListener(response);
    UiApplication.getUiApplication().addFileSystemJournalListener(new FileSystemJournalListener() {

        private long lastUSN;

        public void fileJournalChanged() {
            long USN = FileSystemJournal.getNextUSN();
            for (long i = USN - 1; i >= lastUSN; --i) {
                FileSystemJournalEntry entry = FileSystemJournal.getEntry(i);
                if (entry != null) {
                    if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED) {
                        if (entry.getPath().indexOf(".jpg") != -1) {
                            lastUSN = USN;
                            String path = entry.getPath();
                            // 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
                            }
                            EventLog.getInstance().logInformationEvent("path " + path);
                            captureCallback.fireActionEvent(new ActionEvent("file://" + path));
                            captureCallback = null;
                        }
                    }
                }
            }
            lastUSN = USN;
        }
    });
    app.setWaitingForReply(true);
    synchronized (UiApplication.getEventLock()) {
        Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
    }
}
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) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Aggregations

ActionEvent (com.codename1.ui.events.ActionEvent)2 EventDispatcher (com.codename1.ui.util.EventDispatcher)2 IOException (java.io.IOException)2 CameraArguments (net.rim.blackberry.api.invoke.CameraArguments)2 FileSystemJournalEntry (net.rim.device.api.io.file.FileSystemJournalEntry)2 FileSystemJournalListener (net.rim.device.api.io.file.FileSystemJournalListener)2 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)1 MediaException (javax.microedition.media.MediaException)1 RecordStoreException (javax.microedition.rms.RecordStoreException)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