Subversion Repositories Projects

Rev

Rev 229 | Rev 245 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
206 ligi 1
/***************************************************************
2
 *
3
 * Settings related Part of DUBwise
4
 *  ( e.g. saving to / reading from RMS )
5
 *                                                          
6
 * Author:        Marcus -LiGi- Bueschleb
7
 * Mailto:        LiGi @at@ LiGi DOTT de                    
8
 *
9
***************************************************************/
10
 
11
import javax.microedition.rms.*;
12
 
13
import java.io.*;
14
 
220 ligi 15
public class DUBwiseSettings
16
    extends org.ligi.ufo.ParamsClass
211 ligi 17
    implements org.ligi.ufo.DUBwiseDefinitions,DUBwiseUIDefinitions
206 ligi 18
{
19
    // name/handle for the recordStore to memorize some stuff
220 ligi 20
    private final static String RECORD_STORE_NAME="DUBSETT_V4";
206 ligi 21
 
22
    /* all settings hold here */
23
    //holds id of actual skin
24
    public byte act_skin=SKINID_DARK;
25
 
221 ligi 26
 
27
 
28
    public int key_back;
29
    public int key_fullscreen;
30
    public int key_clear;
31
 
229 ligi 32
    public int voice_delay;
33
    public int voice_volume;
34
 
35
 
36
 
221 ligi 37
    public int remote_cam_stick;
38
 
206 ligi 39
    public String connection_name="";
40
    public String connection_url="";
41
 
42
    public boolean do_vibra=true;
43
    public boolean do_sound=true;
44
    public boolean fullscreen=false;
45
    public boolean do_scrollbg=false;
214 ligi 46
    public boolean expert_mode=false;
206 ligi 47
 
229 ligi 48
    public boolean reload_settings=false;
49
 
50
 
51
    public boolean graph_legend;
52
    public boolean graph_scale;
53
 
222 ligi 54
//#if devicecontrol=="on"
55
    public boolean keep_lighton=false;
56
//#endif
206 ligi 57
 
222 ligi 58
    int[] act_proxy_ip=default_ip; // { ip , ip , ip , ip , port }
59
    int[] act_conn_ip=default_ip; // { ip , ip , ip , ip , port }
60
 
61
 
211 ligi 62
    public byte gps_format=GPS_FORMAT_DECIMAL;
63
    public byte speed_format=SPEED_FORMAT_KMH;
64
 
65
 
220 ligi 66
    int[] settings_field;
211 ligi 67
 
220 ligi 68
    public int get_field_from_act(int pos) { return settings_field[pos];}
69
    public void set_field_from_act(int pos,int val){
70
 
71
        settings_field[pos]=val;
72
        field2setting(pos,val);
73
    }
74
 
75
    public void toggle_fullscreen()
76
    {
77
        //      fullscreen=!fullscreen;
78
         set_field_from_act(1,settings_field[1]^1);
79
         //     if (fullscreen)canvas.setFullScreenMode(true);
80
    }
222 ligi 81
 
82
    public final static int SETTINGS_POS_SKIN=0;
83
    public final static int SETTINGS_POS_BITFIELD1=1;
84
    public final static int SETTINGS_POS_GPS_FORMAT=2;
85
    public final static int SETTINGS_POS_SPEED_FORMAT=3;
86
    public final static int SETTINGS_POS_EXTERN_NICK=4;
87
    public final static int SETTINGS_POS_EXTERN_ROLL=5;
88
    public final static int SETTINGS_POS_EXTERN_GIER=6;
89
    public final static int SETTINGS_POS_EXTERN_GAS=7;
90
    public final static int SETTINGS_POS_EXTERN_HIGHT=8;
91
    public final static int SETTINGS_POS_KEY_BACK=9;
92
    public final static int SETTINGS_POS_KEY_FULL=10;
93
    public final static int SETTINGS_POS_KEY_CLEAR=11;
229 ligi 94
    public final static int SETTINGS_POS_VOICEVOLUME=12;
95
    public final static int SETTINGS_POS_VOICEDELAY=13;
96
    public final static int SETTINGS_POS_BITFIELD2=14;
222 ligi 97
 
98
 
220 ligi 99
    public void field2setting(int pos,int val)
100
    {
101
 
222 ligi 102
        if (pos==SETTINGS_POS_SKIN)
220 ligi 103
            {
104
                act_skin=(byte)val;
221 ligi 105
                canvas.load_skin_images();
220 ligi 106
            }
107
 
222 ligi 108
        if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==1)&&(!fullscreen))
220 ligi 109
            {
110
                fullscreen=true;
111
                canvas.setFullScreenMode(fullscreen);
112
            }
113
 
222 ligi 114
        if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==0)&&(fullscreen))
220 ligi 115
            {
116
                fullscreen=false;
117
                canvas.setFullScreenMode(fullscreen);
118
            }
119
 
222 ligi 120
        if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==2)&&(!do_scrollbg))
220 ligi 121
            {
122
                do_scrollbg=true;
221 ligi 123
                canvas.load_skin_images();
220 ligi 124
            }
125
 
222 ligi 126
        if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==0)&&(do_scrollbg))
220 ligi 127
            {
128
                do_scrollbg=false;
221 ligi 129
                canvas.load_skin_images();
220 ligi 130
            }
229 ligi 131
 
220 ligi 132
 
222 ligi 133
        if (pos==SETTINGS_POS_BITFIELD1)
220 ligi 134
            do_sound=((val&4)!=0);
135
 
222 ligi 136
        if (pos==SETTINGS_POS_BITFIELD1)
220 ligi 137
            do_vibra=((val&8)!=0);
138
 
222 ligi 139
        if (pos==SETTINGS_POS_BITFIELD1)
220 ligi 140
            expert_mode=((val&16)!=0);
141
 
222 ligi 142
        if (pos==SETTINGS_POS_BITFIELD1)
143
            keep_lighton=((val&32)!=0);
144
 
229 ligi 145
        if (pos==SETTINGS_POS_BITFIELD1)
146
            graph_legend=((val&64)!=0);
147
 
148
        if (pos==SETTINGS_POS_BITFIELD1)
149
            graph_scale=((val&128)!=0);
150
 
151
 
152
 
222 ligi 153
        if (pos==SETTINGS_POS_GPS_FORMAT)
220 ligi 154
            gps_format=(byte)val;
155
 
222 ligi 156
        if (pos==SETTINGS_POS_SPEED_FORMAT)
220 ligi 157
            speed_format=(byte)val;
158
 
222 ligi 159
        if (pos==SETTINGS_POS_EXTERN_NICK)
220 ligi 160
            default_extern_control[EXTERN_CONTROL_NICK]=(byte)val;         
161
 
222 ligi 162
        if (pos==SETTINGS_POS_EXTERN_ROLL)
220 ligi 163
            default_extern_control[EXTERN_CONTROL_ROLL]=(byte)val;         
164
 
222 ligi 165
        if (pos==SETTINGS_POS_EXTERN_GIER)
220 ligi 166
            default_extern_control[EXTERN_CONTROL_GIER]=(byte)val;         
167
 
222 ligi 168
        if (pos==SETTINGS_POS_EXTERN_GAS)
220 ligi 169
            default_extern_control[EXTERN_CONTROL_GAS]=(byte)val;          
170
 
222 ligi 171
        if (pos==SETTINGS_POS_EXTERN_HIGHT)
220 ligi 172
            default_extern_control[EXTERN_CONTROL_HIGHT]=(byte)val;        
221 ligi 173
 
174
 
222 ligi 175
        if (pos==SETTINGS_POS_KEY_BACK)
221 ligi 176
            key_back=val;          
177
 
222 ligi 178
        if (pos==SETTINGS_POS_KEY_FULL)
221 ligi 179
            key_fullscreen=val;
180
 
222 ligi 181
        if (pos==SETTINGS_POS_KEY_CLEAR)
221 ligi 182
            key_clear=val;
183
 
184
        if (pos==12)
185
            remote_cam_stick=val;
229 ligi 186
 
187
 
188
        if(pos==SETTINGS_POS_VOICEVOLUME)
189
            {
190
            voice_volume=val;
191
//#if voice_mode!="no_voice"
192
            canvas.status_voice.volume=voice_volume;
193
 
194
//#endif
195
            }
196
        if(pos==SETTINGS_POS_VOICEDELAY)
197
            {
198
            voice_delay=val;
199
//#if voice_mode!="no_voice"
200
            canvas.status_voice.delay=voice_delay;
201
 
202
//#endif
203
            }
204
 
205
        if (pos==SETTINGS_POS_BITFIELD2)
206
            do_sound=((val&1)!=0);      // TODO: FIXME - extra var
207
 
208
        if (pos==SETTINGS_POS_BITFIELD2)
209
            reload_settings=((val&2)!=0);    
220 ligi 210
    }
211
 
212
 
213
    public byte[] default_extern_control;//=default_extern_keycontrol ;
214
 
206 ligi 215
 
216
    /* end of all settings hold here */
217
 
229 ligi 218
    public String[] _tab_names={"User Interface","GPS","Keycontrol","Special Keys","Graph","Voice","Other" };
220 ligi 219
 
222 ligi 220
    public String[][] _field_names={ { "Skin","Fullscreen","Scroll Background"
221
//#if devicecontrol=="on"
222
                                       ,"Permanent Light"
223
//#endif
229 ligi 224
 } , {"GPS Format","Speed Format"},{"Nick","Roll","Gier","Gas Increase","Height Increase"},{"Back to Main-Menu","Fullscreen","Clear"},{"Legend","Scale-Grid"},{"Volts Output","Delay in Seconds","Volume"},{"Sound","Vibra","Remote Cam Stick","Always Reload Params","Expert-Mode"} };
