Search in sources :

Example 16 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project howabout-android by recomio.

the class GroovesharkStreamUrlGetter method parseGroovesharkGetCommunicationToken.

public void parseGroovesharkGetCommunicationToken(JSONObject jsonResponseObject) throws JSONException, UnsupportedEncodingException {
    String lastRandomizer = generateRandomString(6);
    String communicationToken = jsonResponseObject.getString("result");
    String tokenSource = "getStreamKeyFromSongIDEx:" + communicationToken + ":gooeyFlubber:" + lastRandomizer;
    String token = lastRandomizer + bytesToHex(sha1.digest(tokenSource.getBytes()));
    JSONObject headerObject = new JSONObject();
    headerObject.put("client", "mobileshark");
    headerObject.put("clientRevision", "20120830");
    headerObject.put("privacy", "0");
    headerObject.put("country", country);
    headerObject.put("uuid", uuid);
    headerObject.put("session", sessionId);
    headerObject.put("token", token);
    JSONObject parametersObject = new JSONObject();
    parametersObject.put("prefetch", false);
    parametersObject.put("mobile", true);
    parametersObject.put("songID", songId);
    parametersObject.put("country", country);
    JSONObject bodyObject = new JSONObject();
    bodyObject.put("header", headerObject);
    bodyObject.put("method", "getStreamKeyFromSongIDEx");
    bodyObject.put("parameters", parametersObject);
    String groovesharkGetStreamKeyUrl = "https://html5.grooveshark.com/more.php?getStreamKeyFromSongIDEx";
    AjaxCallback<JSONObject> groovesharkGetStreamKeyAjaxCallback = new AjaxCallback<JSONObject>();
    groovesharkGetStreamKeyAjaxCallback.url(groovesharkGetStreamKeyUrl).type(JSONObject.class).handler(this, "groovesharkGetStreamKeyCallback");
    HttpEntity bodyEntity = new StringEntity(bodyObject.toString());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(AQuery.POST_ENTITY, bodyEntity);
    groovesharkGetStreamKeyAjaxCallback.params(params);
    groovesharkGetStreamKeyAjaxCallback.header("Content-Type", "application/json");
    groovesharkGetStreamKeyAjaxCallback.header("Accept", "application/json");
    groovesharkGetStreamKeyAjaxCallback.header("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
    groovesharkGetStreamKeyAjaxCallback.header("Accept-Language", "en-US,en;q=0.8");
    groovesharkGetStreamKeyAjaxCallback.header("Cache-Control", "no-cache");
    groovesharkGetStreamKeyAjaxCallback.header("Connection", "keep-alive");
    groovesharkGetStreamKeyAjaxCallback.header("Host", "html5.grooveshark.com");
    groovesharkGetStreamKeyAjaxCallback.header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1");
    aq.ajax(groovesharkGetStreamKeyAjaxCallback);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) JSONObject(org.json.JSONObject) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback)

Example 17 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AjaxAuthActivity method auth_parallel.

public void auth_parallel() {
    String url1 = "https://picasaweb.google.com/data/feed/api/user/default";
    String url2 = "https://picasaweb.google.com/data/feed/api/user/default?alt=json";
    GoogleHandle gh = new GoogleHandle(this, AQuery.AUTH_PICASA, null);
    AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>();
    cb.url(url1).type(XmlDom.class).weakHandler(this, "pcb1");
    cb.auth(gh);
    AjaxCallback<JSONObject> cb2 = new AjaxCallback<JSONObject>();
    cb2.url(url2).type(JSONObject.class).weakHandler(this, "pcb2");
    cb2.auth(gh);
    cb.async(this);
    cb2.async(this);
//aq.progress(R.id.progress).ajax(cb);
}
Also used : JSONObject(org.json.JSONObject) XmlDom(com.androidquery.util.XmlDom) GoogleHandle(com.androidquery.auth.GoogleHandle) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback)

Example 18 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryXmlTest method testMalformXml.

public void testMalformXml() {
    String url = "http://fotbollskanalen.apps.tv4.se/news/topnews";
    AjaxCallback<XmlDom> cb = new AjaxCallback<XmlDom>() {

        @Override
        public void callback(String url, XmlDom object, AjaxStatus status) {
            done(url, object, status);
        }
    };
    cb.url(url).type(XmlDom.class);
    aq.ajax(cb);
    waitAsync();
    XmlDom xml = (XmlDom) result;
    assertNotNull(xml);
    AQUtility.debug(xml);
}
Also used : XmlDom(com.androidquery.util.XmlDom) AjaxCallback(com.androidquery.callback.AjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 19 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryImageTest method testImageFileUrl.

public void testImageFileUrl() {
    clearCache();
    AjaxCallback<File> cb = new AjaxCallback<File>();
    cb.url(ICON_URL).type(File.class);
    aq.sync(cb);
    final File file = cb.getResult();
    assertNotNull(file);
    AQUtility.post(new Runnable() {

        @Override
        public void run() {
            aq.id(R.id.image).image(file.getAbsolutePath());
        }
    });
    waitAsync(2000);
    assertLoaded(aq.getImageView(), true);
    Bitmap bm = aq.getCachedImage(file.getAbsolutePath());
    assertNotNull(bm);
    AQUtility.debug(bm.getWidth());
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback)

Example 20 with AjaxCallback

use of com.androidquery.callback.AjaxCallback in project androidquery by androidquery.

the class AQueryPerformanceTest method testAjaxPostDuration.

//Test: <K> T ajax(String url, Map<String, Object> params, Class<K> type, AjaxCallback<K> callback)
public void testAjaxPostDuration() {
    String url = "http://192.168.1.165/p/doNothing";
    long totalDur = 0;
    Map<String, String> params = new HashMap<String, String>();
    params.put("q", "androidquery");
    AjaxCallback.setReuseHttpClient(false);
    for (int i = 0; i < 1000; i++) {
        AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
        cb.type(JSONObject.class).url(url).params(params);
        aq.sync(cb);
        //JSONObject jo = (JSONObject) cb.getResult();
        AjaxStatus status = cb.getStatus();
        if (i > 0) {
            totalDur += status.getDuration();
        }
    }
    AjaxCallback.setReuseHttpClient(true);
    AQUtility.debug("duration", totalDur);
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) AjaxCallback(com.androidquery.callback.AjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

AjaxCallback (com.androidquery.callback.AjaxCallback)37 BitmapAjaxCallback (com.androidquery.callback.BitmapAjaxCallback)33 AbstractAjaxCallback (com.androidquery.callback.AbstractAjaxCallback)31 AjaxStatus (com.androidquery.callback.AjaxStatus)28 JSONObject (org.json.JSONObject)23 File (java.io.File)12 HashMap (java.util.HashMap)5 Bitmap (android.graphics.Bitmap)3 StringEntity (org.apache.http.entity.StringEntity)3 XmlDom (com.androidquery.util.XmlDom)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 HttpEntity (org.apache.http.HttpEntity)2 Activity (android.app.Activity)1 AQuery (com.androidquery.AQuery)1 GoogleHandle (com.androidquery.auth.GoogleHandle)1 Gson (com.google.gson.Gson)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1