Creating Asha Web Apps with Brunch and Jade

Asha web apps?

Asha web apps are a lightweight application development framework for creating apps for low end Nokia devices (Asha series and earlier). While JME is the most popular technology for creating apps for Asha, web apps are a reasonably quick and convenient way to expose content on the web – basically, your garden variety front ends for restful services, spiced by some simple navigation.

Since Asha devices don’t have local javascript execution, javascript is executed on proxy server. “Normal” web pages execute all javascript on the proxy, but Asha web apps provide some “shortcuts” for doing simple DOM manipulation (add/remove css classes, set values in input fields) without the proxy roundtrip. Check out “MWL” library for details.

Standard workflow

Normally, you use Eclipse to develop and test Asha web apps. Nokia provides the “Nokia Web Tools” IDE for this; it’s a rather mainstream Eclipse based IDE, spiced with webkit based “local” simulator (that runs javascript locally), and the “cloud” simulator that runs Javacript on the real Nokia proxy servers (but still renders the DOM on the webkit based simulator).

While this is fine for most web developers, there are lots of us relentlessly looking to optimize our workflows, to make it little more efficient, little more fun (or more tolerable, depending how bad an aversion you have for Javascript and HTML) and little more readable and maintainable.

For this kind of developer, there are tools like CoffeeScript, Brunch, Jade, SASS, LESS, HAML. In this exposition we’ll use CoffeeScript, Brunch and Jade.

CoffeeScript is a language that compiles to idiomatic and readable/debuggable JavaScript. It makes producing JavaScript more tolerable for people used to modern languages without semicolons, `function` keywords
and a selection of other nastiness that plagues JavaScript.

JADE is a language that compiles to HTML.

This Jade:

        doctype 5
	html(lang="en")
	  head
	    title= pageTitle
	  body
	    h1 Jade - node template engine
	    #container
	      if youAreUsingJade
	        p You are amazing
	      else
	        p Get on it!

Compiles to this html:

<h1>Jade - node template engine</h1>
<div id="container">
 
You are amazing
 
</div>

As you can see, this makes it easier to “see forest from the trees”, as the eye is not misdirected by stream of redundant characters and endless <div>’s.

Brunch is an “assembler” for HTML5 applications. It picks up all the pieces you have (CoffeeScript files, JADE templates, etc.) and produces a runnable web application out of that. It can watch the files on the background, compiling CoffeeScript files to JavaScript the second you save them, running unit tests immediately, refreshing the browser in real time etc.

We use Brunch as the “skeleton” of our Asha web application.

Getting started

Prerequisites: This flow has been tested on Linux and Windows. Have to install Node.js, git, the usual stuff every self respecting web developer has set up on day one. Anecdotal evidence suggests it’s a good idea to compile Node.js from source instead of using the packaged versions, if you are lucky enough to be on Linux.

We clone the basic scaffolding from github and install the dependencies:

 

$ git clone git@github.com:vivainio/awa-brunch.git awa-helloworld
$ cd awa-helloworld/
$ npm install
npm http GET https://registry.npmjs.org/javascript-brunch
npm http GET https://registry.npmjs.org/css-brunch
npm http GET https://registry.npmjs.org/uglify-js-brunch
npm http GET https://registry.npmjs.org/clean-css-brunc
.. etc ..
This install Brunch, CoffeeScript compile and lots of other packages with npm.

Let’s take a look at the project structure:


ville@ville-tp:~/p/awa-helloworld$ tree app
app
├── assets
│   ├── config.xml
│   ├── icon.png
│   ├── index.html
│   └── s40-theme
│   ├── css
│   │   ├── s40-theme.css
│   │   ├── single_landscape.css
│   │   └── single_portrait.css
│   ├── images
│   │   ├── arrow-close.png
│   │   ├── arrow-open.png
│   │   ├── back_40x40.png
│   │   ├── button-bg_40x40.png
│   │   ├── close_40x40.png
│   │   ├── grid_40x40.png
│   │   ├── option-menu_titlebar.png
│   │   ├── refresh_40x40.png
│   │   ├── search_40x40.png
│   │   ├── tab_bg.png
│   │   └── title-bar.png
│   └── js
│   ├── s40-theme.js
│   └── screensize.js
├── index.jade
├── README.md
├── templates
│   └── mainlist.jade
├── testCs.coffee
└── testJs.js

 

Now, we start “brunch watch” that compiles the application in real time as we edit the files, and for added convenience launches a webserver serving on :3333:


ville@ville-tp:~/p/awa-helloworld$ brunch watch --server
26 Apr 22:03:48 - info: application started on http://localhost:3333/
26 Apr 22:03:48 - info: compiled in 115ms
26 Apr 22:03:49 - info: compiled in 206ms

 

The resulting application that we can deploy, or preview in browser, gets generated in awa-helloworld/public directory:

 

ville@ville-tp:~/p/awa-helloworld$ tree public
public
├── config.xml
├── icon.png
├── index.html
├── javascripts
│   ├── app.js
│   ├── templates.js
│   └── vendor.js
├── js
│   └── templates.js
└── s40-theme
├── css
│   ├── s40-theme.css
│   ├── single_landscape.css
│   └── single_portrait.css
├── images
│   ├── arrow-close.png
│   ├── arrow-open.png
│   ├── back_40x40.png
│   ├── button-bg_40x40.png
│   ├── close_40x40.png
│   ├── grid_40x40.png
│   ├── option-menu_titlebar.png
│   ├── refresh_40x40.png
│   ├── search_40x40.png
│   ├── tab_bg.png
│   └── title-bar.png
└── js
├── s40-theme.js
└── screensize.js

 

“Sources” under app/ directory were processed to produce these files; .coffee files were compiled and concatenated to “app.js”, index.jade was converted to index.html, and so on.

There is one extra directory we didn’t show yet, the “vendor” directory:


ville@ville-tp:~/p/awa-helloworld$ tree vendor/
vendor/
├── jade_runtime.js
└── README.md

If you are using JavaScript libraries like jQuery, you would just copy it under vendor/ and all of them get automatically concatenated to vendor.js. This makes the app fast to load as it reduces the amount of separate files to download. For production, Brunch can also minify the Javascript files to further reduce page weight. jade_runtime.js is here to support *precompiled Jade templates*

Shut up and show it running

In the interest of making things as “familiar” and frictionless as possible, we will preview the application in standard Chrome browser instead of Nokia Web Tools. So we launch Chromium and disable web security to prevent CORS from cramping our style and killing our Ajax requests:

	$ chromium-browser --disable-web-security http://localhost:3333

This doesn’t look at all what you would expect on the phone screen, because we haven’t specified a viewport size:

Chromium inspector has a handy feature of overriding the viewport size (Settings -> Overrides -> Device Metrics), so we use it to set the resolution to match Asha Full Touch devices (240 x 400):

Now, we have a low-fidelity representation of the phone experience! While this certainly wouldn’t satisfy an UI designer, it’s sufficient for a busy software developer that mostly needs to focus on the “logic” side of the web app.

Launching in NWT

Now is the time to get this running with “real” IDE, i.e. Nokia Web Tools. Launch NWT, do File -> New -> Import web app, select public/config.xml and launch the application in local preview:

Is this it?

There is more to show: how to utilize precompiled templates, how to inject the MWL library, and how Jade can help you create MWL UI “components” with reusable, encapsulated logic. These, and other things to smoothen the development flow will be covered in another blog post, as this already got way too long.

It starts with your launcher icon

Continuing with the topic of icons…

From the start, the appearance of your application in the app menu makes a difference in how people interpret your app. If your icon looks stylish, has the correct shape, and people can guess from the app’s name what it does, your app is on the right track.

If the shape of the icon is different from the rest of the icons on the phone, your app will feel alien and not like an integral part of the phone. Some people might think the app is a (cheap?) copy of something else; others might think you simply don’t care. This opens the door to bad reviews, since people launch your app with a negative attitude even before they have really seen it. It is very hard to recover from that initial negative first impression!

bad icon example
Example of a badly shaped launcher icon and truncated app name.

The same holds for the app name; you should try to keep it short enough that it will not be truncated. It’s not easy to come up with a short and catchy name, but it’s definitely worth the effort. In addition to looking better on the phone (let’s be honest here; it does look better when it’s not truncated), a short app name is more likely to be remembered by users. This makes it more likely that they will recommend it to their friends (because they will also love the app, of course!).

So, how to make things right?

By taking care of just these seemingly minor details, you help set people into a positive attitude before they even open your app.

Happy developing,
Sanna

Math behind icon design

Did you know…

The squircle (the matemathical term) is pretty close to the Nokia icon shape. Luckily enough, you don’t need the formula to create your launcher icon; you can always use the Icon templates we have created for you. And you don’t need Photoshop to work with them: they are also available for Inkscape!

Sometimes you might need to generate the shape in your code; either to generate the shape at runtime, you need the mathematical formula for drawing a custom button, or you just want to try it out in Matlab :) In that case, this link might help you: http://en.wikipedia.org/wiki/Squircle.

App launcher icon example

