xUtils3


Source link: https://github.com/wyouflf/xUtils3

xUtils3??

  • xUtils ???orm, http(s), image, view??, ???????(246K), ??????, ????:
    • ?????: AbsTask???????? Callback, ????, ????????????????? onError, ????? onFinished???????????.
    • ??????? orm??, http??????????cookie(??domain, path, expiry???)? ??(??Cache-Control, Last-Modified, ETag???)???.
    • ????? http?????????, image??????????, ???????view??, ??Mem Cache?????, ??????????..
    • view??????400?????????????View???????, ?????????listener???.

????

  • ??????(??2G)??
  • ????http??????(11???)
  • ???????ORM, ?greenDao?????
  • ????????????????...
  • ??????gif(????????, ??gif????????), webp; ????, ??, ?????, ??????...
  • ?3.5.0??????libwebpbackport.so, ???Android4.2??????webp????3.4.0??.

??Gradle???????????:

compile 'org.xutils:xutils:3.5.0'
????eclipse?? ??????aar??, ???zip??, ??jar??.
??????????sample???

????:

  1. ?????????: https://github.com/wyouflf/xUtils3/issues/149
  2. Cookie???: https://github.com/wyouflf/xUtils3/issues/125
  3. ??query??? http?????? header, url, body(???)??; query???url???(?)?????.
  4. ??body??? body????PUT, POST, PATCH, DELETE(???RFC2616?????????????, ??????)????.
  5. ???Http?????????: https://github.com/wyouflf/xUtils3/issues/191

?????

?????
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
???
// ?application?onCreate???? @Override public void onCreate() {

  super.onCreate();

  x.Ext.init(this);

  x.Ext.setDebug(BuildConfig.DEBUG);
 // ????debug??, ??debug?????.
  ... 
}

??@Event????(@ContentView, @ViewInject???????sample??)

/**  * 1. ????????,  * 2. ?????????type???Listener????.  * 3. ????value????: value={
id1, id2, id3
}
  * 4. ???????{
@link org.xutils.event.annotation.Event
}
????.  **/ @Event(value = R.id.btn_test_baidu1,

type = View.OnClickListener.class/*????, ???View.OnClickListener.class*/) private void onTestBaidu1Click(View view) {
 ... 
}

????(??????sample??)

/**  * ???????????:  * ???? {
@link org.xutils.http.annotation.HttpRequest
}
  * ?????????? {
@link org.xutils.http.app.ParamsBuilder
}
  *  * ?????????callback????, ??:  * ???? {
@link org.xutils.http.annotation.HttpResponse
}
  * ?????????? {
@link org.xutils.http.app.ResponseParser
}
  *  * ??: ?? org.xutils.sample.http ?????  */ BaiduParams params = new BaiduParams();
 params.wd = "xUtils"; // ????????multipart??, ?????????. // params.setMultipart(true);
 // ?????? 1 // params.uploadFile = new File("/sdcard/test.txt");
 // ?????? 2 // params.addBodyParameter("uploadFile", new File("/sdcard/test.txt"));
 Callback.Cancelable cancelable

  = x.http().get(params,

  /** 

  * 1. callback???: 

  * callback?????????????{
@link org.xutils.http.loader.LoaderFactory
}
, 

  * ??: ?????File????????, ??params.setSaveFilePath(path)??????????. 

  * ????????(???????????????????). 

  * ???????????LoaderFactory???, 

  * ?????{
@link org.xutils.http.annotation.HttpResponse
}
 

  * ???HttpResponse???????????, ?????ResponseParser???????. 

  * ??????json??, ????????json????????????ResponseParser. 

  * ?????{
@link org.xutils.sample.http.BaiduResponse
}
, ?????BaiduResponse?? 

  * callback???. 

  * 

  * 2. callback???: 

  * ??????????????Callback, ?{
@link org.xutils.common.Callback
}
. 

  * ??: 

  * a. ????CacheCallback????????????????(?GET????). 

  * b. ????PrepareCallback?prepare????callback???????????????, 

  * ??????onCache?onSuccess. 

  * c. ????ProgressCallback???????. 

  * ...(???{
@link org.xutils.image.ImageLoader
}
 

  * ? ?????? {
@link org.xutils.sample.download.DownloadCallback
}
) 

  * 

  * 3. ???????????: ?? {
@link org.xutils.http.app.RequestTracker
}
 

  * 

  * 4. ??Header??: ?? {
@link org.xutils.http.app.RequestInterceptListener
}
 

  * 

  * 5. ??(???, ??, ???, ??, ???): ?? {
@link org.xutils.http.RequestParams
}
 

  * 

  **/

  new Callback.CommonCallback<String>() {

@Override

public void onSuccess(String result) {

 Toast.makeText(x.app(), result, Toast.LENGTH_LONG).show();

}

 @Override

public void onError(Throwable ex, boolean isOnCallback) {

 //Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();


 if (ex instanceof HttpException) {
 // ????

  HttpException httpEx = (HttpException) ex;

  int responseCode = httpEx.getCode();

  String responseMsg = httpEx.getMessage();

  String errorResult = httpEx.getResult();

  // ...

 
}
 else {
 // ????

  // ...

 
}

 Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();

}

 @Override

public void onCancelled(CancelledException cex) {

 Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();

}

 @Override

public void onFinished() {

 
}

  
}
);
  // cancelable.cancel();
 // ????

