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