protected void loadURL (String url) { displayText("Loading: " + url); try { net().req(url).execute(displayer); } catch (Exception e) { displayText(e.toString()); } }
protected void loadURL (String url) { displayText("Loading: " + url); try { game.net.req(url).execute().onSuccess(this::displayResult).onFailure(this::displayError); } catch (Exception e) { displayText(e.toString()); } }
@Override public void init() { Image orange = game.assets.getImage("images/orange.png"); ImageLayer l1 = new ImageLayer(orange); game.rootLayer.addAt(l1.setScale(2).setRotation(FloatMath.PI/8), 50, 50); l1.events().connect(new Mover(l1).listener(game.input)); ImageLayer l2 = new ImageLayer(orange); game.rootLayer.addAt(l2.setScale(1.5f).setRotation(FloatMath.PI/4), 150, 50); l2.events().connect(new Mover(l2).listener(game.input)); Image mdb = game.assets.getRemoteImage("https://www.samskivert.com/images/headshot.jpg"); ImageLayer l3 = new ImageLayer(mdb); game.rootLayer.addAt(l3.setRotation(-FloatMath.PI/4), 50, 150); l3.events().connect(new Mover(l3).listener(game.input)); String l4url = "https://www.samskivert.com/images/2012/12/spellwood-app-icon.png"; game.net.req(l4url).execute().onSuccess(rsp -> { try { Image icon = rsp.payloadImage(new Scale(2)); ImageLayer l4 = new ImageLayer(icon); game.rootLayer.addAt(l4.setRotation(FloatMath.PI/4), 150, 150); l4.events().connect(new Mover(l4).listener(game.input)); } catch (Exception e) { game.log.warn("Failed to decode image: " + e); } }).onFailure(t -> game.log.warn("Failed to load image: " + l4url, t)); }
@Override public Image getRemoteImage(final String url, int width, int height) { final ImageImpl image = createImage(true, width, height, url); plat.net().req(url).execute(). onSuccess(new Slot<Net.Response>() { public void onEmit (Net.Response rsp) { try { image.succeed(toData(Scale.ONE, new UIImage(new NSData(rsp.payload())))); } catch (Throwable t) { plat.log().warn("Failed to decode remote image [url=" + url + "]", t); image.fail(t); } } }). onFailure(new Slot<Throwable>() { public void onEmit (Throwable cause) { image.fail(cause); } }); return image; }
@Override public void get(String url, Callback<String> callback) { req(url).execute(adapt(callback)); }
@Override public Image getRemoteImage(String url, float width, float height) { final RoboAsyncImage image = new RoboAsyncImage(platform.graphics().ctx, width, height, url); platform.net().req(url).execute(new Callback<Net.Response>() { public void onSuccess (Net.Response rsp) { image.setImage(new UIImage(new NSData(rsp.payload())), Scale.ONE); } public void onFailure (Throwable cause) { image.setError(cause); } }); return image; }
/** * Performs an HTTP GET request to the specified URL. */ public RFuture<String> get(String url) { return req(url).execute().map(GET_PAYLOAD); }
public void run () { if (lastPostURL == null) displayText("Click 'Post Test' to post some data first."); else net().req(lastPostURL).execute(displayer); } }, x, 10);
/** * Performs an HTTP POST request to the specified URL. */ public RFuture<String> post(String url, String data) { return req(url).setPayload(data).execute().map(GET_PAYLOAD); }
/** * Performs an HTTP GET request to the specified URL. */ public RFuture<String> get(String url) { return req(url).execute().map(GET_PAYLOAD); }
/** * Performs an HTTP POST request to the specified URL. */ public RFuture<String> post(String url, String data) { return req(url).setPayload(data).execute().map(GET_PAYLOAD); }
@Override public void post(String url, String data, Callback<String> callback) { req(url).setPayload(data).execute(adapt(callback)); }