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


Published on

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.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Some key parts of the UI and technical terminology discuss how mojo apps work like pages in a browser All implemented in HTML, CSS, JavaScript Discuss how many of the concepts you’re familiar with in desktop browsers fit into Mojo apps Accessibility One of the most exciting things about the webOS platform App dev model is much more accessible to people than other mobile platforms Mobile platforms like PalmOS or iPhone, you really have to be a C programmer Many more web developers, and on webOS, they can all leverage the skills they’ve developed & tools they’re familiar with. Goals - give you a conceptual head start When you dl the SDK, you’ll be productive more quickly SDK is publicly available now
  • Applications run in cards, Basis of webOS’s multitasking Native component called SysMgr runs the UI and switches between them Cards are like windows in a desktop browser Implemented entirely on HTML, CSS, JavaScript Each is a small web page -- index.html
  • Terminology: Scenes Various screens in a card are called scenes Stacked up. List, details, edit, etc… Each scene written separately, but not a different HTML document. they’re all sibling divs in the body.
  • There are other types: Dashboards for unobtrusive notifications Popup alerts for more immediate interruptions Picture shows the messaging app -- strips at the bottom are dashboard stages. All of these are implemented as separate HTML documents Child windows of the app Mojo provides APIs to create & manage stages. Job of an app is to coordinate and run the scenes in 1 or more stages Let’s see how they do it…
  • Directory structure, with basic required files Some of these are obvious Icon, images, stylesheets Extras: Miniicon.png framework_config.json Log levels, debug mode, timing, escaping
  • Title - displayed in the launcher Main - the HTML file to load for the app Id - unique identifier for the application Version - used by app catalog, launcher, must follow the 3 part format Vendor - string identifying the maker of the app, displayed in the launcher. Others: Visible: Hidden in the launcher noWindow: Hidden window noWindow:true in appinfo, main stage is hidden instead of shown as a card. This is needed if you don’t want all your stages closed when the user throws away your main card. Apps must always keep at least one stage open. close your card & display only a dashboard stage open a card again if the app is launched
  • Index.html, Pretty much what you’d expect Just a web page -- Don’t actually need to load Mojo at all Can just write content, and it goes into the card. Most useful & trivial app is a flashlight Note that I don’t know of any current apps that actually work this way. Story about Rich’s calculator Frequently surprised by how quickly & easily we could get things working
  • From our framework library app -- Mojo team uses internally Removed doctype & HTML tags Not much left: Script tag to load framework Link tag to load the app’s stylesheet Script tag has x-mojo-version=1… specifies version when we need to make breaking changes, we make a new version Mojo also loads the Prototype framework Empty body When Mojo is loaded, it does everything else: loading & invoking your app code Setting up the first scene Informing SysMgr that the stage is ready for display.
  • Mojo uses sources.json to load your app code List of JS source files Can load them in script tags, but wasteful if you have multiple stages. We put them in the assistants dir, but they can be kept wherever you like. If you’re optimizing app launch time, you can use the ‘scenes’ property. Specifies that the script is only needed for that scene It will be loaded automatically when the scene is pushed
  • JavaScript code Apps coordinate stages & run UI in them. They do this mostly by implementing assistant objects Mojo provides generic controllers for various things Apps provide assistants for the controllers that implement all the app-specific behavior AppController/Assistant - Handling launch arguments, creation of stages StageController/Assistant - Scene management. Encapsulation of common scene behavior. SceneController/Assistant- Most app code. Configures widgets, responds to user input, pushes/pops other scenes, etc, Dialogs, Widgets, etc…
  • app/views Views directory contains the HTML for the app’s scenes. One subdirectory per scene E.g., List, details, edit, options… Scene dirs contain a template for the scene Template is a fragment of HTML Sometimes with property substitutions Basic structure, devoid of dynamic content Declares Mojo widgets Possibly HTML templates for widgets Show you an actual Mojo app, so I added a power switch to the flashlight app
  • Scene template for the main scene in the Mojo flashlight Main scene is pushed by default Template main-scene.html is loaded Declaration of widget Id & custom property to indicate widget name App specifies other info for the widget in the scene assistant Div for light Takes up rest of screen Can adjust the brackground color
  • Source file for the main scene assistant Declares the MainAssistant class You can use Prototype’s Class.create() if you prefer. Implements 2 methods Setup() Configures widgets, Implements app-specific behavior switchLight() Event handler for the radio button that turns the light on & off
  • Three main jobs of a scene assistant’s setup() method: Initialize state in the assistant Set up the scene’s widgets Add event listeners where needed This is an assistant, accesses the scene controller at this.controller. setupWidget() is a SceneController method that tells the framework how to instantiate mojo widgets Attributes control the look & behavior of the widget Model holds the data the widget operates on Note: setupWidget() does not actually instantiate the widget… the framework does that later.
  • switchLight() is our event handler function. Bind it so when it’s triggered, ‘this’ will be a reference to the assistant object instead of the window Here we store the new function back in the object, which prevents us from accidentally using the unbound function. Listen() is a method available on the SceneController object. Wrapper around addEventListener(), Looks up the element by ID propertyChange events sent when a widget modifies some data Get() is another method available on the SceneController object. Simple wrapper around getElementById(), which looks up the element in the correct document. Espcially important if your application is using multiple stages. Saves the main light div in the assistant object, so we can reference it later
  • switchLight() is just the handler for the propertyChange event sent by the Mojo RadioButton widget Fetches the new value from the event uses it to set the background color to turn the light on or off. Note that we can reference ‘this.light’, since we bound the function in setup.
  • This is what it looks like -- Press the on/off button, and the large div toggles between dark blue and light yellow. That’s all there is to creating a basic Mojo app Obviously it can get a lot more complicated, but it’s easy to get things working.
  • Meet Mojo @ Palm Developer Day, 4/24/2010

    1. 2. Meet Mojo™ <ul><li>Jesse Donaldson </li></ul><ul><li>Sr. Manager </li></ul><ul><ul><ul><li>April 24, 2010 </li></ul></ul></ul>A brief introduction to Palm ® webOS™ applications
    2. 3. Goals <ul><li>webOS UI overview </li></ul>Mojo apps are like web pages Development model is accessible App structure, basic framework usage <ul><li>Head start when you download the SDK </li></ul><ul><ul><li> </li></ul></ul>
    3. 4. webOS UI <ul><li>Applications run in cards </li></ul><ul><li>Cards are small web pages </li></ul><ul><li>HTML, CSS, JavaScript </li></ul>
    4. 5. Terminology: Scenes <ul><li>Screens in a card are “scenes” </li></ul><ul><li>Scenes may be stacked up </li></ul><ul><li>Sibling divs in the body </li></ul>
    5. 6. Terminology: Stages <ul><li>Cards are a type of stage </li></ul><ul><li>There are others: </li></ul><ul><ul><li>Dashboards & alerts </li></ul></ul><ul><li>They are all HTML documents </li></ul>
    6. 7. Structure of a webOS app <ul><li>MyApp </li></ul><ul><ul><li>app </li></ul></ul><ul><ul><ul><li>assistants </li></ul></ul></ul><ul><ul><ul><li>views </li></ul></ul></ul><ul><ul><li>appinfo.json </li></ul></ul><ul><ul><li>icon.png </li></ul></ul><ul><ul><li>images </li></ul></ul><ul><ul><li>index.html </li></ul></ul><ul><ul><li>sources.json </li></ul></ul><ul><ul><li>stylesheets </li></ul></ul>
    7. 8. appinfo.json <ul><li>{ </li></ul><ul><li>&quot;title&quot;: &quot;My App&quot;, </li></ul><ul><li>&quot;main&quot;: &quot;index.html&quot;, </li></ul><ul><li>&quot;id&quot;: &quot;com.mycompany.myapp&quot;, </li></ul><ul><li>&quot;version&quot;: &quot;1.0.0&quot;, </li></ul><ul><li>&quot;vendor&quot;: &quot;MyCompany, inc.&quot; </li></ul><ul><li>} </li></ul>
    8. 9. index.html <html> <head></head> <body> <div id=&quot;flashlight&quot; style=&quot;width:100%; height:100%; background-color:#FF9&quot;></div> </body> </html>
    9. 10. Typical Mojo index.html <head> <title>Framework Library</title> <script src=&quot;/usr/palm/frameworks/mojo/mojo.js&quot; type=&quot;text/javascript&quot; x-mojo-version=&quot;1&quot;></script> <link href=&quot;stylesheets/fr-library.css&quot; media=&quot;screen&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /> </head> <body></body>
    10. 11. sources.json [ { &quot;source&quot;: &quot;app/assistants/app-assistant.js&quot; }, { &quot;source&quot;: &quot;app/assistants/detail-assistant.js&quot; }, { &quot;source&quot;: &quot;app/assistants/list-assistant.js&quot;, &quot;scenes&quot;: &quot;list&quot; } ]
    11. 12. The Assistants Directory <ul><li>Usual place for JavaScript code </li></ul><ul><li>Mojo provides generic controller objects </li></ul><ul><li>Apps implement assistants for them </li></ul><ul><li>Assistants are delegates for: </li></ul><ul><ul><li>AppController </li></ul></ul><ul><ul><li>StageController </li></ul></ul><ul><ul><li>SceneController </li></ul></ul><ul><ul><li>WidgetController </li></ul></ul>
    12. 13. The Views Directory <ul><li>One subdirectory per scene </li></ul><ul><li>Contains the HTML for each scene: </li></ul><ul><ul><li>A template for the scene itself </li></ul></ul><ul><ul><li>Templates for widgets (e.g., list items) </li></ul></ul><ul><li>Mojo widgets are declared in this HTML </li></ul>
    13. 14. app/views/ main/main-scene.html <div id=&quot;power-switch&quot; x-mojo-element=&quot;RadioButton&quot;> </div> <div id=&quot;main-light&quot; style=&quot;width:100%; height:382px; background-color:#224;&quot;> </div>
    14. 15. app/assistants/main-assistant.js MainAssistant = function() {}; MainAssistant.prototype.setup = function() {… MainAssistant.prototype.switchLight = function(ev) {…
    15. 16. MainAssistant.prototype.setup() var attributes = { choices: [ {label: &quot;Off&quot;, value: false}, {label: &quot;On&quot;, value: true} ] }; var model = { value: false }; this.controller.setupWidget('power-switch', attributes, model);
    16. 17. 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');
    17. 18. MainAssistant.prototype.switchLight() MainAssistant.prototype.switchLight = function(event) { = event.value ? &quot;#FF9&quot; : &quot;#224&quot;; };
    18. 19. Finished Flashlight App
    19. 20. Dive Deeper <ul><li>Download the SDK </li></ul>