Android Rapid Development Framework Afinal

Source: Internet
Author: User

This article was reproduced from: http://www.oschina.net/p/afinal/

Afinal Introduction
    • Afinal is an Android-SQLite ORM and IOC framework. It also encapsulates the HTTP framework in Android, making it easier to use;

    • With Finalbitmap, there is no need to consider the problem of Oom when the bitmap is loaded in Android and when the image loading position is misplaced when fast sliding.

    • The purpose of afinal is to be concise and fast. The contract is larger than the configured way. Try to do everything in one line of code.

Currently Afinal has four main modules:
    • FINALDB module: The ORM Framework in Android, a line of code can be used for additional deletions and checks. Support one-to-many, many-to-one queries.

    • Finalactivity module: The IOC framework in Android, which is fully annotated to enable UI binding and event binding. No need for Findviewbyid and Setclicklistener.

    • Finalhttp module: Encapsulates HTTP data requests through httpclient, and supports AJAX-mode loading.

    • Finalbitmap module: When loading the bitmap through Finalbitmap,imageview, there is no need to consider the phenomenon of image dislocation when the Oom and the Android container quickly slide during the bitmap loading process. Finalbitmap can configure the number of thread preempted threads, cache size, cache path, load display animation, etc. Finalbitmap's memory management uses the LRU algorithm, Not using weak references (after android2.3, Google has not recommended the use of weak references, android2.3 after the forced recovery of soft and weak references, details of the official Android document), better management bitmap memory. Finalbitmap can customize the downloader to extend other protocols to display network pictures, such as FTP. You can also customize the bitmap display, play animations when ImageView display pictures, and so on (default is the gradient animation display).

The following permissions are required to use the Afinal rapid development Framework:
12 <uses-permissionandroid:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    • The first one is to access the network

    • The second one is to visit sdcard

    • Access to the network is requested when the network image needs or HTTP data requests, access to SDcard is the need for picture caching.

Finaldb How to use
2345 FinalDb db = FinalDb.create(this); User user = newUser(); //这里需要注意的是User对象必须有id属性,或者有通过@ID注解的属性 user.setEmail("[email protected]"); user.setName("michael yang"); db.save(user);

Finalactivity How to use:
    • UI binding and event binding can be done in a fully annotated manner

    • No need for Findviewbyid and Setclicklistener etc.

123456789101112131415 publicclassAfinalDemoActivity extendsFinalActivity {      //无需调用findViewById和setOnclickListener等 @ViewInject(id=R.id.button,click="btnClick") Button button;     @ViewInject(id=R.id.textView) TextView textView;      publicvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);     }      publicvoidbtnClick(View v){        textView.setText("text set form button");     } }
Finalhttp How to use: Normal Get method?
1234567891011121314151617181920212223 FinalHttp fh = newFinalHttp(); fh.get("http://www.yangfuhai.com"newAjaxCallBack(){      @Override    public voidonLoading(longcount, longcurrent) { //每1秒钟自动被回调一次 textView.setText(current+"/"+count);     }      @Override    publicvoidonSuccess(String t) { textView.setText(t==null?"null":t);     }      @Override    public voidonStart() { //开始http请求的时候回调 }      @Override    publicvoidonFailure(Throwable t, String strMsg) { //加载失败的时候回调 } });
Uploading files using finalhttp or submitting data to the server (POST method)
1234567891011121314151617181920 AjaxParams params = newAjaxParams();   params.put("username""michael yang");   params.put("password""123456");   params.put("email""[email protected]");   params.put("profile_picture"newFile("/mnt/sdcard/pic.jpg")); // 上传文件 params.put("profile_picture2", inputStream); // 上传数据流 params.put("profile_picture3"newByteArrayInputStream(bytes)); // 提交字节流   FinalHttp fh = newFinalHttp();   fh.post("http://www.yangfuhai.com", params, newAjaxCallBack(){ @Override publicvoidonLoading(longcount, longcurrent) {     textView.setText(current+"/"+count); }  @Override publicvoidonSuccess(String t) { textView.setText(t==null?"null":t); }   });
To download a file using finalhttp:
    • Support breakpoint continuation, stop downloading task at any time or start task

?
123456789101112131415161718192021 FinalHttp fh = newFinalHttp();       //调用download方法开始下载 HttpHandler handler = fh.download("http://www.xxx.com/下载路径/xxx.apk", //这里是下载的路径     true,//true:断点续传 false:不断点续传(全新下载) "/mnt/sdcard/testapk.apk"//这是保存到本地的路径 newAjaxCallBack() {       @Override    publicvoidonLoading(long count, longcurrent) {    textView.setText("下载进度:"+current+"/"+count);       }        @Override    publicvoidonSuccess(File t) {   textView.setText(t==null?"null":t.getAbsoluteFile().toString());       }    });         //调用stop()方法停止下载 handler.stop();

Finalbitmap How to use

Load network pictures on one line of code Fb.display (Imageview,url), more display overloads see Help documentation

?
1234567891011121314151617181920212223242526272829303132 privateGridView gridView;     privateFinalBitmap fb;     @Override    protectedvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.images);  gridView = (GridView) findViewById(R.id.gridView); gridView.setAdapter(mAdapter);  fb = FinalBitmap.create(this);//初始化FinalBitmap模块 fb.configLoadingImage(R.drawable.downloading); //这里可以进行其他十几项的配置,也可以不用配置,配置之后必须调用init()函数,才生效 //fb.configBitmapLoadThreadSize(int size) //fb.configBitmapMaxHeight(bitmapHeight) }   ///////////////////////////adapter getView//////////////////////////////////////////// publicView getView(intposition, View convertView, ViewGroup parent) {     ImageView iv;     if(convertView == null){ convertView = View.inflate(BitmapCacheActivity.this,R.layout.image_item, null); iv = (ImageView) convertView.findViewById(R.id.imageView); iv.setScaleType(ScaleType.CENTER_CROP); convertView.setTag(iv);     }else{ iv = (ImageView) convertView.getTag();     }     //bitmap加载就这一行代码,display还有其他重载,详情查看源码 fb.display(iv,Images.imageUrls[position

Android Rapid Development Framework Afinal

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.