Wednesday, 9 March 2011

What's New in Honeycomb APIs, UI Point of View

As first Honeycomb tablets are hitting store selveds and the SDK has been out for few weeks Google has been busy updating their documentation for the new OS version.

The Android Dev Guide is massive. Not everybody have time to go through all of it or even just the new posts (tagged with new! -tag). So I've gathered here a quick overview about the technical documentation for Android UI development and design. I hope this overview gives designers decent understanding about what is now possible and developers an overview and a reference of the new articles.

More after the jump...

Fragments are pieces of an activity that can be shown either one by one or as a composite screen.

Fragments is probably the most significant new feature in 3.0. Fragments enables us to write applications that can adapt into very different screen sizes and provide best possible user experience to users whether they're on a tablet or a phone. 
Note: Fragments are now available as a static library that can be included in projects for Android 1.6+. For more info see this post in the Android Developers Blog

A good example for use of fragments is an email application. With fragments it is possible to make emails appear next to the list of emails on tablets but on smaller displays still opening the emails full screen.

An example of how two UI modules that are typically separated into two activities can be combined into one activity, using fragments.
-Picture and caption by Google

See fragments in action in Honeycomb Gmail app:

Loaders make it simpler to disconnect long running tasks from UI. Correct use of loaders will make the UI more responsive as all data is loaded in background.

  • They provide asynchronous loading of data.
  • They monitor the source of their data and deliver new results when the content changes.
  • They automatically reconnect to the last loader's cursor when being recreated after a configuration change. Thus, they don't need to re-query their data.

Action Bar
Action bar is now supported by the Android API. The API support means that it is now easy and straightforward to implement action bar pattern in 3.0+ apps.

  • Display items from the Options Menu directly in the Action Bar, as "action items"—providing instant access to key user actions.
  • Menu items that do not appear as action items are placed in the overflow menu, revealed by a drop-down list in the Action Bar.
  • Provide tabs for navigating between fragments.
  • Provide a drop-down list for navigation.
  • Provide interactive "action views" in place of action items (such as a search box).
Action bar UI pattern is covered in length elsewhere in this blog.

Dragging and Dropping
Drag and drop support in the API makes it simple to implement drag and drop operations inside one application.

  • Allow users to move data within your Activity layout using graphical gestures.
  • Supports operations besides data movement.
  • Only works within a single application.
Copy-Paste API makes it easy to implement copy-paste functionality. It even works between applications.

  • A clipboard-based framework for copying and pasting data.
  • Supports both simple and complex data, including text strings, complex data structures, text and binary stream data, and application assets.
  • Copies and pastes simple text directly to and from the clipboard.

Property animation API allows animation of any property of any object. In practice it means that running animation for moving, resizing etc. of anything in screen is now very simple.

A big advantage compared to the previous animation API is the way this new API works internally. It animates objects' properties instead of animating their visual presentation. From that follows that all the problems with objects not actually being in the place it was drawn in the previous implementation and the problems that it caused with touch events etc. are now gone. Animations can form animation sets and can be combined with interpolators.

The property animation system lets you define the following characteristics of an animation:
  • Duration: You can specify the duration of an animation. The default length is 300 ms.
  • Time interpolation: You can specify how the values for the property are calculated as a function of the animation's current elapsed time.
  • Repeat count and behavior: You can specify whether or not to have an animation repeat when it reaches the end of a duration and how many times to repeat the animation. You can also specify whether you want the animation to play back in reverse. Setting it to reverse plays the animation forwards then backwards repeatedly, until the number of repeats is reached.
  • Animator sets: You can group animations into logical sets that play together or sequentially or after specified delays.
  • Frame refresh delay: You can specify how often to refresh frames of your animation. The default is set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.

3D Rendering with Renderscript
Renderscript is a scripting language that can be used to produce highly optimised 3D graphics and animations.

This is an advanced feature for specialised cases. Using Renderscript requires developers to be familiar with developing in C language. It is an alternative for writing OpenGL code.

Google's ebook reader app is said to be using Renderscript for page turn animations. See this video to see how smooth the result is: