Sun Java Solaris Communities My SDN Account Join SDN
 
Article

MIDP on Danger's hiptop Device

By Michael Powers, November 2005  

Editor's Note: MIDP support for the hiptop is supposed to be out "Real Soon Now" but Danger has not published a specific date. MIDP support gets sent out to all current subscribers as an OTA update.

Danger’s hiptop device is a mobile communication product that is as famous for its celebrity devotees as for its innovative design and feature set. The hiptop is available from a number of wireless operators around the world, notably T-Mobile USA and its larger cousin T-Mobile Germany, where the hiptop is marketed as the T-Mobile Sidekick. Because Danger, Inc. is now a licensee of the Java Platform Micro Edition (Java ME), you can program for it using the industry-standard APIs of the Mobile Information Device Profile (MIDP) 2.0. This article will provide an overview of the hiptop as a development platform, then show you how to get started creating your own applications.

What's a hiptop?
Genealogically somewhere between a RIM Blackberry and the Nokia N-Gage, and with a helping of what was good about the Apple Newton, the hiptop is a development platform unlike any other.
 
Figure 1: The hiptop
Figure 1: The hiptop
The unconventional hardware design of the hiptop, shown in Figure 1, gives a developer much to consider. Unlike most MIDP devices, the display on the hiptop has a wide aspect ratio, measuring 240 by 160 pixels, and the device sports a number of interesting buttons and controls as well. Aside from the directional pad, four navigation buttons frame the corners, and two "shoulder" buttons appear at the top of the device. A scroll wheel akin to the one on a Blackberry is bounded by page-up and page-down buttons. If that weren’t enough buttons, when you open the hiptop’s signature flip-top screen, as seen in Figure 2, you have access to a full QWERTY keyboard. The good news is that the MIDP input APIs afford you the flexibility to take advantage of these hardware features in a platform-independent manner.
 
Figure 2: The Flipscreen
Figure 2: The Flipscreen
Equally compelling as the hardware is the software running inside it, and the two work together to create a seamlessly pleasant user experience. The user interface has a rich selection of GUI components, more nearly comparable to those found on a desktop computer or a PDA than on the typical mobile phone. The implementations of the MIDP Form APIs map directly to this component library. Multitasking is at the core of the interface design: Installed applications can be simultaneously active and resident in memory. How this affects the conventional MIDlet life-cycle I’ll discuss later.

The hiptop is a very network-friendly device. In some respects it operates as a thin client, off-loading certain processing and data storage tasks to a server hosted by the mobile operator. For example, the hiptop's implementation of the Record Management System (RMS) stores data on the device and automatically synchronizes it with a backup copy on the server. Because each hiptop is in constant communication with its server, most mobile operators that support the device do so with a flat-rate data plan. A reasonable inference is that the networking facilities available to you through the MIDP connector framework will be robust.

Despite this network-centric design, the hiptop is not capable of conventional over-the-air software installation from a public web server. Hiptop users install applications and ringtones exclusively from a carrier-operated catalog of content, available directly on the device, shown in Figure 3.

 
Figure 3: The Device-Based Application Catalog
Figure 3: The Device-Based Application Catalog
The hiptop SDK
The built-in merchandising capabilities of the catalog give developers a clear path to market for their applications. To test applications on the device, developers must join the Danger developer program and apply for a digital signature key. Developers must also agree to waive customer support from their mobile operator.

At the core of the hiptop software environment is Danger's Java runtime and custom frameworks. All applications and some portions of the operating system and UI toolkit are completely written in Java. A complete hiptop-specific application framework with supporting utility frameworks affords easy subclassing to create software that conforms to users' expectations of the hiptop environment. On top of this framework, Danger has implemented the Connected Limited Device Configuration (CLDC) 1.1 and MIDP 2.0. This architecture gives developers tremendous flexibility in building their applications, using either the familiar and generic MIDP APIs, or the more powerful but hiptop-specific APIs.

 
To get started, the first thing you need is the hiptop software developer kit (SDK), available from the Danger developer web site at http://developer.danger.com. The SDK is available only to members of the Danger developer program, but it’s free to join the program, and to download the SDK. Once you acknowledge your agreement to the licensing terms, you’ll be allowed into the site, where you’ll find the SDK download links, as well as FAQs, documentation, and a discussion forum. The forum is actively maintained, and a quick search will typically turn up answers to most questions.

