使用 Android快速开发框架 Afinal 0.3 快速开发网络应用相关APK
2012-12-11 11:40
851 查看
这里介绍了android快速开发框架afinal0.3的http操作模块 FinalHttp,希望能对你们有所帮助。
afinal 网址:
https://github.com/yangfuhai/afinal http://code.google.com/p/afinal/
普通的get操作:
FinalHttp fh = new FinalHttp();
fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) { //每1秒钟自动被回调一次
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
@Override
public void onStart() {
//开始http请求的时候回调
}
@Override
public void onFailure(Throwable t, String strMsg) {
//加载失败的时候回调
}
});
FinalHttp fh = new FinalHttp();
fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) { //每5秒钟自动被回调一次,通过progress是否回调onLoading和回调频率
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
}.progress(true,5));//通过这里设置onloading的频率
文件上传或者数据提交:
AjaxParams params = new AjaxParams();
params.put("username", "michael yang");
params.put("password", "123456");
params.put("email", "test@tsz.net");
params.put("profile_picture", new File("/mnt/sdcard/pic.jpg")); // 上传文件
params.put("profile_picture2", inputStream); // 上传数据流
params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字节流
FinalHttp fh = new FinalHttp();
fh.post("http://www.yangfuhai.com", params, new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) {
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
});
android文件下载:
FinalHttp fh = new FinalHttp();
fh.download("http://www.xxx.com/下载路径/xxx.apk", "/mnt/sdcard/testapk.apk", new AjaxCallBack<File>() {
@Override
public void onLoading(long count, long current) {
textView.setText("下载进度:"+current+"/"+count);
}
@Override
public void onSuccess(File t) {
textView.setText(t==null?"null":t.getAbsoluteFile().toString());
}
});
http cookie操作:
BasicClientCookie bcc = new BasicClientCookie("", "");
bcc.setDomain("yangfuhai.com");
bcc.setPath("/");
bcc.setVersion(1);
PreferencesCookieStore pcs = new PreferencesCookieStore(this);
pcs.addCookie(bcc);
FinalHttp fh = new FinalHttp();
hk.setCookieStore(pcs);
fh.post("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) {
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
});
亲,是不是有了这个框架,你就可以减少至少一半的代码呢?
afinal 网址:
https://github.com/yangfuhai/afinal http://code.google.com/p/afinal/
普通的get操作:
FinalHttp fh = new FinalHttp();
fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) { //每1秒钟自动被回调一次
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
@Override
public void onStart() {
//开始http请求的时候回调
}
@Override
public void onFailure(Throwable t, String strMsg) {
//加载失败的时候回调
}
});
FinalHttp fh = new FinalHttp(); fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){ @Override public void onLoading(long count, long current) { //每1秒钟自动被回调一次 textView.setText(current+"/"+count); } @Override public void onSuccess(String t) { textView.setText(t==null?"null":t); } @Override public void onStart() { //开始http请求的时候回调 } @Override public void onFailure(Throwable t, String strMsg) { //加载失败的时候回调 } });
FinalHttp fh = new FinalHttp();
fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) { //每5秒钟自动被回调一次,通过progress是否回调onLoading和回调频率
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
}.progress(true,5));//通过这里设置onloading的频率
FinalHttp fh = new FinalHttp(); fh.get("http://www.yangfuhai.com", new AjaxCallBack<String>(){ @Override public void onLoading(long count, long current) { //每5秒钟自动被回调一次,通过progress是否回调onLoading和回调频率 textView.setText(current+"/"+count); } @Override public void onSuccess(String t) { textView.setText(t==null?"null":t); } }.progress(true,5));//通过这里设置onloading的频率
文件上传或者数据提交:
AjaxParams params = new AjaxParams();
params.put("username", "michael yang");
params.put("password", "123456");
params.put("email", "test@tsz.net");
params.put("profile_picture", new File("/mnt/sdcard/pic.jpg")); // 上传文件
params.put("profile_picture2", inputStream); // 上传数据流
params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字节流
FinalHttp fh = new FinalHttp();
fh.post("http://www.yangfuhai.com", params, new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) {
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
});
AjaxParams params = new AjaxParams(); params.put("username", "michael yang"); params.put("password", "123456"); params.put("email", "test@tsz.net"); params.put("profile_picture", new File("/mnt/sdcard/pic.jpg")); // 上传文件 params.put("profile_picture2", inputStream); // 上传数据流 params.put("profile_picture3", new ByteArrayInputStream(bytes)); // 提交字节流 FinalHttp fh = new FinalHttp(); fh.post("http://www.yangfuhai.com", params, new AjaxCallBack<String>(){ @Override public void onLoading(long count, long current) { textView.setText(current+"/"+count); } @Override public void onSuccess(String t) { textView.setText(t==null?"null":t); } });
android文件下载:
FinalHttp fh = new FinalHttp();
fh.download("http://www.xxx.com/下载路径/xxx.apk", "/mnt/sdcard/testapk.apk", new AjaxCallBack<File>() {
@Override
public void onLoading(long count, long current) {
textView.setText("下载进度:"+current+"/"+count);
}
@Override
public void onSuccess(File t) {
textView.setText(t==null?"null":t.getAbsoluteFile().toString());
}
});
FinalHttp fh = new FinalHttp(); fh.download("http://www.xxx.com/下载路径/xxx.apk", "/mnt/sdcard/testapk.apk", new AjaxCallBack<File>() { @Override public void onLoading(long count, long current) { textView.setText("下载进度:"+current+"/"+count); } @Override public void onSuccess(File t) { textView.setText(t==null?"null":t.getAbsoluteFile().toString()); } });
http cookie操作:
BasicClientCookie bcc = new BasicClientCookie("", "");
bcc.setDomain("yangfuhai.com");
bcc.setPath("/");
bcc.setVersion(1);
PreferencesCookieStore pcs = new PreferencesCookieStore(this);
pcs.addCookie(bcc);
FinalHttp fh = new FinalHttp();
hk.setCookieStore(pcs);
fh.post("http://www.yangfuhai.com", new AjaxCallBack<String>(){
@Override
public void onLoading(long count, long current) {
textView.setText(current+"/"+count);
}
@Override
public void onSuccess(String t) {
textView.setText(t==null?"null":t);
}
});
BasicClientCookie bcc = new BasicClientCookie("", ""); bcc.setDomain("yangfuhai.com"); bcc.setPath("/"); bcc.setVersion(1); PreferencesCookieStore pcs = new PreferencesCookieStore(this); pcs.addCookie(bcc); FinalHttp fh = new FinalHttp(); hk.setCookieStore(pcs); fh.post("http://www.yangfuhai.com", new AjaxCallBack<String>(){ @Override public void onLoading(long count, long current) { textView.setText(current+"/"+count); } @Override public void onSuccess(String t) { textView.setText(t==null?"null":t); } });
亲,是不是有了这个框架,你就可以减少至少一半的代码呢?
相关文章推荐
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 快速开发框架Afinal的使用(数据库操作,HTTP请求,网络图片加载,控件绑定)
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal 开发android应用程序
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal的FinalDb操作android sqlite数据库
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 使用android快速开发框架afinal的FinalDb操作android数据库
- 快速开发框架Afinal的使用(数据库操作,HTTP请求,网络图片加载,控件绑定)
- android -- 框架 使用android快速开发框架afinal的FinalBitmap
- 使用CodeIgniter框架快速开发PHP应用(四)
- 10个快速开发Android/Iphone web App应用的框架
- iOS快速开发框架Bee-Framework应用和解析(一) --- 为什么使用Bee framework
- Afinal 0.2.1 发布 Android的快速开发框架
- 使用 CodeIgniter 框架快速开发 PHP 应用(七)
- Android使用Andbase快速开发框架实现常见侧滑栏和滑动标签页组合效果
- Android快速开发工具ButterKnife Zelezny注解框架使用教程