Android recent projects to use the framework Xutils

Source: Internet
Author: User

Project Address: Https://github.com/wyouflf/xUtils
Xutils Introduction

    • Xutils contains a lot of useful Android tools.

    • Xutils from the afinal framework, the afinal has been heavily reconstructed, allowing the xutils to support large file uploads, more comprehensive HTTP request protocol support, more flexible ORM, more event annotations support, and no confusion affected ...

    • XUITLS Minimum compatible Android 2.2 (API Level 8)


  • dbutils module:

    • ORM Framework in Android, A single line of code can be added and modified;

    • Supports transactions and is closed by default;

    • You can customize table names, column names, foreign keys, uniqueness constraints, and NOT NULL constraints through annotations. CHECK constraints (Please note table and column names when confusing);

    • Supports binding foreign keys, and foreign key associated entities are automatically saved or updated when entities are saved;

    • Automatically load foreign key associated entities, support delay loading;

    • Supports chained expression queries, more intuitive query semantics, as described in the following introductory or sample examples.

  • viewutils module:

    • IOC framework in Android, UI binding and event binding can be done in a fully annotated fashion;

    • New event binding methods that work correctly when confused with obfuscation tools;

    • Currently supports 11 commonly used event bindings. See Viewcommoneventlistener class and package com.lidroid.xutils.view.annotation.event.

  • httputils module:

    • Supports synchronous, asynchronous requests;

    • Support large file upload, upload large files will not oom;

    • supports get,post,put,move,copy,delete,head requests;

    • Download supports 301/302 redirection, which supports setting whether to rename downloaded files according to content-disposition;

    • A GET request that returns text content supports caching, which sets the default expiration time and the expiration time for the current request.

  • Bitmaputils module:

    • When loading the bitmap, there is no need to consider the phenomenon of the image dislocation when the Oom and the Android container move quickly during the bitmap loading process.

    • Support to load network pictures and local images;

    • The memory management uses the LRU algorithm, better manages the bitmap memory;

    • Configurable line preempted thread count, cache size, cache path, load display animation, etc...

The following permissions are required to use the Xutils rapid development Framework:
<uses-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>
Things to note when confusing:
    • Do not confuse the annotation type in xutils, add confusion Configuration:-keep class * extends Java.lang.annotation.Annotation {*;}

    • 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");

Dbutils How to use:
Dbutils db = dbutils.create (this);  user user = new user ();  // It is important to note that the user object must have an id attribute, or a property  user.setemail ("[email protected]") that passes the @id annotation;  user.setname ("Wyouflf") ;  db.save (user); //  when you save an entity using Savebindingid, the ID of the entity is assigned  ... //  found  Parent  Entity = db.findbyid (Parent.class, parent.getid ()); parent entity =  Db.findfirst (entity);//Find  list<parent> list = db.findall (Entity) through the attribute of entity;// Find  parent parent = db.findfirst (Selector.from (Parent.class) through the properties of the entity. Where ("name", "=", " Test ")  list<parent> list = db.findall (Selector.from (Parent.class)  .where (" id ") , "<", " .and" ("Age", ">", "the")  .or ("Age", "<", " .orderby")  .limit ("id")  . Offset (0));  dbmodel dbmodel = db.finddbmodelall (Selector.from (Parent.class). Select ("name") );//select ("name") only takes out the name column  liSt<dbmodel> dbmodels = db.finddbmodelall (Selector.from (Parent.class). GroupBy ("name"). Select ("Name",  "Count (name)"));   ....
Viewutils How to use
    • UI binding and event binding can be done in a fully annotated manner.

    • No need for Findviewbyid and Setclicklistener.

