Android query

3,046 views

Published on

Slides from Android dev meeting in Zilina, Slovakia about AndroidQuery.

follow me on:
www.twitter.com/pavlasek

Published in: Technology, News & Politics
  • Be the first to comment

Android query

  1. 1. Android Query Makes Android codingsimpler, easier, and more fun! Michal CoPLaS Pavlasek www.pavlasek.sk/devel/ twitter.com/pavlasek
  2. 2. About meJava, Android, Grails (etc...) developerIm not creator of Android Query :)Just fan of it
  3. 3. Android QueryLight-weight library for doing asynchronous tasks and manipulating UI elements in Android http://code.google.com/p/android-query/ Inspired by jQuery, a javascript framework for web site, hence the name "Query".
  4. 4. Android Query Things I really like:Less CodeChainingAJAX CallbackImage LoadingIn-app Version CheckMultiple UI, One Piece of Code
  5. 5. Less Code - Beforepublic void renderContent(Content content, View view) { ImageView tbView = (ImageView) view.findViewById(R.id.icon); if(tbView != null){ tbView.setImageBitmap(R.drawable.icon); tbView.setVisibility(View.VISIBLE); tbView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { someMethod(v); } }); } TextView nameView = (TextView) view.findViewById(R.id.name); if(nameView != null){ nameView.setText(content.getPname()); } TextView timeView = (TextView) view.findViewById(R.id.time); if(timeView != null){ long now = System.currentTimeMillis(); timeView.setText(FormatUtility.relativeTime(now, content.getCreate())); timeView.setVisibility(View.VISIBLE); } TextView descView = (TextView) view.findViewById(R.id.desc); if(descView != null){ descView.setText(content.getDesc()); descView.setVisibility(View.VISIBLE); }}
  6. 6. Less Code - Afterpublic void renderContent(Content content, View view) { AQuery aq = new AQuery(view); aq.id(R.id.icon).image(R.drawable.icon).visible().clicked(this, "someMethod"); 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();}
  7. 7. ChainingAll "set" methods in AQuery returns itself.String name = "My name in black text, redbackground, visible, and invoke nameClickedwhen clicked";aq.id(R.id.name).text(name).background(R.color.red).textColor(R.color.black).enabled(true).visible().clicked(this, "nameClicked");
  8. 8. AJAX Callback - JSON Examplepublic void asyncJson(){ //perform a Google search in just a few lines of code String url = "http://www.google.com/uds/GnewsSearch?q=Obama&v=1.0"; aq.ajax(url, JSONObject.class, this, "jsonCallback");}public void jsonCallback(String url, JSONObject json,AjaxStatus status){ if(json != null){ //successful ajax call }else{ //ajax error }}
  9. 9. Image LoadingSimpleMemory & File CachingDown SamplingZoomable (WebView)Fallback ImagePreloadingAnimationDynamic Aspect RatioAvoid Duplicated Simultaneous FetchesCustom Callback
  10. 10. Image Loadingaq.id(R.id.image1).image( "http://www.vikispot.com/z/images/vikispot/android-w.png");//this image is huge, avoid memory cachingboolean memCache = false;boolean fileCache = true;aq.id(R.id.image1).image( "http://www.vikispot.com/z/images/vikispot/android-w.png", memCache, fileCache);aq.id( R.id.image).image("https://graph.facebook.com/" + item.fromId + "/picture?type=large", true, true, 0, 0, null, Aquery.FADE_IN);See more: http://code.google.com/p/android-query/wiki/ImageLoading
  11. 11. In-app Version Check@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MarketService ms = new MarketService(this); ms.level(MarketService.MINOR).checkVersion();}See more: http://code.google.com/p/android-query/wiki/Service
  12. 12. Multiple UI, One Piece of Codepublic void renderContent(Content content, View view) { //this is a phone! //this view exists aq.id(R.id.textInMobileLayoutOnly).text( "Welcome to my Mobile App!"); //this button exist in tablet layout only, but its ok //AQuery will ignore all the operations on this view aq.id(R.id.butttonInTabletOnly).text("Open a new tab!");}
  13. 13. And many more...BindingXML ParsingAuthenticationAlleviate FragmentationExtendableLight WeightNon-intrusiveOpen Source
  14. 14. More info http://code.google.com/p/android-query/ http://twitter.com/AndroidQueryhttp://groups.google.com/group/android-query

×