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

Why are human organs asymmetrical? Cell chirality may provide the answer

Why do we look almost symmetrical on both sides, ...

In addition to defeating Tesla, Audi e-tron has another major mission

Starting with the e-tron, Audi's first electr...

Lock the CPU frequency of Android devices

[[184787]] This article introduces the method of ...

Aite Tribe Stories (2): The Road to Transformation Caused by Chance

【51CTO.com original article】 Use craftsmanship to...

Why do Huawei phones always use HiSilicon processors?

Huawei has just released the P7, which is still eq...

5 Top Traffic Video Marketing and YouTube Video Production Tutorials

For many foreign trade people, video marketing is...

Are we evolving towards "Iron Man" with smart organ implants?

Last week, we launched the special topic "Sm...

On the first day of the new year, beautiful images came from Mars

On New Year's Day 2022, the National Space Ad...

The secret to becoming a king of sales: subvert your understanding of sales

Course Catalog: ├──01 Can you really sell anythin...

APP promotion and operation: How did the first batch of users come?

When developing an APP, we must first understand ...

Android Activity Security

Each Android Application is composed of basic And...