Search in sources :

Example 1 with BasicNameValuePair

use of com.koushikdutta.async.http.BasicNameValuePair in project AndroidAsync by koush.

the class MainActivity method getChartFile.

private void getChartFile() {
    final ImageView iv = chart;
    final String filename = getFileStreamPath(randomFile()).getAbsolutePath();
    ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add(new BasicNameValuePair("cht", "lc"));
    pairs.add(new BasicNameValuePair("chtt", "This is a google chart"));
    pairs.add(new BasicNameValuePair("chs", "512x512"));
    pairs.add(new BasicNameValuePair("chxt", "x"));
    pairs.add(new BasicNameValuePair("chd", "t:40,20,50,20,100"));
    UrlEncodedFormBody writer = new UrlEncodedFormBody(pairs);
    try {
        AsyncHttpPost post = new AsyncHttpPost("http://chart.googleapis.com/chart");
        post.setBody(writer);
        AsyncHttpClient.getDefaultInstance().executeFile(post, filename, new AsyncHttpClient.FileCallback() {

            @Override
            public void onCompleted(Exception e, AsyncHttpResponse response, File result) {
                if (e != null) {
                    e.printStackTrace();
                    return;
                }
                Bitmap bitmap = BitmapFactory.decodeFile(filename);
                result.delete();
                if (bitmap == null)
                    return;
                BitmapDrawable bd = new BitmapDrawable(bitmap);
                assignImageView(iv, bd);
            }
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : BasicNameValuePair(com.koushikdutta.async.http.BasicNameValuePair) NameValuePair(com.koushikdutta.async.http.NameValuePair) ArrayList(java.util.ArrayList) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) AsyncHttpResponse(com.koushikdutta.async.http.AsyncHttpResponse) BasicNameValuePair(com.koushikdutta.async.http.BasicNameValuePair) ImageView(android.widget.ImageView) UrlEncodedFormBody(com.koushikdutta.async.http.body.UrlEncodedFormBody) AsyncHttpPost(com.koushikdutta.async.http.AsyncHttpPost) File(java.io.File) AsyncHttpClient(com.koushikdutta.async.http.AsyncHttpClient)

Aggregations

Bitmap (android.graphics.Bitmap)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ImageView (android.widget.ImageView)1 AsyncHttpClient (com.koushikdutta.async.http.AsyncHttpClient)1 AsyncHttpPost (com.koushikdutta.async.http.AsyncHttpPost)1 AsyncHttpResponse (com.koushikdutta.async.http.AsyncHttpResponse)1 BasicNameValuePair (com.koushikdutta.async.http.BasicNameValuePair)1 NameValuePair (com.koushikdutta.async.http.NameValuePair)1 UrlEncodedFormBody (com.koushikdutta.async.http.body.UrlEncodedFormBody)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1