use of net.rim.device.api.io.file.FileSystemJournalListener 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));
}
}
use of net.rim.device.api.io.file.FileSystemJournalListener 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 net.rim.device.api.io.file.FileSystemJournalListener 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