Search in sources :

Example 1 with AsyncResource

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) AsyncResource(com.codename1.util.AsyncResource) Map(java.util.Map)

Example 2 with AsyncResource

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;
}
Also used : Element(com.codename1.xml.Element) StringReader(java.io.StringReader) AsyncResource(com.codename1.util.AsyncResource)

Example 3 with AsyncResource

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;
}
Also used : AsyncResource(com.codename1.util.AsyncResource) Map(java.util.Map)

Example 4 with AsyncResource

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;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) AsyncResource(com.codename1.util.AsyncResource)

Example 5 with AsyncResource

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;
}
Also used : Motion(com.codename1.ui.animations.Motion) Timer(java.util.Timer) Component(com.codename1.ui.Component) AsyncResource(com.codename1.util.AsyncResource)

Aggregations

AsyncResource (com.codename1.util.AsyncResource)20 IOException (java.io.IOException)6 Timer (java.util.Timer)5 AbstractMedia (com.codename1.media.AbstractMedia)4 AsyncMedia (com.codename1.media.AsyncMedia)4 Media (com.codename1.media.Media)4 Map (java.util.Map)4 JFrame (javax.swing.JFrame)4 Element (com.codename1.xml.Element)3 InputStreamReader (java.io.InputStreamReader)3 Component (com.codename1.ui.Component)2 Form (com.codename1.ui.Form)2 Toolbar (com.codename1.ui.Toolbar)2 Motion (com.codename1.ui.animations.Motion)2 ActionEvent (com.codename1.ui.events.ActionEvent)2 ActionListener (com.codename1.ui.events.ActionListener)2 BorderLayout (com.codename1.ui.layouts.BorderLayout)2 StringReader (java.io.StringReader)2 TimerTask (java.util.TimerTask)2 BillingResult (com.android.billingclient.api.BillingResult)1