220 ligi 225
 
221 ligi 226
    public String[][] _choice_strings={ { "Dark","Light" } , {"km/h","mp/h","cm/s"},{"decimal","min sec"}} ;
222 ligi 227
    public int[][] _field_positions={ {SETTINGS_POS_SKIN,8,9
228
//#if devicecontrol=="on"
229
                                       ,13
230
//#endif
233 ligi 231
} , {2,3} , {4,5,6,7,8} , {9,10,11},{SETTINGS_POS_BITFIELD1*8 +6,SETTINGS_POS_BITFIELD1*8 +7} ,{SETTINGS_POS_BITFIELD2*8+0,SETTINGS_POS_VOICEDELAY,SETTINGS_POS_VOICEVOLUME },  {10,11,12,SETTINGS_POS_BITFIELD2*8+1,12}};
222 ligi 232
    public int[][] _field_types={ {PARAMTYPE_CHOICE+0,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH
233
//#if devicecontrol=="on"
234
                                   ,PARAMTYPE_BITSWITCH
235
//#endif
229 ligi 236
} , {PARAMTYPE_CHOICE+1,PARAMTYPE_CHOICE+2} , {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, {PARAMTYPE_KEY,PARAMTYPE_KEY,PARAMTYPE_KEY} , {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH}, {PARAMTYPE_BITSWITCH,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_STICK,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH}};
220 ligi 237
    DUBwiseCanvas canvas;
238
 
239
 
229 ligi 240
 
220 ligi 241
    public final static int SETTINGS_FIELD_LENGTH=42;
242
    public DUBwiseSettings(DUBwiseCanvas _canvas)
206 ligi 243
    {
220 ligi 244
        canvas= _canvas;
245
        settings_field=new int[SETTINGS_FIELD_LENGTH];
246
        default_extern_control=new byte[11];
247
        // set defaults
248
        settings_field[4]=42; // nick
249
        settings_field[5]=42; // roll
250
        settings_field[6]=42; // gier
251
        settings_field[7]=1; // fas
252
        settings_field[8]=1; // hight
253
 
221 ligi 254
 
255
        settings_field[9]=-4242; //  no key
256
        settings_field[10]=-4242; // no key
257
        settings_field[11]=-4242; // no key
258
 
220 ligi 259
    }
260
 
261
    public void load()
262
    {
263
 
264
        tab_names=_tab_names;
265
        field_names=_field_names;
266
        field_positions=_field_positions;
267
        field_types=_field_types;
268
        choice_strings=_choice_strings;
206 ligi 269
        try
270
            {
271
                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true );
272
 
273
                if (recStore.getNumRecords()==1)
274
                    {
275
                        ByteArrayInputStream bin = new ByteArrayInputStream(recStore.getRecord(1));
276
                        DataInputStream      din = new   DataInputStream( bin );
277
 
278
 
279
                        connection_url=din.readUTF();
280
                        connection_name=din.readUTF();
220 ligi 281
                        // reserve utf's
282
                        din.readUTF();
283
                        din.readUTF();
284
                        din.readUTF();
206 ligi 285
 
286
 
287
 
220 ligi 288
                        for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++)
289
                            settings_field[i]=din.readInt();
211 ligi 290
 
220 ligi 291
                        for ( int i=0;i<5;i++)
214 ligi 292
 
206 ligi 293
                            {
294
                                act_proxy_ip[i]=din.readInt();
295
                                act_conn_ip[i]=din.readInt();
296
                            }
297
 
298
                    }
299
                recStore.closeRecordStore();
300
            }
301
        catch (Exception e)
302
            {       }
303
 
220 ligi 304
 
305
        for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++)
306
            field2setting(i,settings_field[i]);
307
 
206 ligi 308
    }
309
 
310
 
311
    public void save()
312
    {
313
        try
314
            {
315
                RecordStore.deleteRecordStore(RECORD_STORE_NAME);
316
            }
317
        catch (Exception e)
318
            { }
319
 
320
        try {
321
                RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true );
322
 
323
                ByteArrayOutputStream bout = new ByteArrayOutputStream();
324
                DataOutputStream      dout = new   DataOutputStream( bout );
325
 
326
                dout.writeUTF(connection_url);
327
                dout.writeUTF(connection_name);
328
 
211 ligi 329
                dout.writeUTF("");
330
                dout.writeUTF("");
331
                dout.writeUTF("");
332
 
333
 
220 ligi 334
                for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++)
335
                    dout.writeInt(settings_field[i]);
206 ligi 336
                for ( int i=0;i<5;i++)
337
                    {
338
                        dout.writeInt(act_proxy_ip[i]);
339
                        dout.writeInt(act_conn_ip[i]);
340
                    }
341
                recStore.addRecord(bout.toByteArray(),0,bout.size());
342
 
343
                recStore.closeRecordStore();
344
 
345
 
346
            }
347
        catch (Exception e)
348
            {       }
349
 
350
    }
351
 
352
}