Search in sources :

Example 26 with AjaxCallback

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

the class AQueryAsyncTest method testAjaxPutNamedValues.

public void testAjaxPutNamedValues() throws UnsupportedEncodingException {
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("count", "5"));
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, "UTF-8");
    entity.setContentType("application/x-www-form-urlencoded;charset=UTF-8");
    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.put(url, "application/x-www-form-urlencoded;charset=UTF-8", entity, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    AQUtility.debug(jo);
    assertNotNull(jo);
    JSONObject params = jo.optJSONObject("params");
    assertEquals("5", params.optString("count"));
//assertEquals("PUT", jo.optString("method"));
}
Also used : NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) JSONObject(org.json.JSONObject) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 27 with AjaxCallback

use of com.androidquery.callback.AjaxCallback 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 28 with AjaxCallback

use of com.androidquery.callback.AjaxCallback 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 29 with AjaxCallback

use of com.androidquery.callback.AjaxCallback 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 30 with AjaxCallback

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

the class AQueryAsyncTest method testRetryFailed.

public void testRetryFailed() {
    String url = "http://www.androidquery.com/p/retry?wait=5000";
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
    cb.weakHandler(this, "jsonCb").timeout(1000);
    aq.ajax(url, JSONObject.class, cb);
    waitAsync();
    JSONObject jo = (JSONObject) result;
    assertNull(jo);
    assertEquals(-101, status.getCode());
}
Also used : JSONObject(org.json.JSONObject) AjaxCallback(com.androidquery.callback.AjaxCallback) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) BitmapAjaxCallback(com.androidquery.callback.BitmapAjaxCallback)

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