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