Archive for October, 2009

Project Resistance: Day 2

Tuesday, October 27th, 2009

Today I’ll attempt to flesh out the project by drawing the coloured bands onto the resistor image and allowing the user to change them with simple finger swipe gestures. This covers parts of day 2 and day 3 of the Windows Mobile variant of the project. We’ll get back to unit testing in a later day.

Drawing Coloured Bands

A UIScrollView control can be used to present a vertical list of colours which the user can swipe through with their finger. By sizing the control to be the height of the resistor and setting the “paging enabled” setting within Interface Builder, the UIScrollView will automatically snap to a “page” boundary, ensuring the user doesn’t leave the scroll view showing multiple colours.

By using the UIScrollView I get all the required gesture and finger swiping features for free without writing a single line of source code.

Modifying the graphic resources

The Windows Mobile version of the application has a set of graphic resources with each coloured band pre-rendered in each of its four possible positions. For example, here are the four resources used to render the colour green within each band.

Screenshot showing the 4 graphic resources used to draw green bands onto a resistor

Doing this provides less flexibility, as each time I want to introduce a new colour or change the size or shape of the resistor graphic I need to get all of the coloured bands redrawn by a graphic designer (I’m a developer, and don’t have an artistic bone in my body!). For this reason I’ve decided to take a different rendering approach within the iPhone application. I’ve updated the background resistor image to include areas with alpha transparency as demonstrated below:

Image showing resistor blank with transparent areas where each colour band should be located

The checker board pattern indicates areas which are transparent and will show what ever is placed underneath the graphic when it comes time to display it onscreen. Although hard to tell, the areas where the coloured bands go are only partially transparent, allowing them to shade things placed underneath to give a nice “rounded” effect.

By placing the rectangular UIScrollViews containing solid colours underneath this transparent image I automatically get the rounded and shaded effect. However now I only have one image for my graphic artist to create and tweak.

Diagram showing how images with alpha transparency can be composited together to form a single image

Another thing to note is that the UIImage control containing the resistor blank is positioned above the UIScrollView controls. However since the “user interaction enabled” checkbox is unchecked within Interface Builder this control won’t stop events such as finger presses from filtering down to the controls positioned underneath it. Not only is the graphic partially transparent, but it is also “invisible” with respect to user interaction.

Responding to selection changes

By handling the scrollViewDidEndDragging:willDecelerate: and scrollViewDidEndDecelerating: UIScrollViewDelegate messages I can detect the finger swipes and scrolling actions and determine when the user changes the selected colour of each band as follows:

- (void) band:(int)bandIndex didSelectColor:(int)colorIndex
  NSLog(@"Band %d selected colour at index %d", bandIndex, colorIndex);
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  // called on finger up if user dragged. decelerate is true if it will continue moving afterwards
  if (!decelerate)
    [self band:scrollView.tag didSelectColor:scrollView.contentOffset.y / scrollView.bounds.size.height];
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  // called when scroll view grinds to a halt
  [self band:scrollView.tag didSelectColor:scrollView.contentOffset.y / scrollView.bounds.size.height];

The UIScrollView control does all the gesture detection and scrolling animations behind the scenes, so the code is rather clean and logic free. At the moment this simply logs to the console a message similar to the following:

Band 3 selected colour at index 5

I’ll leave it for another day to hook this up to the model, which is yet to be added to the project etc…

Day 2 Summary

Screenshot showing Project Resistance running on the iPhone at the end of day 2By using the UIScrollView control to present a finger selectable list of colours, and being smart about the use of alpha transparency within my resistor graphic I have managed to get a fairly functional user interface with minimal (and easily maintainable) source code. All my layout and positioning can be done visually within Interface Builder without writing source code. As a comparison compare the current version of ResistorViewController.m against the equivalent ResistorView.cs.

It’s interesting to note that to date my source code only consists of application specific logic and very little rendering code, while Chris’s and Alex’s code base currently has a high percentage of source code dedicated to alpha transparency and the drawing of the resistor. In fact at this very moment they have discovered a graphic rendering quirk they currently need to investigate.

Project Resistance: Day 1

Tuesday, October 27th, 2009

Screenshot showing initial version of Project Resistance running on the iPhoneToday I did some of the preliminary work for Project Resistance. For the most part today was about setting up some infrastructure for the application, setting up source code repositories, file layouts and the like.

Creating a GitHub account

For this project I’ve decided to host the source code on GitHub. This seemed a more “iPhone” friendly location than Codeplex and gives me an excuse to try out Git. A distributed source code system I have not used before.