?????????????:

@Event(value = R.id.btn_test_baidu2) private void onTestBaidu2Click(View view) {

  RequestParams params = new RequestParams("https://www.baidu.com/s");

  params.setSslSocketFactory(...);
 // ??ssl
  params.addQueryStringParameter("wd", "xUtils");

  x.http().get(params, new Callback.CommonCallback<String>() {

@Override

public void onSuccess(String result) {

 Toast.makeText(x.app(), result, Toast.LENGTH_LONG).show();

}

 @Override

public void onError(Throwable ex, boolean isOnCallback) {

 Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();

}

 @Override

public void onCancelled(CancelledException cex) {

 Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();

}

 @Override

public void onFinished() {

 
}

  
}
);
 
}

?????????:

BaiduParams params = new BaiduParams();
 params.wd = "xUtils"; // ????????, ??:??.(???????????max-age?Expires) params.setCacheMaxAge(1000 * 60);
 Callback.Cancelable cancelable

// ??CacheCallback, xUtils?????????.
= x.http().get(params, new Callback.CacheCallback<String>() {

private boolean hasError = false;  private String result = null;
@Override  public boolean onCache(String result) {

// ??????, ?????????????.
// ?????????????, ??params.setCacheMaxAge(maxAge)??.

//

// * ???????????? header ? max-age ? expires ?????????? onCache ??.

//
????????? max-age ? expires, ?????????, ???????????false?

//
??, ??xUtils??????, ????.

//

// * ????????? true, ???????;

//
?? false ??????, ?????????ETag, Last-Modified???,

//
???????304, ?????????, ???????.

//

this.result = result;

return false; // true: ??????, ????????; false???????.  
}

@Override  public void onSuccess(String result) {

// ??: ??????304 ? onCache ???????, ??result?null.

if (result != null) {

 this.result = result;

}
  
}

@Override  public void onError(Throwable ex, boolean isOnCallback) {

hasError = true;
Toast.makeText(x.app(), ex.getMessage(), Toast.LENGTH_LONG).show();

if (ex instanceof HttpException) {
 // ????
 HttpException httpEx = (HttpException) ex;
 int responseCode = httpEx.getCode();

 String responseMsg = httpEx.getMessage();

 String errorResult = httpEx.getResult();

 // ...

}
 else {
 // ????
 // ...

}
  
}

@Override  public void onCancelled(CancelledException cex) {

Toast.makeText(x.app(), "cancelled", Toast.LENGTH_LONG).show();
  
}

@Override  public void onFinished() {

if (!hasError && result != null) {

 // ??????
 Toast.makeText(x.app(), result, Toast.LENGTH_LONG).show();

}
  
}
 
}
);

?????(??????sample??)

Parent test = db.selector(Parent.class).where("id", "in", new int[]{
1, 3, 6
}
).findFirst();
 long count = db.selector(Parent.class).where("name", "LIKE", "w%").and("age", ">", 32).count();
 List<Parent> testList = db.selector(Parent.class).where("id", "between", new String[]{
"1", "5"
}
).findAll();

????(??????sample??)

x.image().bind(imageView, url, imageOptions);
  // assets file x.image().bind(imageView, "assets://test.gif", imageOptions);
  // local file x.image().bind(imageView, new File("/sdcard/test.gif").toURI().toString(), imageOptions);
 x.image().bind(imageView, "/sdcard/test.gif", imageOptions);
 x.image().bind(imageView, "file:///sdcard/test.gif", imageOptions);
 x.image().bind(imageView, "file:/sdcard/test.gif", imageOptions);
  x.image().bind(imageView, url, imageOptions, new Callback.CommonCallback<Drawable>() {
...
}
);
 x.image().loadDrawable(url, imageOptions, new Callback.CommonCallback<Drawable>() {
...
}
);
 // ???????? x.image().loadFile(url, imageOptions, new Callback.CommonCallback<File>() {
...
}
);

????

  • Email? [email protected], [email protected]
  • ??????????????????????, ??????QQ??330445659(??), 275967695, 257323060, 384426013, 176778777, 169852490, 261053948, 330108003, ?????idea?? _

Resources

A 'Google Fit' like activity indicator for Android.

The Cult will provide a new layout for your Toolbar. This allow you to use with a custom SearchView with animation and more.

Android quick access to 1000+ pre-loaded @colors!

ColorPhrase is an Android string resource color setting library.

A framework used to bridge one or more spans for use with a TextView.

A practical tool which helps users to slice and share their pictures.

Features:

  • Displaying all pictures of system Gallery
  • Slicing and resizing pictures
  • Sharing all slices at once
  • Concurrent optimization

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes