Archive for the ‘Mobile development’ Category

An easy way to detect mobile devices

So you want to deploy a mobile version of your website? You’ve thought about what your target users would do with a mobile version, written your content, created your design and developed your Flash or HTML, CSS and Javascript (if you haven’t done that yet, read this post instead). Now for the task that can seem most daunting to new mobile web developers — detecting devices and serving the correct version of your site. How do you ensure that users with mobile phones will see the mobile version and vice versa?

The answer: WURFL. The Wireless Universal Resource File (WURFL) is an open source project which collects information about all of the different mobile devices in use. It is constantly being updated, so as long as you keep your WURFL definitions up-to-date you don’t have to worry about your detection scripts not recognising new devices. By querying a WURFL database with your visitor’s User Agent string, you can not only determine whether the device they are using is a mobile device, but whether it has a touch screen, can make phone calls, is a tablet (iPad) and more.

It is reasonably straightforward to install a Tera-WURFL service on your PHP enabled web server. If download speed is critical for your website, it would be best to install Tera-WURFL on the same web server. But if you would prefer to avoid the installation process, feel free to use our quick and easy These Days implementation of Tera-WURFL.

It can be as simple as this:

<?php
require_once ('TeraWurflRemoteClient.php');
$wurflObj = new TeraWurflRemoteClient(
    'http://wurfl.thesedays.com/webservice.php' );
$wurflObj->getCapabilitiesFromAgent(null, array('product_info'));
if ($wurflObj->getDeviceCapability("is_wireless_device")) {
    // Show mobile website
} else {
    // Show normal website
}
?>

Don’t forget to give your users a way of overriding automatic device detection. Even WURFL can get it wrong sometimes, and anyway some users prefer to view full sites on their mobile phones. The user is king!

10 tips for designing mobile websites

10 tips for web designers in 2010 – the year of the mobile.

1. Design with a fluid layout, min-width: 320px

There are two factors that make this a necessity. First, mobile device screens are so small that you really need to utilise all of the available space. Second, there are a lot of different screen resolutions out there. The only way to utilise all of the space available on different sized screens is with a fluid layout.

I have found websites with a minimum width of 320px will look good on most high-end mobile devices like the iPhone, Android and Nokia N97. Here are the screen resolutions of some of the most popular devices:

Device Screen res (height x width)
iPhone 320 x 480
iPhone 4 320 x 480 (scaled by a factor of 2)
Nokia N97 360 x 640
HTC Legend 320 x 480
LG eXpo 480 x 800


Technically, the retina display on the iPhone 4 has a screen resolution of 640 x 960 pixels but don’t worry, if you optimise your site for 320 x 480, the iPhone 4 will scale it up by a factor of two so it fits the whole screen. You will need to insert higher resolution images – but more on that in the next section!

2. Include high res images for the iPhone 4 retina display

The iPhone 4 display has four times the number of pixels as that of the original iPhone. To prevent mobile sites from looking tiny, it magnifies them by 200%. That works great on text and vector images like SVG. But its not so hot on bitmap images (or even the HTML5 canvas so it would seem). To avoid pixelation, you need to insert alternative high resolution images for the iPhone 4.

Designers should create their Photoshop documents with a width of 640 pixels. Developers should export the images at full res for iPhone 4 and 50% res for everything else.

Here’s how to use a CSS media query to insert a high resolution image for iPhone 4:

.myImage {
    height: 40px;
    width: 100px;
    -webkit-background-size: 100px 40px;
    background: url("images/myImage.jpg");
}

@media screen and (-webkit-device-pixel-ratio: 2) {
    .myImage {
        background: url("images/myImage@2x.jpg");
    }
}

The first line that might jump out at you as being a little unusual is probably -webkit-background-size: 100px 40px;. The -webkit-background-size CSS property takes two parameters: width and height. The parameters can be lengths, percentages or "auto", and can even be mixed, i.e. -webkit-background-size: 100% auto. This tells the browser to stretch the background image to a specific size.

The second interesting part is the media query @media screen and (-webkit-device-pixel-ratio: 2) {...}. This means that any styles contained within the curly braces only apply if the device has a pixel ratio of 2 (two physical pixels per measurement pixel). Inside the media query selector, we override the .myImage class, and replace the background image with the high resolution image myImage@2x.jpg.

The left half of this screenshot shows the pixelation that occurs on iPhone 4, and the right half shows how it looks when we insert with a high resolution image:

The left half of this screenshot shows the pixelation that occurs on iPhone 4, and the right half shows how it looks when we insert with a high resolution image

3. Turn off auto-scaling

Mobile devices will assume your website is optimised for desktop computers unless you tell them otherwise. Add a viewport meta tag to the head section of your HTML to set the width of your website to match the width of the display, render with a zoom level of 100% and prevent the user from zooming in/out.

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

Mobile phones will also adjust text size when the screen orientation changes unless you include a special CSS parameter:

