use of com.codename1.ui.events.ActionListener 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.events.ActionListener in project CodenameOne by codenameone.
the class RequestBuilder method getAsStringAsync.
/**
* Executes the request asynchronously and writes the response to the provided
* Callback
* @param callback writes the response to this callback
*/
public void getAsStringAsync(final Callback<Response<String>> callback) {
ConnectionRequest request = createRequest(false);
request.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
Response res = null;
try {
res = new Response(evt.getResponseCode(), new String(evt.getConnectionRequest().getResponseData(), "UTF-8"), evt.getMessage());
callback.onSucess(res);
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
}
});
CN.addToQueue(request);
}
use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToFileSystem.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param destFile local file to store the data into the given path
*/
public static void createImageToFileSystem(String url, ActionListener callback, String destFile) {
Image im = cacheImage(null, false, destFile, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.destinationFile = destFile;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.
the class ImageDownloadService method createImageToStorage.
/**
* Constructs an image request that will automatically populate the given Label
* when the response arrives, it will cache the file locally.
*
* @param url the image URL
* @param callback the callback that should be updated when the data arrives
* @param cacheId a unique identifier to be used to store the image into storage
* @param keep if set to true keeps the file in RAM once loaded
*/
public static void createImageToStorage(String url, ActionListener callback, String cacheId, boolean keep) {
Image im = cacheImage(cacheId, keep, null, null, null, defaultMaintainAspectRatio);
if (im != null) {
callback.actionPerformed(new NetworkEvent(null, im));
return;
}
// image not found on cache go and download from the url
ImageDownloadService i = new ImageDownloadService(url, callback);
i.cacheImages = true;
i.cacheId = cacheId;
i.setFailSilently(true);
NetworkManager.getInstance().addToQueue(i);
}
use of com.codename1.ui.events.ActionListener in project CodenameOne by codenameone.
the class Log method bindCrashProtection.
/**
* Binds pro based crash protection logic that will send out an email in case of an exception thrown on the EDT
*
* @param consumeError true will hide the error from the user, false will leave the builtin logic that defaults to
* showing an error dialog to the user
*/
public static void bindCrashProtection(final boolean consumeError) {
if (Display.getInstance().isSimulator()) {
return;
}
Display.getInstance().addEdtErrorHandler(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if (consumeError) {
evt.consume();
}
p("Exception in " + Display.getInstance().getProperty("AppName", "app") + " version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
p("OS " + Display.getInstance().getPlatformName());
p("Error " + evt.getSource());
if (Display.getInstance().getCurrent() != null) {
p("Current Form " + Display.getInstance().getCurrent().getName());
} else {
p("Before the first form!");
}
e((Throwable) evt.getSource());
sendLog();
}
});
crashBound = true;
}
Aggregations