If you have the Java Development Kit 1.3 or later and the Ant build utility 1.6 or later, all you need to add to start building applications for the hiptop platform is the SDK. While most of the tools, libraries, and, importantly, the hiptop simulator are written in Java and thus portable to virtually any development platform you’d use, a few important utilities exist only as native binaries. For this reason, development is supported only on Windows, Linux, and Mac OS X.

The build environment is completely driven by Ant. You may use the text editor and IDE of your choice, so long as it can drive an Ant build script. You may find the Sun Java Wireless Toolkit (formerly the J2ME Wireless Toolkit) very useful. The SDK’s examples directory contains a diverse collection of sample projects that build and run out-of-the-box with a single call to Ant.

You'll find a set of MIDP-oriented sample projects in the examples/MIDlets subdirectory. Most of these have dependencies on sample projects provided with the wireless toolkit (make sure the WTK_HOME environment variable is defined and points to the root of the WTK installation). The Helloworld projects can run as they are, however. Just change to the Helloworld_src directory, type ant, and the application will build, the hiptop simulator will launch, and the application will run. You'll see it at the bottom the hiptop's "Jump" menu, with a default icon and splash screen, as in Figure 4.

 
Figure 4: A MIDlet in the Jump Menu
Figure 4: A MIDlet in the Jump Menu
For testing, the SDK includes a version of the hiptop operating system software called the simulator. The simulator is based entirely on Java technology, reasonably quick to launch, and it provides a convenient environment in which to test applications before deploying them to a device. You may need to keep a cheat sheet of the keyboard mappings handy because the simulator uses the development machine’s keyboard, including the numeric pad, to simulate all of the input methods on a hiptop.

As I noted earlier, the hiptop is in some respects a thin-client device, deferring some tasks like web-page rendering, network proxy, and data storage to a server hosted by the mobile operator. In hiptop parlance, the functionality offered by this server is called the Service. Danger maintains a separate instance of the Service for developers working with the SDK, although access to it is permitted only on request. Danger's developer web site has a simple form you fill in to request permission to use the Service.

For deployment to a hiptop device, the SDK includes a utility called htconsole. This command-line program opens a terminal-style serial connection to the hiptop over a USB cable, and displays the contents of System.out and System.err messages, and helpful logging info as well.

htconsole includes a number of essential commands, including one to move a compiled application bundle from your development environment to the device. Figure 5 shows htconsole in action, installing an application bundle with the command upload bundle. To make sure that the application stays installed after a reboot, be sure to call loader save. Issuing the help command produces a listing of available commands.

 
Figure 5: Transferring an Application to the Device With <code>htconsole</code>
Figure 5: Transferring an Application to the Device With htconsole
To install applications onto a hiptop device, developers must request from Danger a development key, a file used to sign applications so that they can be installed on a hiptop. Developers that show a sincere interest in writing applications should have no trouble obtaining a key.

At this writing, MIDP support is not available on any hiptop device currently in production. Version 2.3 of the hiptop operating system includes MIDP and is expected to be deployed as an over-the-air update for T-Mobile USA subscribers in late 2005. Until then, developers can write and test MIDlets on the simulator, but won’t be able to test them on the device.

 
Porting a MIDlet to the hiptop
The easiest way to get started with MIDP on the hiptop is to port an existing MIDlet. This scenario is the most common because a vast number of MIDlets have already been written, and Danger makes this process as easy as it can. The supplied build script effectively takes an existing JAD and JAR file and converts them into an application bundle suitable for running in the hiptop environment.

