Afinal简介
- Afinal 是一个android的sqlite orm 和 ioc 框架。同时封装了android中的http框架,使其更加简单易用;
- 使用finalBitmap,无需考虑bitmap在android中加载的时候oom的问题和快速滑动的时候图片加载位置错位等问题。
- Afinal的宗旨是简洁,快速。约定大于配置的方式。尽可能一行代码完成全部事情。
目前Afinal主要有四大模块:
-
FinalDB模块:android中的orm框架,一行代码就能够进行增删改查。支持一对多,多对一等查询。android
-
FinalActivity模块:android中的ioc框架,彻底注解方式就能够进行UI绑定和事件绑定。无需findViewById和setClickListener等。git
-
FinalHttp模块:经过httpclient进行封装http数据请求,支持ajax方式加载。github
-
FinalBitmap模块:经过FinalBitmap,imageview加载bitmap的时候无需考虑bitmap加载过程当中出现的oom和android容器快速滑动时候出现的图片错位等现象。FinalBitmap能够配置线程加载线程数量,缓存大小,缓存路径,加载显示动画等。FinalBitmap的内存管理使用lru算法,没有使用弱引用(android2.3之后google已经不建议使用弱引用,android2.3后强行回收软引用和弱引用,详情查看android官方文档),更好的管理bitmap内存。FinalBitmap能够自定义下载器,用来扩展其余协议显示网络图片,好比ftp等。同时能够自定义bitmap显示器,在imageview显示图片的时候播放动画等(默认是渐变更画显示)。ajax
使用afinal快速开发框架须要有如下权限:
1 |
< uses-permission android:name = "android.permission.INTERNET" /> |
2 |
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" /> |
- 第一个是访问网络
- 第二个是访问sdcard
- 访问网络是请求网络图片的时候须要或者是http数据请求时候须要,访问sdcard是图片缓存的须要。
FinalDB使用方法
关于finalDb的更多介绍,请点击这里算法
1 |
FinalDb db = FinalDb.create( this ); |
2 |
User user = new User(); |
3 |
user.setEmail( "mail@tsz.net" ); |
4 |
user.setName( "michael yang" ); |
FinalActivity使用方法:
- 彻底注解方式就能够进行UI绑定和事件绑定
- 无需findViewById和setClickListener等
01 |
public class AfinalDemoActivity extends FinalActivity { |
04 |
@ViewInject (id=R.id.button,click= "btnClick" ) Button button; |
05 |
@ViewInject (id=R.id.textView) TextView textView; |
07 |
public void onCreate(Bundle savedInstanceState) { |
08 |
super .onCreate(savedInstanceState); |
09 |
setContentView(R.layout.main); |
12 |
public void btnClick(View v){ |
13 |
textView.setText( "text set form button" ); |
FinalHttp使用方法:
普通get方法
01 |
FinalHttp fh = new FinalHttp(); |
02 |
fh.get( "http://www.yangfuhai.com" , new AjaxCallBack(){ |
05 |
public void onLoading( long count, long current) { |
06 |
textView.setText(current+ "/" +count); |
10 |
public void onSuccess(String t) { |
11 |
textView.setText(t== null ? "null" :t); |
15 |
public void onStart() { |
20 |
public void onFailure(Throwable t, String strMsg) { |
使用FinalHttp上传文件 或者 提交数据 到服务器(post方法)
文件上传到服务器,服务器如何接收,请查看这里sql
01 |
AjaxParams params = new AjaxParams(); |
02 |
params.put( "username" , "michael yang" ); |
03 |
params.put( "password" , "123456" ); |
04 |
params.put( "email" , "test@tsz.net" ); |
05 |
params.put( "profile_picture" , new File( "/mnt/sdcard/pic.jpg" )); |
06 |
params.put( "profile_picture2" , inputStream); |
07 |
params.put( "profile_picture3" , new ByteArrayInputStream(bytes)); |
09 |
FinalHttp fh = new FinalHttp(); |
10 |
fh.post( "http://www.yangfuhai.com" , params, new AjaxCallBack(){ |
12 |
public void onLoading( long count, long current) { |
13 |
textView.setText(current+ "/" +count); |
17 |
public void onSuccess(String t) { |
18 |
textView.setText(t== null ? "null" :t); |
使用FinalHttp下载文件:
01 |
FinalHttp fh = new FinalHttp(); |
03 |
HttpHandler handler = fh.download( "http://www.xxx.com/下载路径/xxx.apk" , //这里是下载的路径 |
05 |
"/mnt/sdcard/testapk.apk" , |
08 |
public void onLoading( long count, long current) { |
09 |
textView.setText( "下载进度:" +current+ "/" +count); |
13 |
public void onSuccess(File t) { |
14 |
textView.setText(t== null ? "null" :t.getAbsoluteFile().toString()); |
FinalBitmap 使用方法
加载网络图片就一行代码 fb.display(imageView,url) ,更多的display重载请看帮助文档缓存
01 |
private GridView gridView; |
02 |
private FinalBitmap fb; |
04 |
protected void onCreate(Bundle savedInstanceState) { |
05 |
super .onCreate(savedInstanceState); |
06 |
setContentView(R.layout.images); |
08 |
gridView = (GridView) findViewById(R.id.gridView); |
09 |
gridView.setAdapter(mAdapter); |
11 |
fb = FinalBitmap.create( this ); |
12 |
fb.configLoadingImage(R.drawable.downloading); |
21 |
public View getView( int position, View convertView, ViewGroup parent) { |
23 |
if (convertView == null ){ |
24 |
convertView = View.inflate(BitmapCacheActivity. this ,R.layout.image_item, null ); |
25 |
iv = (ImageView) convertView.findViewById(R.id.imageView); |
26 |
iv.setScaleType(ScaleType.CENTER_CROP); |
27 |
convertView.setTag(iv); |
29 |
iv = (ImageView) convertView.getTag(); |
32 |
fb.display(iv,Images.imageUrls[position]); |