简述afinal 框架的基本用法

  本文只是对afinal做简单的描述,基本和git上给的文档一样,大神绕道!

FinalDB模块本文为涉及到
FinalActivity模块,FinalHttp模块,FinalBitmap模块  代码体现!
 
下载地址:https://github.com/yangfuhai/afinal
解压之后获取最新的jar包,导入项目当中
首先 自己的类继承FinalActivity
public class FinalActivityTest extends FinalActivity
 
对控件的绑定
@ViewInject(id=R.id.f_http_tv) TextView textHttpView;
@ViewInject(id=R.id.f_btn,click="btnClick") Button button;
btnClick为点击事件 
直接写方法即可;pass 方法必须是公有的 不然会找不到
public void btnClick(View v){}
 
然后是 FinalBitmap
//图片类
fb = FinalBitmap.create(this);//初始化FinalBitmap模块
fb.configLoadingImage(R.drawable.ic_launcher);//默认图片
fb.display(iv,"http://219.232.161.206/data/userdata/vismam/downfile/201307/01193033Ppw7.jpeg");//加载的同时 会加入缓存 内部已经处理好
 
网络请求  此时 我直接贴代码了,代码中对参数和属性都做了注释
下载没在代码中,方法基本类似。
/**
* @author AT
* Http网络类
*  此处方法需要是公开的 public
*  如果使用同步(Sync)请方法,请在子线程执行这个操作,否则非常有可能报
*/
public void btnClickRequest(View v){
FinalHttp fh = new FinalHttp();
// fh.get(url, headers, params, callBack);
// fh.get(url, params, callBack);
// fh.post(url, headers, entity, contentType, callBack);
// fh.post(url, entity, contentType, callBack);
// fh.post(url, params, callBack);
// fh.post(url, callBack);
 
// fh.addHeader(header, value);添加头部
// fh.configCookieStore(cookieStore); 设置cookie
// fh.configUserAgent(userAgent);
// fh.configTimeout(timeout);设置超时
// fh.configSSLSocketFactory(sslSocketFactory);配置https请求
// fh.configRequestExecutionRetryCount(count);配置网络异常自动重复连接请求次数
 
AjaxParams param = new AjaxParams();
param.put("city", "北京");
fh.get("http://wthrcdn.etouch.cn/weather_mini",param, new AjaxCallBack<Object>(){
 
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
super.onFailure(t, errorNo, strMsg);
Toast.makeText(FinalActivityTest.this, "onFailure: "+strMsg, Toast.LENGTH_SHORT).show();
}
 
@Override
public void onLoading(long count, long current) {
super.onLoading(count, current);
System.out.println(current+"/"+count);
textHttpView.setText(current+"/"+count);
}
 
@Override
public void onStart() {
System.out.println("onStart");
super.onStart();
}
 
@Override
public void onSuccess(Object t) {
super.onSuccess(t);
 
Toast.makeText(FinalActivityTest.this, "onSuccess: "+t.toString(), Toast.LENGTH_SHORT).show();
textHttpView.setText(t.toString().length());
}
 
});
}
作者:-xu 邮箱:860072925@qq.com QQ群:IOS/Android 25961346
原文地址:https://www.cnblogs.com/qiaoxu/p/3867406.html