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