×
Namespaces

Variants
Actions
(Difference between revisions)

Controlling Light settings in Java ME

From Nokia Developer Wiki
Jump to: navigation, search
IlGolub (Talk | contribs)
(New page: __NOTOC__ __NOEDITSECTION__ {{CodeSnippet |id=  |platform=S60 3rd Edition, FP2 |devices=Nokia N81 |category=Java ME |subcategory=Hardware |creationdate=October 31, 2008 |keywords=com....)
 
hamishwillee (Talk | contribs)
m (Hamishwillee - Update review status)
(20 intermediate revisions by 8 users not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Java ME]][[Category:Code Examples]][[Category:UI]][[Category:Device Management]][[Category:Symbian]][[Category:Series 40]][[Category:Java Runtime 2.3 for Symbian]][[Category:Nokia Belle]][[Category:Series 40 Developer Platform 1.1]][[Category:Series 40 Developer Platform 2.0]][[Category:Hardware]]
__NOEDITSECTION__
+
{{Abstract|This snippet shows how to control the lighting on devices through the {{Icode|setLights()}} method of the {{Icode|DeviceControl}} class.}}
{{CodeSnippet
+
 
|id= 
+
{{ArticleMetaData <!-- v1.2 -->
|platform=S60 3rd Edition, FP2
+
|sourcecode= [[Media:Controlling Light Settings.zip]]
|devices=Nokia N81
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|category=Java ME
+
|devices= Nokia 6131, Nokia N81, Nokia 701, Nokia Asha 305
|subcategory=Hardware
+
|sdk= [http://www.developer.nokia.com/Develop/Java/Tools/ Nokia SDK 1.1 for Java],  [http://www.developer.nokia.com/Develop/Java/Tools/ Nokia SDK 2.0 for Java]
|creationdate=October 31, 2008
+
|platform= Series 40, Symbian
|keywords=com.nokia.mid.ui.DeviceControl, DeviceControl.setLights()
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= com.nokia.mid.ui.DeviceControl, DeviceControl.setLights()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= [[User:mtilli ]]
 +
|review-timestamp= 20120815
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20081128
 +
|author= [[User:IlGolub]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001270
 
}}
 
}}
 
==Overview==
 
 
This snippet shows how to control lighting on devices through <tt>setLights()</tt> method of <tt>DeviceControl</tt> class.
 
  
 
==Source file: ControllingLightMIDlet.java==
 
==Source file: ControllingLightMIDlet.java==
Line 19: Line 31:
 
<code java>
 
<code java>
 
import com.nokia.mid.ui.DeviceControl;
 
import com.nokia.mid.ui.DeviceControl;
 
+
import javax.microedition.lcdui.Alert;
+
 
import javax.microedition.lcdui.Command;
 
import javax.microedition.lcdui.Command;
 
import javax.microedition.lcdui.CommandListener;
 
import javax.microedition.lcdui.CommandListener;
Line 26: Line 37:
 
import javax.microedition.lcdui.Displayable;
 
import javax.microedition.lcdui.Displayable;
 
import javax.microedition.lcdui.Form;
 
import javax.microedition.lcdui.Form;
 
+
 
import javax.microedition.midlet.MIDlet;
 
import javax.microedition.midlet.MIDlet;
 
+
 
+
 
/**
 
/**
 
  *  
 
  *  
Line 44: Line 54:
 
      
 
      
 
     private Form mainForm;
 
     private Form mainForm;
 
+
 
     /**
 
     /**
 
     * The ControllingLightMIDlet constructor.
 
     * The ControllingLightMIDlet constructor.
Line 56: Line 66:
 
     */
 
     */
 
     public void startMIDlet() {
 
     public void startMIDlet() {
         switchDisplayable(null, getForm());
+
         switchDisplayable(getForm());
 
     }
 
     }
 
      
 
      
Line 63: Line 73:
 
     * taken from getDisplay() method. This method is used by all actions  
 
     * taken from getDisplay() method. This method is used by all actions  
 
     * in the design for switching displayable.
 
     * in the design for switching displayable.
    * @param alert the Alert which is temporarily set to the display
 
 
     * @param nextDisplayable the Displayable to be set
 
     * @param nextDisplayable the Displayable to be set
 
     */     
 
     */     
     public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
+
     public void switchDisplayable(Displayable nextDisplayable) {
 
         Display display = getDisplay();
 
         Display display = getDisplay();
         if (alert == null) {
+
         display.setCurrent(nextDisplayable);
            display.setCurrent(nextDisplayable);
+
        } else {
+
            display.setCurrent(alert, nextDisplayable);
+
        }
+
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * From CommandListener.
 
     * From CommandListener.
Line 132: Line 137:
 
         return mainForm;
 
         return mainForm;
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * Returns a display instance.
 
     * Returns a display instance.
Line 140: Line 145:
 
         return Display.getDisplay(this);
 
         return Display.getDisplay(this);
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * Exits MIDlet.
 
     * Exits MIDlet.
 
     */
 
     */
 
     public void exitMIDlet() {
 
     public void exitMIDlet() {
         switchDisplayable (null, null);
+
         switchDisplayable(null);
 
         destroyApp(true);
 
         destroyApp(true);
 
         notifyDestroyed();
 
         notifyDestroyed();
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * From MIDlet.
 
     * From MIDlet.
Line 157: Line 162:
 
     */
 
     */
 
     public void startApp() {
 
     public void startApp() {
         switchDisplayable(null, getForm());
+
         switchDisplayable(getForm());
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * From MIDlet.
 
     * From MIDlet.
Line 167: Line 172:
 
         //Empty implementation
 
         //Empty implementation
 
     }
 
     }
 
+
 
     /**
 
     /**
 
     * From MIDlet.
 
     * From MIDlet.
Line 184: Line 189:
 
==Postconditions==
 
==Postconditions==
  
This Midlet implements a simple example of controlling light property.
+
This [[MIDlet]] implements a simple example of controlling the light property.
  
Turns off the light then rise light level from 1 to 100.
+
Turns off the light then raises the light level from 1 to 100.
  
 
==Supplementary material==
 
==Supplementary material==
  
You can download this application and source code here [[Media:Controlling_Light_Settings.zip]]
+
You can download this application and source code here: [[Media:Controlling Light Settings.zip|Controlling Light Settings.zip]]
 +
 
 +
Related articles:
 +
 
 +
[[Flashing the backlight using Java ME]]
  
[[Category:Java ME]][[Category:Code Examples]]
+
[[How to block the screen saver]]

Revision as of 05:34, 10 October 2012

This snippet shows how to control the lighting on devices through the setLights() method of the DeviceControl class.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 6131, Nokia N81, Nokia 701, Nokia Asha 305
CompatibilityArticle
Keywords: com.nokia.mid.ui.DeviceControl, DeviceControl.setLights()
Created: IlGolub (28 Nov 2008)
Reviewed: mtilli (15 Aug 2012)
Last edited: hamishwillee (10 Oct 2012)

Source file: ControllingLightMIDlet.java

import com.nokia.mid.ui.DeviceControl;
 
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 ControllingLightMIDlet extends MIDlet implements CommandListener {
/**
* Command for setting light
*/

private Command controllingLightCommand;
/**
* exit midlet command
*/

private Command exitCommand;
 
private Form mainForm;
 
/**
* The ControllingLightMIDlet constructor.
*/

public ControllingLightMIDlet() {
//Empty implementation
}
 
/**
* Performs an action assigned to the Mobile Device - MIDlet Started point.
*/

public void startMIDlet() {
switchDisplayable(getForm());
}
 
/**
* Switches a current displayable in a display. The Display instance is
* taken from getDisplay() method. This method is used by all actions
* in the design for switching displayable.
* @param nextDisplayable the Displayable to be set
*/

public void switchDisplayable(Displayable nextDisplayable) {
Display display = getDisplay();
display.setCurrent(nextDisplayable);
}
 
/**
* From CommandListener.
* Called by a system to indicated 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 (displayable == mainForm) {
if (command == exitCommand) {
exitMIDlet();
} else if(command == controllingLightCommand) {
//up light level from 0 to 100
for(int i = 0; i < 100; i++) {
// void setLights(int num, int level) is a static function of
//com.nokia.mid.ui.DeviceControl class that
//activates and deactivates the lights on the device.
//Parameter num indicates the number of the device light
//to control. Currently only one num parameter value is
//specified: num value 0 is used for controlling the
//screen backlight. Parameter level is a value between
//0-100, which indicates the brightness of the light.
//In many implementations, there are only two levels:
//on or off(Sony Ericsson). Value 0 indicates lights off
//for monochrome displays or the minimum brightness setting
//for color displays. All other level values (1-100) are
//used for turning the lights on, possibly with different
//brightness levels, depending on the value. A larger value
//always results in either the same brightness setting as a
//lower one, or a brighter setting. For many products,
//values 1-100 will just turn the lights on.
DeviceControl.setLights(0, i);
try {
Thread.sleep(30);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
}
/**
* Returns an initiliazed instance of mainForm component.
* @return the initialized component instance
*/

public Form getForm() {
if (mainForm == null) {
mainForm = new Form("Lighting test!");
 
exitCommand = new Command("Exit", Command.EXIT, 0);
mainForm.addCommand(exitCommand);
controllingLightCommand = new Command("Light", Command.SCREEN, 0);
mainForm.addCommand(controllingLightCommand);
mainForm.setCommandListener(this);
}
return mainForm;
}
 
/**
* Returns a display instance.
* @return the display instance.
*/

public Display getDisplay () {
return Display.getDisplay(this);
}
 
/**
* Exits MIDlet.
*/

public void exitMIDlet() {
switchDisplayable(null);
destroyApp(true);
notifyDestroyed();
}
 
/**
* From MIDlet.
* Called when MIDlet is started.
* Checks whether the MIDlet have been already started and
* initialize/starts or resumes the MIDlet.
*/

public void startApp() {
switchDisplayable(getForm());
}
 
/**
* From MIDlet.
* Called when MIDlet is paused.
*/

public void pauseApp() {
//Empty implementation
}
 
/**
* From MIDlet.
* 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) {
//Empty implementation
}
}


Postconditions

This MIDlet implements a simple example of controlling the light property.

Turns off the light then raises the light level from 1 to 100.

Supplementary material

You can download this application and source code here: Controlling Light Settings.zip

Related articles:

Flashing the backlight using Java ME

How to block the screen saver

219 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.

×