Android Open source Framework (IV) afinal---The ORM IOC converged framework in Android

Source: Internet
Author: User
Tags sqlite database

Afinal is an ORM and IOC framework for Android SQLite. It is an aggregation framework, chatty. So it is not recommended to use, only to understand. To cope with the temporary project at hand.

Recommended to read, so many open source framework, which is good? :

I. INTRODUCTION

Afinal is an open source Android ORM and IOC application Development framework. In Android application development, the Finalactivity module is automatically bound through the Afinal IOC framework, such as UI bindings, event bindings, and annotations. Afinal's ORM Framework makes it easy to scan and check Android SQLite database, afinal embedded with finalhttp and other easy-to-use tools, can easily request HTTP operation

Two. Introduction to Annotations

Say that the annotation first touches the most is @override: means that the method is to override the method in the parent class, compile time will check the method, if this method is not present in the parent class will be an error.

The java.lang.annotation contains all the original annotations and interfaces needed to define the custom annotations. Interface Java.lang.annotation.Annotation is an interface that is inherited by all annotations, is automatically inherited, does not need to be specified when defined, and is similar to all classes that automatically inherit object. So many java.lang.annotation kinds of registration we can use directly.

Note Three methods of retention:

@Retention: Defining retention policies for annotations

@Retention (Retentionpolicy.source)//annotations only exist in the source code, in the class bytecode file does not contain
@Retention (Retentionpolicy.class)//default retention policy, annotations exist in the CLASS bytecode file, but the runtime cannot
@Retention (retentionpolicy.runtime)//annotations are present in the class bytecode file and can be obtained through reflection at run time

1.SOURCE: Remain in the source code only, not in the class, and not loaded into the virtual machine.
2.CLASS: retained in the source code, but also retained in the CLASS, but not loaded into the virtual machine. Some additional operations are performed according to annotations at the time of program compilation, and the famous Butterknife uses compile-time annotations. Butterknife when we compile, we automatically generate some auxiliary classes based on annotations.
3.RUNING: retained into the source code, but also retained in the class, and finally loaded into the virtual machine. In the runtime environment, using reflection, dynamic acquisition of objects, properties, methods, and so on, the general IOC framework can be sacrificed a little efficiency. Eventbus is the use of runtime annotations, the main function is to run the time to find all the annotated methods, and then to parse the annotations. runtime annotations can affect the performance of a program, after all, there is a lookup process at run time, so the function of the runtime annotations is usually to mark a scope.

Three. Afinal Introduction
four modules of afinal:

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).

Four. Afinal use 1. Introduction of Jar Pack 2. Authorization
<uses-permission android:name="android.permission.INTERNET" />< Uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
3.FinalDB use
FINALDB db = Finaldb.create (Thisnew  User (); User.setemail ("[email protected]  qq.com"); User.setid (1); User.setname ("Oreo "); Db.save (user);

View the following source code: (Final or turn to SQL execution)

 Public void Save (Object entity) {        this. Checktableexist (Entity.getclass ());          This . Exesqlinfo (Sqlbuilder.buildinsertsql (entity));    }
 Public StaticSqlinfo buildinsertsql (Object entity) {List<KeyValue> keyvaluelist =getsavekeyvaluelistbyentity (entity); StringBuffer strSQL=NewStringBuffer (); Sqlinfo Sqlinfo=NULL; if(Keyvaluelist! =NULL&& keyvaluelist.size () >0) {Sqlinfo=NewSqlinfo (); Strsql.append ("INSERT into"); Strsql.append (tableinfo.Get(Entity.getclass ()). Gettablename ()); Strsql.append (" ("); Iterator VAR5=Keyvaluelist.iterator ();  while(Var5.hasnext ()) {KeyValue kv=(KeyValue) var5.next (); Strsql.append (Kv.getkey ()). Append (",");            Sqlinfo.addvalue (Kv.getvalue ()); } Strsql.deletecharat (Strsql.length ()-1); Strsql.append (") VALUES ("); intLength =keyvaluelist.size ();  for(inti =0; i < length; ++i) {strsql.append ("?,"); } Strsql.deletecharat (Strsql.length ()-1); Strsql.append (")");        Sqlinfo.setsql (Strsql.tostring ()); }        returnSqlinfo; }
4.FinalBitmap use
// Start loading picture Finalbitmap.display (iv_afinal,"https://images2018.cnblogs.com/blog/612293/ 201807/612293-20180722160006222-1427704878.jpg");

View the following source:

Private voidDodisplay (View imageView, String URI, Bitmapdisplayconfig displayconfig) {if(! This. Minit) {             This. Init (); }        if(! Textutils.isempty (URI) && ImageView! =NULL) {            if(Displayconfig = =NULL) {Displayconfig= This. Mconfig.defaultdisplayconfig; } Bitmap Bitmap=NULL; if( This. mimagecache! =NULL) {
Priority cache fetching
Bitmap= This. Mimagecache.getbitmapfrommemorycache (URI); } if(Bitmap! =NULL) { if(ImageView instanceof ImageView) {(ImageView) imageView). Setimagebitmap (bitmap); } Else{imageview.setbackgrounddrawable (Newbitmapdrawable (bitmap)); } } Else if(Checkimagetask (URI, ImageView)) {
Finalbitmap Module Loading picture finalbitmap.bitmaploadanddisplaytask task=NewFinalbitmap.bitmaploadanddisplaytask (ImageView, displayconfig); Finalbitmap.asyncdrawable asyncdrawable=NewFinalbitmap.asyncdrawable ( This. Mcontext.getresources (), Displayconfig.getloadingbitmap (), Task); if(ImageView instanceof ImageView) {(ImageView) imageView). setimagedrawable (asyncdrawable); } Else{imageview.setbackgrounddrawable (asyncdrawable); } task.executeonexecutor ( This. Bitmaploadanddisplayexecutor,NewObject[]{uri}); } } }
5.FinalHttp Download File
Finalhttp finalhttp =Newfinalhttp (); //request the address of a network resourceString URL =""; //storing video files to a local locationString target = Getfilesdir () +"/testafinal.mp4"; Finalhttp.download (URL, target,NewAjaxcallback<file>() {@Override Public voidonsuccess (file file) {Tv_afinal_result.settext ("Download File Successful");            super.onsuccess (file); } @Override Public voidOnFailure (Throwable t,intErrorno, String strMsg) {Tv_afinal_result.settext ("failed to download file");            Super.onfailure (t, Errorno, STRMSG); } @Override Public voidOnStart () {Tv_afinal_result.settext ("Start Download");            Super.onstart (); }        });
6.FinalHttp Uploading Files
Finalhttp finalhttp =Newfinalhttp (); //where the files are uploaded to the serverString URL =""; Ajaxparamsparams=NewAjaxparams (); //get local resources to upload        Try {            params. put ("File",NewFile (Getfilesdir () +"/testafinal.mp4")); } Catch(FileNotFoundException e) {e.printstacktrace (); } finalhttp.post (URL,params,NewAjaxcallback<object>() {@Override Public voidOnStart () {Tv_afinal_result.settext ("Start uploading");            Super.onstart (); } @Override Public voidonsuccess (Object o) {tv_afinal_result.settext ("Upload Successful");            Super.onsuccess (o); } @Override Public voidOnFailure (Throwable t,intErrorno, String strMsg) {Tv_afinal_result.settext ("Upload failed");            Super.onfailure (t, Errorno, STRMSG); }        });

Android Open source Framework (IV) afinal---The ORM IOC converged framework in Android

Related Article

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.