use of com.codename1.ui.util.xml.Data 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;
}
use of com.codename1.ui.util.xml.Data in project CodenameOne by codenameone.
the class IOSImplementation method showNativePicker.
@Override
public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) {
datePickerResult = -2;
int x = 0, y = 0, w = 20, h = 20, preferredHeight = 0, preferredWidth = 0;
if (source != null) {
x = source.getAbsoluteX();
y = source.getAbsoluteY();
w = source.getWidth();
h = source.getHeight();
}
if (source instanceof Picker) {
Picker p = (Picker) source;
preferredHeight = p.getPreferredPopupHeight();
preferredWidth = p.getPreferredPopupWidth();
}
if (type == Display.PICKER_TYPE_STRINGS) {
String[] strs = (String[]) data;
int offset = -1;
if (currentValue != null) {
int slen = strs.length;
for (int iter = 0; iter < slen; iter++) {
if (strs[iter].equals(currentValue)) {
offset = iter;
break;
}
}
}
nativeInstance.openStringPicker(strs, offset, x, y, w, h, preferredWidth, preferredHeight);
} else if (type == Display.PICKER_TYPE_DURATION) {
long time;
if (currentValue instanceof Long) {
time = (Long) currentValue;
} else {
time = 0l;
}
int minuteStep = 5;
if (data instanceof String) {
String strData = (String) data;
String[] parts = Util.split(strData, "\n");
for (String part : parts) {
if (part.indexOf("minuteStep=") != -1) {
minuteStep = Integer.parseInt(part.substring(part.indexOf("=") + 1));
}
}
}
nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, minuteStep);
} else {
long time;
if (currentValue instanceof Integer) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.set(java.util.Calendar.HOUR_OF_DAY, ((Integer) currentValue).intValue() / 60);
c.set(java.util.Calendar.MINUTE, ((Integer) currentValue).intValue() % 60);
time = c.getTime().getTime();
} else if (currentValue != null) {
time = ((java.util.Date) currentValue).getTime();
} else {
time = new java.util.Date().getTime();
}
nativeInstance.openDatePicker(type, time, x, y, w, h, preferredWidth, preferredHeight, 5);
}
// wait for the native code to complete
Display.getInstance().invokeAndBlock(new Runnable() {
public void run() {
while (datePickerResult == -2) {
synchronized (PICKER_LOCK) {
try {
PICKER_LOCK.wait(100);
} catch (InterruptedException err) {
}
}
}
}
}, true);
if (datePickerResult == -1) {
// }
return null;
}
if (type == Display.PICKER_TYPE_STRINGS) {
if (datePickerResult < 0) {
return null;
}
return ((String[]) data)[(int) datePickerResult];
}
Object result;
if (type == Display.PICKER_TYPE_DURATION || type == Display.PICKER_TYPE_DURATION_HOURS || type == Display.PICKER_TYPE_DURATION_MINUTES) {
if (datePickerResult < 0) {
return null;
}
return new Long(datePickerResult);
}
if (type == Display.PICKER_TYPE_TIME) {
java.util.Calendar c = java.util.Calendar.getInstance();
c.setTime(new Date(datePickerResult));
result = new Integer(c.get(java.util.Calendar.HOUR_OF_DAY) * 60 + c.get(java.util.Calendar.MINUTE));
} else {
result = new Date(datePickerResult);
}
return result;
}
use of com.codename1.ui.util.xml.Data 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.xml.Data in project CodenameOne by codenameone.
the class CachedDataService method readResponse.
/**
* {@inheritDoc}
*/
protected void readResponse(InputStream input) throws IOException {
data.setData(Util.readInputStream(input));
fireResponseListener(new NetworkEvent(this, data));
data.setFetching(false);
}
use of com.codename1.ui.util.xml.Data 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);
}
Aggregations