|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 /***** |
|
19 * Flash Light |
|
20 */ |
|
21 import javax.microedition.midlet.*; |
|
22 import javax.microedition.lcdui.*; |
|
23 import java.io.*; |
|
24 |
|
25 public class FlashLight extends MIDlet implements CommandListener, Runnable |
|
26 { |
|
27 |
|
28 private Display display = null; |
|
29 private Thread thread = null; |
|
30 private Canvas canvas = null; |
|
31 private Command exitCommand = new Command("Exit", Command.EXIT, 1); |
|
32 private Command stopCommand = new Command("Stop Flashing", Command.SCREEN, 1); |
|
33 private Command startTest10 = new Command("Start Test 10s", Command.SCREEN, 3); |
|
34 private Command startTest60 = new Command("Start Test 60s", Command.SCREEN, 3); |
|
35 private Command startTest120 = new Command("Start Test 120s", Command.SCREEN, 3); |
|
36 private Command startTest240 = new Command("Start Test 240s", Command.SCREEN, 3); |
|
37 private Command currentCommand = null; |
|
38 |
|
39 |
|
40 public FlashLight() |
|
41 { |
|
42 canvas = new TestingCanvas(); |
|
43 display = Display.getDisplay(this); |
|
44 canvas.addCommand(startTest10); |
|
45 canvas.addCommand(startTest60); |
|
46 canvas.addCommand(startTest120); |
|
47 canvas.addCommand(startTest240); |
|
48 canvas.addCommand(stopCommand); |
|
49 canvas.addCommand(exitCommand); |
|
50 canvas.setCommandListener(this); |
|
51 } |
|
52 |
|
53 /** * */ |
|
54 public void displayToForeGround() |
|
55 { |
|
56 display.setCurrent(canvas); |
|
57 } |
|
58 |
|
59 public void startApp() |
|
60 { |
|
61 displayToForeGround(); |
|
62 } |
|
63 /** * Pause */ |
|
64 public void pauseApp() {} |
|
65 |
|
66 /** * Destroy must cleanup everything. */ |
|
67 public void destroyApp(boolean unconditional) { } |
|
68 |
|
69 /** * |
|
70 * From runnable |
|
71 * */ |
|
72 public void run() |
|
73 { |
|
74 try |
|
75 { |
|
76 System.out.println("Thread started ..... "); |
|
77 if (currentCommand == startTest10) |
|
78 display.flashBacklight(10000); |
|
79 else if (currentCommand == startTest60) |
|
80 display.flashBacklight(60000); |
|
81 else if (currentCommand == startTest120) |
|
82 display.flashBacklight(120000); |
|
83 else if (currentCommand == startTest240) |
|
84 display.flashBacklight(240000); |
|
85 |
|
86 Thread.sleep(3000); |
|
87 |
|
88 } |
|
89 catch (Exception e) |
|
90 { |
|
91 System.out.println("E x c e p t t i o n in run" + e.toString()); |
|
92 } |
|
93 } |
|
94 |
|
95 /**** Handle the command */ |
|
96 public void commandAction(Command c, Displayable s) |
|
97 { |
|
98 |
|
99 if (c == exitCommand) |
|
100 { |
|
101 destroyApp(true); |
|
102 notifyDestroyed(); |
|
103 } |
|
104 if (c == stopCommand) |
|
105 { |
|
106 display.flashBacklight(0); |
|
107 } |
|
108 currentCommand = c; |
|
109 thread = new Thread(this); |
|
110 thread.start(); |
|
111 |
|
112 }// end of commandAction |
|
113 |
|
114 /** |
|
115 * |
|
116 */ |
|
117 class TestingCanvas extends Canvas |
|
118 { |
|
119 protected void paint(Graphics g) |
|
120 { |
|
121 |
|
122 g.drawString("Device control", 5, 5, Graphics.TOP|Graphics.LEFT); |
|
123 } |
|
124 } |
|
125 } |
|
126 |