Developing Android Applications with Adobe AIR [95]
Get acquainted with sensors to get ideas. You can detect a variety of things such as light, humidity, temperature, pressure, electric current, sound, and time (for more information, see http://www.arduino.cc/playground/Main/InterfacingWithHardware).
Use of this technology is not limited to mobile devices, but such devices offer freedom of movement and open up new possibilities.
Conclusion
This is just the beginning of what you can do with networking devices. Expanding for chat and video, you can add some of the other APIs covered in this book, such as those for geolocation and displaying maps. You can also access Facebook or Twitter data to connect to your network.
Chapter 16. ViewManager
If the user can’t use it, it doesn’t work.
—Susan Dray
Unlike desktop applications, mobile applications only display one screen, or view, at a time. Each screen should be designed for a single task with clear and focused content. Intuitive single-click navigation to move to previous and next steps is key.
We will explore two approaches in this chapter. The first is a navigation system I wrote for my mobile applications using pure ActionScript. The second approach takes advantage of the ViewNavigator in the Flex Hero framework for mobile applications. It includes a few additional features such as transitions and a global ActionBar.
Navigation
You want your audience to be able to move forward between screens without re-creating the same steps over and over. You may need to provide the logic to navigate back to previous screens.
Google discourages the use of the physical back button for anything but going back to the previous application. However, the functionality exists, and some applications, as well as Flash Builder Mobile, use it to go through the stack of views. In my example, I create a back button within the application instead.
ViewManager
I originally developed this code for a conference scheduler application.
Attendees can carry the scheduler in their pocket and organize and save their own schedules. The application’s business logic is fairly simple, but all the screens are interconnected and can be accessed from several different points. For instance, from the session view, the user can access the session’s speaker(s), and from the speaker view, the user can access one of the sessions he is speaking at.
We will refer to each screen as a view.
NOTE
The source code for this example is provided on this book’s website, http://oreilly.com/catalog/9781449394820. For the sake of simplicity, the partial code in this chapter only demonstrates three views: the menu, sessions, and session views.
Creating views
The ViewManager creates the different views and manages them during the life of the application.
The document class creates an instance of the ViewManager. It calls its init function and passes a reference of the timeline:
import view.ViewManager;
// member variable
private var viewManager:ViewManager;
viewManager = new ViewManager();
viewManager.init(this);
The ViewManager class stores a reference to the timeline to add and remove views from the display list:
private var timeline:MovieClip;
public function init(timeline:MovieClip):void {
this.timeline = timeline;
}
The ViewManager creates an instance of each view and stores them in a viewList object. The following code assumes the MenuView, SessionsView, and SessionView classes exist.
The initialization process for each view, creation of the view’s member variables and references to other objects, only needs to happen once. The process is triggered in the constructor as demonstrated in the section Individual Views. Note that the views are of data type BaseView. We will cover this in more detail later in the chapter: