November 19, 2009
Which Storage Devices Are Considered Removable?
AIR 2 has the ability to detect the mounting and un-mounting of storage volumes like flash drives, hard drives, some types of digital cameras, etc. (to see this in action, see A Demonstration of the New Storage Volume APIs in AIR 2). This feature basically piggybacks off of the operating system's detection of storage devices. In other words, if the OS thinks something is a mass storage device, AIR will also recognize it as such and throw a StorageVolumeChangeEvent. If the OS does not recognize the device as a storage volume, AIR will not react to it. (Note: it is possible to detect and communicate with any type of peripheral in AIR 2 using external processes launched with the new NativeProcess API; the StorageVolume APIs are only for, well, storage volumes.)
The StorageVolumeChangeEvent which is thrown in response to a volume being mounted contains a reference to the StorageVolume object representing the volume that was just mounted. The StorageVolume object contains several interesting properties:
namedrivefileSystemTypeisRemovableisWritablerootDirectory
The isRemovable property indicates whether the operating system considers the media it just detected as removable or not. Initially, this seemed pretty straightforward to me, but as I began playing with the APIs, I found I didn't always agree with the OS's assessment. For instance, my portable 500GB Western Digital USB hard drive is not considered removable even though I plug it in and remove it all the time (note that this is the operating system's decision -- not AIR's). And, for some reason, my Time Capsule is removable, but other network drives are not. Strange.
The table below shows the results of the testing I've done so far:
| Type of Device | StorageVolume.isRemovable |
||
|---|---|---|---|
| OS X | Windows | Linux | |
| CD/DVD (fixed) | true | true | true |
| USB Flash Drive | true | true | true |
| USB Hard Drive | false | false | true |
| FireWire Hard Drive | ? | ? | ? |
| Shared Volume | true | ? | n/a1 |
| Network Drive | false | false | n/a2 |
| Storage Card Reader (empty) | n/a3 | false | n/a3 |
| Storage Card Reader (with SD/CF card) | true | true | true |
1 Linux doesn't have a concept of a shared volume.
2 No StorageVolumeChangeEvent is thrown when drives are mounted using SMB on Linux.
3 Windows considers empty card readers to be non-removable devices while OS X and Linux do not react to them at all.
I'm hoping to get other developers to try out whatever devices they have lying around on whichever OS they favor so we can make this chart as comprehensive as possible. If you have the opportunity to provide data for any of the missing cells, or if you have devices that aren't listed, please leave the information in the comments and I'll update the table. Over time, this should become a very valuable resource for developers googling for answers.
If you need a quick way to test, I threw together this little utility called StorageVolumeTest.air (source code) which will report all the StorageVolume properties as volumes are detected and mounted. This app requires the AIR 2 public beta which can be downloaded here.
For more information on the new storage volume detection capabilities of AIR 2, see Exploring the new file capabilities in Adobe AIR 2. Thanks for your help!
Posted by cantrell at 12:56 PM. Link | Comments (1) | References
November 18, 2009
Demonstration of Gesture APIs in AIR 2
I don't have a multi-touch computer (yet), but I do have a MacBook with a multi-touch trackpad which means I can write AIR 2 applications that incorporate gestures. The video below demonstrates a few of the new gesture APIs in AIR 2:
The code below shows how to indicate that you want to receive gesture events (as opposed to multi-touch, or no touch events at all), and registers for zoom, rotate, and pan gesture events (the watch variable refers to a Sprite which contains the bitmap image of the watch):
Multitouch.inputMode = MultitouchInputMode.GESTURE;
watch.addEventListener(TransformGestureEvent.GESTURE_ZOOM, onZoom);
watch.addEventListener(TransformGestureEvent.GESTURE_ROTATE, onRotate);
watch.addEventListener(TransformGestureEvent.GESTURE_PAN, onPan);
The three functions below show responding to each of the gesture events:
private function onZoom(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
watch.scaleX *= e.scaleX;
watch.scaleY *= e.scaleY;
}
private function onRotate(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
watch.rotation += e.rotation;
}
private function onPan(e:TransformGestureEvent):void
{
var watch:Sprite = e.target as Sprite;
var watchBitmap:Bitmap = watch.getChildAt(0) as Bitmap;
watchBitmap.x += e.offsetX;
watchBitmap.y += e.offsetY;
}
For much more information on how multi-touch and gestures work in both AIR 2 and Flash Player 10.1 (including OS and hardware support, which gestures are supported where, and a thorough review of the APIs), and to download sample code, see Multi-touch and Gesture Support on the Flash Platform. Or, if you just want to see the code for this sample, you can download it here.
Posted by cantrell at 6:50 AM. Link | Comments (2) | References
November 16, 2009
AIR 2 Public Beta Resources
The AIR 2 public beta is now live! Below are all the links you'll need to learn more and get started:
Adobe Labs
- AIR 2 Beta on Adobe Labs
- Download the AIR 2 Public Beta
- AIR 2 Beta Sample Applications
- AIR 2 Beta Release Notes
- AIR 2 Developer FAQ
Adobe Developer Center
- Introducing Adobe AIR 2 Beta
- Interacting with a Native Process
- Multi-touch and Gesture Support on the Flash Platform
- Exploring the New File Capabilities in Adobe AIR 2
- Drag-and-drop Support of Remote Files in Adobe AIR 2
- Creating a Socket Server in Adobe AIR 2
- Using the Microphone Capabilities in Adobe AIR 2
- Creating Accessible Applications in Adobe AIR and Flex
Adobe TV
- Desktop Integration in Adobe AIR 2 (video)
- Command Line Integration in Adobe AIR 2 (video)
- Kevin Lynch Demos AIR 2 Features at MAX (video)
- Multi-touch Demos in Adobe AIR 2 and Flash Player 10.1 (video)
- What's Coming in Adobe AIR 2 (MAX presentation video)
- Building Accessible Flex and Adobe AIR Applications (MAX presentation video)
This Blog
- Exhaustive List of Everything That's New in AIR 2
- Global Error Handling in AIR 2.0 and Flash 10.1
- A Screencast Explaining and Demoing File Promises (video)
- A Demonstration of the ServerSocket API in AIR 2 (video)
- A Demonstration of the New Storage Volume APIs in AIR 2 (video)
- A Demonstration of the NativeProcess APIs in AIR 2 (video)
- A Demonstration of Encrypted Socket Support in AIR 2 (video)
- New AIR 2 API: URLRequest.idleTimeout
Community
- #air on Twitter
- AIR Smart Category on Adobe Feeds
- Google Blog Search for "Adobe AIR"
- Labs Forum for AIR 2
- Adobe AIR-Tight Google Group
- Adobe AIR Support Forum
- Feature Request and Bug Report Form
Posted by cantrell at 8:51 PM. Link | Comments (1) | References
November 13, 2009
A Demonstration of Encrypted Socket Support in AIR 2
I've been wanting to write my own email notifier in AIR for a long time, but without support for encrypted sockets, it wasn't easy to do. But now that AIR 2 added the new SecureSocket class, I was able to write a pretty functional email notifier in just a couple of days:
The new SecureSocket class extends Socket, so MenuMail can use either encrypted or non-encrypted sockets without really having to know the difference:
this.socket = (this.secure) ? new SecureSocket() : new Socket();
The MenuMail application, and all the code for MenuMail, will be available on Adobe Labs after the AIR 2 public beta launch (which is very close!).