Android Open-source Framework (V) xutils---The ORM IOC converged framework in Android

Source: Internet
Author: User

Xutils, like Afinal, is an aggregation framework, chatty, but the more easily reaching. So it is not recommended to use, only to understand. To cope with the temporary project at hand.

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

I. Xutils INTRODUCTION

Xutils is based on afinal development, but it is much better than afinal stability. Xutils was originally derived from the Afinal framework and was heavily refactored, allowing Xutils to support large file uploads, more comprehensive HTTP request protocol support (10 predicates), More flexible ORM, more event annotations support, and are not affected by confusion ...
XUITLS minimum compatible Android 2.2.

Xutils Four modules:
DbManager  Database Access interface
The ORM framework in Android, a line of code can be modified to check; Support transactions, default off; You can customize table names, column names, foreign keys, uniqueness constraints, NOT NULL constraints, check constraints, etc. (note table and column names when confusion is required); Support for binding foreign keys, saving entities When the foreign key associated entity is automatically saved or updated, the foreign key associated entities are loaded automatically, support delay loading, support chain expression query, more intuitive query semantics, refer to the following introduction or sample examples.
Viewinjector View Injection Interface        Android in the IOC framework, fully annotated mode can be UI, resource and event binding,        the new event binding method, using obfuscation tools can still work properly;        Currently supports 20 commonly used event bindings, see Viewcommoneventlistener Class and package com.lidroid.xutils.view.annotation.event.        
Httpmanager HTTP Request Interface    support synchronous, asynchronous request, support large file upload, upload large files will not oom; Support Get,post,put,move,copy,delete,head,options,trace,con Nect request; Download support 301/302 redirect, support setting whether to rename downloaded file according to Content-disposition, request to return text content (by default only GET request is enabled) support cache, set default expiration time and expiration time for current request.    
Imagemanager Picture Binding interface    when loading the bitmap, there is no need to consider the phenomenon of oom and picture dislocation when the fast sliding of the Android container occurs during the bitmap loading; supports loading network pictures and local images; memory management uses LRU algorithms for better Management bitmap memory, configurable line preempted thread count, cache size, cache path, load display animation, etc...
Confusing configuration:

1. Add Android Default obfuscation configuration ${sdk.dir}/tools/proguard/proguard-android.txt
2. Do not confuse the annotation type in xutils, add confusion Configuration:-keep class * extends Java.lang.annotation.Annotation {*;}
3. Do not confuse entity classes that use Dbutils module persistence, or annotate all table and column names @table (name= "xxx"), @Id (column= "xxx"), @Column (column= "xxx"), @Foreign ( column= "xxx", foreign= "xxx");

Two. Xutils use 1. Introduction of Sample Module

    

2. Remember to authorize
<uses-permission android:name="android.permission.INTERNET" />< Uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Init in 3.Application
 Public class MyApplication extends Application {    @Override    publicvoid  onCreate () {        Super.oncreate ();        X.ext.init (this);         // turning on debug can affect performance     }}
4.DbManager Operational Database
Dbmanager.daoconfig Daoconfig =Newdbmanager.daoconfig (). Setdbname ("test.db")            //when Dbdir is not set, it is stored in the app's private directory by default.. Setdbdir (NewFile ("/sdcard"))//"SDcard" is not the best practice, here for the sake of simplicity, this is the first to write.. Setdbversion (2). Setdbopenlistener (NewDbmanager.dbopenlistener () {@Override Public voidondbopened (DbManager db) {//turn on Wal, boost write accelerationdb.getdatabase (). enablewriteaheadlogging (); }}). Setdbupgradelistener (NewDbmanager.dbupgradelistener () {@Override Public voidOnupgrade (DbManager db,intOldversion,intnewversion) {                    //TODO: ...//db.addcolumn (...); //db.droptable (...); // ...                    //or//db.dropdb ();                }            });
DbManager db = X.getdb (daoconfig);        

Finally, the Dbmodelselector class in the db package called Xutils Lib is converted to SQL statement operations Sqllite Database

        

5.HttpManager request, Imagemanager loading picture
Private voidloadimglist (String url) {//Httpmanager Asynchronous GET requestX.http ().Get(NewRequestparams (URL),NewCallback.commoncallback<string>() {@Override Public voidonsuccess (String result) {IMAGELISTADAPTER.ADDSRC (Getimgsrclist (result)); Imagelistadapter.notifydatasetchanged ();//notify ListView of Update Data} @Override Public voidOnError (Throwable ex, Boolean isoncallback) {} @Override Public voidoncancelled (Cancelledexception CeX) {} @Override Public voidonfinished () {}}); }
imageoptions imageoptions; Imageoptions=NewImageoptions.builder (). SetSize (densityutil.dip2px ( -), densityutil.dip2px ( -). Setradius (densityutil.dip2px (5))                //if the size of the ImageView is not defined as wrap_content, do not crop.. Setcrop (true)//Most of the time, it is not necessary to set the appropriate scaletype. //loading or ScaleType of the wrong picture//. Setplaceholderscaletype (ImageView.ScaleType.MATRIX). Setimagescaletype (ImageView.ScaleType.CENTER_CROP). Setloadingdrawableid (r.mipmap.ic_l Auncher). Setfailuredrawableid (R.mipmap.ic_launcher). build ();
X.image (). Bind (Iv_big_img, Getintent (). Getstringextra ("url"), imageoptions);



Android Open-source Framework (V) xutils---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.