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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations