use of com.codename1.util.AsyncResource in project CodeRAD by shannah.
the class ParsingService method parseJSON.
public AsyncResource<Map> parseJSON(InputStream content, JSONParser parser) {
AsyncResource<Map> out = new AsyncResource<Map>();
start();
thread.run(() -> {
try {
Map m = parser.parseJSON(new InputStreamReader(content, "UTF-8"));
if (autoCloseStreams)
content.close();
out.complete(m);
} catch (Throwable ex) {
out.error(ex);
}
});
return out;
}
use of com.codename1.util.AsyncResource in project CodeRAD by shannah.
the class ParsingService method parseXML.
public AsyncResource<Element> parseXML(String content, XMLParser parser) {
AsyncResource<Element> out = new AsyncResource<Element>();
start();
thread.run(() -> {
try {
Element el = parser.parse(new StringReader(content));
out.complete(el);
} catch (Throwable ex) {
out.error(ex);
}
});
return out;
}
use of com.codename1.util.AsyncResource in project CodeRAD by shannah.
the class ParsingService method parseJSON.
public AsyncResource<Map> parseJSON(Reader content, JSONParser parser) {
AsyncResource<Map> out = new AsyncResource<Map>();
start();
thread.run(() -> {
try {
Map m = parser.parseJSON(content);
if (autoCloseStreams)
content.close();
out.complete(m);
} catch (Throwable ex) {
out.error(ex);
}
});
return out;
}
use of com.codename1.util.AsyncResource in project CodenameOne by codenameone.
the class CircleProgressSample method fetchDataAsync.
private AsyncResource<MyData> fetchDataAsync() {
final AsyncResource<MyData> out = new AsyncResource<>();
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
out.complete(new MyData());
}
}, 2000);
return out;
}
use of com.codename1.util.AsyncResource in project CodenameOne by codenameone.
the class VideoTransition method fadeIn.
private AsyncResource<Component> fadeIn(Component cmp, int duration) {
AsyncResource<Component> out = new AsyncResource<Component>();
Motion m = Motion.createEaseInMotion(cmp.getStyle().getOpacity(), 255, duration);
Timer[] ts = new Timer[1];
Timer t = CN.setInterval(30, () -> {
int currOpacity = cmp.getStyle().getOpacity();
int newOpacity = m.getValue();
if (currOpacity != newOpacity) {
cmp.getStyle().setOpacity(newOpacity);
cmp.getStyle().setBgTransparency(newOpacity);
cmp.repaint();
}
if (newOpacity == m.getDestinationValue()) {
ts[0].cancel();
out.complete(cmp);
}
});
ts[0] = t;
m.start();
return out;
}
Aggregations