Building a Web Browser App for Blackberry Playbook Simulator

misc

The blackberry playbook simulator doesn't yet include the web browser application, but I found it pretty easy to write my own using the qnx.media.QNXStageWebView class and calling the loadUrl method. This class also has a loadString(code, mimeType) and executeJavaScript method that looks interesting.

Here's the code for a simple browser:

package 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	
	import qnx.media.QNXStageWebView;
	import qnx.ui.buttons.LabelButton;
	import qnx.ui.text.TextInput;
	
	// The following metadata specifies the size and properties of the canvas that
	// this application should occupy on the BlackBerry PlayBook screen.
	[SWF(width="1024", height="600", backgroundColor="#cccccc", frameRate="30")]
	public class PlaybookTest extends Sprite
	{
		private var addressInput:TextInput = null;
		private var webView:QNXStageWebView = null;
		public function PlaybookTest()
		{
			addressInput = new TextInput();
			addressInput.x = 10;
			addressInput.y = 10;
			addressInput.text = "http://foundeo.com/";
			
			var goButton:LabelButton = new LabelButton();
			goButton.label = "Go";
			goButton.x = addressInput.width + 10;
			goButton.y = addressInput.y;
			goButton.addEventListener(MouseEvent.CLICK, go);
			
			
			var closeButton:LabelButton = new LabelButton();
			closeButton.label = "Close";		
			closeButton.addEventListener(MouseEvent.CLICK, closeWindow);
			closeButton.x = (stage.stageWidth - closeButton.width) - 10;
			closeButton.y = 10;
			
			webView = new QNXStageWebView(); 
			webView.stage= stage;
			webView.autoFit=true;
			webView.viewPort = new Rectangle(10,100,stage.stageWidth,stage.stageHeight-100);
			webView.enableCookies = true; 
			webView.enableJavascript = true; 
			webView.enableScrolling = true; 
			webView.loadURL("http://foundeo.com");
			
			addChild(addressInput);
				
			addChild(goButton);
			addChild(closeButton);
			
			stage.nativeWindow.visible = true;
		}
		
		private function closeWindow(event:MouseEvent):void{
			stage.nativeWindow.close();
		}
		
		private function go(event:MouseEvent):void {
			webView.loadURL(addressInput.text);
		}
	}
}

Here's a screenshot of the app:

Blackberry Playbook Simple Browser App


Related Entries

1 person found this page useful, what do you think?

Trackbacks

Trackback Address: 770/719352250ED307EFF0405FE04372C2DE

Comments

On 11/29/2010 at 3:17:29 PM UTC Raymond Camden wrote:
1
I noticed that QNXStageWebView was not in the API docs (from what I can see). How did you find out the methods for it?

On 11/29/2010 at 3:25:32 PM UTC Pete Freitag wrote:
2
Hi Ray, I found it by browsing through the "BlackBerry Tablet OS SDK 0.9.0 for Adobe AIR" library in the Package Explorer in Flash Buider.

I didn't realize it was undocumented :)

On 11/29/2010 at 3:35:54 PM UTC Raymond Camden wrote:
3
Nice - I keep forgetting we can do that. ;)

On 11/30/2010 at 11:57:38 AM UTC Louis wrote:
4
Great post many thanks!

Do you know how to display local HTML files? If this is possible, where do you keep the local files, and will they be able to link to one another inside the browser?

On 11/30/2010 at 12:00:04 PM UTC Raymond Camden wrote:
5
You should be able to make a local URL request to

app://foo

where app:// represents the application install directory and "foo" is some file underneath it.

On 11/30/2010 at 12:34:14 PM UTC Louis wrote:
6
Thanks Raymond, but I'm having no luck. I have created a subdirectory in my "src" directory called "ce" I then try various:

loadURL("ce://file.htm") loadURL("app://ce/file.htm") loadURL("file://ce/file.htm") loadURL("file:///ce/file.htm")

Nothing happens.

The "ce" directory is recreated in the bin-debug directory. What am I missing?

On 11/30/2010 at 12:34:23 PM UTC Louis wrote:
7
Thanks Raymond, but I'm having no luck. I have created a subdirectory in my "src" directory called "ce" I then try various:

loadURL("ce://file.htm") loadURL("app://ce/file.htm") loadURL("file://ce/file.htm") loadURL("file:///ce/file.htm")

Nothing happens.

The "ce" directory is recreated in the bin-debug directory. What am I missing?

On 11/30/2010 at 12:37:35 PM UTC Raymond Camden wrote:
8
Try app:/ notice it has ONE slash.

http://www.flex888.com/511/adobe-air-url-schemes-for-local-access.html

On 11/30/2010 at 12:51:00 PM UTC Raymond Camden wrote:
9
Actually I may be wrong on that.

So - yesterday I was speaking with Brian Rinaldi. And he mentioned that he saw oddness using app:// syntax under Android. THat may be at play here.

Instead of using app://, you could use FIle.applicationDirectory.nativePath. That should give you a pointer to the directory - and then you just append the file name.

That's not _exactly_ the syntax, but you get the idea I hope.

On 11/30/2010 at 2:04:51 PM UTC Pete Freitag wrote:
10
Thanks for the useful discussion and comments Louis and Ray. I was interested in doing the same thing (to see if I could port a jQuery Mobile app), which is why I tried to figure out how to embed the browser in the first place. I also tried the app:// url without luck. I'll give the File.applicationDirectory.nativePath option a try when I get a chance.

On 12/08/2010 at 2:15:05 PM UTC Louis wrote:
11
Thanks Pete. nativePath does the trick

New topic: Has anyone successfully signed a PlayBook bar file with existing BlackBerry keys (from phone app development?) The java code signing GUI doesn't like bar files, and I just don't understand the command line syntax!

On 12/18/2010 at 1:55:33 PM UTC Basti wrote:
12
Hi! Thanks for this great piece of code. It compiles well and starts up on my emulator but won't show anything but a blank, white page (which is scrollable, according to the chessboard-pattern). I tried everything: HTTP webpages, local files and even "about:test". Any ideas?

On 01/14/2011 at 6:59:21 PM UTC CS wrote:
13
Hi Pete. I run into the same white page that Basti does. Did something change in the SDK that broke the Browser App code?

On 01/19/2011 at 5:12:13 AM UTC pyth wrote:
14
i'm also having the same problem as the two posters before me. could it be because of the beta 3 version? @pete: which version did you use?

On 01/19/2011 at 11:33:15 AM UTC Pete Freitag wrote:
15
Hi Guys, yes this was with the first beta, so things must have changed since then. I'm not sure when I'll get a chance to try this again, but if anyone can find a workaround feel free to post it here.

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?