Meet Mojo @ Palm Developer Day, 4/24/2010

22

description

Get a head start on working with the webOS SDK in this basic introduction to the webOS platform and the Mojo framework. Learn webOS technical terminology and take a look at how applications are put together, with an emphasis on how it relates to a desktop browser environment.

Transcript of Meet Mojo @ Palm Developer Day, 4/24/2010

Page 1: Meet Mojo @ Palm Developer Day, 4/24/2010
Page 2: Meet Mojo @ Palm Developer Day, 4/24/2010

Meet Mojo™

Jesse DonaldsonSr. ManagerApril 24, 2010

A brief introduction to Palm® webOS™ applications

Page 3: Meet Mojo @ Palm Developer Day, 4/24/2010

Goals

webOS UI overview

Mojo apps are like web pages

Development model is accessible

App structure, basic framework usage

Head start when you download the SDK

http://developer.palm.com

Page 4: Meet Mojo @ Palm Developer Day, 4/24/2010

webOS UI

• Applications run in cards

• Cards are small web pages

• HTML, CSS, JavaScript

Page 5: Meet Mojo @ Palm Developer Day, 4/24/2010

Terminology: Scenes

• Screens in a card are “scenes”

• Scenes may be stacked up

• Sibling divs in the body

Page 6: Meet Mojo @ Palm Developer Day, 4/24/2010

Terminology: Stages

• Cards are a type of stage

• There are others:

• Dashboards & alerts

• They are all HTML documents

Page 7: Meet Mojo @ Palm Developer Day, 4/24/2010

Structure of a webOS app

•MyApp•app

•assistants•views

•appinfo.json•icon.png•images•index.html•sources.json•stylesheets

Page 8: Meet Mojo @ Palm Developer Day, 4/24/2010

appinfo.json

{"title": "My App","main": "index.html","id": "com.mycompany.myapp","version": "1.0.0","vendor": "MyCompany, inc."

}

Page 9: Meet Mojo @ Palm Developer Day, 4/24/2010

index.html

<html><head></head><body>

<div id="flashlight" style="width:100%; height:100%; background-color:#FF9"></div>

</body></html>

Page 10: Meet Mojo @ Palm Developer Day, 4/24/2010

Typical Mojo index.html

<head> <title>Framework Library</title>

<script src="/usr/palm/frameworks/mojo/mojo.js"

type="text/javascript" x-mojo-version="1"></script>

<link href="stylesheets/fr-library.css" media="screen" rel="stylesheet" type="text/css" />

</head><body></body>

Page 11: Meet Mojo @ Palm Developer Day, 4/24/2010

sources.json

[ {"source": "app/assistants/app-assistant.js"

},{

"source": "app/assistants/detail-assistant.js"},{

"source": "app/assistants/list-assistant.js","scenes": "list"

} ]

Page 12: Meet Mojo @ Palm Developer Day, 4/24/2010

The Assistants Directory

• Usual place for JavaScript code

• Mojo provides generic controller objects

• Apps implement assistants for them

• Assistants are delegates for:• AppController• StageController• SceneController• WidgetController

Page 13: Meet Mojo @ Palm Developer Day, 4/24/2010

The Views Directory

• One subdirectory per scene

• Contains the HTML for each scene:• A template for the scene itself• Templates for widgets (e.g., list items)

• Mojo widgets are declared in this HTML

Page 14: Meet Mojo @ Palm Developer Day, 4/24/2010

app/views/main/main-scene.html

<div id="power-switch" x-mojo-element="RadioButton">

</div>

<div id="main-light" style="width:100%; height:382px; background-color:#224;">

</div>

Page 15: Meet Mojo @ Palm Developer Day, 4/24/2010

app/assistants/main-assistant.js

MainAssistant = function() {};

MainAssistant.prototype.setup = function() {…

MainAssistant.prototype.switchLight = function(ev) {…

Page 16: Meet Mojo @ Palm Developer Day, 4/24/2010

MainAssistant.prototype.setup()

var attributes = { choices: [{label: "Off", value: false},{label: "On", value: true}] };

var model = { value: false };

this.controller.setupWidget('power-switch', attributes, model);

Page 17: Meet Mojo @ Palm Developer Day, 4/24/2010

MainAssistant.prototype.setup(), Part #2

this.switchLight = this.switchLight.bind(this);

this.controller.listen('power-switch', Mojo.Event.propertyChange, this.switchLight);

this.light = this.controller.get('main-light');

Page 18: Meet Mojo @ Palm Developer Day, 4/24/2010

MainAssistant.prototype.switchLight()

MainAssistant.prototype.switchLight = function(event) {

this.light.style.backgroundColor = event.value ? "#FF9" : "#224";

};

Page 19: Meet Mojo @ Palm Developer Day, 4/24/2010

Finished Flashlight App

Page 20: Meet Mojo @ Palm Developer Day, 4/24/2010

Dive Deeper

• Download the SDK http://developer.palm.com

Page 21: Meet Mojo @ Palm Developer Day, 4/24/2010

&Q A

Page 22: Meet Mojo @ Palm Developer Day, 4/24/2010