Tuesday, May 31, 2011

Google Tests a New Mobile Navigation Bar

Some Google users spotted an experimental interface for Google's mobile search site. The horizontal navigation bar now includes icons, just like the vertical desktop bar. While the new interface is less streamlined, it looks more like a Web app and it makes it easier to select a different search service or a Google app.



{ Thanks, Andrew and David. }

Monday, May 30, 2011

Introducing ViewPropertyAnimator

[This post is by Chet Haase, an Android engineer who specializes in graphics and animation, and who occasionally posts videos and articles on these topics on his CodeDependent blog at graphics-geek.blogspot.com. — Tim Bray]

In an earlier article, Animation in Honeycomb, I talked about the new property animation system available as of Android 3.0. This new animation system makes it easy to animate any kind of property on any object, including the new properties added to the View class in 3.0. In the 3.1 release, we added a small utility class that makes animating these properties even easier.

First, if you’re not familiar with the new View properties such as alpha and translationX, it might help for you to review the section in that earlier article that discusses these properties entitled, rather cleverly, “View properties”. Go ahead and read that now; I’ll wait.

Okay, ready?

Refresher: Using ObjectAnimator

Using the ObjectAnimator class in 3.0, you could animate one of the View properties with a small bit of code. You create the Animator, set any optional properties such as the duration or repetition attributes, and start it. For example, to fade an object called myView out, you would animate the alpha property like this:

    ObjectAnimator.ofFloat(myView, "alpha", 0f).start();

This is obviously not terribly difficult, either to do or to understand. You’re creating and starting an animator with information about the object being animated, the name of the property to be animated, and the value to which it’s animating. Easy stuff.

But it seemed that this could be improved upon. In particular, since the View properties will be very commonly animated, we could make some assumptions and introduce some API that makes animating these properties as simple and readable as possible. At the same time, we wanted to improve some of the performance characteristics of animations on these properties. This last point deserves some explanation, which is what the next paragraph is all about.

There are three aspects of performance that are worth improving about the 3.0 animation model on View properties. One of the elements concerns the mechanism by which we animate properties in a language that has no inherent concept of “properties”. The other performance issues relate to animating multiple properties. When fading out a View, you may only be animating the alpha property. But when a view is being moved on the screen, both the x and y (or translationX and translationY) properties may be animated in parallel. And there may be other situations in which several properties on a view are animated in parallel. There is a certain amount of overhead per property animation that could be combined if we knew that there were several properties being animated.

The Android runtime has no concept of “properties”, so ObjectAnimator uses a technique of turning a String denoting the name of a property into a call to a setter function on the target object. For example, the String “alpha” gets turned into a reference to the setAlpha() method on View. This function is called through either reflection or JNI, mechanisms which work reliably but have some overhead. But for objects and properties that we know, like these properties on View, we should be able to do something better. Given a little API and knowledge about each of the properties being animated, we can simply set the values directly on the object, without the overhead associated with reflection or JNI.

Another piece of overhead is the Animator itself. Although all animations share a single timing mechanism, and thus don’t multiply the overhead of processing timing events, they are separate objects that perform the same tasks for each of their properties. These tasks could be combined if we know ahead of time that we’re running a single animation on several properties. One way to do this in the existing system is to use PropertyValuesHolder. This class allows you to have a single Animator object that animates several properties together and saves on much of the per-Animator overhead. But this approach can lead to more code, complicating what is essentially a simple operation. The new approach allows us to combine several properties under one animation in a much simpler way to write and read.

Finally, each of these properties on View performs several operations to ensure proper invalidation of the object and its parent. For example, translating a View in x invalidates the position that it used to occupy and the position that it now occupies, to ensure that its parent redraws the areas appropriately. Similarly, translating in y invalidates the before and after positions of the view. If these properties are both being animated in parallel, there is duplication of effort since these invalidations could be combined if we had knowledge of the multiple properties being animated. ViewPropertyAnimator takes care of this.

Introducing: ViewPropertyAnimator

ViewPropertyAnimator provides a simple way to animate several properties in parallel, using a single Animator internally. And as it calculates animated values for the properties, it sets them directly on the target View and invalidates that object appropriately, in a much more efficient way than a normal ObjectAnimator could.

Enough chatter: let’s see some code. For the fading-out view example we saw before, you would do the following with ViewPropertyAnimator:

    myView.animate().alpha(0);

Nice. It’s short and it’s very readable. And it’s also easy to combine with other property animations. For example, we could move our view in x and y to (500, 500) as follows:

    myView.animate().x(500).y(500);

There are a couple of things worth noting about these commands:

  • animate(): The magic of the system begins with a call to the new method animate() on the View object. This returns an instance of ViewPropertyAnimator, on which other methods are called which set the animation properties.


  • Auto-start: Note that we didn’t actually start() the animations. In this new API, starting the animations is implicit. As soon as you’re done declaring them, they will all begin. Together. One subtle detail here is that they will actually wait until the next update from the UI toolkit event queue to start; this is the mechanism by which ViewPropertyAnimator collects all declared animations together. As long as you keep declaring animations, it will keep adding them to the list of animations to start on the next frame. As soon as you finish and then relinquish control of the UI thread, the event queue mechanism kicks in and the animations begin.


  • Fluent: ViewPropertyAnimator has a Fluent interface, which allows you to chain method calls together in a very natural way and issue a multi-property animation command as a single line of code. So all of the calls such as x() and y() return the ViewPropertyAnimator instance, on which you can chain other method calls.


You can see from this example that the code is much simpler and more readable. But where do the performance improvements of ViewPropertyAnimator come in?

Performance Anxiety

One of the performance wins of this new approach exists even in this simple example of animating the alpha property. ViewPropertyAnimator uses no reflection or JNI techniques; for example, the alpha() method in the example operates directly on the underlying "alpha" field of a View, once per animation frame.

The other performance wins of ViewPropertyAnimator come in the ability to combine multiple animations. Let’s take a look at another example for this.

When you move a view on the screen, you might animate both the x and y position of the object. For example, this animation moves myView to x/y values of 50 and 100:

    ObjectAnimator animX = ObjectAnimator.ofFloat(myView, "x", 50f);
ObjectAnimator animY = ObjectAnimator.ofFloat(myView, "y", 100f);
AnimatorSet animSetXY = new AnimatorSet();
animSetXY.playTogether(animX, animY);
animSetXY.start();

This code creates two separate animations and plays them together in an AnimatorSet. This means that there is the processing overhead of setting up the AnimatorSet and running two Animators in parallel to animate these x/y properties. There is an alternative approach using PropertyValuesHolder that you can use to combine multiple properties inside of one single Animator:

    PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("x", 50f);
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", 100f);
ObjectAnimator.ofPropertyValuesHolder(myView, pvhX, pvyY).start();

This approach avoids the multiple-Animator overhead, and is the right way to do this prior to ViewPropertyAnimator. And the code isn’t too bad. But using ViewPropertyAnimator, it all gets easier:

    myView.animate().x(50f).y(100f);

The code, once again, is simpler and more readable. And it has the same single-Animator advantage of the PropertyValuesHolder approach above, since ViewPropertyAnimator runs one single Animator internally to animate all of the properties specified.

But there’s one other benefit of the ViewPropertyAnimator example above that’s not apparent from the code: it saves effort internally as it sets each of these properties. Normally, when the setX() and setY() functions are called on View, there is a certain amount of calculation and invalidation that occurs to ensure that the view hierarchy will redraw the correct region affected by the view that moved. ViewPropertyAnimator performs this calculation once per animation frame, instead of once per property. It sets the underlying x/y properties of View directly and performs the invalidation calculations once for x/y (and any other properties being animated) together, avoiding the per-property overhead necessitated by the ObjectAnimator property approach.

An Example

I finished this article, looked at it ... and was bored. Because, frankly, talking about visual effects really begs having some things to look at. The tricky thing is that screenshots don’t really work when you’re talking about animation. (“In this image, you see that the button is moving. Well, not actually moving, but it was when I captured the screenshot. Really.”) So I captured a video of a small demo application that I wrote, and will through the code for the demo here.

Here’s the video. Be sure to turn on your speakers before you start it. The audio is really the best part.

In the video, the buttons on the upper left (“Fade In”, “Fade Out”, etc.) are clicked one after the other, and you can see the effect that those button clicks have on the button at the bottom (“Animating Button”). All of those animations happen thanks to the ViewPropertyAnimator API (of course). I’ll walk through the code for each of the individual animations below.

When the activity first starts, the animations are set up to use a longer duration than the default. This is because I wanted the animations to last long enough in the video for you to see. Changing the default duration for the animatingButton object is a one-line operation to retrieve the ViewPropertyAnimator for the button and set its duration:

    animatingButton.animate().setDuration(2000);

The rest of the code is just a series of OnClickListenerobjects set up on each of the buttons to trigger its specific animation. I’ll put the complete listener in for the first animation below, but for the rest of them I’ll just put the inner code instead of the listener boilerplate.

The first animation in the video happens when the Fade Out button is clicked, which causes Animating Button to (you guessed it) fade out. Here’s the listener for the fadeOut button which performs this action:

    fadeOut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animatingButton.animate().alpha(0);
}
});

You can see, in this code, that we simply tell the object to animate to an alpha of 0. It starts from whatever the current alpha value is.

The next button performs a Fade In action, returning the button to an alpha value of 1 (fully opaque):

    animatingButton.animate().alpha(1);

The Move Over and Move Back buttons perform animations on two properties in parallel: x and y. This is done by chaining calls to those property methods in the animator call. For the Move Over button, we have the following:

    int xValue = container.getWidth() - animatingButton.getWidth();
int yValue = container.getHeight() - animatingButton.getHeight();
animatingButton.animate().x(xValue).y(yValue);

And for the Move Back case (where we just want to return the button to its original place at (0, 0) in its container), we have this code:

    animatingButton.animate().x(0).y(0);

One nuance to notice from the video is that, after the Move Over and Move Back animations were run, I then ran them again, clicking the Move Back animation while the Move Over animation was still executing. The second animation on the same properties (x and y) caused the first animation to cancel and the second animation to start from that point. This is an intentional part of the functionality of ViewPropertyAnimator. It takes your command to animate a property and, if necessary, cancels any ongoing animation on that property before starting the new animation.

Finally, we have the 3D rotation effect, where the button spins twice around the Y (vertical) axis. This is obviously a more complicated action and takes a great deal more code than the other animations (or not):

    animatingButton.animate().rotationYBy(720);

One important thing to notice in the rotation animations in the video is that they happen in parallel with part of the Move animations. That is, I clicked on the Move Over button, then the Rotate button. This caused the movement to stat, and then the Rotation to start while it was moving. Since each animation lasted for two seconds, the rotation animation finished after the movement animation was completed. Same thing on the return trip - the button was still spinning after it settled into place at (0, 0). This shows how independent animations (animations that are not grouped together on the animator at the same time) create a completely separate ObjectAnimator internally, allowing the animations to happen independently and in parallel.

Play with the demo some more, check out the code, and groove to the awesome soundtrack for 16.75. And if you want the code for this incredibly complex application (which really is nothing more than five OnClick listeners wrapping the animator code above), you can download it from here.

And so...

For the complete story on ViewPropertyAnimator, you might want to see the SDK documentation. First, there’s the animate() method in View. Second, there’s the ViewPropertyAnimator class itself. I’ve covered the basic functionality of that class in this article, but there are a few more methods in there, mostly around the various properties of View that it animates. Thirdly, there’s ... no, that’s it. Just the method in View and the ViewPropertyAnimator class itself.

ViewPropertyAnimator is not meant to be a replacement for the property animation APIs added in 3.0. Heck, we just added them! In fact, the animation capabilities added in 3.0 provide important plumbing for ViewPropertyAnimator as well as other animation capabilities in the system overall. And the capabilities of ObjectAnimator provide a very flexible and easy to use facility for animating, well, just about anything! But if you want to easily animate one of the standard properties on View and the more limited capabilities of the ViewPropertyAnimator API suit your needs, then it is worth considering.

Note: I don’t want to get you too worried about the overhead of ObjectAnimator; the overhead of reflection, JNI, or any of the rest of the animator process is quite small compared to what else is going on in your program. it’s just that the efficiencies of ViewPropertyAnimator offer some advantages when you are doing lots of View property animation in particular. But to me, the best part about the new API is the code that you write. It’s the best kind of API: concise and readable. Hopefully you agree and will start using ViewPropertyAnimator for your view property animation needs.

Tuesday, May 24, 2011

No More Offline Gmail in Google Chrome

Chrome 12, the upcoming version of Google's browser which is likely to be released today, removes a useful feature: the built-in Gears plugin. While most Google services dropped support for Gears and removed offline access, Gears is still being used in Gmail. Google no longer maintains Gears, which is now legacy software, and focuses on implementing offline support using HTML5.


But why remove Gears support without implementing the features using HTML5 first? Google says that you'll only need to wait for a few weeks or you can still older versions of Firefox, Internet Explorer and mail client such as Thunderbird or Outlook.

"The new Gmail Offline capability is targeted for delivery as a Chrome browser web app this summer. As we move the Gmail Offline capability to a Chrome web app, we will deprecate the Google Gears-based Gmail Offline. This coincides with the version 12 release of the Google Chrome browser which no longer supports Gears. As a result, Google Gears-based Gmail Offline will no longer work with the Chrome browser as of Tuesday May 24, 2011. Google Gears-based Gmail Offline will continue to work in Internet Explorer 8 and Mozilla Firefox 3.6," explains Google.

It's not the best thing to do after convincing users to switch to Chrome and use Web apps, but it's just a temporary issue. If the HTML5 offline Gmail wasn't ready to be released, removing Gears from Chrome could have been delayed.

{ via François }

Google Tests Extended Flight OneBox

Google started to test a more advanced OneBox for flight-related searches. Right now, when you search for [flights from London to Barcelona] Google links to services like Expedia, Orbitz or Kayak. The OneBox is useful, but it doesn't show a list of flights.


After acquiring ITA Software, Google has access to a lot more information about flights and no longer have to send users to services like Expedia. Google can even provide information when you enter a vague query like [flights to Barcelona].

Here's the experimental flight OneBox, as spotted by Richard from SEO Gadget:


When you click "expand all non-stop routes to Barcelona", Google shows a very long list of cities. It's probably the biggest and most overwhelming Google OneBox. Maybe a drop-down would've been more useful.


After selecting one of the cities, Google sends you to a new search results page that shows a long list of flights.


It's nice to have all this information at your fingertips, but it's too overwhelming and these kinds of details aren't suited for an OneBox. Richard also noticed that "you get to data, with no call to action. I think this means most folks would be forced to repeat their search again on a flight provider."

Hopefully, Google will launch a Flight Search service that will also include the brilliant visualizations developed by ITA Software and the OneBox will just be a gateway to the new service.

Update: The feature is now available to everyone. "With the close of our ITA acquisition last month, we're eager to begin developing new flight search tools to make it easier for you to plan a trip. While this flight schedule feature does not currently use ITA's search technology, this is just a small step towards making richer travel information easier to find, and we hope to make finding flights online feel so easy, it'll feel like... well, a vacation," explains Google.

{ Thanks, Richard. }

Monday, May 23, 2011

Music Album Filtering in Google Video

Google started to learn more about music. After improving the Web search results for music videos by adding metadata, Google added the same enhancements to Google Video. Now you can even find a list of popular albums when you search for an artist. Select one of the albums and you'll restrict the results to the songs from the album. The nice thing is that Google's algorithms make sure that the results are diverse and songs aren't repeated too often.


Saturday, May 21, 2011

Google Business Profiles?

The source code of the Google Profiles page includes a broken link that has a revealing anchor text: "business profiles". The link sends you to a page that doesn't exist: http://www.google.com/_/managepages, but this feature could add Google Profiles to Google Apps and allow users to create multiple profile pages.


Another interesting thing is that Google has a new subdomain: https://plusone.google.com, which redirects to Google Profiles. There's already a Web page about the +1 button, so it's not clear why Google has a new address for Google +1. Maybe profiles will be a feature of Google +1.

{ Thanks, Florian. }

How Google Docs Killed GDrive

"In The Plex", Steven Levy's recently launched book about Google, has an interesting story about GDrive, an online storage service developed by Google. People first found about GDrive from a leaked Google document, back in 2006. GDrive (or Platypus) turned out to be a service used by Google employees that offered many impressive features: syncing files, viewing files on the Web, shared spaces for collaborating on a document, offline access, local IO speeds. But Google wanted to launch GDrive for everyone.

At the time [2008], Google was about to launch a project it had been developing for more than a year, a free cloud-based storage service called GDrive. But Sundar [Pichai] had concluded that it was an artifact of the style of computing that Google was about to usher out the door. He went to Bradley Horowitz, the executive in charge of the project, and said, "I don't think we need GDrive anymore." Horowitz asked why not. "Files are so 1990," said Pichai. "I don't think we need files anymore."

Horowitz was stunned. "Not need files anymore?"

"Think about it," said Pichai. "You just want to get information into the cloud. When people use our Google Docs, there are no more files. You just start editing in the cloud, and there's never a file."

When Pichai first proposed this concept to Google's top executives at a GPS—no files!—the reaction was, he says, "skeptical." [Linus] Upson had another characterization: "It was a withering assault." But eventually they won people over by a logical argument—that it could be done, that it was the cloudlike thing to do, that it was the Google thing to do. That was the end of GDrive: shuttered as a relic of antiquated thinking even before Google released it. The engineers working on it went to the Chrome team.

In 2009, Google Docs started to store PDF files and one year later you could store any type of file in Google Docs. The service still doesn't offer a way to sync files. Even if GDrive was never released, Google Docs inherits most of its features. The main difference is that you no longer have to worry about file formats because you can open and edit documents in Google Docs.

{ Thanks, Kristian. }

More Features in Google Maps for Mobile Browsers

One of the most underrated Google mobile Web apps is Google Maps. Most smartphones and tablets have a native app for Google Maps, so a mobile Web app doesn't seem necessary. Unfortunately, native apps aren't always updated frequently and there are many missing features. Google does a good job at updating Google Maps for Android, but Apple's Maps app for iOS rarely includes new Google Maps features.

That's probably one of the reasons why the Google Maps mobile site was updated to include most of the features from the desktop site. Another reason is that Google wants to offer "a consistent Google Maps experience wherever you use it."

The updated Google Maps mobile site has features like local business search, Google Places, driving directions, layers, My Maps, starred locations, search suggestions. If you can't find biking directions or information about businesses in the Maps app for the iPhone, you can go to maps.google.com in your mobile browser and use these features.


Just like the mobile YouTube site, "Google Maps for mobile browsers is platform independent - you will always get a consistent experience and the latest features without needing to install any updates, no matter what phone you use."

I've tried the updated mobile interface on an iPhone 3GS, a Nexus One and an iPad 2. While all the new features are great, the site is still too slow and unresponsive to be useful. Until Google solves performance issues and mobile browsers become more powerful, people will still use the native app.

Google's Black Navigation Bar

For some reason, the navigation bar displayed at the top of Google's "connected accounts" page is special. The bar has a black background and grey links. Hopefully, this is just a bug and not a redesigned navigation bar.


The "connected accounts" page lets you add accounts from services like Facebook, Twitter, Linkedin, Yelp and use them to personalize search results. This way, you can include your accounts from other social sites without adding them to your Google Profile.

{ Thanks, Herin. }

Friday, May 20, 2011

ADK at Maker Faire

This weekend is Maker Faire, and Google is all over it.

Following up on yesterday’s ADK post, we should take this opportunity to note that the Faire has chased a lot of ADK-related activity out of the woodwork. The level of traction is pretty surprising giving that this stuff only decloaked last week.

Convenience Library

First, there’s a new open-source project called Easy Peripheral Controller. This is a bunch of convenience/abstraction code; its goal is to help n00bs make their first robot or hardware project with Android. It takes care of lots of the mysteries of microcontroller wrangling in general and Arduino in particular.

Bits and Pieces from Googlers at the Faire

Most of these are 20%-project output.

Project Tricorder: Using the ADK and Android to build a platform to support making education about data collection and scientific process more interesting.

Disco Droid: Modified a bugdroid with servos and the ADK to show off some Android dance moves.

Music Beta, by Google: Android + ADK + cool box with lights for a Music Beta demo.

Optical Networking: Optical network port connected to the ADK.

Interactive Game: Uses ultrasonic sensors and ADK to control an Android game.

Robot Arm: Phone controlling robot arm for kids to play with.

Bugdroids: Balancing Bugdroids running around streaming music from an Android phone.

The Boards

We gave away an ADK hardware dev kit sample to several hundred people at Google I/O, with the idea of showing manufacturers what kind of thing might be useful. This seems to have worked better than we’d expected; we know of no less than seven makers working on Android Accessory Development Kits. Most of these are still in “Coming Soon” mode, but you’ll probably be able to get your hands on some at the Faire.

  1. RT Technology's board is pretty much identical to the kit we handed out at I/O.

  2. SparkFun has one in the works, coming soon.

  3. Also, SparkFun’s existing IOIO product will be getting ADK-compatible firmware.

  4. Arduino themselves also have an ADK bun in the oven.

  5. Seeedstudio’s Seeeeduino Main Board.

  6. 3D Robotics’ PhoneDrone Board.

  7. Microchip’s Accessory Development Starter Kit.

It looks like some serious accessorized fun is in store!

Google Image Search in SSL

Probably the most important missing feature in Google SSL Search was image search. Now this feature is available, but there's a drawback: the page that shows a bigger image preview doesn't use SSL.


Google's encrypted flavor supports most of the features of the regular Google site. The left side of the navigation bar is still missing, you can't use Google Instant and the Wonder Wheel, but hopefully these features will be added in the near future.

Google Chrome has recently implemented a feature called SSL False Start which "reduces the latency of a SSL handshake by 30%". SSL sites load slower and one of the reasons is that SSL handshakes are more CPU intensive, use more network round-trips and more packets.

Google eBooks Integrates with Google Dictionary, Google Translate and Google Search

Google's eBook Reader for the Web added a contextual menu that lets you define, translate and search for a selected word or text. "To select text in a Google eBook within the Web Reader, double-click or highlight it with your mouse and a pop-up menu opens with the following options: Define, Translate, Search Book, Search Google and Search Wikipedia," explains the Google Books blog.


Definitions are obtained from Google Dictionary, while translation is powered by Google Translate. If you click "Search Book", Google shows a list of all the instances in which the selected text appears in the book.




These features aren't available yet in the Google Books apps for Android and iPhone.

7 Google Features Only Available in Google Chrome

Google Chrome is at the forefront of the new technologies and Google services are the first to use them. Here are some examples of features only available in Google Chrome:

1. Native printing in Google Docs. You no longer have to download PDF files and use Adobe Reader or a similar PDF reader to print documents. Google implemented a W3C working draft from 2006.

2. Uploading folders in Google Docs. While you can install a Java applet in other browsers to upload folders, Chrome is the only browser that supports this feature natively.


3. Voice Input in Google Translate. The latest Chrome version supports the HTML Speech API, which provides speech recognition and input to web pages. The first Google service that supports this feature is Google Translate, but it's also tested for Google Web Search. Instead of typing your query or the text you want to translate, you can speak into your computer's microphone.

4 & 5. Desktop notifications in Gmail and Google Calendar. It's a really useful feature that replaces the annoying pop-up notification in Google Calendar and shows an unobtrusive notification when you receive a new message.


6. Open PDF attachments in Gmail using the built-in PDF reader, instead of Google Docs Viewer. It's not clear why Google doesn't detect Adobe Reader's plug-in to use a more full-featured PDF reader.

7. Drag and drop Gmail attachments to your desktop. Instead of clicking the "download" link, you can drag the file icon to your desktop.

Thursday, May 19, 2011

Google Maps OneBox Outlines

Google's OneBox displayed when you search for the name of a country, a city or a zip code got smarter. Google added an outline around the location you want to find, so the map is even more useful. For example, try searching for [Bronx], [Detroit 48238], [Baku], [Paraguay map].

Chris, a reader of this blog, says that he used CityData before noticing the new Google feature. While CityData is only useful for the US, the Google Maps OneBox is displayed for almost any city in the world.


{ via Search Engine Land. Thanks, Chris. }

A Bright Idea: Android Open Accessories

[This post is by Justin Mattson, an Android Developer Advocate, and Erik Gilling, an engineer on the Android systems team. — Tim Bray]

Android’s USB port has in the past been curiously inaccessible to programmers. Last week at Google I/O we announced the Android Open Accessory APIs for Android. These APIs allow USB accessories to connect to Android devices running Android 3.1 or Android 2.3.4 without special licensing or fees. The new “accessory mode” does not require the Android device to support USB Host mode. This post will concentrate on accessory mode, but we also announced USB Host mode APIs for devices with hardware capable of supporting it.

To understand why having a USB port is not sufficient to support accessories let’s quickly look at how USB works. USB is an asymmetric protocol in that one participant acts as a USB Host and all other participants are USB Devices. In the PC world, a laptop or desktop acts as Host and your printer, mouse, webcam, etc., is the USB Device. The USB Host has two important tasks. The first is to be the bus master and control which device sends data at what times. The second key task is to provide power, since USB is a powered bus.

The problem with supporting accessories on Android in the traditional way is that relatively few devices support Host mode. Android’s answer is to turn the normal USB relationship on its head. In accessory mode the Android phone or tablet acts as the USB Device and the accessory acts as the USB Host. This means that the accessory is the bus master and provides power.

Establishing the Connection

Building an Open Accessory is simple as long as you include a USB host and can provide power to the Android device. The accessory needs to implement a simple handshake to establish a bi-directional connection with an app running on the Android device.

The handshake starts when the accessory detects that a device has been connected to it. The Android device will identify itself with the VID/PID that is appropriate based on the manufacturer and model of the device. The accessory then sends a control transaction to the Android device asking if it supports accessory mode.

Once the accessory confirms the Android device supports accessory mode, it sends a series of strings to the Android device using control transactions. These strings allow the Android device to identify compatible applications as well as provide a URL that Android will use if a suitable app is not found. Next the accessory sends a control transaction to the Android device telling it to enter accessory mode.

The Android device then drops off the bus and reappears with a new VID/PID combination. The new VID/PID corresponds to a device in accessory mode, which is Google’s VID 0x18D1, and PID 0x2D01 or 0x2D00. Once an appropriate application is started on the Android side, the accessory can now communicate with it using the first Bulk IN and Bulk OUT endpoints.

The protocol is easy to implement on your accessory. If you’re using the ADK or other USB Host Shield compatible Arduino you can use the AndroidAccessory library to implement the protocol. The ADK is one easy way to get started with accessory mode, but any accessory that has the required hardware and speaks the protocol described here and laid out in detail in the documentation can function as an Android Open Accessory.

Communicating with the Accessory

After the low-level USB connection is negotiated between the Android device and the accessory, control is handed over to an Android application. Any Android application can register to handle communication with any USB accessory. Here is how that would be declared in your AndroidManifest.xml:

<activity android:name=".UsbAccessoryActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>

<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity>

Here's how you define the accessories the Activity supports:

<resources>
<usb-accessory manufacturer="Acme, Inc" model="Whiz Banger" version="7.0" />
</resources>

The Android system signals that an accessory is available by issuing an Intent and then the user is presented with a dialog asking what application should be opened. The accessory-mode protocol allows the accessory to specify a URL to present to the user if no application is found which knows how communicate with it. This URL could point to an application in Android Market designed for use with the accessory.

After the application opens it uses the Android Open Accessory APIs in the SDK to communicate with the accessory. This allows the opening of a single FileInputStream and single FileOutputStream to send and receive arbitrary data. The protocol that the application and accessory use is then up to them to define.

Here’s some basic example code you could use to open streams connected to the accessory:

public class UsbAccessoryActivity extends Activity {
private FileInputStream mInput;
private FileOutputStream mOutput;

private void openAccessory() {
UsbManager manager = UsbManager.getInstance(this);
UsbAccessory accessory = UsbManager.getAccessory(getIntent());

ParcelFileDescriptor fd = manager.openAccessory(accessory);

if (fd != null) {
mInput = new FileInputStream(fd);
mOutput = new FileOutputStream(fd);
} else {
// Oh noes, the accessory didn’t open!
}
}
}

Future Directions

There are a few ideas we have for the future. One issue we would like to address is the “power problem”. It’s a bit odd for something like a pedometer to provide power to your Nexus S while it’s downloading today’s walking data. We’re investigating ways that we could have the USB Host provide just the bus mastering capabilities, but not power. Storing and listening to music on a phone seems like a popular thing to do so naturally we’d like to support audio over USB. Finally, figuring out a way for phones to support common input devices would allow for users to be more productive. All of these features are exciting and we hope will be supported by a future version of Android.

Accessory mode opens up Android to a world of new possibilities filled with lots of new friends to talk to. We can’t wait to see what people come up with. The docs and samples are online; have at it!

[Android/USB graphic by Roman Nurik.]

Tuesday, May 17, 2011

Gmail's New Ad System

I've previously reported about Gmail's experiments with image ads and personalized ads, but it seems that these tests are two pieces from a puzzle: a new ad-matching system for Gmail.

New York Times reports that the new algorithms try to find better ads. "Alex Gawley, Google's senior product manager overseeing Gmail, (...) said Gmail's revamped ad-matching system, now in limited tests, analyzes context as well as the content of an individual message. It looks at what he calls 'signals in your inbox,' like whether you open messages with particular keywords and don't open those with other keywords."

Gmail will also include static image ads. "For example, an e-mailed offer for a ski package showing a skier on the slopes could be accompanied by an ad on the right side of the screen, showing a competing offer, replete with another skier coming down another slope. Mr. Gawley said the image used in the ad would be static, not animated, and would be used only in cases where the e-mail message itself showed images."

Gmail's new ads will still be related to your messages, but Google will add other signals that will make the ads an extension of your inbox. Just like Google shows small images ads next to images search results and uses your preferences to personalize ads, Gmail's contextual ads will improve using more data.

As long as the ads are relevant, moderately useful and they aren't distracting, Google is still on the right track. It might take a while to get used to the image ads, but the ad displayed below the messages and the list of messages will be the most obnoxious. "Gmail presents a single text ad when you look at an inbox view and haven't selected a particular message," according to the New York Times.

Pivot Tables in Google Spreadsheets

Google Spreadsheets added an advanced feature that's really useful for summarizing data: pivot tables. "In essence, a pivot table does just that -- it allows you to 'pivot' or rotate data, thus looking at it from different angles and seeing a variety of patterns which may not be immediately obvious," explains Google Docs blog.

A pivot table is a powerful reporting tool that lets you group, filter, sort, count data. Google has an example of spreadsheet that includes information about some students, but it's not easy to summarize the data without using a pivot table. For example, you can group the students from each class level by gender. Just select "Pivot table report" from the "Data" menu, choose the categories of data to include (gender and class level) and the values to summarize ("class level" summarized by "COUNTA").


"A pivot table report is a dynamic table that lets you interpret data in different ways without ever having to enter a formula. Pivot table reports are particularly useful when you want to narrow down a large data set or analyze relationships between data points," suggests Google's help center, which also includes a guide for using this feature.

Monday, May 16, 2011

A New Interface for Google News: No Clusters, No Clutter

Google News has a redesigned interface that tries to remove the visual clutter and make multimedia content more discoverable. All Google News clusters are collapsed by default, except for the top news story. Clusters include more links, a special section for images and videos, but you have to manually expand them.

"The newly expandable stories on Google News in the U.S., released today, give you greater story diversity with less clutter. Now you can easily see more content, see less of what you don't use and have a more streamlined experience," explains Google.


By default, Google uses the single column view, but you can switch to the two column view with the added benefit of going back to the old interface. Here's the new interface:


... and the classic interface:



The redesigned UI shows a single news article instead of a group of related articles. Although the cluster is still available, it's strange to see that Google hides one of the main features of Google News: grouping articles about the same topic. As Krishna Bharat, the founder of Google News, has recently said, the service "groups news articles by story, thus providing visual structure and giving users access to diverse perspectives from around the world in one place".

Power users can try Google's keyboard shortcuts (j/k for navigating to the next/previous story, o/u for expanding/collapsing a story), but most users will rarely expand stories and only click the main news article.

More Google News Settings

Barry Schwartz spotted some new options that let you personalize Google News. If you go to the Google News settings page, you can tweak Google News to show fewer press releases, more blog posts or even hide all the blog posts and press releases. "The neat part of the control of how you see blog and press release results is that there is a lever. You can pick from None to Fewer to Normal to More. Everyone by default is set to normal," says Barry Schwartz.

You can also disable the automatic refresh of the Google News homepage. By default, Google reloads the page every 15 minutes.


I tried to hide all the blog posts and press releases, but this only worked for search results. Google News sections still included blog posts and press releases:

Google's Define Operator, No Longer Useful

Last month, Google added a new search options in the sidebar: dictionary. It's a new interface for Google Dictionary that combines definitions from a reputable dictionary with definitions from the Web, usage examples and other useful information.

At the same time, some users reported that Google's define: operator no longer works. The operator was useful to find definitions obtained from Web pages, so you could type [define:iffy] and find a list of definitions. Now the operator is no longer broken, but it only shows the definition from Google Dictionary and links to the dictionary page. You could type [define iffy] and get similar results.


Maybe Google should send users to the dictionary page when they use the define: operator. It's an advanced feature that's not used by many people, but it's very useful.

Here's how it looked:


{ Thanks, Henry. }

Playlists in YouTube's Drop Down Menu

YouTube's drop down menu at the top of the page now includes a list of all your playlists and makes it easier to access your favorite videos, your liked videos and the videos added to the "Watch later" playlist.


"You will now see a different set up when you click on your username in the upper right hand corner of any page. In addition to showing the same links to access your Account, My Videos, etc. you will be able to click on thumbnails to automatically load your playlists, Liked, Favorites, and Watch Later lists. The songs in your playlists will be accessible in the strip across the bottom of your screen -- so you can easily navigate to different videos in the playlist you are watching," explained a Google employee.

Another way to access your playlists is to expand the small bar displayed at the bottom of the page, click "Options" and select "Load a different playlist".

{ Thanks, Andrew. }

Thursday, May 12, 2011

Google Promotes Google Accounts

Google created a new Web page that explains users why it's a good idea to create a Google account. "One name, one password. That's all you need. Its free. Take a look at how you can personalize and optimize your experience across all Google products and services."


Using a Google account, you can share photos, track your favorite stocks, get more storage for your email, share your schedule, create web pages and collaborate on documents, make free phone calls and chat face to face, get personalized search results and personalized news, create custom maps and get the same experience on multiple devices. There's a lot you can do if you have a Google account.

While most of the new Google services and features require an account, back in January 2005 Google didn't have many services that required authentication. As the Wayback Machine shows, the initial services available with a Google account were Google Groups, Google Alerts, Google Answers and Google Web APIs, but Google promised that "in the future, your Google account will provide access to all Google programs requiring sign in including: Google AdWords, Google Store and more." One year later, Google already offered Froogle, Personalized Search and a Personalized Homepage and it was preparing to launch Google Calendar, Google Spreadsheets, Google Writely and to acquire YouTube.

Angry Birds as a Web App

Angry Birds, the most popular game for smartphones, has a Web interface. You can install it as a Chrome app or play it from chrome.angrybirds.com using the latest versions of the most important browsers.


Nelson Minar says that "calling it Chrome Angry Birds is missing the point because what's really interesting is that it's a real-time multimedia cross-platform HTML 5 app" and he's right. Angry Birds works well in Internet Explorer 9 and even in Firefox 3.6, but there are some upcoming features that will only work if you install the Chrome app: for example, in-app payments.

CNet reports that "Rovio has built some special levels available only for the Chrome browser and the game includes some Chrome-specific tidbits like Chrome rocks, flowers, and clouds. Rovio will use the new in-app payments from Google to allow users to get to premium levels." Unfortunately for Rovio, a Web developer found a way to unlock all the levels injecting a very simple JavaScript code.

The game caches most of the resources, so you can play it offline.

Wednesday, May 11, 2011

Chromebooks

Fast, simple, secure, built for the Web, doesn't require administration. It's a Chromebook, a Chrome OS notebook that will be available starting from next month.

"Chromebooks will be available online June 15 in the U.S., U.K., France, Germany, Netherlands, Italy and Spain. More countries will follow in the coming months. In the U.S., Chromebooks will be available from Amazon and Best Buy and internationally from leading retailers," informs Google.

Google's simplified computing model puts the browser at the core and creates an operating system that revolves around Google Chrome. Samsung and Acer are the launch partners. Samsung's notebooks have 12.1" displays, Atom Dual-Core processors, 16 GB solid state drives, weigh 1.48 kg and get 8.5 hours of continuous usage. They're similar to the Acer notebooks, which have 11.6" displays, a higher resolution, but only get 6 hours of usage. Some of the notebooks include 3G support, while other notebooks are Wi-Fi only. "The Samsung Chromebook will cost $429 in the U.S. for the Wi-Fi only version and $499 for the 3G version. Acer's Wi-Fi only Chromebook will cost $349," reports CNet.

Here's one of the Samsung Chromebooks:


While Chromebooks don't require administration, businesses and schools need a way to manage hundreds or thousands of notebooks, so Google decided to offer a service that includes a cloud management console, support, device warranties and regular hardware refreshes for only $20/user (schools) or $28/user (businesses).

Chromebooks are actually the real netbooks, lightweight and inexpensive computers built for simple tasks like browsing the Web. Unfortunately, netbooks are no longer very popular and users replace them with tablets like the iPad, which have better displays, better battery and are easier to use. For now, Chromebooks will compete with Windows netbooks and it won't be easy to convince people to buy a Chrome netbook when they could run Chrome on a regular netbook. The good news is that Chromebooks will force Google to improve its web applications, to offer more advanced features, more free storage and all Google users will benefit even if they don't buy a Chromebook.

Google Tasks API

Just when you thought that Google Tasks was abandoned, Google releases an API for Google Tasks. "The Google Tasks API provides developers with a powerful set of API endpoints for searching, reading, and updating Google Tasks content and metadata." Developers will be able to create applications for mobile devices, software that integrates Google Tasks with Outlook and other apps using an official API and a proper authentication mechanism.

Google Tasks has a lot to improve before becoming as powerful as Remember the Milk and it's surprising that the missing features aren't added faster. In January, Google listed some of the most common feature requests: repeating tasks, notifications, task sharing, tasks API, synchronization, visual distinction for overdue tasks. The Tasks API is the first feature that's now available.


{ via Kristian. }

Tuesday, May 10, 2011

Android: Past, Present and Future

Google I/O's first keynote was all about Android and there were many impressive announcements.

Android stats continue to be surprising: 100 million activated Android devices, 400,000 Android devices activated every day, 200,000 apps in the Android Market, 4.5 billion apps downloaded from the Android Market, 310 Android devices.

The next major Android release is called Ice Cream Sandwich and the goal is to create a unified operating system that runs on phones, tablets and TVs. Ice Cream Sandwich will be released later this year, but there's a Honeycomb 3.1 update that adds support for USB accessories and for Google TV. This summer, people who bought Google TV devices will be able to install Android 3.1 and run apps from the Android Market.


Android users from the US can now rent movies from the Android Market. "You can choose to rent from thousands of movies starting at $1.99 and have them available across your Android devices — rent a movie on your home computer, and it'll be available for viewing on your tablet or phone. You can rent from Android Market on the web today, and we'll be rolling out an update to Verizon XOOM customers beginning today. We'll start rolling out the update to Android 2.2 and above devices in the coming weeks," informs Google.


There's no music subscription service, but Google launched an invitation-only service that stores all your music on Google's servers and lets you stream it from almost any computer and Android device.

iPhone/iPod/iPad users can install the latest software updates for at least two years, but that's not always the case when it comes to Android devices. Some Android phones run outdated software at launch and not all of them are updated to the latest version because phone manufacturers and carriers don't think that's really important. Google and some of the other members of the Open Handset Alliance (Verizon, HTC, Samsung, Sprint, Sony Ericsson, LG, T-Mobile, Vodafone, Motorola and AT&T) started to develop some guidelines for updating firmware. "To start, we're jointly announcing that new devices from participating partners will receive the latest Android platform upgrades for 18 months after the device is first released, as long as the hardware allows," informs Google.

Google also developed Android Open Accessory, "which allows external USB hardware (an Android USB accessory) to interact with an Android-powered device in a special accessory mode. (...) Many previously released Android-powered devices are only capable of acting as a USB device and cannot initiate connections with external USB devices. Android Open Accessory support overcomes this limitation and allows you to build accessories that can interact with an assortment of Android-powered devices by allowing the accessory initiate the connection."

Probably the most interesting announcement is Android@Home, a framework that allows Android devices to communicate with home appliances and other devices. It's an ambitious project that could make home automation part of everyday life. That's also one of the main reasons why Google bought Android: bringing Google's software to new devices, finding new ways to use Google's information in everyday life, creating an ecosystem of smart devices with standard features and APIs that make "the world's information" more useful.

Android 3.1 Platform, New SDK tools

As we announced at Google I/O, today we are releasing version 3.1 of the Android platform. Android 3.1 is an incremental release that builds on the tablet-optimized UI and features introduced in Android 3.0. It adds several new features for users and developers, including:

  • Open Accessory API. This new API provides a way for Android applications to integrate and interact with a wide range of accessories such as musical equipment, exercise equipment, robotics systems, and many others.
  • USB host API. On devices that support USB host mode, applications can now manage connected USB peripherals such as audio devices. input devices, communications devices, and more.
  • Input from mice, joysticks, and gamepads. Android 3.1 extends the input event system to support a variety of new input sources and motion events such as from mice, trackballs, joysticks, gamepads, and others.
  • Resizable Home screen widgets. Developers can now create Home screen widgets that are resizeable horizontally, vertically, or both.
  • Media Transfer Protocol (MTP) Applications can now receive notifications when external cameras are attached and removed, manage files and storage on those devices, and transfer files and metadata to and from them.
  • Real-time Transport Protocol (RTP) API for audio. Developers can directly manage on-demand or interactive data streaming to enable VOIP, push-to-talk, conferencing, and audio streaming.

For a complete overview of what’s new in the platform, see the Android 3.1 Platform Highlights.

To make the Open Accessory API available to a wide variety of devices, we have backported it to Android 2.3.4 as an optional library. Nexus S is the first device to offer support for this feature. For developers, the 2.3.4 version of the Open Accessory API is available in the updated Google APIs Add-On.

Alongside the new platforms, we are releasing an update to the SDK Tools (r11).

Visit the Android Developers site for more information about Android 3.1, Android 2.3.4, and the updated SDK tools. To get started developing or testing on the new platforms, you can download them into your SDK using the Android SDK Manager.

Google Music Streaming

Wall Street Journal reports that Google will unveil a music streaming service at the Google I/O developer conference.

"Users of the service are expected to be able to listen to songs they have uploaded to the service in a so-called streaming mode but won't be able to download the files themselves. That limit appears to be a bid by Google to hinder the service from being used to spread pirated music. (...) The service is unlikely to be tied to an online music store like Amazon MP3, which gives users the option of adding new songs to their music locker at the time they buy them."

If you go to http://music.google.com/music/, you'll get an error message: "We're sorry. Music Beta is currently only available in the United States," but you'll at least see Google Music's logo, borrowed from a new version of the Android music app.



Update: As Google's blog informs, "Music Beta by Google [is] a new service that lets you upload your personal music collection to the cloud for streaming to your computer and Android devices. With the new service, your music and playlists are automatically kept in sync, so if you create a new playlist on your phone, it's instantly available on your computer or tablet. You can use a feature called Instant Mix to create a playlist of songs that go well together. You can even listen to music when you're offline: we automatically store your most recently played music on your Android device and you can choose to make specific albums or playlists available when you're not connected. The service is launching in beta today to U.S. users and is available by invitation." While it's in beta, the new service is available for free. To upload your music, you can use a Windows/Mac application called Media Manager. There's also a new version of the Android music app that has a new interface and integrates with the Google Music service.


{ Thanks, Scott. }

Google Image Search Clustering

Google Image Search added a new feature that lets you group images by subject. Instead of showing images related to different topics in a single view, Google's image search engine finds the most relevant related searches and shows the top results for each category. For example, when you search for [dog], Google shows the results for [german shepherd], [golden retriever], [great dane], [pug dog], [boxer dog], [rottweiler dog], [border collie] and more. Unfortunately, the clusters for [cat] aren't that great: [funny cats], [cute cats], [cats and kittens], [fat cat], [lol cats].


"Sorting gives you a new way to start your search by exploring categories visually. If you need a particular image, like a picture of coffee for a presentation, sorting can help you hone in on exactly what you're looking for. Searching for broad topics sorted by subject, like the 1940s or Sydney, allows you to explore and learn visually," explains Google.

You only need to select "images" from the Google sidebar and click "sort by subject". By default, Google still sorts the results by relevance.

Monday, May 9, 2011

Google Calendar Adds Event Colors

