Showing posts with label midlet. Show all posts
Showing posts with label midlet. Show all posts

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…

Nov 15, 2009

New MIDlets: Screen Saver

Hi all,

A MIDlet, as we know today, is an application model defined by Mobile Information Device Profile (MIDP) that allow us to create resource limited applications. A MIDlet merely consists of a class that extends the javax.microedition.midlet.MIDlet class. Until MIDP 2.1, MIDlets have been developed to work as entertainment or business applications, for instance. In other words, they have been developed to aggregate some value to the devices. From MIDP 3.0 this story is about to change.

MIDP 3.0 brings new types of MIDlet that will allow developers to create applications that can work as device's feature and not just as a single application. These new types are:
  • Screen Savers
  • Idle Screen
In this post, we will focus on screen saver MIDlet. Let's talk about idle screen MIDlets in a next post.

A screen saver MIDlet is an application that can be launched automatically when the device enters in the idle state, in other words, after a certain period of inactivity. For instance, no call ongoing and the user has not pressed any keys. As soon as a screen saver MIDlet is launched, it keeps running until it is deactivated by an external event or user action, e.g., by pressing any key.

The structure of a screen saver MIDlet is same as any ordinary MIDlet. The only difference is in JAD/JAR files. To set a MIDlet as a screen saver, the entry “MIDlet--Type: screensaver” must be defined. The rest is just the same as you are already used to.

MIDlet-1: Clock3DSaver, /icon.png, ClockScreenSaverMIDlet
MIDlet-1-Type: screensaver

The way the user will set a given MIDlet as the current screen saver is totally up to the platform. I believe it is not a big deal. The manufactures must just add the MIDlet names in the current screen savers list already available in the devices.

To identify whether a screen saver MIDlet is the current selected one, the method MIDlet.isSelectedScreenSaver() was created to answer this question. Naturally, if the MIDlet is not a screen saver, this method will return false.

MIDP 3.0 brings a new feature, which is a mechanism for notifying an application of changes in the system state and for an applications communicate to each other (we will talk more about it in the next posts). In the context of screen saver MIDlet, this event notification works to inform the screen saver if it was activated or deactivated. For that, the MIDlet must implement the interface EventDataListener and then registers itself through the method DataManager.addEventListener. From this moment on, the MIDlet just needs to handle the EventData.SCREENSAVER_MODE event (SCREENSAVER_MODE_ACTIVATED or SCREENSAVER_MODE_DEACTIVATED). For instance, to deactivate a screen saver MIDlet, the device can decide to use any key to perform this task. In addition, an incoming call can also force a screen saver to be deactivated.

I liked this new possibility, because it gives to us more power to create applications that can really customize our devices. Sony Ericsson, for instance, since its JP7 platform, already allows that a MIDlet can be set as wallpaper. Now, for more details, consult the MIDP 3.0 specification.

See you in the next post…

Nov 9, 2009

ActivityMIDlet: A MIDlet++

Hi all,

In the post "Life Cycle Methods: Do you use them?", I wrote about MIDlet's life cycle methods. Also in this post, I quickly mentioned how interesting is the life cycle of an Activity in Android platform. I said that, because an Activity provides more life cycle methods, providing more control and possibilities for the developers. For instance, an Activity has 7 life cycle methods, against only 3 of a MIDlet. With numbers, nobody discusses, right? To understand more about an Activity's life cycle, click here.

Anyway, after having written that post, I decided to implement a custom MIDlet that provided as many life cycle methods as possible as an Android's Activity. Unfortunately, not all methods were possible to put in this class; onRestart() and onStop() do not fit for Java ME, since it does provide a state where an application is shut down and restart by own application manager. That's why I left it out.

On the other hand, I haved added onCreate() and onResume(). The first one works like a constructor and the second is called when the application returns to the foreground, after a certain period on pause. In addition, the method's invoking order is such an Activity.

Other interesting method that I have added is onLowMemory(). This notifies the application when it is running on low memory level, allowing the application to take any providence to avoid crashing. This memory level can be configured by setMinimumMemory(long) method. For further information about these new methods, check the Javadoc.

To download the ActivityMIDlet class, click here. I hope you guys enjoy it.

See you in the next post...

Aug 9, 2008

MIDP3.0 is coming...

Hi all,

It seems that the new MIDP 3.0 is about to be launched. The specification is now done and approved. A group of over 100 members, leaded by Mike Milikich (Motorola), has been working on this specification since March 2005. See below some of the new features:
  • Enhanced LCDUI
  • LIBlets - Shared code between MIDlets
  • Application and System Events
  • Inter MIDlet Communication - IMC
  • Screen Saver MIDlet
Now, we just have to wait for the first model. Does somebody guess which vendor will be the pioneer? I have a guess. :)

For further information, see a presentation on the link below:
http://www.scribd.com/doc/481345/MIDP30-overview

See you in the next post...