I have just completed my App in a Week session on targeting Mobile and Devices, as promised, here are the source files for EVA on Android. So that you don’t get lost in the huge swathe of code let’s run through some of the features to get you started.
Target Multiple Screens:
The goal of this application was to target Android devices running AIR, or indeed the Flash Player running in mobile browsers. So it was important to include some pointers on how to dynamically layout the application.
I chose to implement two pretty simple examples of how to do this using the widgetComponent and the footerMenu. In the Application class I listen to the “Event.RESIZE” event through the doLayout function. As you stretch the SWF (use the standalone player) you can see the widgetComponent always displays in the middle, the footerMenu will always be at the bottom.
Of course the menu, widgets and background should all change dynamically. This won’t require a huge set of changes and as you can see it’s quite simple to control the layout. In a later build I will investigate a more dynamic approach to laying out the UI.
To demonstrate the data-centric features of Flash Builder, Mihai and Piotr created a database with PHP services that describe common Evangelist activities as well as data about us. In the mobile demo I have coded as few of these database interactions in the UsersService class:
- “UsersService.getByUsername” – Is used to login and returns an object with user details including their name, photo url etc
- “UsersService.setLocation” – Is used to store the lastest location after login, this is then synchronized with other Evangelists.
I have created a User object to represent the user of the service, this class also manages the loading of the user image using ContentLoader. The primary function of ContentLoader is to abstract the loading of SWF/image files, handling the various possible error cases.
An interesting new feature of Adobe AIR on Android is the ability to use the GPS hardware to get an accurate location fix. Although EVA was designed to run inside, or outside of the browser and as such I have built a few fallbacks.
In addition to these two approaches I have also deployed the MaxMind GeoIP service on my blog. This is a huge database of IP addresses that can be used to determine an approximate location, usually your nearest city. This is used when the application is running in standalone mode for debugging purposes, or as a failure fallback.
Using each of these methods I can reverse geocode the latitude and longitude to discover the users current location. The UI displays the current city and country. The open geonames database is an incredible free webservices that cover all manner of data, I couldn’t have wished for more.
One of the more interesting features of the application is the local weather service. There are only two services that can produce weather data for a give latitude and longitude, and those are Geonames and Google Weather.
I chose Google because it comes with the added bonus of providing a weather icon to display. Unfortunately this icon isn’t up to the quality of Serge’s design and so I ultimately swap it out, but at least I can easily change the URL.
- The stage is running in low quality mode – perfect for use with device fonts
- Layers have been minimized and flattened as much as possible
- The Frame rate of the application is 15FPS – as low as possible
- The EVA background is an 8KB PNG-8 128
- All other images are mobile optimized PNG-8 128 Dithered and under 4KB
- Bitmap caching is not used, the application is relatively static
- Special care has been taken to ensure that all assets are snapped to pixels (not 23.43 etc)
- No assets are loaded off stage and nothing is invisible, ever – if they are unused, then they are unloaded
- All assets use “Sprite” as their base class, as set in the properties panel in Flash Professional
- TLF is not used anywhere due to performance and size issues
- Only device fonts are used, they perform and render much better
- Flex is not used due to the overhead of the framework on devices.
In later blog posts I will discuss the Widgets in more depth, including the Social and Radar widgets. It’s also worth noting that Tom did a great job to deliver his P2P widget ready for integration, amazingly within 12kb!