Search in sources :

Example 46 with AjaxStatus

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

the class AQueryImageTest method testImageIOError.

public void testImageIOError() {
    clearCache();
    AQUtility.cleanCache(AQUtility.getCacheDir(getActivity()), 0, 0);
    File file = aq.getCachedFile(LAND_URL);
    assertNull(file);
    AQUtility.TEST_IO_EXCEPTION = true;
    AQUtility.post(new Runnable() {

        @Override
        public void run() {
            BitmapAjaxCallback cb = new BitmapAjaxCallback() {

                protected void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {
                    AQUtility.debug("bm", bm);
                    //iv.setImageBitmap(bm);
                    bmResult = bm;
                }
            };
            aq.id(R.id.image).image(LAND_URL, true, true, 0, 0, cb);
        }
    });
    waitAsync(2000);
    assertNull(bmResult);
    File file2 = aq.getCachedFile(LAND_URL);
    if (file2 != null) {
        AQUtility.debug("file length", file2.length());
    }
    assertNull(file2);
}
Also used : BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) File(java.io.File) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 47 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPostMulti.

public void testAjaxPostMulti() {
    String url = "http://www.androidquery.com/p/multipart";
    Map<String, Object> params = new HashMap<String, Object>();
    byte[] data = new byte[1234];
    byte[] data2 = new byte[2345];
    params.put("data", data);
    params.put("data2", data2);
    aq.ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
        }
    });
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    assertEquals(1234, jo.optInt("data"));
    assertEquals(2345, jo.optInt("data2"));
}
Also used : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) JSONObject(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 48 with AjaxStatus

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

the class AQueryAsyncTest method testFile404.

public void testFile404() {
    String url = "http://androidquery.appspot.com/test/fake";
    File old = aq.getCachedFile(url);
    if (old != null) {
        old.delete();
    }
    old = aq.getCachedFile(url);
    assertNull(old);
    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();
    AjaxStatus status = cb.getStatus();
    assertNull(file);
    assertEquals(404, status.getCode());
    old = aq.getCachedFile(url);
    assertNull(old);
}
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)

Example 49 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxProxy.

//http://www.proxynova.com/proxy-server-list/
public void testAjaxProxy() throws ClientProtocolException, IOException {
    String url = "http://www.google.com";
    aq.ajax(url, String.class, new AjaxCallback<String>() {

        @Override
        public void callback(String url, String json, AjaxStatus status) {
            done(url, json, status);
        }
    }.proxy("192.168.0.105", 3128));
    waitAsync();
    assertNotNull(result);
    List<Header> headers = status.getHeaders();
    assertTrue(headers.size() > 0);
    Header c = headers.get(0);
    AQUtility.debug(c.getName(), c.getValue());
}
Also used : Header(org.apache.http.Header) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 50 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxProxyStaticNTLMCredential.

public void testAjaxProxyStaticNTLMCredential() throws ClientProtocolException, IOException {
    String url = "http://www.google.com";
    String proxyHost = "192.168.111.20";
    String domain = "AIGENSTEST.com";
    String user = "user3";
    String password = "Orange99";
    int port = 8081;
    //ProxyHandle handle = new BasicProxyHandle(host, port, user, password);
    ProxyHandle handle = new NTLMProxyHandle(proxyHost, port, domain, user, password);
    AjaxCallback.setProxyHandle(handle);
    aq.ajax(url, String.class, new AjaxCallback<String>() {

        @Override
        public void callback(String url, String json, AjaxStatus status) {
            done(url, json, status);
        }
    });
    waitAsync();
    assertNotNull(result);
}
Also used : ProxyHandle(com.androidquery.callback.ProxyHandle) 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