Introduction to AQuery – Android Query

Welcome back readers 🙂

It’s enough discussing about creating simple android applications, let us also look into some useful libraries that are available for Android.

Recently I came across an Android library called ‘AQuery’ and literally I stumbled after looking at its features. I believe they derived the name ‘AQuery’ from ‘jQuery’ which is another library for Javascript.

AQuery Library Documentation

In this post, I will just walk you through the Introduction to AQuery and I will also be discussing the features of AQuery.

Introduction to AQuery

Android-Query (AQuery) is a light-weight library for doing asynchronous tasks and manipulating UI elements in Android in efficient way. The main goal of AQuery library is to make Android coding simpler, easier, and more fun. It allows developer to write less code to do lot more.

aquery_introduction

Why AQuery?

AQuery has abundant of features in it and they are:

Less Code
AJAX Callback
Image Loading
XML Parsing
Chaining
Binding
Authentication
Multiple UI, One Piece of Code
Light Weight
Non-intrusive

AQuery Features

Less Code
AQuery allows the developer to be more expressive in terms of writing code i.e., write-less/do-more. Simpler code is always easier to read and maintain.

Compare the length of these pieces of code that does the same thing:
Before using AQuery

public void onCreate(Bundle savedInstanceState) {

	super.onCreate(savedInstanceState);
	setContentView(R.layout.test);              

     TextView nameView = (TextView) findViewById(R.id.name);      
       nameView.setText("Hello");         

	Button button = (Button) findViewById(R.id.button);
	button.setText("Click Me");

	button.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
			button.setText("Hello World");	
		}
    }             

}

After using AQuery

private AQuery aq;
public void onCreate(Bundle savedInstanceState) {

	super.onCreate(savedInstanceState);
	setContentView(R.layout.test);              

        aq = new AQuery(this);          

        aq.id(R.id.text).text("Hello");          

        aq.id(R.id.button).text("Click Me").clicked(this, "buttonClicked");

}

public void buttonClicked(View button){

        //update the text
        aq.id(R.id.text).text("Hello World");

}

Take a look at the simple example to understand how to Write less code to Do more.

AJAX Callback
Asynchronous AJAX or RPC calls are made simple with built in methods and it supports following types:

  • JSONObject
  • JSONArray
  • String (HTML, XML)
  • XmlDom (XML parsing)
  • XmlPullParser (Large XML files)
  • byte array
  • User defined custom type (Transformer)
  • Bitmap

Image Loading
AQuery library supports easy asynchronous image loading from network, with automatic file and memory caching. Best of it’s image loading features are:

  • Simple Loading
  • Memory & File Caching
  • Down Sampling
  • Zoomable (WebView)
  • Fallback Image
  • Preloading
  • Animation
  • Dynamic Aspect Ratio
  • Avoid Duplicated Simultaneous Fetches
  • Custom Callback

XML Parsing
AQuery library provides a light weight XML parser called XmlDom.

XmlDom is simple and can be used for doing XML parsing.

Chaining
AQuery library designed set methods in such a way that it will return itself, so it is quite easy for developers to chain set methods. Here is an example:

String name = "AQuery is a simple Android Library";
aq.id(R.id.txtname).text(name).background(R.color.red).textColor(R.color.black).enabled(true).visible();

Binding
AQuery makes binding listeners to views simple and easy. Here is an example:

@Override
protected void onCreate(Bundle savedInstanceState){

        //set content view here...

        AQuery aq = new AQuery(this);   

        aq.id(R.id.button).clicked(this, "buttonClicked");
        aq.id(R.id.list).itemClicked(this, "itemClicked")
}

public void buttonClicked(View view){

        //a button is clicked

}

public void itemClicked(AdapterView<?> parent, View v, int pos, long id) {

        //list item is clicked

}

Authentication
AQuery provides an easy and simple authentication mechanism for Google and other OAuth enabled services.

Multiple UI, One Piece of Code
With the advent of new Tablet devices, Android apps will need to support a wider range of screen sizes. Developers might need to design different UI layout for phone and tablets, but do we need to write a different set of code also?

AQuery allows developers to manage different layouts with the same piece of code. If a view is not in a layout, AQuery will just ignore all the operations performed on the view.

Light Weight
Memory is scarce for mobile apps. The AQuery lib is standalone and relatively small and optimized with proguard (~60k). The actual increase in apk size will be even smaller.

Non-intrusive
AQuery has no dependency and does not require developers to inherit specialized views or activities. Developers are free to use AQuery along with any other library without any conflict.

Related Articles

Author: Udhay

Share This Post On
468 ad
  • siddhu

    it is not programmer guru,great guru excellent,love u admin

  • maddogZ

    I have an LG Optimus L9, and my aquery is 280MB. Is there a safe way to truncate this size as my phone has very limited internal storage?

  • DuduFi

    Very nice! Thank you.
    Can you please make more like this?
    can you do an AQ Image example…?

  • HI Dudu

    Please find AQuery Image loading example from here:

    http://programmerguru.com/android-tutorial/aquery-image-loading/

    • DuduFi

      Thank you,
      Daownloading

  • Hi @MaddogZ

    Please note that AQuery is a library, which will present within Applications. When you uninstall Applications, library will also be delete automatically. You don’t need to explicitly truncate or delete AQuery files.

Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest

Shares