After signing up for a free account and following their instructions on creating an SSH key-pair to help verify my identity I was ready to create a new project repository by answering a few questions (such as name and homepage URL).

Since I don’t have Git installed on my machine I next downloaded and installed it via the Git OSX Installer. Once installed I needed to perform a small amount of configuration from the terminal.

git config --global "Christopher Fairbairn"
git config --global

With this out of the way I was ready to create a local git repository.

Creating a git repository

To create a new repository you simply create a new directory in a convenient location and execute the “git init” command within it.

mkdir Project-Resistance
cd Project-Resistance
git init

One benefit of a distributed source control system is that I can work against this local reposistory, committing changes and even branching the project without needing to be connected to a centralised server. This could come in handy as I tend to work in a number of environments without decent connectivity.

To test out git I decided to create a short README file that describes the purpose of the project. Once I had created the file in a text editor I needed to make git aware of it, and then finally commit the change to the repository with a short explanation of what I had done.

git add README
git commit -m 'added README file'

With all the changes committed locally, it was time to perform the really big smoke test and push the changes I had made up to the repository stored on github. I could achieve this by performing the following two commands from a terminal window.

git remote add origin
git push origin master

Stubbing out a project

Within XCode I created a new iPhone application by selecting the Tab Bar Application project template. I then added some of the graphic files as resources.

Unlike the Windows Mobile application which required a small amount of plumbing code to be developed in order to draw images with alpha transparency I was simply able to drag and drop the images onto my view within Interface Builder. The Cocoa Touch framework supports controls with transparency out of the box.

Within a couple of minutes I was displaying the alpha blended images within the iPhone Simulator.

Day 1 Summary

Today was relatively straight forward. The process to create a git repository on github was rather quick, and now that I have the git utility installed I could even have started the project without internet connectivity.

Likewise by using the Tab Bar Application project template within XCode I was able to get the main screen of the application looking pretty good without writing a single line of source code.

Luckily I was able to reuse many of the graphical assets commissioned by Chris Tacke on his first day, although eventually I’ll need to replace these to cope with the iPhone’s different screen resolution (480×320). Currently I’m stretching them. It will be interesting to see how Chris handles this situation himself, as the screen resolution and orientation of Windows Mobile devices can vary significantly.

Project Resistance – Developing an iPhone Application

Tuesday, October 27th, 2009

Screenshot of Windows Mobile version of Project ResistanceChris Tacke and Alex Feinman have started blogging about a new project called Project Resistance. The idea is to document the end to end experience of developing and selling a small utility application for the Windows Mobile platform. Along the way they’ll comment about their experiences, struggles and productivity wins etc. All the source code and related material will be available online as the project progresses.

The application is rather simple. It allows you to select colour bands on a resistor and will tell you the resistor’s resistance. See the Wikipedia entry on resistors if you have no idea what any of that means.

In light of my previous blog post and after talking to Chris Tacke, I’ve offered to follow his blog posts and create an iPhone variant of the application. It’ll be interesting to contrast the relative strengths and weaknesses of each platform, and how the App Store experience compares.

The first blog post I’ll make on the iPhone application will be covering signing up to to host the project’s source code.

I’m a mobile developer (and author)!

Tuesday, October 27th, 2009

Front Cover of Objective-C for the iPhone book by Christopher FairbairnYou might have noticed a few changes around here of late, including the renaming of this blog to /dev/mobile.

When I started blogging almost 3 years ago it was a way to contribute back to the community and share my passion for mobile development. I started with the community and platform I was most commercially involved with at the time – Windows Mobile.

However Windows Mobile was (and still is) only one of the many platforms I develop for. In fact as my bio hints next year will mark my 10th year developing mobile based applications and solutions! Windows Mobile, iPhone, Android and WebOS all didn’t exist back then. How time (and technology) flies…

For the last year or so I’ve wondered (similiar to others such as Joel Ivory Johnson) how to expand the scope of my blog to cover other platforms and technology stacks in which I’m invovled. I’m passionate about mobile development in general, and do a lot beside the visible Windows Mobile related content I post here.

Front Cover of Objective-C for the iPhone book by Christopher FairbairnThis came to a head in the last couple of months when I was asked by Manning to author an iPhone related programming book. How could I raise my visibility within the iPhone community and contribute content on a blog with “Windows Mobile” in the title?

In the end I decided to rebrand and re-organise the blog to enable me to introduce additional topics for which I’ve been keen to share.