Google Calendar still doesn't offer support for labels, but you can now pick a color for each event. By default, each event inherits the calendar's color, but you can change it by clicking the event and using the small drop-down displayed next to the event's title.

"Color Coded Events lets you assign specific colors to certain events: put pink on your daughter's soccer practice or make your lunch dates red. It's a great way to stay organized, keep track of recurring events, and add a little flair to your calendar. Color coding is private to you and anybody who can edit your calendar," explains Google.



If you want even more options, go to Google Calendar Labs and enable "Event flair" to be able to add icons to your events.

{ Thanks, Brahm. }

Sunday, May 8, 2011

Google's Humans.txt File

Google has a robots.txt file that lists all paths that can't be crawled by Web spiders, but there's also a humans.txt file which tries to show that Google is not all about bots and algorithms.


"Google is built by a large team of engineers, designers, researchers, robots, and others in many different sites across the globe. It is updated continuously, and built with more tools and technologies than we can shake a stick at. If you'd like to help us out, see google.com/jobs."

Google's Tim Bray linked to this text file and the Google Jobs Twitter account made it more popular.

YouTube's robots.txt file has recently added a humorous comment: "Created in the distant future (the year 2000) after the robotic uprising of the mid 90's which wiped out all humans."

{ via Blogoscoped Forum }

Saturday, May 7, 2011

Google Talk and AIM to Become Interoperable

When you log in to your AIM account in Gmail, you get a message from AOL that links to this page.


In the next few days, Google and AOL are working together to change the way you connect to AIM buddies within Gmail. After this change, Gmail and AIM users can talk directly to each other without having to log into both services (you will no longer be able to log into AIM within Gmail's "Chat" section).

It's nice to know that AIM and Gmail Chat (Google Talk) will finally become interoperable and the Gmail integration will no longer be necessary. Back in 2005, Google and AOL announced that "Google Talk users and AIM users will be able to communicate with one another" and two years later Gmail Chat integrated with AIM, but they didn't become interoperable.

{ Thanks, Josh. }

Google Tests a New Search Interface

Many users noticed a new interface for Google's search results pages that tries to better separate results. There's a lot of space between the results, but that's not useful when you try to find the best answer for your query.


Huffington Post notices that "the new design looks less cluttered. Rows of text are spaced farther apart and text colors are more muted than previous versions." TechCrunch calls the new interface "ugly" and less useful because "it actually gives you much less information on the screen. This will require users to do more scrolling and paging through results to find what they're looking for."

Links are no longer underlined and one of the experiments uses dotted lines to separate results.


Fortunately. the new interface is still an experiment.

{ Thanks, John, Silviu, James, Ken, Steve and Josh. }

Thursday, May 5, 2011

Commerce Tracking with Google Analytics for Android

[This post is by Jim Cotugno and Nick Mihailovski, engineers who work on Google Analytics — Tim Bray]

Today we released a new version of the Google Analytics Android SDK which includes support for tracking e-commerce transactions. This post walks you through setting it up in your mobile application.

Why It’s Important

If you allow users to purchase goods in your application, you’ll want to understand how much revenue your application generates as well as which products are most popular.

With the new e-commerce tracking functionality in the Google Analytics Android SDK, this is easy.

Before You Begin

In this post, we assume you’ve already configured the Google Analytics Android SDK to work in your application. Check out our SDK docs if you haven’t already.

We also assume you have a Google Analytics tracking object instance declared in your code:

GoogleAnalyticsTracker tracker;

Then in the activity’s onCreate method, you have initialized the tracker member variable and called start:

tracker = GoogleAnalyticsTracker.getInstance();
tracker.start("UA-YOUR-ACCOUNT-HERE", 30, this);

Setting Up The Code

The best way to track a transaction is when you’ve received confirmation for a purchase. For example, if you have a callback method that is called when a purchase is confirmed, you would call the tracking code there.

public void onPurchaseConfirmed(List purchases) {
// Use Google Analytics to record the purchase information here...
}

Tracking The Transaction

The Google Analytics Android SDK provides its own Transaction object to store values Google Analytics collects. The next step is to copy the values from the list of PurchaseObjects into a Transaction object.

The SDK’s Transaction object uses the builder pattern, where the constructor takes the required arguments and the optional arguments are set using setters:

Transaction.Builder builder = new Transaction.Builder(
purchase.getOrderId(),
purchase.getTotal())
.setTotalTax(purchase.getTotalTax())
.setShippingCost(purchase.getShippingCost()
.setStoreName(purchase.getStoreName());

You then add the transaction by building it and passing it to a Google Analytics tracking Object:

tracker.addTransaction(builder.build());

Tracking Each Item

The next step is to track each item within the transaction. This is similar to tracking transactions, using the Item class provided by the Google Analytics SDK for Android. Google Analytics uses the OrderID as a common ID to associate a set of items to it’s parent transaction.

Let’s say the PurchaseObject above has a list of one or more LineItem objects. You can then iterate through each LineItem and create and add the item to the tracker.

for (ListItem listItem : purchase.getListItems()) {
Item.Builder itemBuilder = new Item.Builder(
purchase.getOrderId(),
listItem.getItemSKU(),
listItem.getPrice(),
listItem.getCount())
.setItemCategory(listItem.getItemCategory())
.setItemName(listItem.getItemName());

// Now add the item to the tracker. The order ID is the key
// Google Analytics uses to associate this item to the transaction.
tracker.addItem(itemBuilder.build());
}

Sending the Data to Google Analytics

Finally once all the transactions and items have been added to the tracker, you call:

tracker.trackTransactions();

This sends the transactions to the dispatcher, which will transmit the data to Google Analytics.

Viewing The Reports

Once data has been collected, you can then log into the Google Analytics Web Interface and go to the Conversions > Ecommerce > Product Performance report to see how much revenue each product generated.

Here we see that many people bought potions, which generated the most revenue for our application. Also, more people bought the blue sword than the red sword, which could mean we need to stock more blue items in our application. Awesome!

Learning More

You can learn more about the new e-commerce tracking feature in the Google Analytics SDK for Android developer documentation.

What’s even better is that we’ll be demoing all this new functionality this year at Google IO, in the Optimizing Android Apps With Google Analytics session.

Wednesday, May 4, 2011

Google's New Snippets for News Sites

After changing the snippets for Twitter accounts, Google now displays the latest headlines in the snippets for news sites. Search for [washington post], [nytimes], [le monde], [gazzetta dello sport] and you'll find the latest news from the snippets.


Probably the best way to try the new feature is to search for [news] and check the new snippets.


It's likely that the headlines are obtained from Google News, but not all the sites included in Google News have the new snippets.