Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [105]

By Root 2480 0
to the next view:

function clickAway(event:MouseEvent):void {

touchEnd(event);

clearTimeOut(timeout);

if (selected == event.currentTarget && isMoving == false) {

dispatchEvent(new ClickEvent(ClickEvent.NAV_EVENT,

{view:"speaker", id:selected.id}));

}

Now let’s add to the frameEvent code to handle deactivating the element when scrolling. Check that an element was pressed, and check that the selected variable holds a value and that the motion is more than two pixels. This is to account for screens that are very responsive. If both conditions are met, change the boolean value, reset the look of the element, and set the selected variable to null:

function frameEvent(event:Event):void {

if (newY != oldY) {

var newPos = newY - oldY;

oldY = newY;

container.y += newPos;

for (var i:int = 0; i < totalChildren; i++) {

var mc:MovieClip = container.getChildAt(i) as MovieClip;

var pos:Number = container.y + mc.y;

mc.visible = (pos > topBounds && pos < deviceHeight);

}

if (selected != null && Math.abs(newPos) > 2) {

isMoving = true;

selected.what.textColor = 0x000000;

selected = null;

}

}

}

There are various approaches to handle scrolling. For a large number of elements, the optimal way is to only create as many element containers as are visible on the screen and populate their content on the fly. Instead of moving a large list, move the containers as in a carousel animation and update their content by pulling the data from a Vector or other form of data content.

If you are using Flash Builder and components, look at the Adobe lighthouse package (http://www.adobe.com/devnet/devices/fpmobile.html). It contains DraggableVerticalContainer for display objects and DraggableVerticalList for items.

Desktop Functionality


The AIR desktop application, as shown in Figure 17-7, is set to receive the data and display it. Seeing a high resolution on a large screen demonstrates how good the camera quality of some devices can be. The image can be saved on the desktop as a JPEG.

Figure 17-7. AIR desktop companion application to display images received from the device

Another technology, not demonstrated here, is Pixel Bender, used for image manipulation. It is not available for AIR for Android but is for AIR on the desktop. So this would be another good use case where devices and the desktop can complete one another.

Conclusion

The application we discussed in this chapter has a simple purpose, but it covers many aspects of what you can do with AIR for Android. Feel free to expand on it and publish your own application.

Chapter 18. Asset Management

Good design is obvious. Great design is transparent.

—Joe Sparano

Preparing and managing art in mobile development requires a close collaboration between the designer and the developer.

In addition to planning ahead for multiple screens, good design needs to conform to acceptable performance. Some of the work takes place in the preparation, but a lot needs to happen during development.

In this chapter, we will cover some aspects of design, from preparation to management at runtime.

Text


Text should be a particular concern. The absence of a physical keyboard introduces a new interface and user experience. Embedding and rendering fonts affects size and performance.

The Virtual Keyboard


On most devices, pressing on an input text field brings up the virtual keyboard. AIR for Android only uses the Android default alphabet keyboard.

Be aware of the space the keyboard occupies. The stage position is automatically adjusted to keep the text field visible. If the text field is toward the bottom, the application moves the stage up. To dismiss the virtual keyboard, the user usually needs to tap on the stage. Make sure you leave a noninteractive area for the user to tap on.

If you want to overwrite the default behavior, set the softKeyboardBehavior tag of the application descriptor to none.

none

To control how the application moves, set a listener on the softKeyboardActivating event, which is dispatched

Return Main Page Previous Page Next Page

®Online Book Reader