标签:row param cli his map 下载地址 client 返回 ima
上文记录了一些ThinkAndroid常用的模块,本文继续介绍ThinkAndroid中的网络化模块。
按照惯例先上Github原文地址:https://github.com/white-cat/ThinkAndroid
一、Http模块使用方法:
AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler()
{
@Override
public void onSuccess(String content)
{
// TODO Auto-generated method stub
super.onSuccess(content);
TALogger.d(LoginActivity.this, content);
}
@Override
public void onStart()
{
// TODO Auto-generated method stub
super.onStart();
}
@Override
public void onFailure(Throwable error)
{
// TODO Auto-generated method stub
super.onFailure(error);
}
@Override
public void onFinish()
{
// TODO Auto-generated method stub
super.onFinish();
}
});
TASyncHttpClient client = new TASyncHttpClient();
client.get("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler()
{
@Override
public void onSuccess(String content)
{
// TODO Auto-generated method stub
super.onSuccess(content);
TALogger.d(LoginActivity.this, content);
}
@Override
public void onStart()
{
// TODO Auto-generated method stub
super.onStart();
}
@Override
public void onFailure(Throwable error)
{
// TODO Auto-generated method stub
super.onFailure(error);
}
@Override
public void onFinish()
{
// TODO Auto-generated method stub
super.onFinish();
}
});
RequestParams params = new RequestParams();
params.put("username", "white_cat");
params.put("password", "123456");
params.put("email", "2640017581@qq.com");
params.put("profile_picture", new File("/mnt/sdcard/testpic.jpg")); // 上传文件
params.put("profile_picture2", inputStream); // 上传数据流
params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字节流
client.post("http://www.thinkandroid.cn/", new AsyncHttpResponseHandler()
{
@Override
public void onSuccess(String content)
{
// TODO Auto-generated method stub
super.onSuccess(content);
TALogger.d(LoginActivity.this, content);
}
@Override
public void onStart()
{
// TODO Auto-generated method stub
super.onStart();
}
@Override
public void onFailure(Throwable error)
{
// TODO Auto-generated method stub
super.onFailure(error);
}
@Override
public void onFinish()
{
// TODO Auto-generated method stub
super.onFinish();
}
});
}
调用syncHttpClient的download(url,fileHttpResponseHandler);方法,传入url地址及FileHttpResponseHandler对象
ps:一般在onProgress里执行处理下载进度,速度等操作;
实例代码:
实例代码如下:
final DownloadManager mDownloadManager = DownloadManager.getDownloadManager();
mDownloadManager.addHandler(url);
二、图片模块 方法
加载:
@TAInjectView(id = R.id.listView)
ListView lv;
Adapter adapter = new Adapter(this, getTAApplication());//传入TAapplication
lv.setAdapter(adapter);
绑定数据:
1、实例化TADownloadBitmapHandler对象传入参数context,图片宽高
2、实例化TABitmapCallBackHanlder对象,设置图片的加载中图片通过setLoadingImage方法
3、实例化TABitmapCahceWork对象
4、该对象调用setFileCache实现设置缓存路径
5、该对象调用步骤2的bitmap回掉方法并传入tcbh对象
6、该对象调用步骤1的setProcessDataHandler方法传入TDBH对象
7、TABitmapCacheWork对象调用loadFormCache方法Object对象及imageview 进行图片缓存读取
实例代码如下:
getView方法中进行数据适配:
三、缓存模块 方法
调用缓存处理方法:
四、下载器模块
private DownloadManager downloadManager;
downloadManager = DownloadManager.getDownloadManager();
downloadManager.setDownLoadCallback(new DownLoadCallback()
{
@Override
public void onSuccess(String url)
{
}
@Override
public void onLoading(String url, String speed, String progress)
{
// TODO Auto-generated method stub
}
});
//添加
downloadManager.addHandler(url);
//继续
downloadManager.continueHandler(url);
//暂停
downloadManager.pauseHandler(url);
//删除
downloadManager.deleteHandler(url);
}
private IDownloadService downloadService;
ServiceConnection serviceConnection=new ServiceConnection()
{
@Override
public void onServiceDisconnected(ComponentName name)
{
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service)
{
// TODO Auto-generated method stub
downloadService=(IDownloadService)service;
}
};
//添加任务
downloadService.addTask(url)
//暂停任务
downloadService.pauseTask(url)
//继续任务
downloadService.continueTask(url)
//删除任务
downloadService.deleteTask(url)
标签:row param cli his map 下载地址 client 返回 ima
原文地址:http://www.cnblogs.com/cold-ice/p/6080958.html