Search in sources :

Example 6 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxCallback.

//Test: public <K> T ajax(String url, Class<K> type, AjaxCallback<K> callback)
public void testAjaxCallback() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    };
    aq.ajax(url, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 7 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxBitmap.

public void testAjaxBitmap() {
    String url = ICON_URL;
    AjaxCallback<Bitmap> cb = new AjaxCallback<Bitmap>() {

        @Override
        public void callback(String url, Bitmap bm, AjaxStatus status) {
            done(url, bm, status);
        }
    };
    aq.ajax(url, Bitmap.class, 15 * 60 * 1000, cb);
    waitAsync(2000);
    assertNotNull(result);
    File cached = aq.getCachedFile(url);
    assertTrue(cached.exists());
    assertTrue(cached.length() > 100);
}
Also used : Bitmap(android.graphics.Bitmap) File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 8 with AjaxStatus

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

the class AQueryAsyncTest method testWaitBlockInputStream.

public void testWaitBlockInputStream() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    AjaxCallback<InputStream> cb = new AjaxCallback<InputStream>();
    cb.url(url).type(InputStream.class);
    aq.sync(cb);
    String u = cb.getUrl();
    InputStream is = cb.getResult();
    AjaxStatus status = cb.getStatus();
    byte[] data = AQUtility.toBytes(is);
    JSONObject jo = null;
    String str = null;
    try {
        str = new String(data, "UTF-8");
        jo = (JSONObject) new JSONTokener(str).nextValue();
    } catch (Exception e) {
        AQUtility.debug(e);
        AQUtility.debug(str);
    }
    assertNotNull(jo);
    assertNotNull(jo.opt("responseData"));
    checkStatus(status);
}
Also used : JSONTokener(org.json.JSONTokener) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Example 9 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxDelete.

public void testAjaxDelete() {
    String url = "http://www.androidquery.com/p/doNothing";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    };
    //aq.ajax(cb);
    aq.delete(url, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals("DELETE", jo.optString("method"));
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 10 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPostRaw.

public void testAjaxPostRaw() throws UnsupportedEncodingException {
    String url = "http://www.androidquery.com/p/doNothing";
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("q", "androidquery"));
    HttpEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(AQuery.POST_ENTITY, entity);
    aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNotNull(jo);
    assertNotNull(jo.opt("params"));
    assertEquals("POST", jo.optString("method"));
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpEntity(org.apache.http.HttpEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Aggregations

AjaxStatus (com.androidquery.callback.AjaxStatus)55 BitmapAjaxCallback (com.androidquery.callback.BitmapAjaxCallback)33 AjaxCallback (com.androidquery.callback.AjaxCallback)28 AbstractAjaxCallback (com.androidquery.callback.AbstractAjaxCallback)27 JSONObject (org.json.JSONObject)27 File (java.io.File)15 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)10 JsonObject (com.google.gson.JsonObject)8 Bitmap (android.graphics.Bitmap)7 Location (android.location.Location)4 ImageView (android.widget.ImageView)4 LocationAjaxCallback (com.androidquery.callback.LocationAjaxCallback)4 ArrayList (java.util.ArrayList)3 NameValuePair (org.apache.http.NameValuePair)3 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 ProxyHandle (com.androidquery.callback.ProxyHandle)2 Gson (com.google.gson.Gson)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2