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