|
1 /* |
|
2 * Copyright (c) 2002-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 * import midp classes. |
|
20 */ |
|
21 import javax.microedition.midlet.*; |
|
22 import javax.microedition.lcdui.*; |
|
23 |
|
24 import java.io.*; |
|
25 /** |
|
26 * This is the class to test the Alert test cases: |
|
27 * 1.Alert title |
|
28 * 2.Default Alert texts and tones |
|
29 * 3.Alert images and |
|
30 * 4.Timed Alerts |
|
31 */ |
|
32 |
|
33 public class AlertTests extends Form implements CommandListener |
|
34 { |
|
35 |
|
36 //reference to parent MIDlet |
|
37 private Midp_Alert_01 parent = null; |
|
38 |
|
39 //The TextField to get Alert title |
|
40 private TextField title = new TextField("Title:", "Alert Title", 500, TextField.ANY); |
|
41 |
|
42 //The TextField to get Alert text |
|
43 private TextField text = new TextField("Text:", "Alert Text", 500, TextField.ANY); |
|
44 |
|
45 //Alert time |
|
46 private TextField time = new TextField("Time:", "5000", 100, TextField.NUMERIC); |
|
47 |
|
48 /** |
|
49 * These are the types of the alerts to show within the choice group |
|
50 */ |
|
51 private final static String[] CHOOSABLE_ALERTS = |
|
52 { |
|
53 "NULL", |
|
54 "ALARM", |
|
55 "CONFIRMATION", |
|
56 "ERROR", |
|
57 "INFO", |
|
58 "WARNING" |
|
59 }; |
|
60 //alert types |
|
61 private final static AlertType[] CHOOSEABLE_ALERT_TYPES = |
|
62 { |
|
63 null, |
|
64 AlertType.ALARM, |
|
65 AlertType.CONFIRMATION, |
|
66 AlertType.ERROR, |
|
67 AlertType.INFO, |
|
68 AlertType.WARNING |
|
69 }; |
|
70 |
|
71 //These are the image names shown in the ChoiceGroup |
|
72 private final static String[] ALERT_IMAGES = |
|
73 { |
|
74 "Null", |
|
75 "Small Image", |
|
76 "Big Image", |
|
77 "Invalid Image" |
|
78 }; |
|
79 //image names |
|
80 private final static String[] ALERT_IMAGES_FILE_NAMES = |
|
81 { |
|
82 null, |
|
83 "/small.png", |
|
84 "/fractal.png", |
|
85 "/invalid.png" |
|
86 }; |
|
87 |
|
88 //the ChoiceGroup with Alert types |
|
89 private ChoiceGroup alertTypes = new ChoiceGroup("Alert Type:", ChoiceGroup.EXCLUSIVE, |
|
90 CHOOSABLE_ALERTS, null); |
|
91 //the ChoiceGroup with Alert images |
|
92 private ChoiceGroup alertImages = new ChoiceGroup("Alert Image:", |
|
93 ChoiceGroup.EXCLUSIVE, ALERT_IMAGES, null); |
|
94 //Command to show alert |
|
95 private Command cmdShowAlert = new Command("Show alert", Command.SCREEN, 1); |
|
96 private Command cmdExit = new Command("Exit", Command.EXIT, 1); |
|
97 private Alert newAlert; |
|
98 /** |
|
99 * @param m the parent MIDlet of this class |
|
100 */ |
|
101 public AlertTests(Midp_Alert_01 m) |
|
102 { |
|
103 super("AlertTests"); |
|
104 this.parent = m; |
|
105 newAlert = new Alert(null); |
|
106 append(title); |
|
107 append(text); |
|
108 append(time); |
|
109 append(alertTypes); |
|
110 append(alertImages); |
|
111 addCommand(cmdShowAlert); |
|
112 addCommand(cmdExit); |
|
113 setCommandListener(this); |
|
114 Display.getDisplay(parent).setCurrent(this); |
|
115 } |
|
116 |
|
117 /** |
|
118 * This method handles command invocations. |
|
119 * |
|
120 *@param c This is the command responsible for the event. |
|
121 *@param s Should be equal to this. |
|
122 */ |
|
123 public void commandAction(Command c, Displayable s) |
|
124 { |
|
125 if (c == cmdShowAlert) |
|
126 { |
|
127 Image image = null; |
|
128 int index= 0; |
|
129 String element = null; |
|
130 try |
|
131 { |
|
132 index = alertTypes.getSelectedIndex(); |
|
133 element = alertTypes.getString(index); |
|
134 |
|
135 int imgIndex = alertImages.getSelectedIndex(); |
|
136 if (ALERT_IMAGES_FILE_NAMES[imgIndex] != null) |
|
137 { |
|
138 image = Image.createImage(ALERT_IMAGES_FILE_NAMES[imgIndex]); |
|
139 } |
|
140 newAlert.setTitle(title.getString()); |
|
141 newAlert.setString(text.getString()); |
|
142 newAlert.setImage(image); |
|
143 newAlert.setType(CHOOSEABLE_ALERT_TYPES[index]); |
|
144 |
|
145 if (time.size() != 0) |
|
146 newAlert.setTimeout(Integer.parseInt(time.getString())); |
|
147 |
|
148 Display.getDisplay(parent).setCurrent(newAlert); |
|
149 } |
|
150 catch (java.io.IOException e) |
|
151 { |
|
152 System.out.println("commandAction: can't open Image: " + |
|
153 e.toString()); |
|
154 Alert errorAlert = new Alert("Cannot open Image", e.toString(), null, |
|
155 AlertType.ERROR); |
|
156 errorAlert.setTimeout(Alert.FOREVER); |
|
157 Display.getDisplay(parent).setCurrent(errorAlert); |
|
158 } |
|
159 } |
|
160 else if (c == cmdExit) |
|
161 { |
|
162 parent.destroyApp(false); |
|
163 parent.notifyDestroyed(); |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 |