Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [106]

By Root 2508 0
when the keyboard opens. Use the softKeyboardRect property of the stage, which contains the dimensions of the area covered by the keyboard:

import flash.events.SoftKeyboardEvent;

import flash.text.TextField;

import flash.text.TextFieldType;

var textField:TextField = new TextField();

textField.type = TextFieldType.INPUT;

textField.width = 400;

textField.height = 200;

addChild(textField);

textField.addEventListener

(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, onKeyboard);

textField.addEventListener

(SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, onKeyboard);

function onKeyboard(event:SoftKeyboardEvent):void {

trace(stage.softKeybardRect.y);

trace(stage.softKeybardRect);

}

For fullscreen mode, use the keyboard dimensions as an approximation. The values returned may not be perfectly exact.

Fonts


Try to use device fonts for input text fields, as they render faster than embedded fonts. The Font Embedding dialog box monitor in Flash Professional CS5 and later monitors font usage in your application. You can also generate a size report that lists all the assets, including fonts. Only include the font families you use.

The choice of Android font families is limited but well targeted to the Android style. Figure 18-1 shows the Droid Serif font, created by Steve Matteson of Ascender Corporation.

With AIR 2.6 and up, support is provided for scrolling text; text selection for cut, copy, and paste; and context menus.

Figure 18-1. The Droid Serif font

Consider using an alternative to input text fields, such as already populated fields or plus and minus buttons for digits. The recommended font size is at least 14 pixels, so that text is readable on high-density devices.

The Flash Text Engine


An application with impeccable typography stands out. The Text Layout Framework (TLF) provides the tooling for text quality but is heavy and not yet ready for mobile.

The Flash Text Engine (FTE) is the low-level API below the TLF. It is light and renders exquisite script with great precision. It is not as immediately accessible as other tools, however. For simplicity, use it for read-only text and keep the classic TextField object for input text if needed.

Here is a “Hello world” example:

import flash.text.engine.*;

var fd:FontDescription = new FontDescription();

var ef:ElementFormat = new ElementFormat(fd);

var te:TextElement = new TextElement("Hello world", ef);

var tb:TextBlock = new TextBlock();

tb.content = te;

var tl:TextLine = tb.createTextLine(null, 200);

addChild(tl);

FontDescription is for the font family. ElementFormat is for styling and layout. TextElement is for the content as text and inline graphic. TextBlock is the Factory to create one block of text. Finally, TextLine is the display object for a single line of text. Figure 18-2 depicts the classes needed to create text using the Flash Text Engine.

Figure 18-2. The various classes needed to create text using the Flash Text Engine

This is a lot of classes for such a simple example, but it introduces the benefit of using this engine. It gives you access to a vast range of typographic settings, bidirectional layout, and support for most scripts. Please refer to the article I wrote on FTE to learn more (see http://www.developria.com/2009/03/flash-text-engine.html).

Optimizing Art

If you or your designer uses Flash Professional as a paint tool, optimize the shapes under Modify→Shape→Optimize. Then, convert strokes to fill.

Use a utility to optimize PNG and JPEG formats. Both PNG Optimizer (http://www.pngoptimizer.com/) and ImageOptim (http://imageoptim.pornel.net/) are free and will reduce the file size of your images.

If you have several vectors that are not moving, are grouped, or are on top of each other, convert them to a single bitmap. Crop the alpha channel of your bitmap carefully. Remove the alpha channel completely on PNGs if you don’t need it. In Photoshop, use the File→Save for Web & Devices option instead of File→Save As. Save your image as PNG-8.

Never put an image on top of a video, especially if it has an alpha

Return Main Page Previous Page Next Page

®Online Book Reader