body {
    -webkit-text-size-adjust: none;
}

4. Make clickable elements big enough for a fingertip, ≈44px²

Your mobile visitors don’t have the accuracy of a mouse – they are often using their fingertips on a touch screen. Don’t make them put their fingers through a pencil sharpener just to click your button! Apple has said that the average finger tap on an iPhone is 44px by 44px (in your high res Photoshop doc that will be 88px by 88px), so aim to make clickable areas at least that size. This doesn’t mean you have to design gigantic looking buttons. Just add some padding to your small buttons to enlarge the clickable area.

5. Don’t use hover states

Today’s touch screens can’t detect when a finger is getting close to touching, so the concept of rollovers does not apply. On the iPhone your :hover style will actually display on click and then remain on screen even after the user takes their finger away, which can be really annoying. So the rule is – don’t use :hover in your CSS or mouseover in your JavaScript.

6. Create icons for your site

Hopefully users will really love your site and add it to their home screen for easy access. Don’t ruin the mood with an ugly default icon! Add these meta tags to the head section of your HTML to define icons.

<!-- 57 x 57 Android and iPhone 3 icon -->
<link rel="apple-touch-icon" media="screen and (resolution: 163dpi)" href="icon57x57.png" />
<!-- 114 x 114 iPhone 4 icon -->
<link rel="apple-touch-icon" media="screen and (resolution: 326dpi)" href="icon57.png" />
<!-- 57 x 57 Nokia icon -->
<link rel="shortcut icon" href="icon57x57.png" />

Note: The iPhone will automatically add rounded corners and a glossy effect to your icon. If you want to turn this off, change the rel attribute to apple-touch-icon-precomposed. Thanks to Jesse Dodds for discovering how to specify a seperate high res icon for the iPhone 4 retina display.

7. Reduce load time by using CSS3 instead of images for gradients, rounded corners, shadows, etc.

Depending on the devices you are targeting, CSS3 can be an excellent option for mobile design. With old school web design techniques, a button with a gradient and rounded corners might consist of 9 separate image slices, a bunch of nasty non-semantic markup and a hefty amount of CSS. With CSS3, you can create this:

CSS3 button

With this:

.redButton {
    color: #B91440;
    font-size: 19px;
    line-height: 25px;
    padding: 10px 30px;
    border: 1px solid #FFFFFF;
    background: -webkit-gradient(linear, left top, left bottom, from(#F2F2F2), to(#FFFFFF));
    -webkit-box-shadow: 0 0 2px #E4E3E3;
    -webkit-border-radius: 5px;
}

Go here for everything you need to know about CSS3.

But be careful! While the iPhone, Android and Nokia all have good CSS3 support, the Windows Mobile 6.5 browser is built on a version of IE6 (sigh…). Define, define, define your target devices before you begin design and development.

8. Use an HTML5 doctype

Not all browsers implement HTML5 features, but they will still accept an HTML5 doctype.

<!DOCTYPE html>

Using this doctype declaration will allow you to display HTML4 elements to all browsers, and then add in additional functionality for the browsers that support HTML5.

9. Make your site operate offline

Your visitors won’t always have a fast Internet connection. If you’re designing the type of site that will have return visitors, consider leveraging the client-side storage capabilities of HTML5. It can be as simple as creating a cache manifest file that tells the browser what files it needs to cache for offline access. A more advanced option is to create an SQLite database on the client with JavaScript.

10. Include an option for your mobile visitors to view the normal website

Detection scripts can get it wrong, or a user might simply prefer not to use the mobile optimised interface. So my final tip is, always offer users a way to switch back to ‘normal mode’.

So there’s a few mobile web tips I’ve picked up over the last few months. I’d love to hear yours too in the comments!

What technologies does your browser support?

Visit this webpage to see what technologies are supported by the device / browser you are using.

HTML5 and CSS3 support varies widely and its hard to keep track of what is supported by each device. To make our mobile development process at These Days a little bit easier, I have put together a webpage which shows what technology is supported by the current browser.

To see it in action, point your browser to http://playground.thesedays.com/browser/

Try visiting the page on a Windows Mobile, Nokia or other mobile device to see how the page responds. You can scan this barcode to open the site easily on your phone:
QR code for http://playground.thesedays.com/browser/

This tool was built with the awesome Modernizr Javascript library. Modernizr lets you detect features in the users’ browser and control fallbacks for older browsers. I just put a skin on top of Modernizr that shows the result of its tests.

The webpage on a BlackBerry, iPhone and Android

Choosing the right platform for your mobile website

A summary of the capabilities and specifications of common mobile devices

The hardest thing about mobile web development is trying to cater to the huge variety of devices used by consumers. They have different screen sizes, different standards, different input mechanisms (keyboard, touch-screen, etc.,) some have Flash player, some don’t… the list goes on. How can you build a mobile website that caters to everyone?

The answer is – you can’t. The key to mobile development is to know which devices you will cater for right from the start, and which devices you will not support. Sometimes we have the luxury of being able to support one device exclusively – especially when we are developing web apps – but more often than not, our websites must cater to a larger group. Some options we have are to target devices with Flash player, devices with HTML5 support, or even just devices with a solid HTML, CSS and JavaScript browser.

To make this decision a little bit easier, I have compiled a table showing a basic summary of the capabilities and specifications of some of the most common mobile devices used to browse the web today.

Brand Device Web browser Screen res Flash player HTML5 HTML, JavaScript, CSS WiFi
Apple iPhone Safari (based on WebKit) 320 x 480 No Yes Yes Yes
Apple iPod Touch Safari (based on WebKit) 320 x 480 No Yes Yes Yes
Motorola Droid Android (based on WebKit) 854 x 480 Flash Player 10.1 Yes Yes Yes
HTC HD2 Microsoft Internet Explorer 480 x 800 Flash Player 10.1 No Yes Yes
HTC Dream Android (based on WebKit) 320 x 480 No Yes Yes
Palm Pre Palm Pre (based on WebKit) 320 x 480 Flash Player 10.1 Yes Yes Yes
Nokia N900 Maemo 800 x 480 Flash Player 10.1 No Yes Yes
Samsung SCH-R350 Openwave Mobile 6.2 176 x 220 No¹ No No³ No
HTC Hero Android (based on WebKit) 320x 480 Flash Lite 3.1 No Yes Yes
HTC Magic Android (based on WebKit) 320x 481 No Yes Yes
Motorola CLIQ Android (based on WebKit) 320 x 482 No Yes Yes
Nokia N70 Nokia (WAP 2.0 only) 176 × 208 No¹ No No³ No
Samsung SCH-R450 Openwave Mobile 6.2 176 x 220 No¹ No No³ No
RIM BlackBerry 8300 BlackBerry Browser 320 x 240 No¹ No² Yes No
Nokia N97 Nokia (based on WebKit) 360 x 640 Flash Lite 3.0 No Yes Yes
HTC Desire Android (based on WebKit) 480 X 800 Flash Player 10.1 Yes Yes Yes

¹ Many phone companies are collaborating in the Open Screen Project to bring a consistent Flash platform to a large number of devices.
² RIM are currently developing a new browser which will support HTML5.
³ Newer Samsung and Nokia devices such as the i8910, 5530 and N97 have WiFi and a WebKit based browser which supports HTML, JavaScript and CSS but not HTML5.

Some of the devices in this table were drawn from the AdMob Mobile Metrics Report for February 2010 as the most common mobile devices and smart phones encountered by AdMob’s extensive international ad network. Of course, this report probably doesn’t represent the target audience of your mobile website, but it’s a good place to start if you don’t know what devices you should be targeting.

Various phones displaying the same HTML websiteThe last two mobile websites we have developed at These Days have been built with HTML, CSS and JavaScript. That has enabled us to target a large group of devices but still create rich, attractive, interactive websites. We designed the websites with a fluid layout and a minimum width of 320 pixels.  That meant the sites would display correctly on the iPhone and flow out to fill larger displays. HTML5 was also a strong contender because it would have allowed us to create websites that could run in ‘offline mode’ and play videos. But for these particular projects, we decided that reaching other devices such as Nokia S60 5th Edition phones was more important.

Note: I have tried to ensure the information in the table is accurate but I can’t guarantee that my sources were correct. For more information about the specifications of mobile devices, try these sites:

Review of Appcelerator Titanium

Appcelerator Titanium is an open source mobile application development tool for iPhone and Android which allows you to code apps with HTML, CSS and JavaScript. I tested out the platform this morning. Having developed an iPhone application with Objective C before, I can tell you that Titanium makes the iPhone development process a whole lot easier. Getting the Android SDK working was a bit tricky but development itself is simple. I love being able to compile native applications by writing standard web code!

Here’s an example of just how easy it can be:

Code for a simple Titanium App

Code for a simple Titanium App

The Titanium app in iPhone

The Titanium app in iPhone

The Titanium app in Android

The Titanium app in Android

.

Getting the Andriod emulator installed correctly can be a real pain. After you have downloaded the Android SDK, open the Android SDK and AVD Manager and make sure you install all of these:

  • Android SDK Tools
  • SDK Platform Android 1.5, API 3
  • Google APIs by Google Inc., Android API 3

In your Titanium Developer profile, set the Android API location to /Applications/android-sdk-mac_86. Also, I found the Android emulator to be frustratingly slow, but I don’t think that’s Titanium’s fault.

To create useful mobile applications I think it would be a good idea to start with the following:

I have included some screenshots of the Kitchen Sink application built in Titanium below so you can get an idea of what can be done.

Slider UI

Slider UI

Entering text input

Entering text input

Saving data on the device

Saving data on the device