To start my venture into blogging about iPhone related topics I have decided to create a 30 days of iPhone project. This will closely follow the existing 30 Days of Windows Mobile applications and will form a useful comparison between the two platforms (yes I am aware of AppsAmuck). Likewise I’m still committed to bloging about Windows Mobile, so at the same time I’m going to put in an concerted effort to blog about the existing Windows Mobile mobile based applications which are currently located within the codeplex based source code repository but haven’t been blogged about.

In the mean time please investigate my book “Objective-C for the iPhone” and consider purchasing a copy. It’s currently available via Manning’s MEAP (Early Access Programme), which means you can start to get chapters in PDF form during the editing process, before the final paper back book is published.

Your feedback on the book, becoming a first time author or how best to maintain a blog covering multiple technologies / interests would be greatly appreciated! One thing I haven’t fully worked out is how best to tag or categorise posts to allow filtering of iPhone or Windows Mobile specific content…

DNUG Meeting: How to Become an Exceptional DBA

Monday, October 12th, 2009
Photo of Brad BcGehee
Date: Wednesday October 21st 2009
Time: Gather at 5:30 pm, starting at 6:00 pm
Location: Room N510, CPIT, Madras Street
Presenter: Brad McGehee

Becoming a DBA doesn’t have to be just a job; it can be a very rewarding career. While many DBAs are happy with just getting by, the Exceptional DBA is not only outstanding in their knowledge of SQL Server, they are consummate professionals who are in high demand, and command high salaries.

In this session, Brad McGehee, Director of DBA Edution for Red Gate Software will focus on the following topics:

  • Why I Should Become an Exceptional DBA
  • Characteristics of the Exceptional DBA
  • Specialize: You Can’t Do It All
  • Hone Your Skill Set
  • Is Professional Certification Really Necessary
  • Participate in the SQL Server Community
  • Manage Your Career, Don’t Let it Manage You
  • Take Action Now

This should be a brilliant presentation, even if you’re not a DBA. I’m sure the content will be relevant no matter your role within IT. Up-skilling, staying relevant and in-demand is key to virtually everyone’s career.

Since this presentation is taking place at a different venue this month I’ve included a map outlining its location below.
Map of CPIT showing location of room N510
Room N510 can be found on the 5th floor of N-S block, best accessed by the entrance off the corner of Madras and St Asaph Street.

SQL Server MVP Deep Dives book – order your copy today!

Monday, October 12th, 2009

Cover of SQL Server MVP Deep Dives bookI’m a bit late to the game, but if you haven’t heard already you should investigate buying a book called SQL Server MVP Deep Dives that is about to be published by Manning. This book has contributions by 53 MVPs (mostly SQL Server based, although there are a few representing other specialties).

The book has over 60 short chapters on a wide range of SQL Server related topics. You’d be hard pressed to find another knowledge packed book written by some of the biggest names in the community.

All the authors donated their time and energy to this project. Even better all author royalties for the book are being donated to War Child International. So buying a copy is a great way to support a charity.

As the description on the Manning website states:

This is not an ordinary SQL Server Book. SQL Server MVP Deep Dives brings together the world’s most highly-regarded SQL Server experts to create a masterful collection of tips, techniques, and experience-driven best practices for SQL Server development and administration. These SQL Server MVPs—53 in all—each selected a topic of great interest to them, and in this unique book, they share their knowledge and passion with you.

I urge to to consider buying a copy, and when you do take a look at chapter 22 – “Placing SQL Server in your pocket” – which was written by me :-)

A much better way to side deploy WM6.5 widgets

Monday, October 12th, 2009

Picture of a sad smiley faceSometimes I can be a bit of a dope…

You can ignore my previous post about side loading widgets which are deployed via a web server… There’s a much easier way.. the entire post was based upon incorrect assumptions and feedback from a couple of people with actual WM6.5 devices (hacked based ROMS no less…).

I’ve since discovered that most widgets should automatically install (without hacks) if you simply provide a hyperlink to the *.widget file directly. Although the crappy internet explorer dialog with less than obvious “open” option is still part of the installation process which may trip up less technology savvy users (or at-least require additional guidance on the download page).

Depending upon your webserver you may need to alter your mime types however to get the file correctly detected. If this is the case, add an entry for the .widget file extension with the mime type specified as “application/widget”.

Gerr… sometimes it really pains me the lack of developer documentation and support for WM6.5. This is not the first time I’ve gone down incorrect paths.

If you have access to an actual WM6.5 device with non hacked ROM, I would love for this to be verified. I’m sick of second guessing emulator behavior vs actual released ROM behavior.

Deploying WM6.5 Widgets from your own webserver

Monday, October 12th, 2009


Screenshot showing main window of Widget Packager utilityBy default Windows Mobile 6.5 widgets must be distributed via the Windows Marketplace for Mobile. Although you can host your *.widget files on a webserver of your choice the OS will refuse to install them without setting a couple of registry settings on the device.

There is a possible work around for this situation however… and that is packaging up your *.widget file inside of a *.cab file, as the web browser already knows how to download and install those. The challenge with this approach then becomes how to conveniently build the CAB file which will auto-magically install your widget.

Introducing Widget Packager


Widget Packager is a small utility I have developed which can run on your development desktop machine. Once you have developed your WM6.5 widget, you simply drag and drop the resultant *.widget file onto the widget packager main window and you will be prompted to save a matching CAB file.

Place this CAB file on a correctly configured webserver and you are ready to post a link within the mobile version of your website. Anyone that clicks on the link within Internet Explorer for Mobile will be prompted to save or open the file.

Opening the CAB file (or saving it and selecting it within File Explorer at a later date) will cause the standard widget installer to launch to install your new widget. Once installed no trace of the CAB file (such as an entry within the remove programs list) can be found.

As an example, use the web browser on your mobile device to install the following MobileFlashlight widget that I have packaged as a cab file. This should demonstrate the installation process, but don’t take it as a good example of widget design. It was simply the first *.widget file I grabbed while developing this proof of concept.

Limitations of this approach


The dynamic creation of a CAB file, and the installation of widgets from an arbitary webserver is a cool demo, but is it really worth the effort? At this stage I’m not sure it really is. Potential problems with this approach include:

  • The CAB file is unsigned – The CAB file (and a setup.dll within it) are unsigned. This means some devices may refuse to install it, or atleast display warning prompts. In order to resolve this you would need to sign the CAB with a Mobile2Market certifcate which is probably more expensive than the Windows Marketplace for Mobile process you are trying to avoid.
  • Lack of upgrade mechanism – You would need to develop your own solution for detecting and installing updates to your widget, as obviously you can’t rely upon the marketplace for these features.
  • WM6.1+ has a “feature” – Since WM6.1 a feature or bug depending upon your viewpoint means if you create a CAB file and configure it to leave no uninstallation information the OS still detects it when the CAB file is re-ran. This means the user is prompted to uninstall the previous version, and even worse, since no uninstallation information is available the uninstall fails. This isn’t a road block (as the user simply needs to tap “Yes” twice), but it’s not exactly a great user experience either if you attemp to upgrade your widget.
  • Internet Explorer’s open/save file dialog sucks – The file save dialog in Pocket Internet Explorer was never that nice, but in WM6.5 it’s a case of one step forwards, two steps backwards. Now it is full screen, but the options are hidden away within menus… As a small hint, you’ll find the “open” option within the menu that pops up when you click the “Menu” softkey. Why they don’t use all that whitespace within the dialog to display two big finger friendly graphical buttons is anyones guess…

So is it really worth it? I’ll let you be the judge of that. One case where it may be useful, is if your widget needs the use of an ActiveX control which needs to be installed as part of the widget installation process. *.widget files don’t support that particular feature, while the Widget Packager could easily be extended to support that.

Download the utility


[Download - 197KB]

If you’re interested in trying out the utility, it is available for download. The ZIP file includes the utility, as well as an example *.widget. There are three ways to run the utility

  • Run the WidgetPackager.exe GUI, then drag and drop a *.widget file from file explorer onto the main window. You will be prompted for a CAB filename, and it will then be generated.
  • Place a shortcut to WidgetPackager.exe on your desktop or quick launch toolbar etc. Drag a *.widget file onto this icon and a *.CAB will appear in the same location.
  • Call WidgetPackager.exe from the command line (perhaps as part of an automated build process). Simply specify the name of the *.widget file as a command line parameter and optionally the path for the CAB file (will default to naming the CAB the same as the *.widget file).

For those that are interested the source code for the utility is also included. Perhaps of most interest to developers is the way in which the *.CAB file is built programatically (without the use of cabwiz.exe). This will be the topic of a future blog post.

Is this utility of use to people? Some of the limitations and loose ends (such as no warning if attempting to install on a Windows Mobile 5.0 or 6.0 device) could be resolved with a little more effort and hacking if there was demand.