Android uses the Android-query framework to develop combat (i) _android

Source: Internet
Author: User

The development of Android using the Android-query framework can be fast, much less than the traditional development of Android code to write a lot of, easy to read and other advantages.

Download the document and its example and package address: http://code.google.com/p/android-query/

Here are some of the lessons I learned to share:

First section:

It is necessary to implement aquery this class
 aquery aq = new Aquery (view);
 Order Analysis: Get the XML corresponding control ID, set the picture, the settings can be displayed, click the event (method SomeMethod must be public decorated) 
 aq.id (R.id.icon). Image (R.drawable.icon). Visible (). Clicked (This, "SomeMethod"); 
 Sets the text content
  aq.id (r.id.name). Text (Content.getpname ());
  Aq.id (r.id.time). Text (Formatutility.relativetime (System.currenttimemillis (), Content.getcreate ())). visible ();

Aq.id (R.ID.DESC). Text (Content.getdesc ()). visible ();

Aquery also supports fragment:

 @Override public
 View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {
  
  View view = Inflater.inflate (Getcontainerview (), container, false);    
    
  AQ = new Aquery (getactivity (), view);
  return view;
 

Section Two: Use Aquery to load pictures asynchronously

2.1 Reading pictures from the internet

Aq.id (R.id.image1). Image ("Picture url");

2.2 Cache Control: If the picture is too large, avoid memory cache

Boolean memCache = false;
Boolean filecache = true;
Aq.id (R.id.image1). Image ("Http://www.vikispot.com/z/images/vikispot/android-w.png", MemCache, Filecache);

2.3 The current load too many pictures need to reduce the picture sampling rate, the fourth parameter to ensure the quality of the picture, the general range of 200-399

Aq.id (R.id.image1). Image (ImageUrl, True, True, 200, 0);

2.4 If downloading a picture fails, the processing method: 1. Set a scheduled picture of 2. Make ImageView invisible or gone

Aq.id (R.id.image1). Image (ImageUrl, True, True, 0, r.drawable.default_image);
Aq.id (R.id.image1). Image (ImageUrl, True, True, 0, aquery.invisible);
Aq.id (R.id.image1). Image (ImageUrl, True, True, 0, Aquery.gone);

2.5 Pre-loading pictures

Get a small picture from the previous URL
String thumbnail = "http://farm6.static.flickr.com/5035/5802797131_a729dac808_s.jpg";
Bitmap preset = aq.getcachedimage (thumbnail);
Show small pictures before loading large pictures
String imageUrl = "Http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
Aq.id (r.id.image). Image (ImageUrl, False, False, 0, 0, preset, aquery.fade_in);

2.6 Display the progress bar when loading the picture, progress incoming ID inside

String imageUrl = "Http://farm6.static.flickr.com/5035/5802797131_a729dac808_b.jpg";
Aq.id (R.id.image). Progress (r.id.progress). Image (ImageUrl, false, false);

2.7 Picture fillet display, large picture not supported

Imageoptions options = new Imageoptions ();
Options.round = 15;
Aq.id (r.id.image). Image (URL, options);

2.8 Picture Height-to-width ratio

Keep the original picture proportions
Aq.id (r.id.image). Image (ImageUrl, True, True, 0, 0, NULL, aquery.fade_in, aquery.ratio_preserve);
Custom picture Proportions
1:1, a square
Aq.id (R.id.image2). Image (ImageUrl, True, True, 0, 0, NULL, 0, 1.0f/1.0f);
Aq.id (R.id.image3). Image (ImageUrl, True, True, 0, 0, NULL, 0, 1.5f/1.0f);
16:9, a video thumbnail
Aq.id (r.id.image4). Image (ImageUrl, True, True, 0, 0, NULL, 0, 9.0f/16.0f);
Aq.id (R.id.image5). Image (ImageUrl, True, True, 0, 0, NULL, 0, 3.0f/4.0f);

2.9 picture strokes, if the picture is too high, the stroke can be used to describe which part of the picture is displayed

Anchor values:
1.0:display top of the image
0:display the center of the image
-1.0:display bottom of the image
AQuery.ANCHOR_DYNAMIC:Display image with Ace bias for photos.
=======================================================
Imageoptions options = new Imageoptions ();
Options.ratio = 1;
Options.anchor = 1.0;
Aq.id (R.id.image1). Image (ImageUrl, options);

2.10 Custom image processing after loading

Aq.id (R.id.image1). Image (ImageUrl, True, True, 0, 0, new Bitmapajaxcallback () {});

2.11 Asynchronously load pictures from file, recommend using lower sample rate to avoid oom

 File File = new file (path);  
 Load image from file, down sample to target width of pixels 
 aq.id (R.id.avatar). Image (file,)
 Load image from file with callback
 aq.id (R.id.avatar). Image (file, False, new Bitmapajaxcallback () {
 @ Override public
 void callback (String URL, ImageView IV, Bitmap BM, ajaxstatus status) {
  iv.setimagebitmap (BM); c8/>}
});

2.12 If the previous image ("url") has been successful, the following can be used directly without having to access the network again, which means that the image resource can be accessed offline later

2.13 file to get the buffer picture

File File = aq.getcachedfile (URL);

2.14 In addition to Imageview,webview can also be used to put pictures

Aq.id (R.id.web). Progress (r.id.progress). Webimage (URL);

2.15 Delay picture loading to help you load the ListView with fast Scrolling, details reference document use

2.16 Pictures do not use caching

Aq.id (r.id.image). Image (URL, false, false);

2.17 cache configuration, the cache is generally stored in the internal file system, but also can be saved in the sdcard inside

File ext = environment.getexternalstoragedirectory ();
File Cachedir = new file (ext, "MyApp");
Aqutility.setcachedir (Cachedir);

2.18 share the picture, in order to share the picture with other programs, you need to put the file in the Sdcard,makesharedfile method to create a copy of the cached address

 File File = aq.makesharedfile (URL, "Android.png");
   if (file!= null) {
    Intent Intent = new Intent (intent.action_send);
    Intent.settype ("Image/jpeg");
    Intent.putextra (Intent.extra_stream, Uri.fromfile (file));
    Startactivityforresult (Intent.createchooser (Intent, "Share via:"), send_request);
  

2.19 configuration, it is best to write the configuration in the application OnCreate method, detailed reference documentation

2.20 the cache needs to be erased when the program exits.

  if (Istaskroot ()) {
 Aqutility.cleancacheasync (this);
 }

Or:

  if (Istaskroot ()) {
 //clean the file cache with advance option
  long triggersize = 3000000;///greater than 3M start
  clear Long Ta Rgetsize = 2000000;  Until less than 2M
  Aqutility.cleancacheasync (This, triggersize, targetsize);
  }

2.21 Low Memory processing

  public class MainApplication extends application{
   @Override public
   void Onlowmemory () { 
  //clear all memory Cached images when system are in low memory
  //note so you can configure the max image cache count, and the CONFIGURATION
   Bitmapajaxcallback.clearcache ();
 }

The above content is small make up with you introduced the use of Android Android-query Framework Development (i), I hope you like, the next article with you to introduce the use of Android Android-query Framework Development Combat (II), interested friends Please continue to pay attention to this site.

Related Article

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.