Search in sources :

Example 36 with AjaxCallback

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

the class AQueryAsyncTest method testAjaxFileUrl.

public void testAjaxFileUrl() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    AjaxCallback<File> cb = new AjaxCallback<File>();
    cb.url(url).type(File.class);
    //aq.ajax(url, JSONObject.class, cb);
    aq.sync(cb);
    File file = cb.getResult();
    assertNotNull(file);
    AQUtility.debug(file.getAbsolutePath());
    String path = file.getAbsolutePath();
    AjaxCallback<String> cb2 = new AjaxCallback<String>();
    cb2.url(path).fileCache(true).type(String.class);
    aq.sync(cb2);
    String html = cb2.getResult();
    AQUtility.debug(html);
    assertNotNull(html);
}
Also used : File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback)

Example 37 with AjaxCallback

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

the class AQueryAsyncTest method testFile404NotOverwritenOldFile.

public void testFile404NotOverwritenOldFile() throws IOException {
    String url = "http://androidquery.appspot.com/test/fake";
    File old = AQUtility.getCacheFile(AQUtility.getCacheDir(getActivity()), url);
    if (old != null) {
        old.createNewFile();
        AQUtility.write(old, new byte[1234]);
    }
    old = aq.getCachedFile(url);
    assertNotNull(old);
    assertEquals(1234, old.length());
    AjaxCallback<File> cb = new AjaxCallback<File>();
    cb.url(url).type(File.class);
    aq.sync(cb);
    File file = cb.getResult();
    AjaxStatus status = cb.getStatus();
    assertNull(file);
    assertEquals(404, status.getCode());
    old = aq.getCachedFile(url);
    assertNotNull(old);
    assertEquals(1234, old.length());
}
Also used : File(java.io.File) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) 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