Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [78]

By Root 2468 0
if you wanted to simulate the desktop experience.

The title and location properties return the page information. The stop and reload methods will, as their names indicate, stop the loading of a page or reload it.

The historyBack and historyForward methods load pages that were previously visited. Check that the isHistoryBackEnabled and isHistoryForwardEnabled properties are true to ensure the pages exist in either direction. Currently, the history is not available as a whole. If you want to access it, you must store it yourself as the user navigates through pages.

We will discuss the loadString method in Local Use.

As mentioned before, StageWebView is not added to the display list. To remove it, use the dispose method. Setting the object and its viewPort property to null is meant to aid in the garbage collection process:

webView.viewPort = null;

webView.dispose();

webView = null;

Design Considerations


You should design your application for the best possible user experience. Toward that end, here are some points you should consider.

First, you have full control of the viewPort dimensions, but not its content. The vast majority of sites are designed only for the desktop. The few that deliver a mobile version take stage dimension into account and offer an adaptive layout and optimized content.

You can reduce the locations to a limited choice using the preventDefault method as previously discussed. If you want to keep the user experience open, prepare your application to accommodate multiple designs as much as possible.

Present your application in landscape mode and full screen. Align your application to the upper-left corner. This will mirror the web experience and users’ expectations:

import flash.display.StageAlign;

stage.align = StageAlign.TOP_LEFT;

If the web page is larger than the viewPort, the StageWebView displays a scroll bar and zoom controls. There is no option to suppress these controls.

If you choose to keep auto-rotation enabled, you need to set a listener for the stage Event.RESIZE event and prevent scaling:

import flash.display.StageScaleMode;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.addEventListener(Event.RESIZE, onStageResized);

When the screen rotates, re-create the viewPort at the appropriate dimension. It does not resize dynamically:

import flash.events.Event;

function onStageResized(event:Event):void {

webView.viewPort = null;

var verticalBounds:int = stage.stageHeight*0.75;

webView.viewPort =

new Rectangle(0, 0, stage.stageWidth, verticalBounds);

}

If you navigate between locations, the native back button takes you back to the previous open application or home. It does not work as a back button for StageWebView. This is the expected behavior, of course, because the Internet content is part of your application, not a separate intent.

Either provide an internal back button or override the native back button. Do consider that this is not a recommended Android practice. It is not possible to put elements on top of StageWebView, but you can simulate a top navigation above it.

The drawViewPortToBitmap function can be used to take a screen capture of the StageWebView. You can take advantage of this feature to temporarily replace StageWebView with a bitmap and display other elements on top of it.

Local Use


You can package HTML files with your application and then load them inside StageWebView. You can use this to display a help page for your users, or other HTML content.

Copy the HTML page into a temporary file and load it using its url:

import flash.filesystem.File;

var file:File = File.applicationDirectory.resolvePath("assets/test.html");

var local:File = File.createTempFile();

file.copyTo(local, true);

webView.loadURL(local.url);

Note that it is possible to load a local HTML file to make an Ajax XMLHttpRequest on another domain or to make JavaScript calls, as demonstrated in the next paragraph.

The loadString method is for displaying HTML formatted text in the viewPort area. The text must be fully HTML formatted:

// define the string in html

Return Main Page Previous Page Next Page

®Online Book Reader