Developing Android Applications with Adobe AIR [80]
NOTE
A security token is provided by a server and acts as an electronic key. The client application sends a request to a remote service and, upon receipt of the token, uses it to proceed with requesting additional data. It is a way to protect particularly sensitive data. Typically, the token is only valid within a small time frame. It appears that Twitter tokens are persistent, and therefore could be stored on the device for multiple registrations. To guarantee long-term validity, add listeners for Error events and be prepared to request a new token if needed.
OAuth is a robust open standard authorization system. It allows users to hand out tokens instead of usernames and passwords. The token is for a specific site and resources for a defined duration.
Twitter uses OAuth. You can allow users to access their account for authentication and log in to your application so that they can use their account data seamlessly without leaving AIR. You need to register a URL on Twitter to obtain a Consumer key and a Consumer secret, both of which are necessary in your application (see http://twitter.com/oauth/ for more information).
Sandro Ducceschi offers a library called Tweetr that supports pinless OAuth (see http://wiki.swfjunkie.com/tweetr). For a similar application for Facebook, refer to Mark Doherty’s example at http://www.flashmobileblog.com/2010/10/14/facebook-connect-with-air-on-android/.
Limitations
Despite its benefits, StageWebView also has some limitations:
You cannot layer elements on top of StageWebView, although you can simulate it by taking a screen grab as described earlier.
The interaction between ActionScript and JavaScript is very limited. There is currently no support for ExternalInterface, even though you can fake URLs to communicate from HTML to AS.
You should not use StageWebView as a substitute for the native browser. Use it only as a bridge between your application and some needed Internet content. Android devices, for instance, do not support the QuickTime codec.
There is no direct way in ActionScript to prevent StageWebView instances from accepting cookies or to clear cookies.
The HTMLLoader class is supported in AIR for the desktop but not in AIR for Android.
If your application requires more advanced HTML features, consider using other tools. PhoneGap (http://www.phonegap.com), for instance, is an open source framework for developing applications for Android, iPhone, iPad, BlackBerry, and Symbian devices.
Conclusion
You can simulate the browser experience further. For instance, you can create bookmarks by storing the locations as local persistent data. You can also simulate the Android native browser window’s functionality to display pages in a thumbnail version. To do so, save a bitmap of each page visited and display them at a smaller resolution on request.
Chapter 14. Hardware Acceleration
In this new wave of technology, you can’t do it all yourself, you have to form alliances.
—Carlos Slim Helu
We tend to forget that the content on our device’s display—the high-definition video, the complex animation moving across the screen, the panels that we touch to drag around—none of it is real. We are looking at pixels being updated at a very fast rate to keep us engaged and fooled. It works.
Hardware accelerators use dedicated hardware to perform tasks faster than they would be done in software. They are used to accelerate both video and graphics, to draw changing content on the screen.
This performance technique is relatively new to Flash. NVIDIA, which specializes in the development of GPUs, and Adobe teamed up in 2009 to enable the Flash platform to leverage GPUs on the desktop as well as on smartphones and tablets. The adoption has been easier on mobile devices because each model uses one predictable driver, whereas the desktop has a multitude of scenarios.
In this chapter, we will discuss some of this technology and see how it can best be used for our