Search in sources :

Example 21 with Entry

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

Example 22 with Entry

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

the class BlackBerryImplementation method captureAudio.

public void captureAudio(ActionListener response) {
    int h = CodeModuleManager.getModuleHandle("net_rim_bb_voicenotesrecorder");
    if (h == 0) {
        throw new RuntimeException("capture audio works only if Voice Notes is installed");
    }
    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) {
                    String path = entry.getPath();
                    if (entry.getEvent() == FileSystemJournalEntry.FILE_ADDED && path.endsWith(".amr")) {
                        UiApplication.getUiApplication().removeFileSystemJournalListener(this);
                        try {
                            EventInjector.KeyEvent inject = new EventInjector.KeyEvent(EventInjector.KeyEvent.KEY_DOWN, Characters.ESCAPE, 0, 200);
                            inject.post();
                        } catch (Exception e) {
                        // try to close the voicenotesrecorder
                        }
                        captureCallback.fireActionEvent(new ActionEvent("file://" + path));
                        captureCallback = null;
                        break;
                    }
                }
            }
            lastUSN = USN;
        }
    });
    app.setWaitingForReply(true);
    ApplicationDescriptor desc = new ApplicationDescriptor(CodeModuleManager.getApplicationDescriptors(h)[0], null);
    try {
        ApplicationManager.getApplicationManager().runApplication(desc, true);
    } catch (ApplicationManagerException e) {
        EventLog.getInstance().logErrorEvent("err " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : 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) FileSystemJournalEntry(net.rim.device.api.io.file.FileSystemJournalEntry) EventDispatcher(com.codename1.ui.util.EventDispatcher)

Aggregations

IOException (java.io.IOException)7 Hashtable (java.util.Hashtable)5 ActionEvent (com.codename1.ui.events.ActionEvent)4 Container (com.codename1.ui.Container)3 Form (com.codename1.ui.Form)3 AnimationObject (com.codename1.ui.animations.AnimationObject)3 RoundBorder (com.codename1.ui.plaf.RoundBorder)3 RoundRectBorder (com.codename1.ui.plaf.RoundRectBorder)3 EventDispatcher (com.codename1.ui.util.EventDispatcher)3 SpanButton (com.codename1.components.SpanButton)2 Component (com.codename1.ui.Component)2 EditorFont (com.codename1.ui.EditorFont)2 EditorTTFFont (com.codename1.ui.EditorTTFFont)2 EncodedImage (com.codename1.ui.EncodedImage)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 Border (com.codename1.ui.plaf.Border)2 LegacyFont (com.codename1.ui.util.xml.LegacyFont)2 DataInputStream (java.io.DataInputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2