First webOS (web) App

So finally I have started to play with some programming on the Palm Pre 2. It is interesting to find that web applications runs as smooth as native onces in this device. What is more interesting is that, like Android, you can program in Windows, Linux and Mac. It is nice to know you have official tools that runs in all platforms, and you don’t have to stick with XCode or Visual Studio.
Apart from web applications, Palm’s (now HP) webOS let’s you program in C/C++ with native SDL and OpenGL 1 and 2 support. Most of low level hardware of the device can be access using standard linux procedure to open a stream and write or read. This is particularly interested because because it changes the mobile world a bit in two ways. You don’t have to root your phone (like in Android OS) or jailbreak it (like in iPhone) to access low level functions. webOS is built over a standard Linux, so if you want to take Python sources, compile it for ARM and put the library inside your C/C++ project (something I’m planning to do in the few months) YOU CAN, and it’s legal in the Application Catalog!
The second good thing about having such a strong native part in the platform is not only that web applications can make use of low level functions written in C or C++, But also that in average a C/C++ application with SDL or OpenGL can be ported to webOS in 5 hours. I tried making a simple C++ program, and the same program that runs on my Mac, runs in the Palm Pre with only two lines of code modified. So even though te platform is oriented to a high level development based on HTML, CSS and JavaScript, there is a string background that can be used without limitations by programmers used to deal with low-level software (like me).
The lastest SDK, emulators and documentation of webOS can be found at Palm’s Developer Site. These tools are completely free and you only have to sign-up to get them, no need of 99U$D per year. Just download the tools for your platform, read the tutorials, understand what MOJO is about, and go on! It also has a development tool called ARES, which is a full feature IDE in the web, so may be you can even program in an iPad using Safari.
This first and very simple program is a web app that converts decimal to hex and binary and viceversa.  It is very simple and I bet in runs in a browser with a small modifications to the HTML, and a few lines in Javascript.
Creating an (empty) application
Let’s run Eclipse with Palm SDK plug-in and create a basic application.

Once created, you will see a project structure like this:
webOS development is MVC oriented. Inside “app” you will find views, models and assistants. Views are HTML files that represents a scene (in webOS applications have stages/cards and scenes, learn more about The Anatomy of a webOS App). An assistant is a Javascript file that contains the controller. As you may guess, some applications also have a model folder, but this is not necessary to build an application. The basic stuffs are Views and Assistants, and the plug-in provides a Wizzard for that.
A basic (and empty) scene can be created by clicking on the Palm icon, and selecting. I will name this scene “home”

The “home” scene recently created adds two files to the project. “home-asssiant.js” (aka.  a Controller for the Home scene) and “home-scene.html” (the view). So now the project looks like this

from now on, everything is HTML CSS and Javascript. You will see a few more screenshots with HTML and Javascript code from this app. But the most important part is the deploying of the application into the device.

From a terminal window (or command line) , place in a directory before the project directory and type

palm-package <name of the project>

This will generate a “ipk” file which is the application packaged. Then in order to install the package into the device, just type

palm-install <ipk file>

This will produce the output you will see in the following screenshot

Now, a few screenshots that shows interesting parts of the view and the controller. There is not much to say about this, it’s just HTML and the MOJO framework that webOS uses in Javascript is very well documented on Palm’s website.

Here you will see the setup method of the assistant, widgets should be initialized here, and you can add some validations methods inside this setup. Like, for example, chars allowed in a TextField.

In the setup method you can also declare event handlers for the widgets, as I do in this piece of code

A function that handles one of these events, it’s like any other javascript function. In this case, it takes the value from a TextField, makes some transformations, and update the value of others TextFields.

The view of this project it’s quite simple as you can see in this screenshot. Everything is HTML, every widget is identified by id, and you will use that id with the MOJO framework to customize the widget and manage it. The most relevant part if that you define a x-mojo-element property that tells the framework which type of object it is.

The final app looks like this without modifying the stylesheet or applying any custom style.