use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class IOSImplementation method captureVideo.
/**
* Captures a video and notifies with the data when available
* @param response callback for the resulting video
*/
public void captureVideo(ActionListener response) {
if (!nativeInstance.checkCameraUsage() || !nativeInstance.checkMicrophoneUsage()) {
throw new RuntimeException("Please add the ios.NSCameraUsageDescription and ios.NSMicrophoneUsageDescription build hints");
}
captureCallback = new EventDispatcher();
captureCallback.addListener(response);
nativeInstance.captureCamera(true);
dropEvents = true;
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class NetworkManager method fireProgressEvent.
void fireProgressEvent(ConnectionRequest c, int type, int length, int sentReceived) {
// progressListeners might be made null by a separate thread
EventDispatcher d = progressListeners;
if (d != null) {
NetworkEvent n = new NetworkEvent(c, type);
n.setLength(length);
n.setSentReceived(sentReceived);
d.fireActionEvent(n);
}
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class NetworkManager method addErrorListener.
/**
* Adds a generic listener to a network error that is invoked before the exception is propagated.
* Notice that this doesn't apply to server error codes!
* Consume the event in order to prevent it from propagating further.
*
* @param e callback will be invoked with the Exception as the source object
*/
public void addErrorListener(ActionListener<NetworkEvent> e) {
if (errorListeners == null) {
errorListeners = new EventDispatcher();
errorListeners.setBlocking(true);
}
errorListeners.addListener(e);
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class AndroidImplementation method openImageGallery.
/**
* Opens the device image gallery
*
* @param response callback for the resulting image
*/
public void openImageGallery(ActionListener response) {
if (getActivity() == null) {
throw new RuntimeException("Cannot open image gallery in background mode");
}
if (!checkForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, "This is required to browse the photos")) {
return;
}
if (editInProgress()) {
stopEditing(true);
}
callback = new EventDispatcher();
callback.addListener(response);
Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
this.getActivity().startActivityForResult(galleryIntent, OPEN_GALLERY);
}
use of com.codename1.ui.util.EventDispatcher in project CodenameOne by codenameone.
the class AndroidImplementation method execute.
public void execute(String url, ActionListener response) {
if (response != null) {
callback = new EventDispatcher();
callback.addListener(response);
}
try {
Intent intent = createIntentForURL(url);
if (intent == null) {
return;
}
if (response != null && getActivity() != null) {
getActivity().startActivityForResult(intent, IntentResultListener.URI_SCHEME);
} else {
getContext().startActivity(intent);
}
return;
} catch (Exception ex) {
com.codename1.io.Log.e(ex);
}
try {
if (editInProgress()) {
stopEditing(true);
}
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations