Search in sources :

Example 16 with EventDispatcher

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

the class AndroidImplementation method captureVideo.

@Override
public void captureVideo(ActionListener response) {
    if (getActivity() == null) {
        throw new RuntimeException("Cannot capture video in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to take a video")) {
        return;
    }
    callback = new EventDispatcher();
    callback.addListener(response);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
    File newFile = getOutputMediaFile(true);
    Uri videoUri = Uri.fromFile(newFile);
    Storage.getInstance().writeObject("videoUri", newFile.getAbsolutePath());
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, videoUri);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    this.getActivity().startActivityForResult(intent, CAPTURE_VIDEO);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Uri(android.net.Uri)

Example 17 with EventDispatcher

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

the class AndroidImplementation method capturePhoto.

@Override
public void capturePhoto(ActionListener response) {
    if (getActivity() == null) {
        throw new RuntimeException("Cannot capture photo in background mode");
    }
    if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to take a picture")) {
        return;
    }
    callback = new EventDispatcher();
    callback.addListener(response);
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    File newFile = getOutputMediaFile(false);
    Uri imageUri = Uri.fromFile(newFile);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
    String lastImageID = getLastImageId();
    Storage.getInstance().writeObject("imageUri", newFile.getAbsolutePath() + ";" + lastImageID);
    intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    this.getActivity().startActivityForResult(intent, CAPTURE_IMAGE);
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Uri(android.net.Uri)

Example 18 with EventDispatcher

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

the class BrowserComponent method getEventDispatcher.

private EventDispatcher getEventDispatcher(String type, boolean autoCreate) {
    if (listeners == null) {
        if (!autoCreate) {
            return null;
        }
        listeners = new Hashtable();
        EventDispatcher ev = new EventDispatcher();
        listeners.put(type, ev);
        return ev;
    }
    EventDispatcher ev = (EventDispatcher) listeners.get(type);
    if (ev == null) {
        if (autoCreate) {
            ev = new EventDispatcher();
            listeners.put(type, ev);
        }
    }
    return ev;
}
Also used : EventDispatcher(com.codename1.ui.util.EventDispatcher) Hashtable(java.util.Hashtable)

Example 19 with EventDispatcher

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

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

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