Nov 18, 2009

New MIDlets: Idle Screen

Hi all,

The concept of an idle screen is generally defined as an area of the device’s display, where are presented some information to the user, when no activity is taking place on the device. In other words, this area is often filled by UI gadgets, e.g., network signal strength, battery level, etc. In addition, some native applications also utilize this space to provide some quick information, for instance, the number of unread e-mails or shortcut controls.

MIDP 3.0 brings a new feature that allows MIDlets to be displayed as a gadget on the device’s idle screen. They call it Idle Screen MIDlet. To create an Idle Screen MIDlet, the developer must firstly define in the JAD file, the following entry: “MIDlet--Type: idlescreen”. The remaining steps that are necessary to create an Idle Screen MIDlet are related to the classes you must implement to create the content to be presented and the way you set it in the display.

MIDlet-1: NewsTicker, /icon.png, NewsTickerMIDlet
MIDlet-1-Type: idlescreen

The code itself there is no secret. If you are already familiar with Custom Items, you do not have what to worry about. The class you must create to present the MIDlet’s information on the idle screen must extend the class javax.microedition.lcdui.IdleItem, which extends javax.microedition.lcdui.CustomItem. So all the rules and features (e.g. rendering, event handling, commands, etc.) you know about creating custom items also work for Idle Screen MIDlets. Just grab the Graphics object and let you imagination works.

public class NewsTickerIdleItem extends IdleItem {
public void paint(Graphics g, int w, int h) {
g.drawString(“Unread news (” + unrnews + “)”, 0, 0, ...);
}
}


To set a idle item in the device’s display, use the new method of Display class, called setIdleItem(IdleItem). Once set, the idle item will be present as soon as the device switches to the idle state. It means that you can create ordinary MIDlets that when minimized still can present some quick information to the user. On the other hand, your MIDlet can also just present an idle item. For that, do not set any screen in the display, through Display.setCurrent(Displayable). It is important to mention that only one idle item can be set at time per MIDlet.

IdleItem idleItem = new NewsTickerIdleItem();
Display d = Display.getDisplay(this);
d.setIdleItem(idleItem); // new method in Display class

The methods IdleItem.showNotify() and IdleItem.hideNotify() methods are called to indicate when the current idle item is actually visible on the idle screen. On the other hand, the methods addedToDisplay() and removedFromDisplay() and used to indicate the moment at which the idle item is added and removed from the display.

It is countless the number of possibilities you can create using an Idle Screen MIDlet. For instance, we can create an RSS reader that displays the number of unread feeds you have, besides providing a link back to the application to read them. A music player that provides some controls (e.g. play, stop, etc.) to manage the current song.

Such as Screen Saver MIDlets, it also provides us some new possibilities to enhance our applications and improve the user experience on the devices. For more details, consult the MIDP 3.0 specification.

See you in the next post…

No comments:

News

Loading...