Rev 291 | 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 | import javax.microedition.rms.*; |
16 | |||
280 | ligi | 17 | public class DUBwiseInstaller |
18 | extends MIDlet |
||
19 | implements Runnable,CommandListener |
||
20 | { |
||
21 | public Display display; |
||
22 | public DUBwiseInstallerCanvas canvas; |
||
23 | public boolean loaded=false; |
||
24 | |||
25 | |||
26 | String browser_dest=""; |
||
27 | |||
28 | |||
29 | public int[][] res_vals = { {480,640},{340,400},{240,320},{200,300},{176,220},{128,128} }; |
||
30 | public String[] res_strings; |
||
31 | |||
32 | public String[] feature_strings={"Bluetooth","Location API","File Connection","Device Control","Fullscreen","cldc11"}; |
||
33 | |||
34 | public String[] sound_strings={"en_speedy","en_wav","de_tts","de_wav","de_64kbit_tts","wav","no_voice"}; |
||
285 | ligi | 35 | public String[] firmware_strings={"No Firmwars","All Firmwares","FC&MK3MAF Firmwares"}; |
36 | public String[] firmware_clean_strings={"no_firmwares","all_firmwares","fc_mk3mag_firmwares"}; |
||
280 | ligi | 37 | |
38 | public String[] installmethod_strings={"online Install","show Filename"};//,"email URL"}; |
||
39 | |||
40 | public String[] installsrc_strings={"stable (latest tag)","Bleeding Edge (trunk)"}; |
||
41 | public String[] installsrc_clean_strings={"tags","trunk"}; |
||
42 | |||
43 | public int res_select=-1; |
||
44 | public int sound_select=0; |
||
45 | public int firmware_select=0; |
||
46 | public int installsrc_select=0; |
||
47 | |||
48 | |||
285 | ligi | 49 | String helper_url=null; |
50 | String download_url=null; |
||
51 | |||
52 | boolean http_possible; |
||
53 | |||
54 | |||
55 | ChoiceGroup res_choice; |
||
56 | ChoiceGroup features_choice; |
||
57 | ChoiceGroup sound_choice; |
||
58 | ChoiceGroup installmethod_choice; |
||
59 | ChoiceGroup installsrc_choice; |
||
60 | ChoiceGroup firmware_choice; |
||
61 | |||
62 | |||
63 | protected void startApp() |
||
64 | throws MIDletStateChangeException |
||
65 | { |
||
66 | |||
67 | if (loaded)return; |
||
68 | display = Display.getDisplay(this); |
||
69 | canvas=new DUBwiseInstallerCanvas(this); |
||
70 | |||
71 | // fire up canvas |
||
72 | display.setCurrent(canvas); |
||
73 | } |
||
74 | |||
75 | |||
280 | ligi | 76 | public String installsrc_str() |
77 | { |
||
78 | return installsrc_clean_strings[installsrc_select]; |
||
79 | } |
||
80 | |||
81 | public String cldc_str() |
||
82 | { |
||
83 | if (canvas.cldc11) |
||
84 | return "-CLDC11"; |
||
85 | else |
||
86 | return ""; |
||
87 | } |
||
88 | |||
89 | public String bt_str() |
||
90 | { |
||
91 | if (canvas.bluetooth) |
||
92 | return "-BluetoothAPI"; |
||
93 | else |
||
94 | return ""; |
||
95 | } |
||
96 | |||
97 | public String fileapi_str() |
||
98 | { |
||
99 | if (canvas.fileapi) |
||
100 | return "-FileAPI"; |
||
101 | else |
||
102 | return ""; |
||
103 | } |
||
104 | |||
105 | |||
106 | public String firmware_str() |
||
107 | { |
||
285 | ligi | 108 | return firmware_clean_strings[firmware_select]; |
280 | ligi | 109 | } |
110 | |||
111 | public String devicecontrol_str() |
||
112 | { |
||
113 | if (canvas.devicecontrol) |
||
114 | return "-DeviceControl"; |
||
115 | else |
||
116 | return ""; |
||
117 | } |
||
118 | |||
119 | public String sound_str() |
||
120 | { |
||
121 | return sound_strings[sound_select]; |
||
122 | } |
||
123 | |||
124 | |||
125 | public String getURL() |
||
126 | { |
||
127 | return download_url+installsrc_str()+"/"+getFileName(); |
||
128 | } |
||
129 | |||
130 | public String getFileName() |
||
131 | { |
||
132 | return "DUBwise-"+res_str()+"-" + sound_str() + "-" + firmware_str() + cldc_str() + fileapi_str() + bt_str() + devicecontrol_str() +".jad"; |
||
133 | } |
||
134 | |||
135 | public boolean url_check() |
||
136 | { |
||
137 | return (!InstallHelper.get_http_string(getURL()).equals("err")); |
||
138 | } |
||
139 | |||
140 | public String res_str() |
||
141 | { |
||
142 | try |
||
143 | { |
||
144 | return res_strings[res_select]; |
||
145 | } |
||
146 | catch(Exception e) |
||
147 | { |
||
148 | return res_strings[0]; |
||
149 | } |
||
150 | } |
||
151 | |||
152 | |||
153 | public void run() |
||
154 | { |
||
155 | |||
156 | helper_url=InstallHelper.get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/helper_url") ; |
||
157 | |||
158 | http_possible=((!helper_url.equals("err"))); |
||
159 | |||
160 | |||
161 | download_url=InstallHelper.get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/download_url") ; |
||
162 | |||
163 | if ((download_url==null) || (!download_url.startsWith("http"))) |
||
164 | download_url=helper_url+"dl/"; |
||
165 | |||
166 | if (http_possible) System.out.println(InstallHelper.get_http_string(helper_url+"mail?subject=DUBwiseInstall&text="+InstallHelper.urlEncode( description_str() + "\nDownload OK:" + url_check()+"\n" ))); |
||
167 | |||
168 | try |
||
169 | { |
||
170 | Thread.sleep(500); |
||
171 | platformRequest(getURL()); |
||
172 | } |
||
173 | catch ( Exception e) {} |
||
174 | |||
175 | notifyDestroyed(); |
||
176 | |||
177 | } |
||
178 | |||
179 | |||
180 | public String description_str() |
||
181 | { |
||
291 | ligi | 182 | |
183 | int rms_avail=0; |
||
184 | try { |
||
185 | RecordStore recStore = RecordStore.openRecordStore("test", true ); |
||
186 | rms_avail=recStore.getSizeAvailable(); |
||
187 | } |
||
188 | catch ( Exception e) {} |
||
289 | ligi | 189 | System.gc(); |
280 | ligi | 190 | return |
191 | "Screenwidth:" + canvas.canvas_width + "\n" |
||
192 | +"Screenheight:" + canvas.canvas_height + "\n" |
||
193 | +"Screenwidth FS:" + canvas.canvas_full_width + "\n" |
||
194 | +"Screenheight FS:" + canvas.canvas_full_height + "\n" |
||
195 | +"CLDC1.1:" + canvas.cldc11 + "\n" |
||
196 | +"JSR-82:" + canvas.bluetooth + "\n" |
||
197 | +"JSR-179:" + canvas.locationprovider + "\n" |
||
198 | +"FileConn:" + canvas.fileapi + "\n" |
||
316 | ligi | 199 | +"SensorAPI:" + canvas.sensorapi + "\n" |
280 | ligi | 200 | +"DeviceControl:" + canvas.devicecontrol + "\n" |
201 | +"comports:" + canvas.comports + "\n" |
||
289 | ligi | 202 | |
203 | +"freeMemory:" + Runtime.getRuntime().freeMemory()+ "\n" |
||
290 | ligi | 204 | +"totalMemory:" + Runtime.getRuntime().totalMemory()+ "\n" |
291 | ligi | 205 | +"RMSAvail:" + rms_avail+ "\n" |
280 | ligi | 206 | +"Download URL:" + getURL() + "\n" |
207 | +canvas.props; |
||
208 | |||
209 | } |
||
210 | |||
211 | |||
285 | ligi | 212 | |
280 | ligi | 213 | public void quit() { |
214 | |||
215 | try |
||
216 | { |
||
217 | res_strings=new String[res_vals.length]; |
||
218 | for (int i=0;i<res_vals.length;i++) |
||
219 | { |
||
220 | if ((canvas.canvas_width>=res_vals[i][0])&&(res_select==-1)) |
||
221 | res_select=i; |
||
222 | res_strings[i]=res_vals[i][0]+"x"+res_vals[i][1]; |
||
223 | } |
||
224 | } |
||
225 | catch(Exception e) |
||
226 | { |
||
227 | res_strings=new String[0]; |
||
228 | } |
||
229 | |||
230 | if (res_select==-1) res_select=0; |
||
231 | show_edit_form(); |
||
232 | |||
233 | } |
||
234 | |||
235 | |||
236 | public void show_edit_form() |
||
237 | { |
||
238 | Form form = new Form("Install DUBwise"); |
||
239 | |||
240 | installsrc_choice = new ChoiceGroup( |
||
241 | "Install Source", |
||
242 | Choice.EXCLUSIVE, |
||
243 | installsrc_strings, |
||
244 | null); |
||
245 | |||
246 | installsrc_choice.setSelectedIndex(installsrc_select,true); |
||
247 | form.append(installsrc_choice); |
||
248 | |||
249 | installmethod_choice = new ChoiceGroup( |
||
250 | "Install Method", |
||
251 | Choice.EXCLUSIVE, |
||
252 | installmethod_strings, |
||
253 | null); |
||
254 | |||
255 | form.append(installmethod_choice); |
||
256 | |||
257 | res_choice = new ChoiceGroup( |
||
258 | "Resolution (Real " +canvas.canvas_full_width + "x"+ canvas.canvas_full_height+")", |
||
259 | Choice.EXCLUSIVE, |
||
260 | res_strings, |
||
261 | null); |
||
262 | |||
263 | res_choice.setSelectedIndex(res_select,true); |
||
264 | form.append(res_choice); |
||
265 | |||
285 | ligi | 266 | |
280 | ligi | 267 | features_choice = new ChoiceGroup( |
268 | "Features ", |
||
269 | Choice.MULTIPLE, |
||
270 | feature_strings, |
||
271 | null); |
||
272 | |||
273 | |||
274 | features_choice.setSelectedIndex(0,canvas.bluetooth); |
||
275 | features_choice.setSelectedIndex(1,canvas.locationprovider); |
||
276 | features_choice.setSelectedIndex(2,canvas.fileapi); |
||
277 | features_choice.setSelectedIndex(3,canvas.devicecontrol); |
||
278 | features_choice.setSelectedIndex(4,canvas.fullscreen); |
||
279 | features_choice.setSelectedIndex(5,canvas.cldc11); |
||
280 | form.append(features_choice); |
||
281 | |||
285 | ligi | 282 | |
283 | |||
284 | firmware_choice = new ChoiceGroup( |
||
285 | "Firmwares:", |
||
286 | Choice.EXCLUSIVE, |
||
287 | firmware_strings, |
||
288 | null); |
||
289 | |||
290 | firmware_choice.setSelectedIndex(firmware_select,true); |
||
291 | form.append(firmware_choice); |
||
292 | |||
293 | |||
280 | ligi | 294 | sound_choice = new ChoiceGroup( |
295 | "Sound ", |
||
296 | Choice.EXCLUSIVE, |
||
297 | sound_strings, |
||
298 | null); |
||
299 | |||
300 | sound_choice.setSelectedIndex(sound_select,true); |
||
301 | form.append(sound_choice); |
||
302 | |||
303 | form.addCommand(new Command("OK", Command.OK, 1)); |
||
304 | form.addCommand(new Command("Exit", Command.EXIT, 2)); |
||
305 | |||
306 | // set itself as the command listener |
||
307 | form.setCommandListener(this); |
||
308 | display.setCurrent(form); |
||
309 | |||
310 | |||
311 | } |
||
312 | |||
313 | public void show_url_form() |
||
314 | { |
||
315 | |||
316 | Form url_form = new Form("FileName"); |
||
317 | TextField txtField = new TextField( |
||
318 | "FileName", getFileName() , 250, TextField.ANY); |
||
319 | url_form.append(txtField); |
||
320 | url_form.setCommandListener(this); |
||
321 | url_form.addCommand(new Command("Back", Command.OK, 2)); |
||
322 | display.setCurrent(url_form); |
||
323 | } |
||
324 | |||
325 | public void process_edit_form() |
||
326 | { |
||
327 | res_select=res_choice.getSelectedIndex(); |
||
285 | ligi | 328 | firmware_select=firmware_choice.getSelectedIndex(); |
280 | ligi | 329 | sound_select=sound_choice.getSelectedIndex(); |
330 | installsrc_select= installsrc_choice.getSelectedIndex(); |
||
331 | |||
332 | canvas.bluetooth= features_choice.isSelected(0); |
||
333 | canvas.locationprovider=features_choice.isSelected(1); |
||
334 | canvas.fileapi= features_choice.isSelected(2); |
||
335 | canvas.devicecontrol= features_choice.isSelected(3); |
||
336 | canvas.fullscreen= features_choice.isSelected(4); |
||
337 | canvas.cldc11 = features_choice.isSelected(5); |
||
338 | |||
339 | |||
340 | |||
341 | switch (installmethod_choice.getSelectedIndex()) |
||
342 | { |
||
343 | case 0: |
||
344 | // browser_dest= getURL(); |
||
345 | new Thread(this).start(); |
||
346 | break; |
||
347 | |||
348 | case 1: |
||
349 | show_url_form(); |
||
350 | break; |
||
351 | } |
||
352 | |||
353 | |||
354 | } |
||
355 | |||
356 | public void commandAction( Command com, Displayable dis) |
||
357 | { |
||
358 | |||
359 | String label = com.getLabel(); |
||
360 | |||
361 | if("Exit".equals(label)) |
||
362 | notifyDestroyed(); |
||
363 | else if("OK".equals(label)) |
||
364 | process_edit_form(); |
||
365 | else if("Back".equals(label)) |
||
366 | show_edit_form(); |
||
367 | } |
||
368 | |||
369 | |||
370 | |||
371 | protected void pauseApp() {} // not needed right now |
||
372 | protected void destroyApp(boolean arg0) { } |
||
373 | |||
374 | |||
375 | |||
376 | |||
377 | } |