use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class IOSImplementation method openGallery.
@Override
public void openGallery(ActionListener response, int type) {
if (!nativeInstance.checkPhotoLibraryUsage()) {
throw new RuntimeException("Please add the ios.NSPhotoLibraryUsageDescription build hint");
}
captureCallback = new EventDispatcher();
captureCallback.addListener(response);
nativeInstance.openGallery(type);
}
use of com.codename1.ui.util.EventDispatcher 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 com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class BrowserComponent method fireWebEvent.
/**
* Used internally by the implementation to fire an event from the native browser widget
*
* @param type the type of the event
* @param ev the event
*/
public void fireWebEvent(String type, ActionEvent ev) {
if (onLoad.equals(type)) {
synchronized (readyLock) {
ready = true;
readyLock.notifyAll();
}
}
EventDispatcher e = getEventDispatcher(type, false);
if (e != null) {
e.fireActionEvent(ev);
}
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class ConnectionRequest method addResponseCodeListener.
/**
* Adds a listener that would be notified on the CodenameOne thread of a response code that
* is not a 200 (OK) or 301/2 (redirect) response code.
*
* @param a listener
*/
public void addResponseCodeListener(ActionListener<NetworkEvent> a) {
if (responseCodeListeners == null) {
responseCodeListeners = new EventDispatcher();
responseCodeListeners.setBlocking(false);
}
responseCodeListeners.addListener(a);
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class IOSImplementation method capturePhoto.
/**
* Captures a photo and notifies with the image data when available
* @param response callback for the resulting image
*/
public void capturePhoto(ActionListener response) {
if (!nativeInstance.checkCameraUsage()) {
throw new RuntimeException("Please add the ios.NSCameraUsageDescription build hint");
}
captureCallback = new EventDispatcher();
captureCallback.addListener(response);
nativeInstance.captureCamera(false);
dropEvents = true;
}
Aggregations