Featured recommendation: Detailed explanation of the use of xUtils framework

Featured recommendation: Detailed explanation of the use of xUtils framework

Introduction to xUtils

xUtils was originally derived from the Afinal framework, and has undergone a lot of refactoring, making xUtils support large file uploads, more comprehensive http request protocol support (10 predicates), more flexible ORM, more event annotation support and not affected by confusion...

xUtils is compatible with Android 2.2 (API level 8). Currently xUtils has four main modules:

DbUtils Module

The orm framework in android can add, delete, modify and check with one line of code;

Support transactions, closed by default;

You can customize table names, column names, foreign keys, unique constraints, NOT NULL constraints, CHECK constraints, etc. through annotations (please annotate table names and column names when confusion is required);

Supports binding foreign keys. When saving an entity, the foreign key-associated entity is automatically saved or updated.

ViewUtils Module

The IOC framework in Android can perform UI, resource and event binding completely through annotations;

New event binding method, which can still work normally after being obfuscated by obfuscation tools;

HttpUtils Module

Support synchronous and asynchronous requests;

Support large file upload, no OOM when uploading large files;

Support GET, POST, PUT, MOVE, COPY, DELETE, HEAD, OPTIONS, TRACE, CONNECT requests;

BitmapUtils Module

  1. When loading a bitmap, you don't need to consider the OOM that occurs during the bitmap loading process and the image misalignment that occurs when the Android container slides quickly;
  2.  
  3. Support loading network pictures and local pictures;
  4.  
  5. Memory management uses the LRU algorithm to better manage bitmap memory;

2. How to use DbUtils

  1. DbUtils db = DbUtils.create( this );
  2. User user = new User(); //It should be noted here that the User object must have an id attribute, or an attribute annotated with @ID  
  3. user.setEmail( "[email protected]" );
  4. user.setName( "jerehedu" );
  5. db.save(user); // When saving an entity using saveBindingId, the entity's id will be assigned a value  
  6.  
  7. ..
  8. // Search  
  9. Parent entity = db.findById(Parent. class , parent.getId());
  10. List<Parent> list = db.findAll(Parent. class ); //Search by type  
  11.  
  12. Parent Parent = db.findFirst(Selector.from(Parent. class ).where( "name" , "=" , "test" ));
  13.  
  14. // IS NULL  
  15. Parent Parent = db.findFirst(Selector.from(Parent. class ).where( "name" , "=" , null ));
  16. // IS NOT NULL  
  17. Parent Parent = db.findFirst(Selector.from(Parent. class ).where( "name" , "!=" , null ));
  18.  
  19. // WHERE id<54 AND (age>20 OR age<30) ORDER BY id LIMIT pageSize OFFSET pageOffset  
  20. List<Parent> list = db.findAll(Selector.from(Parent. class )
  21. .where( "id" , "<" , 54 )
  22. .and(WhereBuilder.b( "age" , ">" , 20 ).or( "age" , " < " , 30 ))
  23. .orderBy( "id" )
  24. .limit(pageSize)
  25. .offset(pageSize * pageIndex));
  26.  
  27. // When op is "in", the first parameter must be an array or an implementation class of Iterable (such as List, etc.)  
  28. Parent test = db.findFirst(Selector.from(Parent. class ).where( "id" , "in" , new   int []{ 1 , 2 , 3 }));
  29. // When op is "between", the first parameter must be an array or an implementation class of Iterable (such as List, etc.)  
  30. Parent test = db.findFirst(Selector.from(Parent. class ).where( "id" , "between" , new String[]{ "1" , "5" }));
  31.  
  32. DbModel dbModel = db.findDbModelAll(Selector.from(Parent. class ).select( "name" )); //select("name") only takes out the name column  
  33. List<DbModel> dbModels = db.findDbModelAll(Selector.from(Parent. class ).groupBy( "name" ).select( "name" , "count(name)" ));
  34. ...
  35.  
  36. List<DbModel> dbModels = db.findDbModelAll(sql); // Custom sql query  
  37. db.execNonQuery(sql) // Execute custom sql  
  38. 3. How to use HttpUtils
  39.  
  40. HttpUtils http = new HttpUtils();
  41. http.send(HttpRequest.HttpMethod.GET,
  42. "http://www.jerehedu.com" ,
  43. new RequestCallBack<String>(){
  44. @Override  
  45. public   void onLoading( long total, long current, boolean isUploading) {
  46. testTextView.setText(current + "/" + total);
  47. }
  48.  
  49. @Override  
  50. public   void onSuccess(ResponseInfo<String> responseInfo) {
  51. textView.setText(responseInfo.result);
  52. }
  53.  
  54. @Override  
  55. public   void onStart() {
  56. }
  57.  
  58. @Override  
  59. public   void onFailure(HttpException error, String msg) {
  60. }
  61. });

<<:  Let’s talk about overcalculation! Is your calculation method overcalculated?

>>:  iOS 9 new features revealed, artificial intelligence becomes another highlight

Recommend

Get these six points, attracting seed users will not be a problem

After everyone has experienced the first three ti...

Why is he called the “chief designer” of China’s aerospace industry?

Ren Xinmin, one of the important pioneers of Chin...

How can a promotion account achieve the best delivery effect? Here are 8 tips

Have you ever encountered this situation? You too...

Alien biology? Bacterial RNA encodes new genes, breaking the central dogma

Produced by: Science Popularization China Author:...

How to design a complete operation plan?

This article hopes to help entry-level product ma...

Planetary Exploration and "Look, Smell, Ask, and Touch"

Some time ago, I read Dr. Li Mingtao's articl...

What's the difference between Google and Tesla's self-driving technology?

Would you watch how a rice cooker cooks rice? You...

Taobao merchants' internet cables were cut at midnight on "Double 11"

The sales from 0:00 to 1:00 in the morning of &qu...

How can SaaS companies reduce user churn?

Reducing customer churn is a proven way for SaaS ...