×
Namespaces

Variants
Actions
Revision as of 04:19, 16 August 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Flashing the backlight using Java ME

From Nokia Developer Wiki
Jump to: navigation, search

Contents

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

Article Metadata

Overview

This snippet demonstrates how to flash the backlight of the device for a specified duration. In practice, the MIDlet constructs a menu item through which the user can select the Flash option in order to force the screen's brightness to periodically increase and decrease for a certain duration. Unlike Symbian devices, where a MIDlet has full control of the device's lights, on Series 40 devices, the user has to specify if the lights should be controlled by the application, or whether their behavior should be defined by the active Profile.

Controlling the lights on application level on Series 40 Development Platform 1.1

Controlling the lights on application level on Series 40 Development Platform 2.0

Source

Flashing the backlight can be implemented as follows:

// Flash the backlight for 5 seconds
Display.getDisplay(this).flashBacklight(5000);

Here is a complete example:

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class FlashingBacklight extends MIDlet implements CommandListener {
private Command flashCommand;
private Command exitCommand;
private Form mainForm;
 
/**
* Constructor. Constructs the object and initializes displayables.
*/

public FlashingBacklight() {
mainForm = new Form("Flashing Backlight");
 
flashCommand = new Command("Flash", Command.SCREEN, 0);
mainForm.addCommand(flashCommand);
 
exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
 
mainForm.setCommandListener(this);
}
 
/**
* Called when the MIDlet is started.
*/

public void startApp() {
Display.getDisplay(this).setCurrent(mainForm);
}
 
/**
* Called when MIDlet is paused.
*/

public void pauseApp() {
}
 
/**
* Called to signal the MIDlet to terminate.
*
* @param unconditional if true, then the MIDlet has to be unconditionally
* terminated and all resources has to be released.
*/

public void destroyApp(boolean unconditional) {
}
 
/**
* From CommandListener.
* Called by the system to indicate that a command has been invoked on a
* particular displayable.
* @param command the command that was invoked
* @param displayable the displayable where the command was invoked
*/

public void commandAction(Command command, Displayable displayable) {
if (command == flashCommand) {
// Flash the backlight for 5 seconds
boolean flashAllowed = Display.getDisplay(this).flashBacklight(5000);
if (!flashAllowed) {
// TODO: Flashing is not allowed. Inform the user.
}
} else if (command == exitCommand) {
// Exit the MIDlet
destroyApp(true);
notifyDestroyed();
}
}
}

Postconditions

If the user selects the Flash menu item, the backlight is flashed for 5 seconds.

This page was last modified on 16 August 2013, at 04:19.
186 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×