January 21, 2010

How to Take Screenshots on Android Devices

I've been playing around with Android recently, and I ran into a situation where I needed to take screenshots of applications running on the device (as opposed to on my desktop with the emulator). Most of the information I found on Google recommended that I install a third-party application, but I learned a quick and simple way to do it without having to install anything.

Assuming you have the Android SDK installed (which, if you're doing development, you obviously do), simply:

  1. Connect your Android device (I'm using a Droid) via USB.
  2. Run android-sdk-mac_86/tools/ddms (hint: put the tools directory in your path to make your life much easier).
  3. Select the device in the Dalvik Debug Monitor.
  4. Type Control + s, or go to Device > Screen Capture.

Not quite as easy as taking screenshots on the iPhone (simply press the power button, then the menu button at the same time), but if you need the screenshot on your desktop rather than in your photo album on your phone, it's a very efficient solution.

Posted by cantrell at 10:23 AM. Link | Comments (0)

January 4, 2010

Setting HTML Focus From Flash or Flex Content in AIR

It is possible to set HTML focus from Flash or Flex content in AIR, but it takes a little finessing. The key is to focus the HTMLLoader before setting focus to something inside the HTMLLoader. The code below shows an HTML text input getting focus when the document loads, and it shows how to set focus on-demand from Flash or Flex. I'll let the code explain the rest:

Continue reading "Setting HTML Focus From Flash or Flex Content in AIR"

Posted by cantrell at 12:58 PM. Link | Comments (0)

December 18, 2009

Get the Full Version of Google Tasks on Your Desktop

I started using Google Tasks about a month ago in order to make it easier for me to use multiple computers and multiple operating systems. Google Tasks is a nice, simple, straightforward application with one small shortcoming: it's tied to the browser.

Continue reading "Get the Full Version of Google Tasks on Your Desktop"

Posted by cantrell at 7:33 AM. Link | Comments (4)

December 10, 2009

Four New Properties Added to Socket

In response to feedback from the AIR 2 public beta, it looks like we're going to be adding four new properties to the flash.net.Socket class:

  • Socket.localAddress: The local IP address of this Socket if it has been bounded locally — otherwise null.
  • Socket.localPort: The local port of this Socket if it has been bounded locally — otherwise 0.
  • Socket.remoteAddress: The remote IP address of this Socket if it has been connected — otherwise null.
  • Socket.remotePort: The remote port of this Socket if it has been connected — otherwise 0.

They're not yet available in the current public beta build, but I would expect them to be in the next one. As always, thanks for the feedback!

(I've added these properties to Exhaustive List of Everything That's New in AIR 2, so that's still the definitive list.)

Posted by cantrell at 10:17 AM. Link | Comments (3)

December 2, 2009

Labels in ActionScript 3

There's a little-known feature of ActionScript 3 called labels which can give you better control over nested loops. In particular, labels give you control over the depth of your continue and break statements.

Consider the following piece of code which compares two arrays to find which elements exist in outerArray that do not exist in innerArray:

var outerArray:Array = ["coffee", "juice", "water", "beer"];
var innerArray:Array = ["liquor", "beer", "wine", "juice"];

for each (var foo:String in outerArray)
{
    var found:Boolean = false;
    for each (var bar:String in innerArray)
    {
        if (foo == bar)
        {
            found = true;
        }
    }
    if (!found)
    {
        trace(foo);
    }
}

(Note: I know there are better ways of doing this particular comparison; this technique is for demonstration purposes only.)

The same code could be written using labels like this:

var outerArray:Array = ["coffee", "juice", "water", "beer"];
var innerArray:Array = ["liquor", "beer", "wine", "juice"];

outerLoop: for (var i:uint = 0; i < outerArray.length; ++i)
{
    var foo:String = outerArray[i];
    innerLoop: for (var j:uint = 0; j < innerArray.length; ++j)
    {
        var bar:String = innerArray[j];
        if (foo == bar)
        {
            continue outerLoop;
        }
    }
    trace(foo);
}

Notice how the labels outerLoop and innerLoop precede my for loops, and how I can reference the outerLoop label in my continue statement. Without specifying a label, continue would have continued from the top of innerLoop rather than outerLoop.

Labels will also work with break statements, and can even be used to create their own blocks as in the following example:

dateCheck:
{
    trace("Good morning.");
    var today:Date = new Date();
    if (today.month == 11 && today.date == 25)  // Christmas!
    {
        break dateCheck;
    }
    trace("Time for work!");
}

Some things to keep in mind about labels:

  • You can't use a continue statement in the context of a labeled code block since the result would be an infinite loop. This will be caught by the compiler.
  • You obviously can't reference labels that don't exist. The compiler will catch your mistake and let you know that the target wasn't found.
  • In using labels yesterday for new application I'm working on, I discovered that they don't play well with for each..in loops. If you're going to use labels, you'll want to make sure you're using regular for or while loops. (A bug has been filed and will hopefully be fixed soon.)

Posted by cantrell at 6:23 AM. Link | Comments (11)

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.)

Continue reading "Which Storage Devices Are Considered Removable?"

Posted by cantrell at 12:56 PM. Link | Comments (2)

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 (7)

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

Adobe Developer Center

Adobe TV

This Blog

Community

Posted by cantrell at 8:51 PM. Link | Comments (1)

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:

Continue reading "A Demonstration of Encrypted Socket Support in AIR 2"

Posted by cantrell at 7:20 AM. Link | Comments (5)

November 12, 2009

A Demonstration of the NativeProcess APIs in AIR 2

SearchCentral uses the new NativeProcess APIs in AIR 2 in order to integrate with Spotlight and provide very fast local file system search. Here's a demo:

Continue reading "A Demonstration of the NativeProcess APIs in AIR 2"

Posted by cantrell at 7:25 AM. Link | Comments (6)

Copyright © 2009 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).