Search in sources :

Example 41 with AjaxStatus

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

the class AQueryAsyncTest method testExtendTransformer.

public void testExtendTransformer() {
    String url = "https://graph.facebook.com/205050232863343";
    AjaxCallback<Profile> cb = new AjaxCallback<Profile>() {

        @Override
        protected Profile transform(String url, byte[] data, AjaxStatus status) {
            Profile profile = null;
            if (data != null) {
                Gson g = new Gson();
                profile = g.fromJson(new String(data), getType());
            }
            return profile;
        }

        @Override
        public void callback(String url, Profile profile, AjaxStatus status) {
            done(url, profile, status);
        }
    };
    aq.ajax(url, Profile.class, cb);
    waitAsync(2000);
    assertNotNull(result);
}
Also used : Gson(com.google.gson.Gson) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 42 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPost.

//Test: <K> T ajax(String url, Map<String, Object> params, Class<K> type, AjaxCallback<K> callback)
public void testAjaxPost() {
    String url = "http://www.androidquery.com/p/doNothing";
    Map<String, String> params = new HashMap<String, String>();
    params.put("q", "androidquery");
    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 : JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 43 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxInactiveActivity.

public void testAjaxInactiveActivity() {
    String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0";
    Activity act = getActivity();
    act.finish();
    assertTrue(act.isFinishing());
    AQuery aq = new AQuery(act);
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            assertFalse(true);
            done(url, jo, status);
        }
    };
    aq.ajax(url, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNull(jo);
}
Also used : AQuery(com.androidquery.AQuery) JSONObject(org.json.JSONObject) Activity(android.app.Activity) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 44 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxTransformErrorWontCache.

public void testAjaxTransformErrorWontCache() {
    String url = "http://www.google.com";
    /*
        AjaxCallback<String> cb = new AjaxCallback<String>(){
            
            @Override
            public void callback(String url, String str, AjaxStatus status) {
                
               
           
            }
            
        };
        
        aq.ajax(url, String.class, 0, cb);
        
        waitAsync(2000);
        
        assertNotNull(aq.getCachedFile(url));
        */
    AjaxCallback<JSONObject> cb2 = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            done(url, jo, status);
        }
    };
    aq.ajax(url, JSONObject.class, 0, cb2);
    waitAsync(2000);
    assertEquals(AjaxStatus.TRANSFORM_ERROR, status.getCode());
    JSONObject jo = (JSONObject) result;
    assertNull(jo);
    File file = aq.getCachedFile(url);
    AQUtility.debug("check file", file);
    assertNull(file);
}
Also used : JSONObject(org.json.JSONObject) 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 45 with AjaxStatus

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

the class AQueryAsyncTest method testAjaxPostMultiWithProxyHandle.

public void testAjaxPostMultiWithProxyHandle() {
    BasicProxyHandle handle = new BasicProxyHandle("192.168.0.102", 3128, null, null);
    AjaxCallback.setProxyHandle(handle);
    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);
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            AQUtility.debug(status.getCode(), status.getError());
            AQueryAsyncTest.this.result = jo;
        }
    };
    aq.ajax(url, params, JSONObject.class, cb);
    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) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) 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