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();
}
}
Aggregations