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