<span id="Label3"></p><p><p>Reproduced</p></p><p># # XUTILS3 Introduction<br>* Xutils contains a lot of useful Android Tools.<br>* Xutils support for large files (over 2G) uploads, more comprehensive HTTP request protocol support (11 predicates), more flexible orm, more event annotations support and no confusion ...<br>* Xutils minimum compatible Android 4.0 (API level 14). ([Android 2.3?] (https://github.com/wyouflf/xUtils3/issues/8))<br>* XUTILS3 changes more so the new project is not maintained on the previous version (github.com/wyouflf/xutils), as opposed to the previous version:<br>1. HTTP implementation replaces httpclient with urlconnection, automatically resolves callback generics, and more secure breakpoint continuation Policy.<br>2. Support Standard cookie policy, differentiate domain, path ...<br>3. Event annotations Remove infrequently used features to improve performance.<br>4. Database API simplification improves performance to achieve and Greendao consistent performance.<br>5. Image binding Support GIF (affected by system compatibility, Some GIF files can only be displayed statically), webp; Support round, round, Square and other cropping, support automatic rotation ...<br><br><br># # # # # # # # Add dependencies when building with Gradle:<br>"' JavaScript<br>Compile ' org.xutils:xutils:3.3.4 '<br>```<br>##### If you use eclipse you can [click here to download AAR files] (http://dl.bintray.com/wyouflf/maven/org/xutils/xutils/), then extract the jar and so files with Zip.<br>##### Obfuscation Configuration Reference sample project sample configuration<br><br><br><br><br># # # Faq:<br>1. Better management of picture Cache: https://github.com/wyouflf/xUtils3/issues/149<br>2. Use of Cookies: https://github.com/wyouflf/xUtils3/issues/125<br>3. about the query parameter? HTTP requests can be transmitted via header, url, body (request body); The query parameter is a question mark (?) in the Url. The following Parameters.<br>4. about the Body parameter? The body parameter is only put, POST, PATCH, DELETE (the old version of the RFC2616 document does not explicitly indicate whether it is supported, so it is temporarily supported) to request Support.<br><br><br># # # # before use configuration<br>Permissions required by #####<br>"' XML<br><uses-permission android:name= "android.permission.INTERNET"/><br><uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE"/><br>```<br>##### initialization<br>"' Java<br>Initialize in Application's OnCreate<br>@Override<br>public void OnCreate () {<br>Super.oncreate ();<br>X.ext.init (this);<br>X.ext.setdebug (true); Whether to output debug logs<br>...<br>}<br>```<br><br><br># # # Use @event event annotations (@ContentView, @ViewInject and more examples refer to the sample Project)<br>"' Java<br>/**<br>* 1. Method must be private qualified,<br>* 2. The method parameter form must be the same as the listener interface for the Type.<br>* 3. Annotation parameter value support array: value={id1, id2, id3}<br>* 4. See the description of the {@link org.xutils.event.annotation.Event} class for additional parameter Descriptions.<br>**/<br>@Event (value = r.id.btn_test_baidu1,<br>Type = view.onclicklistener.class/* Optional parameter, default is View.onclicklistener.class*/)<br>private void Ontestbaidu1click (view View) {<br>...<br>}<br>```<br><br><br># # # access Network (more examples refer to the sample Project)<br>"' Java<br>/**<br>* For custom entity parameter classes, please refer to:<br>* Request Note {@link org.xutils.http.annotation.HttpRequest}<br>* Request Annotation Processing template interface {@link org.xutils.http.app.ParamsBuilder}<br>*<br>* When you need a custom type as a generic for callback, refer to:<br>* Response Note {@link org.xutils.http.annotation.HttpResponse}<br>* Response to Annotation processing template interface {@link org.xutils.http.app.ResponseParser}<br>*<br>* Example: View the code in the Org.xutils.sample.http package<br>*/<br>Baiduparams params = new Baiduparams ();<br>PARAMS.WD = "xutils";<br>Use the multipart form when uploading a file, otherwise upload the original file Stream.<br>Params.setmultipart (true);<br>Upload file Mode 1<br>Params.uploadfile = new File ("/sdcard/test.txt");<br>Upload file Mode 2<br>Params.addbodyparameter ("uploadfile", New File ("/sdcard/test.txt"));<br>Callback.cancelable cancelable<br>= X.http (). Get (params,<br>/**<br>* 1. Generics for Callback:<br>* Callback parameters are supported by default for generic types see {@link org.xutils.http.loader.LoaderFactory},<br>* For example: specifies that the generic is file to be downloaded, using Params.setsavefilepath (path) to specify the full path of the file to be Saved.<br>* The default support for the continuation of the breakpoint (using the file lock and end check to continue the consistency of the file).<br>* Other common types can be registered in loaderfactory,<br>* You can also use {@link org.xutils.http.annotation.HttpResponse}<br>* Add annotation HttpResponse to the custom return value type and implement a custom Responseparser interface to unify the Transformation.<br>* If the return value is in JSON form, then using a third-party JSON tool will be very easy to define your own responseparser.<br>* For example code {@link org.xutils.sample.http.BaiduResponse}, you can use Baiduresponse directly as<br>* Generic type of CALLBACK.<br>*<br>* 2. Combination of Callback:<br>* You can combine types of Callback with a base class or interface, see {@link org.xutils.common.Callback}.<br>For example<br>* A. Combined use of cachecallback will cause the request to detect the cache or cache the results (only get requests Take effect).<br>* B. Combining the prepare method with Preparecallback will give callback an opportunity to perform time-consuming tasks in the Background.<br>* Then give the result to Oncache or onsuccess.<br>* C. Combined use of progresscallback will provide a progress callback.<br>* ... (refer to {@link org.xutils.image.ImageLoader}<br>* or {@link org.xutils.sample.download.DownloadCallback} in the sample Code)<br>*<br>* 3. Request process interception or logging: reference {@link org.xutils.http.app.RequestTracker}<br>*<br>* 4. Request Header Fetch: Reference {@link org.xutils.http.app.RequestInterceptListener}<br>*<br>* 5. Other (thread pool, timeout, redirect, retry, proxy, etc.): reference {@link org.xutils.http.RequestParams}<br>*<br>**/<br>New Callback.commoncallback<string> () {<br>@Override<br>public void onsuccess (String Result) {<br>Toast.maketext (x.app (), result, toast.length_long). show ();<br>}<br><br><br>@Override<br>public void OnError (throwable ex, boolean Isoncallback) {<br>Toast.maketext (x.app (), ex.getmessage (), toast.length_long). show ();<br>If (ex instanceof Httpexception) {//network Error<br>HttpException Httpex = (httpexception) ex;<br>int responsecode = Httpex.getcode ();<br>String responsemsg = Httpex.getmessage ();<br>String Errorresult = Httpex.getresult ();<br>// ...<br>} else {//other Error<br>// ...<br>}<br>Toast.maketext (x.app (), ex.getmessage (), toast.length_long). show ();<br>}<br><br><br>@Override<br>public void oncancelled (cancelledexception Cex) {<br>Toast.maketext (x.app (), "cancelled", toast.length_long). show ();<br>}<br><br><br>@Override<br>public void onfinished () {<br><br><br>}<br>});<br><br><br>Cancelable.cancel (); Cancel Request<br>```<br># # # # # # # # If you only need a simple version:<br>"' Java<br>@Event (value = R.id.btn_test_baidu2)<br>private void Ontestbaidu2click (view View) {<br>Requestparams params = new Requestparams ("https://www.baidu.com/s");<br>Params.setsslsocketfactory (...); Setting Up SSL<br>Params.addquerystringparameter ("wd", "xutils");<br>X.http (). get (params, new callback.commoncallback<string> () {<br>@Override<br>public void onsuccess (String Result) {<br>Toast.maketext (x.app (), result, toast.length_long). show ();<br>}<br><br><br>@Override<br>public void OnError (throwable ex, boolean Isoncallback) {<br>Toast.maketext (x.app (), ex.getmessage (), toast.length_long). show ();<br>}<br><br><br>@Override<br>public void oncancelled (cancelledexception Cex) {<br>Toast.maketext (x.app (), "cancelled", toast.length_long). show ();<br>}<br><br><br>@Override<br>public void onfinished () {<br><br><br>}<br>});<br>}<br>````<br># # # Examples of requests with caching:<br>"' Java<br>Baiduparams params = new Baiduparams ();<br>PARAMS.WD = "xutils";<br>Default cache survival time, in MILLISECONDS. (if the service does not return a valid max-age or expires)<br>Params.setcachemaxage (1000 * 60);<br>Callback.cancelable cancelable<br>With cachecallback, Xutils will cache the data for the Request.<br>= X.http (). Get (params, new callback.cachecallback<string> () {<br><br><br>Private Boolean haserror = false;<br>Private String result = null;<br><br><br>@Override<br>public boolean Oncache (String Result) {<br>The cached data is received and the cache expires without entering this method.<br>If the service side does not return an expiration time, refer to the Params.setcachemaxage (maxAge) method.<br>//<br>* The client determines whether the local cache is given the Oncache method based on Max-age or expires in the header returned by the Server.<br>If the server does not return Max-age or expires, then the cache will be saved unless you define a return of false<br>logic, then Xutils will request new data to overwrite it.<br>//<br>* If you trust that the cache returns true, the network will no longer be requested;<br>Returns false to continue requesting the network, but adds the etag, last-modified, and other information to the request header,<br>If the server returns 304, the data is not updated and the data is not Loaded.<br>//<br>This.result = result;<br>Return false; True: Trust cached data, not initiating network requests; False does not trust cached Data.<br>}<br><br><br>@Override<br>public void onsuccess (String Result) {<br>Note: If the service returns 304 or Oncache chooses the trust cache, this will not be called,<br>But onfinished is always called.<br>This.result = result;<br>}<br><br><br>@Override<br>public void OnError (throwable ex, boolean Isoncallback) {<br>Haserror = true;<br>Toast.maketext (x.app (), ex.getmessage (), toast.length_long). show ();<br>If (ex instanceof Httpexception) {//network Error<br>HttpException Httpex = (httpexception) ex;<br>int responsecode = Httpex.getcode ();<br>String responsemsg = Httpex.getmessage ();<br>String Errorresult = Httpex.getresult ();<br>// ...<br>} else {//other Error<br>// ...<br>}<br>}<br><br><br>@Override<br>public void oncancelled (cancelledexception Cex) {<br>Toast.maketext (x.app (), "cancelled", toast.length_long). show ();<br>}<br><br><br>@Override<br>public void onfinished () {<br>If (!haserror && result! = null) {<br>Successful data acquisition<br>Toast.maketext (x.app (), result, toast.length_long). show ();<br>}<br>}<br>});<br>```<br><br><br># # # Use database (more examples refer to sample Project)<br>"' Java<br>Parent test = Db.selector (parent.class). where ("id", "in", new int[]{1, 3, 6}). FindFirst ();<br>Long Count = Db.selector (parent.class). where ("name", "like", "w%"). and ("age", ">", +). count ();<br>list<parent> testlist = Db.selector (parent.class). where ("id", "between", new string[]{"1", "5"}). findAll ();<br>```<br><br><br># # # Bound Pictures (more examples Refer to the sample Project)<br>"' Java<br>X.image (). bind (imageView, url, imageoptions);<br><br><br>Assets file<br>X.image (). bind (imageView, "assets://test.gif", imageoptions);<br><br><br>Local file<br>X.image (). bind (imageView, new File ("/sdcard/test.gif"). touri (). toString (), imageoptions);<br>X.image (). bind (imageView, "/sdcard/test.gif", imageoptions);<br>X.image (). bind (imageView, "file:///sdcard/test.gif", imageoptions);<br>X.image (). bind (imageView, "file:/sdcard/test.gif", imageoptions);<br><br><br>X.image (). bind (imageView, url, imageoptions, new callback.commoncallback<drawable> () {...});<br>X.image (). loaddrawable (url, imageoptions, new callback.commoncallback<drawable> () {...});<br>X.image (). loadFile (url, imageoptions, new callback.commoncallback<file> () {...});<br>```<br><br><br>____<br># # # about Libwebpbackport<br>* Some 4.x models support the WEBP format still has problems, need to use WEBP.<br>* WEBP from: HTTPS://GITHUB.COM/WEBMPROJECT/LIBWEBP<br>* Webpbackport from: Https://github.com/alexey-pelykh/webp-android-backport<br>* Webpbackport added Nativedecodefile implementation and fixed bug in Android 5.0 + system:<br>"' CPP<br>Android_backport_webp.cpp<br>Modify:<br>Jclassref = Jnienv->findclass (...);<br>For:<br>Jclass temp = Jnienv->findclass (...);<br>Jclassref = (jclass) Jnienv->newglobalref (temp);<br>Jnienv->deletelocalref (temp);<br>Other JNI code modifications see: http://my.oschina.net/u/1171837/blog/533153</p><p><p>Android Toolkit Xutils 3.3.16</p></p></span>
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