Tuesday, December 2, 2008

Device Specific Library Part Four

The Nokia UI API

Sound


The Nokia UI also includes the abality to play sounds on compatible MIDs. The most basic support you can rely on is playing simple tones as well as Nokia ring-tone format (RTPL) tunes. More advanced MIDs can also play digitized audio using the WAV format.

Playing Tones
The first thing to playing sounds is determining the support for the device. The getSupportFormats method will return an array of integers containing either FORMAT_WAF or FORMAT_TONE.

Device Specific Library Part Three

Device Control

You can control of the extra physical of Nokia devices using the com.nokia.mid.ui.DeviceControl class. The table shows the methods available.
The two device elements you can control are the lights and vibration. To temporarily flash the lights on and off, use the flashLights method. For example :

import com.nokia.mid.ul.DeviceControl;
.......

This code will cause the lights (such as the LEDs) to flash. If there is no support for this feature, then nothing will happen (duh). The integer value specifies the length of time (in milliseconds) to keep the light on, althought the device might override this value if you specify a number that is too large.

The other method relating to lights, setLights, allows you to control any of the lights on the device individually, such as the backlight or the LEDs ... in theory. In reality, Nokia only gives you the abality to control the device's backlight (if it has one). To do this, call the method with the light number (the first integer) set to 0 for the bachklight and the level integer set to a number between 0 and 100 (where 0 is off and 100 is the brightest level).

For device that don't support graded backlighting, all values between 1 and 100 just translate to on. Here's an example of setLights in action :

DeviceControl.setLights(0,100);

Controlling the vibration of the phone is one of those cool things you really want to do Crashing into a side railing or taking, shield damage feels much cooler if you give the phone a jiggle when it happens. To start the phone vibrating, use ;

DeviceControl.startVibra(10,100);

The first parameter, the frequency, is an integer in the range of 0 to 100. This number represents how violent the shaking should be. The second integer is the duration of the vibration in milliseconds. You can vary these numbers depending on what's happening in the game. For example, you might make the phone vibrate violently for bigger shield hits or for a longer duration as the shield weakens.

A call to startVibra will return immediately, regardless of the duration of the call. If the device does not support vibration it will throw an IllegalStateExpection. This can happen even on a device that supports vibration if, for example, it's docked in a cradle.

To immediately stop any current vibration, use the stopVibra method.

Device Specific Library Part Two

NOKIA

As you saw, Nokia has an impressive range of J2ME-compatible MIDs on the market. In a fact, they provide a significant portion of the installed user base your games. Fortunately, Nokia has backed thir J2ME hardware with solid support for Java developers -especially game developers.

Using the Nokia SDKs, you will be able to add the following features to your games.
  • Device control for flashing the lights or making the device vibrate
  • Expanded sound support
  • Full screen drawing (beyond Canvas)
  • Extra graphics, including triangle and polygon drawing, transparent image blitting rotation, alpha channels, and direct pixel access.
Nokia provide two distinct tools to help you develop J2ME games for their range or MIDs -the NDS (Nokia Developer's Suite) for J2ME and Java SDKs for individual device. You 'll download and install both of these in the next section.

Installing th Tools

The NDS provides a basic Nokia phone emulator, audio tools, and a simple development environment somewhat similar to Sun's J2ME Wireless Toolkit. (Actually, th NDS is a little better in some ways). It also has supprt for JBuilder and Sun ONE Studio integration, so download it from the Nokia Web site and let's take to tour. To download the NDS, you need to visit Forum Nokia at http://forum.nokia.com.

Navigate to the Java section and then to the Tools and SDKs page. (There's a ton of tool stuff around there, so don't get distracted now!). What you're after is the Nokia Developer's Suite for J2ME. You need to become a member of the developer forum (free of charge) to download these tools .. As you can see, after you download the NDS, install it as you normally would and select the IDE integration you prefer.

The Nokia UI API

Nokia makes additional MIDP features available through the Nokia UI API. You will find a version of the API, in the form of documentation and class files (classes.zip), packaged width most of the device SDKs (such as C:\J2ME\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0). Each device comes packaged with a complete copy of the Nokia UI, however they are all the same thing.

Life on planet Nokia consist of the classes and interfaces highlighted in Figure 1.

To see a Nokia emulator in action you can just run the executable (such as 7210.exe) found in the bin directory for each device (C:\J2ME\Nokia\Devices\Nokia_7210_MIDP_SDK_v1_0\bin) and then use the file menu to open a Jar file contiaing your classes.

To get things working, you need to add lib/classes.zip to your build class path. Then you will be able to use the classes in the com.nokia.mid.* package. Take a look at the detail of these clause.

Device Specific Library Part One

We 've seen J2ME does a great job of abstracting the features of an MID. The MDIP API gives you the comfort of working with a (relative) standart to develop the platform your game. MIDP 1.0 represents the features that are common to all MIDs that support that version. There are some expeptions where support is optional, such as repeating keys and pointer device input. Generally, though, what you see in the specifications is what you can experct to get.

As you can imagine, many mobile device have features beyond those supported by MIDP 1.0 -especially features that are unique to particular devices (such as vibration support). This will naturally continue as the hardware improves. The MIDP specifications will continue to update. You 'll notice that many of the features made available as manufacturer-specific extensions under MIDP 2. However, it is the nature of a standardizes common platform to leave room for manufacturer extensions.

Manufacturers make additional featurer available to developers through J2ME software development kits (SDKs). For example, Nokia provides an SDK for many of their device, which provide features such as transparent image blitting, playing sounds, and turing the device into a vibrator (settle down).

You also need to regularly test, if not directly develop, using the various emulators supported for different phones. Trust me, switch phones regurally during development to keep some perpective on the idiosyncrasies of different device. It'll save you from some monster surprises later.

In the next few sections, you 'll take a book at the features made available by some of the more popular MID manufatcuters : NOKIA, Siemens, and Motorolla.