Rev 316 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
280 | ligi | 1 | /*********************************************************************** |
2 | * |
||
3 | * DUBwise == Digital UFO Broadcasting with intelligent service equipment |
||
4 | * main MIDLet Source file |
||
5 | * |
||
6 | * Author: Marcus -LiGi- Bueschleb |
||
7 | * Mailto: LiGi @at@ LiGi DOTT de |
||
8 | * |
||
9 | ************************************************************************/ |
||
10 | |||
11 | |||
12 | import javax.microedition.lcdui.*; |
||
13 | import javax.microedition.midlet.*; |
||
14 | |||
291 | ligi | 15 | |
531 | ligi | 16 | |
280 | ligi | 17 | public class DUBwiseInstaller |
18 | extends MIDlet |
||
19 | implements Runnable,CommandListener |
||
20 | { |
||
21 | |||
22 | |||
531 | ligi | 23 | public String[] installmethod_strings={"online Install","show Filename"};//,"email URL"}; |
24 | public String[] installoption_strings={"default","full featured","minimal","custom","expert"}; |
||
280 | ligi | 25 | |
531 | ligi | 26 | public final static byte INSTALLOPTIONID_DEFAULT=0; |
27 | public final static byte INSTALLOPTIONID_FULL=1; |
||
28 | public final static byte INSTALLOPTIONID_MINIMAL=2; |
||
29 | public final static byte INSTALLOPTIONID_CUSTOM=3; |
||
30 | public final static byte INSTALLOPTIONID_EXPERT=4; |
||
280 | ligi | 31 | |
531 | ligi | 32 | public final static byte INSTALLMETHODID_ONLINE=0; |
33 | public final static byte INSTALLMETHODID_SHOWURL=1; |
||
280 | ligi | 34 | |
531 | ligi | 35 | public Display display; |
36 | public DUBwiseInstallerCanvas canvas; |
||
37 | private DUBwiseProps props; |
||
280 | ligi | 38 | |
531 | ligi | 39 | public boolean app_running=false; // to prevent 2 instances |
280 | ligi | 40 | |
41 | |||
531 | ligi | 42 | String browser_dest=""; |
280 | ligi | 43 | |
44 | |||
285 | ligi | 45 | String helper_url=null; |
46 | String download_url=null; |
||
47 | |||
48 | boolean http_possible; |
||
49 | |||
50 | |||
531 | ligi | 51 | Form installoptions_form; |
52 | Form install_form; |
||
53 | |||
54 | |||
55 | ChoiceGroup installmethod_choice; |
||
56 | ChoiceGroup installoption_choice; |
||
57 | |||
285 | ligi | 58 | ChoiceGroup sound_choice; |
59 | ChoiceGroup firmware_choice; |
||
60 | |||
531 | ligi | 61 | ChoiceGroup optional_features_choice; |
285 | ligi | 62 | |
531 | ligi | 63 | |
64 | Form expert_form; |
||
65 | |||
66 | ChoiceGroup res_choice; |
||
67 | ChoiceGroup device_features_choice; |
||
68 | ChoiceGroup installsrc_choice; |
||
69 | |||
70 | |||
71 | |||
285 | ligi | 72 | protected void startApp() |
73 | throws MIDletStateChangeException |
||
74 | { |
||
75 | |||
531 | ligi | 76 | if (app_running)return; |
285 | ligi | 77 | display = Display.getDisplay(this); |
78 | canvas=new DUBwiseInstallerCanvas(this); |
||
79 | |||
80 | // fire up canvas |
||
81 | display.setCurrent(canvas); |
||
82 | } |
||
83 | |||
84 | |||
280 | ligi | 85 | |
86 | |||
87 | public String getURL() |
||
88 | { |
||
531 | ligi | 89 | return download_url+props.installsrc_str()+"/"+props.getFileName(); |
280 | ligi | 90 | } |
91 | |||
92 | public boolean url_check() |
||
93 | { |
||
531 | ligi | 94 | return (InstallHelper.get_http_string(getURL()).startsWith("MIDlet-Jar-URL:")); |
280 | ligi | 95 | } |
531 | ligi | 96 | // fire up browser for online install |
280 | ligi | 97 | public void run() |
98 | { |
||
99 | helper_url=InstallHelper.get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/helper_url") ; |
||
100 | http_possible=((!helper_url.equals("err"))); |
||
531 | ligi | 101 | download_url=InstallHelper.get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/installer_meta/dl_url") ; |
280 | ligi | 102 | |
103 | if ((download_url==null) || (!download_url.startsWith("http"))) |
||
104 | download_url=helper_url+"dl/"; |
||
105 | |||
531 | ligi | 106 | if (http_possible) System.out.println(InstallHelper.get_http_string(helper_url+"mail?subject=DUBwiseInstall&text="+InstallHelper.urlEncode( "Installer Version: 0.8 \nDownload URL:" + getURL() + "\nDownload OK:" + url_check()+ "\nInstall Options:" + installoption_strings[installoption_choice.getSelectedIndex()] + "\n\n------Device Infos---\n" + canvas.description_str() +"\n" ))); |
280 | ligi | 107 | |
108 | try |
||
109 | { |
||
110 | Thread.sleep(500); |
||
111 | platformRequest(getURL()); |
||
112 | } |
||
113 | catch ( Exception e) {} |
||
114 | |||
531 | ligi | 115 | notifyDestroyed(); //quit |
280 | ligi | 116 | |
117 | } |
||
118 | |||
119 | |||
291 | ligi | 120 | |
289 | ligi | 121 | |
280 | ligi | 122 | |
123 | |||
531 | ligi | 124 | public void canvas_hw_detect_finish() |
125 | { |
||
280 | ligi | 126 | |
531 | ligi | 127 | props=new DUBwiseProps(); |
128 | props.set_res_by_screensize(canvas.canvas_width,canvas.canvas_height); |
||
285 | ligi | 129 | |
280 | ligi | 130 | |
531 | ligi | 131 | props.bluetooth=canvas.bluetooth; |
132 | props.locationprovider=canvas.locationprovider; |
||
133 | props.fileapi=canvas.fileapi; |
||
134 | props.devicecontrol=canvas.devicecontrol; |
||
135 | props.cldc11=canvas.cldc11; |
||
280 | ligi | 136 | |
137 | |||
138 | |||
531 | ligi | 139 | // create forms |
280 | ligi | 140 | |
531 | ligi | 141 | install_form = new Form("Install DUBwise"); |
142 | installoptions_form=new Form("Install Options"); |
||
143 | expert_form=new Form("Expert Settings"); |
||
144 | |||
145 | |||
146 | // create widgets |
||
147 | |||
148 | res_choice = new ChoiceGroup( |
||
149 | "Resolution (Detected " +canvas.canvas_full_width + "x"+ canvas.canvas_full_height+")", |
||
280 | ligi | 150 | Choice.EXCLUSIVE, |
531 | ligi | 151 | props.res_strings, |
280 | ligi | 152 | null); |
153 | |||
531 | ligi | 154 | res_choice.setSelectedIndex(props.res_select,true); |
155 | expert_form.append(res_choice); |
||
280 | ligi | 156 | |
531 | ligi | 157 | |
158 | device_features_choice = new ChoiceGroup( |
||
159 | "Features ", |
||
160 | Choice.MULTIPLE, |
||
161 | props.feature_strings, |
||
280 | ligi | 162 | null); |
163 | |||
164 | |||
531 | ligi | 165 | device_features_choice.setSelectedIndex(0,props.bluetooth); |
166 | device_features_choice.setSelectedIndex(1,props.locationprovider); |
||
167 | device_features_choice.setSelectedIndex(2,props.fileapi); |
||
168 | device_features_choice.setSelectedIndex(3,props.devicecontrol); |
||
169 | device_features_choice.setSelectedIndex(4,props.cldc11); |
||
170 | |||
171 | expert_form.append(device_features_choice); |
||
172 | |||
173 | |||
174 | |||
175 | |||
176 | |||
177 | System.out.println("install build"); |
||
178 | /* Install form */ |
||
179 | |||
180 | |||
181 | |||
182 | |||
183 | |||
184 | |||
185 | optional_features_choice = new ChoiceGroup( |
||
186 | "Optional Features ", |
||
187 | Choice.MULTIPLE, |
||
188 | props.optional_feature_strings, |
||
280 | ligi | 189 | null); |
190 | |||
191 | |||
285 | ligi | 192 | |
531 | ligi | 193 | // |
194 | |||
195 | installmethod_choice = new ChoiceGroup( |
||
196 | "Install Method", |
||
197 | Choice.EXCLUSIVE, |
||
198 | installmethod_strings, |
||
199 | null); |
||
200 | |||
201 | |||
202 | |||
203 | installoption_choice = new ChoiceGroup ( |
||
204 | "Install Options", |
||
205 | Choice.EXCLUSIVE, |
||
206 | installoption_strings, |
||
207 | null); |
||
208 | |||
209 | |||
210 | /* device_features_choice = new ChoiceGroup( |
||
280 | ligi | 211 | "Features ", |
212 | Choice.MULTIPLE, |
||
213 | feature_strings, |
||
214 | null); |
||
215 | |||
531 | ligi | 216 | */ |
280 | ligi | 217 | |
218 | |||
285 | ligi | 219 | firmware_choice = new ChoiceGroup( |
220 | "Firmwares:", |
||
221 | Choice.EXCLUSIVE, |
||
531 | ligi | 222 | props.firmware_strings, |
285 | ligi | 223 | null); |
224 | |||
531 | ligi | 225 | firmware_choice.setSelectedIndex(props.firmware_select,true); |
285 | ligi | 226 | |
227 | |||
531 | ligi | 228 | |
280 | ligi | 229 | sound_choice = new ChoiceGroup( |
230 | "Sound ", |
||
231 | Choice.EXCLUSIVE, |
||
531 | ligi | 232 | props.sound_strings, |
280 | ligi | 233 | null); |
234 | |||
531 | ligi | 235 | sound_choice.setSelectedIndex(props.sound_select,true); |
280 | ligi | 236 | |
237 | |||
238 | |||
239 | |||
531 | ligi | 240 | install_form.append(installmethod_choice); |
241 | install_form.append(installoption_choice); |
||
242 | |||
243 | installoptions_form.append(optional_features_choice); |
||
244 | installoptions_form.append(firmware_choice); |
||
245 | |||
246 | |||
247 | installoptions_form.append(sound_choice); |
||
248 | |||
249 | |||
250 | expert_form.addCommand(new Command("OK", Command.OK, 1)); |
||
251 | expert_form.addCommand(new Command("Back", Command.BACK, 2)); |
||
252 | |||
253 | installoptions_form.addCommand(new Command("OK", Command.OK, 1)); |
||
254 | installoptions_form.addCommand(new Command("Back", Command.BACK, 2)); |
||
255 | |||
256 | |||
257 | install_form.addCommand(new Command("OK", Command.OK, 1)); |
||
258 | install_form.addCommand(new Command("Exit", Command.EXIT, 2)); |
||
259 | |||
260 | // set this class as the command listener |
||
261 | installoptions_form.setCommandListener(this); |
||
262 | install_form.setCommandListener(this); |
||
263 | expert_form.setCommandListener(this); |
||
264 | |||
265 | |||
266 | if (!canvas.bluetooth) |
||
267 | { |
||
268 | |||
269 | Alert myAlert = new Alert("Warning", "The Bluetooth API (JSR-82) on your Phone was not found. Without this API DUBwise is not very usefull for most users ( You can only connect via TCP/IP or Serial port ). \n If you have a Windows Mobile Phone this issue can be solved by using DUBwise with a diffrent JRE ( PhoneME or J9 ).\n There is Information in the Internet to show you how to do that - just use your preferred search engine.", null, AlertType.ERROR); |
||
270 | |||
271 | myAlert.setTimeout(Alert.FOREVER); |
||
272 | |||
273 | display.setCurrent( myAlert,install_form ); |
||
274 | } |
||
275 | else |
||
276 | display.setCurrent( install_form ); |
||
280 | ligi | 277 | } |
278 | |||
531 | ligi | 279 | |
280 | ligi | 280 | public void show_url_form() |
281 | { |
||
282 | |||
283 | Form url_form = new Form("FileName"); |
||
284 | TextField txtField = new TextField( |
||
531 | ligi | 285 | "FileName", props.getFileName() , 250, TextField.ANY); |
280 | ligi | 286 | url_form.append(txtField); |
287 | url_form.setCommandListener(this); |
||
531 | ligi | 288 | url_form.addCommand(new Command("Exit", Command.EXIT, 1)); |
289 | url_form.addCommand(new Command("Back", Command.BACK, 2)); |
||
280 | ligi | 290 | display.setCurrent(url_form); |
291 | } |
||
292 | |||
293 | public void process_edit_form() |
||
294 | { |
||
295 | |||
531 | ligi | 296 | // copy form to props |
297 | props.res_select=res_choice.getSelectedIndex(); |
||
298 | props.firmware_select=firmware_choice.getSelectedIndex(); |
||
299 | props.sound_select=sound_choice.getSelectedIndex(); |
||
300 | // installsrc_select= installsrc_choice.getSelectedIndex(); |
||
280 | ligi | 301 | |
531 | ligi | 302 | props.bluetooth= device_features_choice.isSelected(0); |
303 | props.locationprovider=device_features_choice.isSelected(1); |
||
304 | props.fileapi= device_features_choice.isSelected(2); |
||
305 | props.devicecontrol= device_features_choice.isSelected(3); |
||
306 | props.cldc11 = device_features_choice.isSelected(4); |
||
280 | ligi | 307 | |
531 | ligi | 308 | props.j2memaps = optional_features_choice.isSelected(0); |
280 | ligi | 309 | |
310 | switch (installmethod_choice.getSelectedIndex()) |
||
311 | { |
||
531 | ligi | 312 | |
313 | case INSTALLMETHODID_ONLINE: |
||
314 | // online Install -> fire up browser |
||
280 | ligi | 315 | new Thread(this).start(); |
316 | break; |
||
317 | |||
531 | ligi | 318 | case INSTALLMETHODID_SHOWURL: |
319 | // show URL -> fire up browser |
||
280 | ligi | 320 | show_url_form(); |
321 | break; |
||
322 | } |
||
323 | |||
324 | |||
325 | } |
||
326 | |||
531 | ligi | 327 | public void commandAction( Command cmd, Displayable dis) |
280 | ligi | 328 | { |
531 | ligi | 329 | switch(cmd.getCommandType()) |
330 | { |
||
280 | ligi | 331 | |
531 | ligi | 332 | case Command.BACK: |
333 | if(dis==expert_form) |
||
334 | display.setCurrent(installoptions_form); |
||
335 | else |
||
336 | switch(installoption_choice.getSelectedIndex()) |
||
337 | { |
||
338 | case INSTALLOPTIONID_CUSTOM: |
||
339 | display.setCurrent(installoptions_form); |
||
340 | case INSTALLOPTIONID_EXPERT: |
||
341 | display.setCurrent(expert_form); |
||
342 | break; |
||
343 | default: |
||
344 | display.setCurrent(install_form); |
||
345 | } |
||
346 | |||
347 | break; |
||
348 | |||
349 | |||
350 | case Command.EXIT: |
||
351 | notifyDestroyed(); |
||
352 | break; |
||
353 | |||
354 | case Command.ITEM: |
||
355 | display.setCurrent(expert_form); |
||
356 | break; |
||
357 | |||
358 | case Command.OK: |
||
359 | if (dis==install_form) |
||
360 | |||
361 | switch(installoption_choice.getSelectedIndex()) |
||
362 | { |
||
363 | case INSTALLOPTIONID_DEFAULT: |
||
364 | firmware_choice.setSelectedIndex(0,true); |
||
365 | sound_choice.setSelectedIndex(1,true); |
||
366 | |||
367 | |||
368 | |||
369 | process_edit_form(); |
||
370 | break; |
||
371 | case INSTALLOPTIONID_MINIMAL: |
||
372 | firmware_choice.setSelectedIndex(0,true); |
||
373 | sound_choice.setSelectedIndex(0,true); |
||
374 | process_edit_form(); |
||
375 | break; |
||
376 | |||
377 | case INSTALLOPTIONID_FULL: |
||
378 | firmware_choice.setSelectedIndex(1,true); |
||
379 | sound_choice.setSelectedIndex(1,true); |
||
380 | process_edit_form(); |
||
381 | break; |
||
382 | |||
383 | |||
384 | case INSTALLOPTIONID_CUSTOM: |
||
385 | case INSTALLOPTIONID_EXPERT: |
||
386 | display.setCurrent(installoptions_form); |
||
387 | break; |
||
388 | } |
||
389 | else if (dis==installoptions_form) |
||
390 | { |
||
391 | |||
392 | switch(installoption_choice.getSelectedIndex()) |
||
393 | { |
||
394 | |||
395 | case INSTALLOPTIONID_CUSTOM: |
||
396 | process_edit_form(); |
||
397 | break; |
||
398 | case INSTALLOPTIONID_EXPERT: |
||
399 | display.setCurrent(expert_form); |
||
400 | break; |
||
401 | |||
402 | } |
||
403 | |||
404 | } |
||
405 | else if (dis==expert_form) |
||
406 | process_edit_form(); |
||
407 | break; |
||
408 | } |
||
409 | |||
280 | ligi | 410 | } |
411 | |||
412 | |||
413 | protected void pauseApp() {} // not needed right now |
||
414 | protected void destroyApp(boolean arg0) { } |
||
415 | |||
416 | |||
417 | |||
418 | |||
419 | } |