Happy developing,
Sanna

LWUIT library is out!

Hi all,

Fresh from the oven, we have just published the LWUIT Developer’s Library. LWUIT Developer’s Library describes how to use the LWUIT for Series 40, the port of the Lightweight UI Toolkit for Nokia’s Series 40 phones.

LWUIT for Series 40 brings a number of improvements: several Series 40 platform features have been integrated to it, the style and functionality of UI components have been changed to match the Series 40 look and feel, and the performance has been optimised. Also the Resource Editor tool has been updated with Series 40 changes.

A common practice has been that the new features would always provide a fallback mechanism. Even if a feature was not available on the device, the application would still run gracefully. The wrappers are transparent to the application.

The library, or course, includes a UX chapter that describes how LWUIT UI components should behave or how a component should be adopted in case it is used with Series 40 phones.

Try it out and let us know how it works for you!

Happy developing,
Sanna

Design documentation updates – design a great UX!

Happy New Year!

Work on the UX front continues with full speed. We’ve started the year by updating our Design process documentation. The process is a cook-book approach that works well for small applications such as mobile apps. Following the process will generate a proper plan for your app, and help you concentrate on the essentials.

Take a look and tell us what you think! We always welcome your feedback.

Happy developing,

Sanna

Greetings from the world of Series 40 UX!

It’s been a busy year, and I wanted to share some of what has been published in 2012 (just in case you missed it the first time):

In addition, tons of great Series 40 example apps.

I hope the above will help you in creating great apps.

Happy developing!

YouTube player with draggable playback controls in Java ME

I was always wondering, if streaming a YouTube video would work on Nokia Devices with Java ME. I was pleased to find out that it did! And it did, very well, over a 3G connection on the stunning screen of Nokia PureView 808.

The idea is pretty simple. All you need is a Canvas with a YouTube logo, a Video Window for displaying the stream and playback controls for starting, stopping fast forwarding or rewinding the video. The cursor is draggable so that it offers the same user experience as the standard YouTube player.

This wiki article, explains how.

 

Introduction to Series 40 full touch for developers

Car Race 3D Exercise App running on the Nokia Asha 311We’re kicking of the webinar series for the new Series 40 Touch phones tomorrow! The first session will walk you through the new Java ME APIs introduced in the Developer Platform 2.0.

The packed agenda covers all the important topics that you will need to know about when you’re moving your Java ME apps to the new touch UI:

  •  Introduction
    • Platforms & Versions
  • New features for developers
    • UI
    • LWUIT
    • Text Input
    • Touch Input
    • Sensors
    • Location & Maps
  • App Compatibility
  • Publishing & Monetization
  • Resources
     

The recording of the first webinar session is online for viewing. The downloadable version of the slides is slightly extended, featuring some more details than in the 1h webinar. 

You can download the full source code of all the apps shown during the presentation – the blue text box in the top right corner or the slide always refers to the full example being demonstrated.

JavaME-Touch-Examples-v2.0.0.zip

As a special bonus, the example package and the downloadable slides also include a few exercises (+ the corresponding solutions), so that you can put your new knowledge about the APIs into use right away! The excercises are both based on 3D graphics:

  • In Monkey Touch 3D you’ll add drag & pinch support to view the 3D model of a monkey, and add orientation support to dynamically switch the app between landscape & portrait mode, depending on the physical orientation of the phone.
  • Car Race 3D let’s you extend an endless 3D racing game with support for controlling the car using acceleration sensors, instead of physical keys (which would no longer be availble on the new touch phones)
     

Registration

In different webinars during the following days we’ll also look at the design aspect and the IDEs (both the new Nokia IDE for Java ME as well as NetBeans). Every session is held two times, so that you can join no matter which time zone you live in.

Register for the webinars now!

Tools for full-touch Series 40 coming June 25, documentation available now

Beta versions of updated Java and web tools for targeting full-touch Nokia Asha devices will be released Monday June 25.

Information, documentation and guides for these upcoming releases are available now, allowing you to familiarise yourself with the new capabilities of the tools.

Today’s documentation releases include: 

More guides and material, including ‘getting started’ technical videos, will be published on June 25 to coincide with the release of the new tools.

The Nokia Asha 305Asha 306 and Asha 311 are the first all-touch Series 40 devices, and are expected to ship in the third quarter of 2012 (second quarter for Asha 305). They will have an estimated retail price in the EUR 63-68 range for Asha 305, Asha 306 and EUR 92 for Asha 311 (excluding taxes and subsidies).

Meet the Nokia SDK 2.0 for Java

Introduction to Nokia Web Tools 2.0