Rev 245 | Rev 258 | 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}; |
||
229 | public String[][] _field_names={ { "Language","Skin","Fullscreen","Scroll Background" |
||
222 | ligi | 230 | //#if devicecontrol=="on" |
231 | ,"Permanent Light" |
||
232 | //#endif |
||
229 | ligi | 233 | } , {"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 | 234 | |
255 | ligi | 235 | public String[][] _choice_strings={ { "Dark","Light" } , {"km/h","mp/h","cm/s"},{"decimal","min sec"},{"English","Deutsch"} } ; |
236 | public int[][] _field_positions={ {SETTINGS_POS_LANG,SETTINGS_POS_SKIN,8,9 |
||
222 | ligi | 237 | //#if devicecontrol=="on" |
238 | ,13 |
||
239 | //#endif |
||
233 | ligi | 240 | } , {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}}; |
255 | ligi | 241 | public int[][] _field_types={ {PARAMTYPE_CHOICE+3,PARAMTYPE_CHOICE+0,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH |
222 | ligi | 242 | //#if devicecontrol=="on" |
243 | ,PARAMTYPE_BITSWITCH |
||
244 | //#endif |
||
229 | ligi | 245 | } , {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 | 246 | DUBwiseCanvas canvas; |
247 | |||
248 | |||
229 | ligi | 249 | |
220 | ligi | 250 | public final static int SETTINGS_FIELD_LENGTH=42; |
251 | public DUBwiseSettings(DUBwiseCanvas _canvas) |
||
206 | ligi | 252 | { |
220 | ligi | 253 | canvas= _canvas; |
254 | settings_field=new int[SETTINGS_FIELD_LENGTH]; |
||
255 | default_extern_control=new byte[11]; |
||
256 | // set defaults |
||
257 | settings_field[4]=42; // nick |
||
258 | settings_field[5]=42; // roll |
||
259 | settings_field[6]=42; // gier |
||
245 | ligi | 260 | settings_field[7]=1; // gas |
220 | ligi | 261 | settings_field[8]=1; // hight |
262 | |||
221 | ligi | 263 | settings_field[9]=-4242; // no key |
264 | settings_field[10]=-4242; // no key |
||
265 | settings_field[11]=-4242; // no key |
||
266 | |||
220 | ligi | 267 | } |
268 | |||
269 | public void load() |
||
270 | { |
||
255 | ligi | 271 | tab_stringids=_tab_stringids; |
220 | ligi | 272 | |
255 | ligi | 273 | // tab_names=_tab_names; |
220 | ligi | 274 | field_names=_field_names; |
275 | field_positions=_field_positions; |
||
276 | field_types=_field_types; |
||
277 | choice_strings=_choice_strings; |
||
206 | ligi | 278 | try |
279 | { |
||
280 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true ); |
||
281 | |||
282 | if (recStore.getNumRecords()==1) |
||
283 | { |
||
284 | ByteArrayInputStream bin = new ByteArrayInputStream(recStore.getRecord(1)); |
||
285 | DataInputStream din = new DataInputStream( bin ); |
||
286 | |||
287 | |||
288 | connection_url=din.readUTF(); |
||
289 | connection_name=din.readUTF(); |
||
220 | ligi | 290 | // reserve utf's |
291 | din.readUTF(); |
||
292 | din.readUTF(); |
||
293 | din.readUTF(); |
||
206 | ligi | 294 | |
295 | |||
296 | |||
220 | ligi | 297 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
298 | settings_field[i]=din.readInt(); |
||
211 | ligi | 299 | |
220 | ligi | 300 | for ( int i=0;i<5;i++) |
214 | ligi | 301 | |
206 | ligi | 302 | { |
303 | act_proxy_ip[i]=din.readInt(); |
||
304 | act_conn_ip[i]=din.readInt(); |
||
305 | } |
||
306 | |||
307 | } |
||
308 | recStore.closeRecordStore(); |
||
309 | } |
||
310 | catch (Exception e) |
||
311 | { } |
||
312 | |||
220 | ligi | 313 | |
314 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
||
315 | field2setting(i,settings_field[i]); |
||
316 | |||
206 | ligi | 317 | } |
318 | |||
319 | |||
320 | public void save() |
||
321 | { |
||
322 | try |
||
323 | { |
||
324 | RecordStore.deleteRecordStore(RECORD_STORE_NAME); |
||
325 | } |
||
326 | catch (Exception e) |
||
327 | { } |
||
328 | |||
329 | try { |
||
330 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true ); |
||
331 | |||
332 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
||
333 | DataOutputStream dout = new DataOutputStream( bout ); |
||
334 | |||
335 | dout.writeUTF(connection_url); |
||
336 | dout.writeUTF(connection_name); |
||
337 | |||
211 | ligi | 338 | dout.writeUTF(""); |
339 | dout.writeUTF(""); |
||
340 | dout.writeUTF(""); |
||
341 | |||
342 | |||
220 | ligi | 343 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
344 | dout.writeInt(settings_field[i]); |
||
206 | ligi | 345 | for ( int i=0;i<5;i++) |
346 | { |
||
347 | dout.writeInt(act_proxy_ip[i]); |
||
348 | dout.writeInt(act_conn_ip[i]); |
||
349 | } |
||
350 | recStore.addRecord(bout.toByteArray(),0,bout.size()); |
||
351 | |||
352 | recStore.closeRecordStore(); |
||
353 | |||
354 | |||
355 | } |
||
356 | catch (Exception e) |
||
357 | { } |
||
358 | |||
359 | } |
||
360 | |||
361 | } |