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);
}
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);
}
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;
}
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());
}
}
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();
}
}
Aggregations