This is the web.
This is netrunner.

Porting Widgets to Nokia S40
Written by Anthony   
Saturday, 15 October 2011 08:12

Porting Widgets to Nokia S40

Another platform, another list of quirks.  With Nokia's Create for Millions competition, there was finally a compelling reason to look at the Series 40 platform. These somewhat ubiquitous phones are not smartphones. They are not even kinda-smart, or smart-ish. They are feature-phones. That means that they do more than make calls, but if you come from the position of building tools for smart phones, these babies appear woefully underpowered.

Nokia is pushing their ability to run "web apps", which on the face of it looks like something similar to the WRT for Symbian, but once you delve in under the hood, the architecture of it all is very different, and once again, you're very limited in what you can do. To do anything funky, like use the camera or the GPS, you need to use Java. Fair enough, but I want to leverage the investment I've made so far into widgets based upon web standards.


The main difference between Symbian widgets and S40 web apps is that when an S40 app is uploaded, it goes to a server and is parsed, repackaged and simplified. When you access it, you do so over the web and bar for a subset of methods (the mobile web library), all functionality happens server-side and is returned complete to the handset. So the trick is to try to design your apps so that it minimises the round trips to the server. The handset can add and remove classes, show/hide elements and scroll to a particular element, but not a whole lot more.

So the main things that need changing at a code level are:  

Your usual jQuery-based show/hide methods, e.g.

 $("#myDiv").show();

becomes

mwl.show("#myDiv");

Of course, local storage is slightly different too.

widget.setPreferenceForKey('my value','preference name');

becomes 

widget.preferences.setItem('preference name','my value');

Similarly, checking for the existence of a preference and creating a new one looks like this:

if( widget.preferences.getItem('pregnancyStartDate')==null){
widget.preferences.setItem( 'pregnancyStartDate','0');
}

So now that I've read through what is and is not supported, e.g. Float in CSS and alert() and confirm() in javascript!, it's not too hard to port my simpler WRT apps to S40. It'll be interesting to see what the takeup is in the Ovi store in comparison to WRT.