Search in sources :

Example 26 with AjaxStatus

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

the class AjaxLoadingActivity method async_file_custom.

public void async_file_custom() {
    String url = "https://picasaweb.google.com/data/feed/base/featured?max-results=16";
    File ext = Environment.getExternalStorageDirectory();
    File target = new File(ext, "aquery/myfolder2/photos1.xml");
    aq.progress(R.id.progress).download(url, target, new AjaxCallback<File>() {

        public void callback(String url, File file, AjaxStatus status) {
            if (file != null) {
                showResult("File:" + file.length() + ":" + file, status);
            } else {
                showResult("Failed", status);
            }
        }
    });
}
Also used : File(java.io.File) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 27 with AjaxStatus

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

the class AjaxAuthActivity method auth_facebook.

public void auth_facebook() {
    FacebookHandle handle = new FacebookHandle(this, APP_ID, PERMISSIONS) {

        @Override
        public boolean expired(AbstractAjaxCallback<?, ?> cb, AjaxStatus status) {
            //custom check if re-authentication is required
            if (status.getCode() == 401) {
                return true;
            }
            return super.expired(cb, status);
        }
    };
    String url = "https://graph.facebook.com/me/feed";
    aq.auth(handle).progress(R.id.progress).ajax(url, JSONObject.class, this, "facebookCb");
}
Also used : FacebookHandle(com.androidquery.auth.FacebookHandle) AbstractAjaxCallback(com.androidquery.callback.AbstractAjaxCallback) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 28 with AjaxStatus

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

the class AjaxLoadingActivity method async_post_entity.

/*
	public void async_post2(){
		
        String url = "your url";
		
        //get your byte array or file
        byte[] data = new byte[1000];
        
		Map<String, Object> params = new HashMap<String, Object>();
		
		//put your post params
		params.put("paramName", data);
		
		AjaxCallback<byte[]> cb = new AjaxCallback<byte[]>() {

            @Override
            public void callback(String url, byte[] data, AjaxStatus status) {
               
            	System.out.println(data);
            	System.out.println(status.getCode() + ":" + status.getError());
                
            	
            }
        };
        
        cb.url(url).type(byte[].class);
        
        //set Content-Length header
        cb.params(params).header("Content-Length", Integer.toString(data.length));
		cb.async(this);
		
	}
	*/
public void async_post_entity() throws UnsupportedEncodingException {
    String url = "http://search.twitter.com/search.json";
    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.progress(R.id.progress).ajax(url, params, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject json, AjaxStatus status) {
            showResult(json, status);
        }
    });
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) 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(org.json.JSONObject) AjaxStatus(com.androidquery.callback.AjaxStatus)

Example 29 with AjaxStatus

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

the class ImageLoadingActivity method image_file_custom.

public void image_file_custom() {
    String imageUrl = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
    File file = aq.getCachedFile(imageUrl);
    final int tint = 0x77AA0000;
    if (file != null) {
        aq.id(R.id.image).progress(R.id.progress).visible().image(file, true, 300, new BitmapAjaxCallback() {

            @Override
            public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {
                iv.setImageBitmap(bm);
                iv.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
                showMeta(status);
            }
        });
    }
}
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 30 with AjaxStatus

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

the class AjaxLoadingActivity method async_put.

public void async_put() throws JSONException, UnsupportedEncodingException {
    String url = "http://www.androidquery.com/p/doNothing";
    JSONObject input = new JSONObject();
    input.put("param1", "value1");
    input.put("param2", "value2");
    StringEntity entity = new StringEntity(input.toString(), "UTF-8");
    aq.progress(R.id.progress).put(url, "application/json", entity, JSONObject.class, new AjaxCallback<JSONObject>() {

        @Override
        public void callback(String url, JSONObject jo, AjaxStatus status) {
            showResult(jo);
        }
    });
}
Also used : StringEntity(org.apache.http.entity.StringEntity) 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