1 package com.badlogic.gdx.tests; 2 3 import com.badlogic.gdx.Gdx; 4 import com.badlogic.gdx.Net.HttpMethods; 5 import com.badlogic.gdx.Net.HttpRequest; 6 import com.badlogic.gdx.Net.HttpResponse; 7 import com.badlogic.gdx.Net.HttpResponseListener; 8 import com.badlogic.gdx.files.FileHandle; 9 import com.badlogic.gdx.graphics.GL20; 10 import com.badlogic.gdx.graphics.Pixmap; 11 import com.badlogic.gdx.graphics.Texture; 12 import com.badlogic.gdx.graphics.g2d.PixmapPacker; 13 import com.badlogic.gdx.graphics.g2d.SpriteBatch; 14 import com.badlogic.gdx.graphics.glutils.PixmapTextureData; 15 import com.badlogic.gdx.tests.utils.GdxTest; 16 17 public class DownloadTest extends GdxTest { 18 Texture texture; 19 SpriteBatch batch; 20 21 @Override create()22 public void create () { 23 batch = new SpriteBatch(); 24 HttpRequest request = new HttpRequest(HttpMethods.GET); 25 request.setUrl("https://www.google.at/images/srpr/logo11w.png"); 26 Gdx.net.sendHttpRequest(request, new HttpResponseListener() { 27 @Override 28 public void handleHttpResponse (HttpResponse httpResponse) { 29 final byte[] bytes = httpResponse.getResult(); 30 31 Gdx.app.postRunnable(new Runnable() { 32 @Override 33 public void run () { 34 Pixmap pixmap = new Pixmap(bytes, 0, bytes.length); 35 texture = new Texture(new PixmapTextureData(pixmap, pixmap.getFormat(), false, false, true)); 36 } 37 }); 38 } 39 40 @Override 41 public void failed (Throwable t) { 42 t.printStackTrace(); 43 Gdx.app.log("EmptyDownloadTest", "Failed", t); 44 } 45 46 @Override 47 public void cancelled () { 48 Gdx.app.log("EmptyDownloadTest", "Cancelled"); 49 } 50 }); 51 } 52 53 @Override render()54 public void render () { 55 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 56 batch.begin(); 57 if(texture != null) batch.draw(texture, 0, 0); 58 batch.end(); 59 } 60 }