The first step is to duplicate the Helloworld_jar project directory from the SDK’s examples/MIDlets directory, so you can use it as a template for your project. For my project, I ported the JBenchmark2 tool, which exercises the MIDP 2.0 APIs and measures the performance of a device's Java implementation, available as a free download from Kishonti LP. I named my project directory JBenchmark2.

Next, modify your project's build.xml file, replacing references to HelloWorld with references to your project. The fields to update are the project name, the APP_CLASS_NAME property, and the APP_PACKAGE_NAME property. Here's the build.xml for JBenchmark2:


<project name="JBenchmark2" default="run">
    <property environment="env"/>
    <property name="DANGER_HOME" value="${env.DANGER_HOME}"/>

    <!-- NOTE: the fully qualified class name is actually
         JBenchmark2.JBenchmark2, so in this case the class
         and package name happen to be identical.
         Don't be confused. -->
    <property name="APP_CLASS_NAME"  value="JBenchmark2"/>
    <property name="APP_PACKAGE_NAME" value="JBenchmark2"/>

    <property name="APP_MIDLET_FROM_JAR" value="true"/>

    <import file="${DANGER_HOME}/tools/build_common.xml"/>
</project>

 

Now, in your project's bin directory, replace the existing HelloWorld.jar with your JAR file. It's important that the name of your JAR file match exactly the value of APP_CLASS_NAME in the manifest. In my JBenchmark2 project, the JAR's name must be JBenchmark2.jar.

Last, in your project's locale/en_US directory, rename the existing HelloWorld.rsrc file to match the name of your MIDlet's APP_CLASS_NAME from the build file. For JBenchmark2, the file's name is JBenchmark2.rsrc. This file is Danger's proprietary resource format used for localizing applications for different regions and languages. In this case, the default file is for the en_US locale, and you should change the entry for ID_APP_NAME to the American English name for your application.

This resource file is also where you specify custom icons and splash screens. Because the defaults are reasonable for now, don't make any other changes.

Here are the contents of JBenchmark2.rsrc:


string ID_APP_NAME    "JBenchmark2"
string ID_APP_CLASS   "danger.midlet.Launcher"

string ID_LOCALE      "en_US"

javaResources         "{resources}"

 

That's all you need to do. Launch the build script from your project directory with the ant command and the JAR will be repackaged as a hiptop bundle and launched in the simulator. Figure 6 shows JBenchmark2 running on the hiptop.

 
Figure 6: JBenchmark2 Running as a hiptop Application
Figure 6: JBenchmark2 Running as a hiptop Application
Building a MIDlet for the hiptop
If you want to tweak your MIDlet to take better advantage of the hiptop hardware or optimize the user experience, you need to build your projects from the source code instead of the compiled JAR file.

This time, the first step is to duplicate the Helloworld_src directory and give it a different name. For this example, I’m going to use the source code for the venerable MicroTank MIDlet. You can download the MicroTank project from http://developers.sun.com/mobility/midp/articles/game.

Next, replace the contents of your project’s bin and src directories with the contents of the MicroTank project's bin and src directories. Add a res directory to your project and copy the files from MicroTank's res directory. Now the bin directory should contain the files MANIFEST.MF and muTank.jad, and the src directory should contain MicroTankCanvas.java, MicroTankMIDlet.java, and MicroTankSprite.java. The res directory should contain board.png and tank.png.

Update the build.xml file to reflect the project name, the application's main class, and the package that class is in. Because MicroTank’s classes have no declared package, just remove the APP_PACKAGE_NAME property. Here is MicroTank's build.xml:


<?xml version="1.0"?>

<project name="MicroTank" default="run">
    <property environment="env"/>
    <property name="DANGER_HOME" value="${env.DANGER_HOME}"/>

    <property name="APP_CLASS_NAME" value="MicroTankMIDlet"/>

    <property name="APP_MIDLET_FROM_SRC" value="true"/>

    <import file="${DANGER_HOME}/tools/build_common.xml"/>
</project>

 

