Rev 266 | Rev 269 | 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 |
||
255 | ligi | 17 | implements org.ligi.ufo.DUBwiseDefinitions,DUBwiseUIDefinitions,org.ligi.ufo.DUBwiseLangDefs |
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 | public int key_back; |
27 | public int key_fullscreen; |
||
28 | public int key_clear; |
||
29 | |||
229 | ligi | 30 | public int voice_delay; |
31 | public int voice_volume; |
||
32 | |||
33 | |||
262 | ligi | 34 | public byte graph_interval=1; |
229 | ligi | 35 | |
262 | ligi | 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; |
||
265 | ligi | 44 | public boolean do_volts_sound=true; |
45 | public boolean do_altimeter_sound=true; |
||
46 | |||
47 | |||
266 | ligi | 48 | public boolean horizon_invert_nick=true; |
49 | public boolean horizon_invert_roll=true; |
||
50 | public boolean horizon_display_altitude=true; |
||
51 | public boolean horizon_display_flytime=true; |
||
52 | |||
206 | ligi | 53 | public boolean fullscreen=false; |
54 | public boolean do_scrollbg=false; |
||
214 | ligi | 55 | public boolean expert_mode=false; |
266 | ligi | 56 | public boolean dev_mode=false; |
206 | ligi | 57 | |
229 | ligi | 58 | public boolean reload_settings=false; |
267 | ligi | 59 | public boolean instant_error_show=false; |
229 | ligi | 60 | |
61 | public boolean graph_legend; |
||
62 | public boolean graph_scale; |
||
63 | |||
222 | ligi | 64 | //#if devicecontrol=="on" |
65 | public boolean keep_lighton=false; |
||
66 | //#endif |
||
206 | ligi | 67 | |
222 | ligi | 68 | int[] act_proxy_ip=default_ip; // { ip , ip , ip , ip , port } |
69 | int[] act_conn_ip=default_ip; // { ip , ip , ip , ip , port } |
||
70 | |||
71 | |||
266 | ligi | 72 | // public byte gps_format=GPS_FORMAT_DECIMAL; |
73 | // public byte speed_format=SPEED_FORMAT_KMH; |
||
211 | ligi | 74 | |
75 | |||
220 | ligi | 76 | int[] settings_field; |
211 | ligi | 77 | |
220 | ligi | 78 | public int get_field_from_act(int pos) { return settings_field[pos];} |
79 | public void set_field_from_act(int pos,int val){ |
||
80 | |||
81 | settings_field[pos]=val; |
||
82 | field2setting(pos,val); |
||
83 | } |
||
84 | |||
85 | public void toggle_fullscreen() |
||
86 | { |
||
87 | // fullscreen=!fullscreen; |
||
88 | set_field_from_act(1,settings_field[1]^1); |
||
89 | // if (fullscreen)canvas.setFullScreenMode(true); |
||
90 | } |
||
222 | ligi | 91 | |
92 | public final static int SETTINGS_POS_SKIN=0; |
||
93 | public final static int SETTINGS_POS_BITFIELD1=1; |
||
94 | public final static int SETTINGS_POS_GPS_FORMAT=2; |
||
95 | public final static int SETTINGS_POS_SPEED_FORMAT=3; |
||
96 | public final static int SETTINGS_POS_EXTERN_NICK=4; |
||
97 | public final static int SETTINGS_POS_EXTERN_ROLL=5; |
||
98 | public final static int SETTINGS_POS_EXTERN_GIER=6; |
||
99 | public final static int SETTINGS_POS_EXTERN_GAS=7; |
||
100 | public final static int SETTINGS_POS_EXTERN_HIGHT=8; |
||
101 | public final static int SETTINGS_POS_KEY_BACK=9; |
||
102 | public final static int SETTINGS_POS_KEY_FULL=10; |
||
103 | public final static int SETTINGS_POS_KEY_CLEAR=11; |
||
229 | ligi | 104 | public final static int SETTINGS_POS_VOICEVOLUME=12; |
105 | public final static int SETTINGS_POS_VOICEDELAY=13; |
||
106 | public final static int SETTINGS_POS_BITFIELD2=14; |
||
255 | ligi | 107 | public final static int SETTINGS_POS_LANG=15; |
262 | ligi | 108 | public final static int SETTINGS_POS_GRAPHINTERVAL=16; |
267 | ligi | 109 | public final static int SETTINGS_POS_BITFIELD3=17; |
222 | ligi | 110 | |
111 | |||
220 | ligi | 112 | public void field2setting(int pos,int val) |
113 | { |
||
114 | |||
262 | ligi | 115 | if (pos==SETTINGS_POS_GRAPHINTERVAL) |
116 | { |
||
117 | if (val<1) |
||
118 | graph_interval=1; |
||
119 | else |
||
120 | graph_interval=(byte)val; |
||
121 | } |
||
255 | ligi | 122 | |
123 | if (pos==SETTINGS_POS_LANG) |
||
124 | { |
||
125 | canvas.act_lang=(byte)val; |
||
126 | canvas.load_strings(); |
||
127 | } |
||
128 | |||
129 | |||
222 | ligi | 130 | if (pos==SETTINGS_POS_SKIN) |
220 | ligi | 131 | { |
132 | act_skin=(byte)val; |
||
221 | ligi | 133 | canvas.load_skin_images(); |
220 | ligi | 134 | } |
135 | |||
222 | ligi | 136 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==1)&&(!fullscreen)) |
220 | ligi | 137 | { |
138 | fullscreen=true; |
||
139 | canvas.setFullScreenMode(fullscreen); |
||
140 | } |
||
141 | |||
222 | ligi | 142 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==0)&&(fullscreen)) |
220 | ligi | 143 | { |
144 | fullscreen=false; |
||
145 | canvas.setFullScreenMode(fullscreen); |
||
146 | } |
||
147 | |||
222 | ligi | 148 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==2)&&(!do_scrollbg)) |
220 | ligi | 149 | { |
150 | do_scrollbg=true; |
||
221 | ligi | 151 | canvas.load_skin_images(); |
220 | ligi | 152 | } |
153 | |||
222 | ligi | 154 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==0)&&(do_scrollbg)) |
220 | ligi | 155 | { |
156 | do_scrollbg=false; |
||
221 | ligi | 157 | canvas.load_skin_images(); |
220 | ligi | 158 | } |
229 | ligi | 159 | |
220 | ligi | 160 | |
222 | ligi | 161 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 162 | do_sound=((val&4)!=0); |
163 | |||
222 | ligi | 164 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 165 | do_vibra=((val&8)!=0); |
166 | |||
222 | ligi | 167 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 168 | expert_mode=((val&16)!=0); |
169 | |||
222 | ligi | 170 | if (pos==SETTINGS_POS_BITFIELD1) |
171 | keep_lighton=((val&32)!=0); |
||
172 | |||
229 | ligi | 173 | if (pos==SETTINGS_POS_BITFIELD1) |
174 | graph_legend=((val&64)!=0); |
||
175 | |||
176 | if (pos==SETTINGS_POS_BITFIELD1) |
||
177 | graph_scale=((val&128)!=0); |
||
178 | |||
179 | |||
180 | |||
222 | ligi | 181 | if (pos==SETTINGS_POS_GPS_FORMAT) |
266 | ligi | 182 | canvas.mk.gps_position.act_gps_format=(byte)val; |
220 | ligi | 183 | |
222 | ligi | 184 | if (pos==SETTINGS_POS_SPEED_FORMAT) |
266 | ligi | 185 | canvas.mk.gps_position.act_speed_format=(byte)val; |
220 | ligi | 186 | |
222 | ligi | 187 | if (pos==SETTINGS_POS_EXTERN_NICK) |
220 | ligi | 188 | default_extern_control[EXTERN_CONTROL_NICK]=(byte)val; |
189 | |||
222 | ligi | 190 | if (pos==SETTINGS_POS_EXTERN_ROLL) |
220 | ligi | 191 | default_extern_control[EXTERN_CONTROL_ROLL]=(byte)val; |
192 | |||
222 | ligi | 193 | if (pos==SETTINGS_POS_EXTERN_GIER) |
220 | ligi | 194 | default_extern_control[EXTERN_CONTROL_GIER]=(byte)val; |
195 | |||
222 | ligi | 196 | if (pos==SETTINGS_POS_EXTERN_GAS) |
220 | ligi | 197 | default_extern_control[EXTERN_CONTROL_GAS]=(byte)val; |
198 | |||
222 | ligi | 199 | if (pos==SETTINGS_POS_EXTERN_HIGHT) |
220 | ligi | 200 | default_extern_control[EXTERN_CONTROL_HIGHT]=(byte)val; |
221 | ligi | 201 | |
202 | |||
222 | ligi | 203 | if (pos==SETTINGS_POS_KEY_BACK) |
221 | ligi | 204 | key_back=val; |
205 | |||
222 | ligi | 206 | if (pos==SETTINGS_POS_KEY_FULL) |
221 | ligi | 207 | key_fullscreen=val; |
208 | |||
222 | ligi | 209 | if (pos==SETTINGS_POS_KEY_CLEAR) |
221 | ligi | 210 | key_clear=val; |
211 | |||
266 | ligi | 212 | if (pos==12) |
221 | ligi | 213 | remote_cam_stick=val; |
229 | ligi | 214 | |
215 | |||
216 | if(pos==SETTINGS_POS_VOICEVOLUME) |
||
217 | { |
||
218 | voice_volume=val; |
||
219 | //#if voice_mode!="no_voice" |
||
220 | canvas.status_voice.volume=voice_volume; |
||
221 | |||
222 | //#endif |
||
223 | } |
||
224 | if(pos==SETTINGS_POS_VOICEDELAY) |
||
225 | { |
||
226 | voice_delay=val; |
||
227 | //#if voice_mode!="no_voice" |
||
228 | canvas.status_voice.delay=voice_delay; |
||
229 | |||
230 | //#endif |
||
231 | } |
||
232 | |||
233 | if (pos==SETTINGS_POS_BITFIELD2) |
||
265 | ligi | 234 | do_volts_sound=((val&1)!=0); |
229 | ligi | 235 | |
266 | ligi | 236 | if (pos==SETTINGS_POS_BITFIELD2) |
229 | ligi | 237 | reload_settings=((val&2)!=0); |
265 | ligi | 238 | |
266 | ligi | 239 | if (pos==SETTINGS_POS_BITFIELD2) |
240 | do_altimeter_sound=((val&4)!=0); |
||
241 | |||
242 | |||
243 | if (pos==SETTINGS_POS_BITFIELD2) |
||
244 | horizon_invert_roll=((val&8)!=0); |
||
245 | |||
246 | if (pos==SETTINGS_POS_BITFIELD2) |
||
247 | horizon_invert_nick=((val&16)!=0); |
||
248 | |||
249 | if (pos==SETTINGS_POS_BITFIELD2) |
||
250 | horizon_display_flytime=((val&32)!=0); |
||
251 | |||
252 | if (pos==SETTINGS_POS_BITFIELD2) |
||
253 | horizon_display_altitude=((val&64)!=0); |
||
254 | |||
255 | if (pos==SETTINGS_POS_BITFIELD2) |
||
256 | dev_mode=((val&128)!=0); |
||
267 | ligi | 257 | |
258 | |||
259 | if (pos==SETTINGS_POS_BITFIELD3) |
||
260 | instant_error_show=((val&1)!=0); |
||
220 | ligi | 261 | } |
262 | |||
263 | |||
264 | public byte[] default_extern_control;//=default_extern_keycontrol ; |
||
265 | |||
206 | ligi | 266 | |
267 | /* end of all settings hold here */ |
||
268 | |||
255 | ligi | 269 | // public String[] _tab_names={"User Interface","GPS","Keycontrol","Special Keys","Graph","Voice","Other" }; |
220 | ligi | 270 | |
255 | ligi | 271 | |
266 | ligi | 272 | public int[] _tab_stringids={STRINGID_USERINTERFACE,STRINGID_UNITS,STRINGID_KEYCONTROL,STRINGID_SPECIALKEYS,STRINGID_GRAPH,STRINGID_SOUND,STRINGID_COCKPIT,STRINGID_OTHER}; |
220 | ligi | 273 | |
258 | ligi | 274 | |
275 | public int[][] _field_stringids ={ |
||
276 | { |
||
277 | STRINGID_LANGUAGE, |
||
278 | STRINGID_SKIN, |
||
279 | STRINGID_FULLSCREEN, |
||
280 | STRINGID_SCROLLBG |
||
281 | //#if devicecontrol=="on" |
||
282 | ,STRINGID_PERMALIGHT |
||
283 | //#endif |
||
284 | }, |
||
266 | ligi | 285 | {STRINGID_SPEEDFORMAT,STRINGID_GPSFORMAT}, |
286 | {STRINGID_NICK ,STRINGID_ROLL,STRINGID_GIER,STRINGID_GASINCREASE,STRINGID_HEIGHTINCREASE }, |
||
258 | ligi | 287 | {STRINGID_BACKTOMAINMENU,STRINGID_FULLSCREEN,STRINGID_CLEAR }, |
262 | ligi | 288 | {STRINGID_LEGEND,STRINGID_SCALEGRID,STRINGID_GRAPHINTERVAL}, |
266 | ligi | 289 | {STRINGID_SOUND,STRINGID_VOLTS,STRINGID_DELAYINS,STRINGID_ALTIMETER,STRINGID_VOLUME}, |
290 | {STRINGID_SHOWALTITUDE,STRINGID_SHOWFLIGHTTIME,STRINGID_INVERTROLL,STRINGID_INVERTNICK}, |
||
267 | ligi | 291 | {STRINGID_INSTANTERRORSHOW,STRINGID_VIBRA,STRINGID_REMOTECAMSTICK,STRINGID_ALWAYSRELOADPARAMS,STRINGID_EXPERTMODE,STRINGID_DEVMODE}}; |
258 | ligi | 292 | |
293 | |||
294 | |||
295 | |||
296 | public int[][] _choice_stringids={ {STRINGID_LANG0,STRINGID_LANG1}, /* FIXME - make dynamic */{ STRINGID_DARK,STRINGID_LIGHT } , {STRINGID_KMH,STRINGID_MPH,STRINGID_CMS},{STRINGID_DECIMAL,STRINGID_MINSEC} } ; |
||
297 | |||
298 | |||
299 | |||
266 | ligi | 300 | public int[][] _field_positions= { |
301 | {SETTINGS_POS_LANG,SETTINGS_POS_SKIN,8,9 |
||
222 | ligi | 302 | //#if devicecontrol=="on" |
262 | ligi | 303 | |
266 | ligi | 304 | ,13 |
222 | ligi | 305 | //#endif |
266 | ligi | 306 | } , {2,3 } , {4,5,6,7,8} , {9,10,11},{SETTINGS_POS_BITFIELD1*8 +6,SETTINGS_POS_BITFIELD1*8 +7, SETTINGS_POS_GRAPHINTERVAL} , |
307 | {10,SETTINGS_POS_BITFIELD2*8+0,SETTINGS_POS_VOICEDELAY,SETTINGS_POS_BITFIELD2*8+2,SETTINGS_POS_VOICEVOLUME }, |
||
308 | {SETTINGS_POS_BITFIELD2*8+6,SETTINGS_POS_BITFIELD2*8+5,SETTINGS_POS_BITFIELD2*8+3,SETTINGS_POS_BITFIELD2*8+4}, |
||
267 | ligi | 309 | {SETTINGS_POS_BITFIELD3*8+0,SETTINGS_POS_BITFIELD1*8+3,12,SETTINGS_POS_BITFIELD2*8+1,SETTINGS_POS_BITFIELD1*8+4,SETTINGS_POS_BITFIELD2*8+7} |
266 | ligi | 310 | }; |
258 | ligi | 311 | public int[][] _field_types={ {PARAMTYPE_CHOICE+0,PARAMTYPE_CHOICE+1,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH |
222 | ligi | 312 | //#if devicecontrol=="on" |
266 | ligi | 313 | ,PARAMTYPE_BITSWITCH |
222 | ligi | 314 | //#endif |
266 | ligi | 315 | } , {PARAMTYPE_CHOICE+2,PARAMTYPE_CHOICE+3} , {PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE}, {PARAMTYPE_KEY,PARAMTYPE_KEY,PARAMTYPE_KEY} , {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BYTE}, |
316 | {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BYTE,PARAMTYPE_BITSWITCH,PARAMTYPE_BYTE} , |
||
317 | {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH}, |
||
267 | ligi | 318 | {PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_STICK,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH} |
266 | ligi | 319 | }; |
220 | ligi | 320 | DUBwiseCanvas canvas; |
321 | |||
322 | |||
229 | ligi | 323 | |
220 | ligi | 324 | public final static int SETTINGS_FIELD_LENGTH=42; |
325 | public DUBwiseSettings(DUBwiseCanvas _canvas) |
||
206 | ligi | 326 | { |
220 | ligi | 327 | canvas= _canvas; |
328 | settings_field=new int[SETTINGS_FIELD_LENGTH]; |
||
329 | default_extern_control=new byte[11]; |
||
330 | // set defaults |
||
331 | settings_field[4]=42; // nick |
||
332 | settings_field[5]=42; // roll |
||
333 | settings_field[6]=42; // gier |
||
245 | ligi | 334 | settings_field[7]=1; // gas |
220 | ligi | 335 | settings_field[8]=1; // hight |
336 | |||
221 | ligi | 337 | settings_field[9]=-4242; // no key |
338 | settings_field[10]=-4242; // no key |
||
339 | settings_field[11]=-4242; // no key |
||
340 | |||
220 | ligi | 341 | } |
342 | |||
343 | public void load() |
||
344 | { |
||
255 | ligi | 345 | tab_stringids=_tab_stringids; |
220 | ligi | 346 | |
255 | ligi | 347 | // tab_names=_tab_names; |
258 | ligi | 348 | |
220 | ligi | 349 | field_positions=_field_positions; |
350 | field_types=_field_types; |
||
258 | ligi | 351 | |
352 | choice_stringids=_choice_stringids; |
||
353 | |||
354 | field_stringids=_field_stringids; |
||
355 | //choice_strings=new String[_choice_strings.length+1][]; |
||
356 | /* |
||
357 | // FIXME |
||
358 | choice_strings[0]=new String[2]; |
||
359 | choice_strings[0][0]="English"; |
||
360 | choice_strings[0][1]="Deutsch"; |
||
361 | for ( int i=1; i<_choice_strings.length+1;i++) |
||
362 | { |
||
363 | choice_strings[i]=new String[_choice_strings[i-1].length+1]; |
||
364 | for ( int ii=0; ii<_choice_strings[i-1].length;ii++) |
||
365 | choice_strings[i][ii]=canvas.l(_choice_strings[i-1][ii]); |
||
366 | } |
||
367 | */ |
||
368 | // choice_strings=_choice_strings; |
||
206 | ligi | 369 | try |
370 | { |
||
371 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true ); |
||
372 | |||
373 | if (recStore.getNumRecords()==1) |
||
374 | { |
||
375 | ByteArrayInputStream bin = new ByteArrayInputStream(recStore.getRecord(1)); |
||
376 | DataInputStream din = new DataInputStream( bin ); |
||
377 | |||
378 | |||
379 | connection_url=din.readUTF(); |
||
380 | connection_name=din.readUTF(); |
||
220 | ligi | 381 | // reserve utf's |
382 | din.readUTF(); |
||
383 | din.readUTF(); |
||
384 | din.readUTF(); |
||
206 | ligi | 385 | |
386 | |||
387 | |||
220 | ligi | 388 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
389 | settings_field[i]=din.readInt(); |
||
211 | ligi | 390 | |
220 | ligi | 391 | for ( int i=0;i<5;i++) |
214 | ligi | 392 | |
206 | ligi | 393 | { |
394 | act_proxy_ip[i]=din.readInt(); |
||
395 | act_conn_ip[i]=din.readInt(); |
||
396 | } |
||
397 | |||
398 | } |
||
399 | recStore.closeRecordStore(); |
||
400 | } |
||
401 | catch (Exception e) |
||
402 | { } |
||
403 | |||
220 | ligi | 404 | |
405 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
||
406 | field2setting(i,settings_field[i]); |
||
407 | |||
206 | ligi | 408 | } |
409 | |||
410 | |||
411 | public void save() |
||
412 | { |
||
413 | try |
||
414 | { |
||
415 | RecordStore.deleteRecordStore(RECORD_STORE_NAME); |
||
416 | } |
||
417 | catch (Exception e) |
||
418 | { } |
||
419 | |||
420 | try { |
||
421 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true ); |
||
422 | |||
423 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
||
424 | DataOutputStream dout = new DataOutputStream( bout ); |
||
425 | |||
426 | dout.writeUTF(connection_url); |
||
427 | dout.writeUTF(connection_name); |
||
428 | |||
211 | ligi | 429 | dout.writeUTF(""); |
430 | dout.writeUTF(""); |
||
431 | dout.writeUTF(""); |
||
432 | |||
433 | |||
220 | ligi | 434 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
435 | dout.writeInt(settings_field[i]); |
||
206 | ligi | 436 | for ( int i=0;i<5;i++) |
437 | { |
||
438 | dout.writeInt(act_proxy_ip[i]); |
||
439 | dout.writeInt(act_conn_ip[i]); |
||
440 | } |
||
441 | recStore.addRecord(bout.toByteArray(),0,bout.size()); |
||
442 | |||
443 | recStore.closeRecordStore(); |
||
444 | |||
445 | |||
446 | } |
||
447 | catch (Exception e) |
||
448 | { } |
||
449 | |||
450 | } |
||
451 | |||
452 | } |