Flex Pasta » iPhone
Consider from the beginning of Flex, there have always been 4 layout types inside the SDK: Absolute, Horizontal, Vertical, and Tile. Yes, tile layout(formerly the tilelist in 3.5), the much forgotten child, has been given new life in the Flex 4.5 SDK. For the most part in applications, I never really had a use for a tile layout. Enter Flex 4.5 and the multitude of different screen sizes that now exist for mobile applications. For more larger mobile applications, the home screen component usually consists of some sort of navigation. For example, icons tiled in a scrollable list:
Tile layout makes it easy to have an icon screen that flows among many different screen sizes, without any coding changes. The same code generated the two screens above. One showing the Motorola Droid and the other is the Samsung Tab. The tile layout automatically takes advantage of the space given to it and lays out the icons to get the maximum utilization of the space.
Here is a live example on the Droid. Notice that TileLayout automatically repositions the icons when the phone changes from portrait to landscape mode.
Check out how simple the code is to accomplish a tile layout. Read the rest of this entry…
When using the Flex 4.5 SDK for mobile application, there is a built in Geolocation class for reading information about a user’s current GPS location. Here is a simple example of how it works:
private var geo:Geolocation = new Geolocation();
private function gpsRun():void
{
geo.addEventListener(GeolocationEvent.UPDATE, updateLocation);
}
private function updateLocation(geoEvent:GeolocationEvent):void
{
geo.removeEventListener(GeolocationEvent.UPDATE, updateLocation);
}
…
s:creationComplete
Geolocation.isSupported = Is this device a GPS device?
geo.muted = The device is a GPS device but the GPS has been disabled.
In this example, when the Geolocation is supported and not muted, the GeolocationEvent.UPDATE event listener is added. Assume that the target device for this application is a mobile device which will have geolocation and it will also not be muted. When the event listener GeolocationEvent.UPDATE is added, the device will immediately fire its gps signal and begin searching for a location. A phone’s GPS is one of the biggest drainers of the phone’s battery. To shut off the GPS, the event listener must be removed(as shown above). Without removing the event listener, the GPS on the device will run until the application is killed. With that in mind, there is another issue that comes in to play with the above example. To get an accurate reading, the application will need to listen for GPS for indeterminate amounts of time. Just listening for one GeolocationEvent.UPDATE will likely result in the accuracy being off be hundreds of miles!
How much event listening time is needed to get an accurate GPS location?
One update event is not enough to get even a close GPS reading. However, listening forever is also not desired as battery drainage will occur. Further complicating the issue is some users might be indoors, others might have better hardware, and others may be in more prime GPS locations. There is really no way to tell how long it will take to get an accurate reading. Putting a timer or a count on the number of times the event listener fires will result in mixed results. And of course it all depends how important an accurate and up to date GPS location is to the application.
There are a set of properties on the GeolocationEvent. Besides latitude and longitude, there properties for horizontalAccuracy(horizontal accuracy in meters), verticalAccuracy(vertical accuracy in meters), altitude(altitude in meters), speed(meters per second). After quite a bit of GPS testing with a Droid, moving indoors and outdoors, it seems a good location event happens when the horizontalAccuracy is lower than 100 meters. It is worth testing at different locations and on a variety of devices. Removing the event listener and turning off the GPS seems to work when the horizontal accuracy falls below 100.
What do the Android Docs say about GPS accuracy?
According to the Google Android docs, GPS accuracy is broken down into three categories:
High Accuracy - Less than 100 meters in horizontal accuracy
Medium Accuracy - Between 100-500 meters in horizontal accuracy
Low Accuracy - Greater than 500 meters in horizontal accuracy
The high accuracy of 100 meters or less is close to what AIR for Android reported for an accurate location. Following the guide for Google, it is fair to say that the above accuracy levels can be used when determining when to keep listening for the GeolocationEvent and when to stop it. This will help get the best possible GPS location without draining the battery.
There are two big advantages for using the Flex 4.5 SDK for mobile, in my opinion.
1) Code once for multiple platforms, and
2) Reuse existing Flex knowledge have made it easy to create applications quickly.
Today I wanted to put to the test some effects on a mobile device. Flex offers some great and easy to use effect tags. Would they perform on a mobile device? In my brief test, the answer is yes!
This demo app has two images. When I tap the image, it runs the following effect:
<s:Parallel id=”eff“>
<s:Move3D yFrom=”{img.y}” yTo=”{yTo}” xFrom=”0” xTo=”{yTo}“/>
<s:Rotate3D angleXFrom=”0” angleXTo=”45“/>
</s:Parallel>
It will move the image to the top of the screen while at the same time, do a 3d rotate. The second image will then fade in at the bottom.
Here is a video of the effect running on the Motorola Droid.
Full code….follow the link:
Adobe has released Flex and Flash Builder 4.5 With this release, you can now start building AIR apps that can run on android and iPhone devices(including the blackberry playbook). The upside to Flash Builder 4.5 for mobile devices is that I can build my application once, and deploy it to multiple platforms. Being a Java and Flex developer, this is huge! I don’t want to buy a mac book, learn objective C, or write an app multiple times just to publish something. AIR will reduce my cost to create a multi-platform application.
About 5 minutes to get an AIR app on your Android Device
Download the flash builder 4.5 release. Once it’s installed it literally takes 5 minutes to get a hello world app running on the phone. Here is a rough outline on the steps to get a project up in running in flash builder 4.5
Step 1: Create a new mobile project from the file menu.
Step 2: Create a project name
Step 3: Determine the mobile settings. These include the target platforms, device permissions the application will need, and even a set of starter templates!
Click finish and the project is setup and ready to go!
Running the AIR app on the Android Device
To run the AIR app on an android phone, the following prerequisites are required:
- The phone is plugged in the computer via USB
- The phone is in developer mode. On the android device, go to Settings > Applications > Development > Check the USB debugging check box
- Adobe AIR is installed on the mobile device
Once this is setup, right click on the AIR test project in Flash Builder and do Run As > Mobile Application. The launch configuration screen appears.
Be sure to check the “Clear application data on each launch”. The will deploy the latest code to the phone each time it is run.
Within minutes an AIR app can be running on the phone! To get started using device specific features, try downloading the Tour de Mobile Flex application available in the Android Market.







