Subversion Repositories Projects

Rev

Rev 291 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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