@ViewInject (R.id.textview) TextView TextView; Cancels the way the method name binding event was used before, using the ID binding is not affected by confusion @OnClick (R.id.test_button) public void Testbuttonclick (View v) {...} ...//before using the annotation object (e.g. in onCreate): @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); Viewutils.inject (this); ... textview.settext ("some text ..."); ... }
Httputils How to use: Normal Get method
Httputils http = new Httputils (); Http.send (HttpRequest.HttpMethod.GET, "http://www.lidroid.com", new Requestcallback<string> () {@Override public void onloading (long total, long current) {Testtextview.settext (current + "/" + total), @Override public void OnS Uccess (String result) {Textview.settext (result),} @Override public void OnStart () {} @Override public void OnFailure (H Ttpexception error, String msg) {}});
Uploading files using Httputils or submitting data to the server (POST method)
Requestparams params = new requestparams ();  params.addheader ("Name",  "value");  params.addquerystringparameter ("name",  "value"); //  only contains string arguments when used by default bodyparamsentity, / /  is similar to urlencodedformentity ("application/x-www-form-urlencoded").  params.addbodyparameter ("name",  "value"); //  use multipartentity after adding a file parameter ("multipart/ Form-data "), //  if" multipart/related "is required, the Multipartentity support settings provided in Xutils subtype to" related ".  //  use Params.setbodyentity (httpentity) to set more types of httpentity such as:  // multipartentity, bodyparamsentity,fileuploadentity,inputstreamuploadentity,stringentity).  params.addbodyparameter ("File",  new file ("path"));  ... httputils http =  new httputils ();  http.send (httprequest.httpmethod.post,  "Uploadurl ....",  params,  new RequestCallBack<String> ()  {  @Override  public void onstart ()  { testtextview.SetText ("conn ..."); }  @Override  public void onloading (long total, long  current)  { testtextview.settext (current +  "/"  + total);  } @ Override public void onsuccess (String result)  { testtextview.settext ("Upload  response: " + result.getpath ()); }  @Override  public void onfailure ( httpexception error, string msg)  { testtextview.settext (Error.getExceptionCode ()  +  ":"  + msg);  } });
To download a file using httputils:
    • Support breakpoint continuation, stop downloading task at any time, start task

Httputils http = new httputils ();  httphandler handler = http.download ( "Http://apache.dataguru.cn/httpcomponents/httpclient/source/httpcomponents-client-4.2.5-src.zip",  "/ Sdcard/httpcomponents-client-4.2.5-src.zip ", true, //  If the destination file exists, then the unfinished portion continues to download.  true, //  If the file name is obtained from the request return information, it is automatically renamed after the download is complete.  new RequestCallBack<File> ()  {  @Override  public void onstart ()  {  testtextview.settext ("conn ..."); }  @Override  public void onloading (long  total, long current)  { testtextview.settext (current +  "/"  + total);  }  @Override  public void onsuccess (file result)  { testtextview.settext ("Downloaded:"  + result.getpath ()); }  @Override  public void onfailure ( httpexception error, string msg)  { testtextview.settext (msg);  } }) ... //Call the Stop () method to stop downloading  handler.stop ();  .. 
Bitmaputils How to use
Bitmaputils.create (This). Display (Testimageview, "http://bbs.lidroid.com/static/image/common/logo.png"); Bitmaputils.create (This). Display (Testimageview, "/sdcard/test.jpg"); Support loading of local images//using containers such as listView to display pictures when you can control the slide through the Pauseonscrolllistener and the rapid sliding process during the pause loading picture Listview.setonscrolllistener (new Pauseonscrolllistener (Bitmaputils, False, true)); Listview.setonscrolllistener (New Pauseonscrolllistener (Bitmaputils, False, True), Customlistener);
Other (* * * More sample code see code in the sample folder * * *) output log logutils
Automatically add tag, format: Classname[methodname, linenumber]//can set the global allowd,allowe ..., control whether to output log. LOGUTILS.D ("Wyouflf");


This article is from the "unity of Knowledge" blog, please be sure to keep this source http://poarry.blog.51cto.com/5970996/1552680

Android recent projects to use the framework Xutils

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.