It's important that you now rename the JAD file to match your APP_CLASS_NAME – not your project name. For MicroTank, rename the JAD file in the bin directory from muTank.jad to MicroTankMIDlet.jad.

Likewise, you must change the name of the resource file in the locale/en_US directory to match your APP_CLASS_NAME value. For MicroTank, this is MicroTankMIDlet.rsrc. Then, update the file's ID_APP_NAME entry to reflect the American English name of the application. Here is MicroTank's MicroTankMIDlet.rsrc file:


string ID_APP_NAME    "MicroTank"
string ID_APP_CLASS   "danger.midlet.Launcher"

string ID_LOCALE      "en_US"

javaResources         "{resources}"

 

Because absolutely no code changes are required, you're now ready to compile and run. Execute the build with the ant command from your project directory. The source code will compile, the resources, JAD file, and classes will be packaged into a hiptop application bundle, and the simulator will launch. Figure 7 shows MicroTank playing on the hiptop. (The prerelease build of the SDK seems to have some problems with transparency.)

 
Figure 7: MicroTank on the hiptop
Figure 7: MicroTank on the hiptop
More Considerations
MIDlets running on the hiptop are meant to look and feel as much like native applications as possible. As such, they are expected to conform to the platform usability standards in a way not typically required of most MIDlets. There are several aspects of the hiptop platform that developers should keep in mind.

While the life-cycle of a MIDlet on the hiptop conforms to the MIDP specification, it may be different from what some developers would expect. The first time the user launches the application, the hiptop runtime instantiates the MIDlet and calls startApp(). After that, the runtime calls pauseApp() when the user switches to another application, and startApp() again when the MIDlet returns to the foreground.

Because hiptop users are incessant multitaskers, MIDlets must be sure to pause their threads and generally minimize their resource consumption when pauseApp() is called, or they can severely degrade the performance of the device. The hiptop runtime calls destroyApp() only if the MIDlet explicitly requests it or when the MIDlet is deleted by htconsole, but not when the device shuts down. Developers must furnish clean-up routines in pauseApp(), not only in destroyApp().

The hiptop screen has a completely different aspect ratio from most other MIDP devices. While form-based MIDlets won’t have a problem, games and other canvas-based applications should scale their user interface to take better advantage of the full screen, based on the dimensions the Canvas class’s getWidth() and getHeight() methods return.

To make this transition easier, Danger has provided some compatibility modes, configurable from the resource file, that force Canvas to return the dimensions of many other popular MIDP devices.

User input is handled through the Canvas class’s keyPressed() and keyReleased() methods. The keyboard buttons generate their corresponding ASCII key codes, and Canvas.getGameAction() correctly interprets the hiptop’s direction pad and fire button. All other buttons produce negative key codes as permitted by the MIDP specification. These values map to their equivalents documented in the hiptop API.

For ease of transition, Danger supports a compatibility mode, where certain buttons on the keyboard (see Figure 2) map to the 12-key pad found on most phones. You enable this mode through a property in the application’s resource file.

The Audio Building Block implementation required by the MIDP 2.0 specification allows applications to produce sounds and music. The hiptop supports MIDI through its embedded high-quality Beatnik audio engine. Neither MMAPI nor video capture through the built-in camera is yet available.

A final word of caution: You might want some MIDlets to take full advantage of the platform-specific APIs available on the hiptop platform. Be aware that the hiptop doesn’t support mixing its own UI toolkit with MIDP’s lcdui packages. After you choose how to implement the user interface, the other, non-UI libraries are fair game.

 
Conclusion
The Danger hiptop is certainly one of the more striking MIDP-capable devices on the market, and developers will need to be cognizant of the platform's myriad idiosyncrasies if they plan to bring an application to market. Danger's toolset makes it easy to take existing MIDP code and get it running on the hiptop. The rest is up to you.

Editor's Note: MIDP support for the hiptop is supposed to be out "Real Soon Now" but Danger has not published a specific date. MIDP support gets sent out to all current subscribers as an OTA update.

 
Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.