Rev 221 | Rev 229 | 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 |
||
211 | ligi | 17 | implements org.ligi.ufo.DUBwiseDefinitions,DUBwiseUIDefinitions |
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 | |
27 | |||
28 | public int key_back; |
||
29 | public int key_fullscreen; |
||
30 | public int key_clear; |
||
31 | |||
32 | public int remote_cam_stick; |
||
33 | |||
206 | ligi | 34 | public String connection_name=""; |
35 | public String connection_url=""; |
||
36 | |||
37 | public boolean do_vibra=true; |
||
38 | public boolean do_sound=true; |
||
39 | public boolean fullscreen=false; |
||
40 | public boolean do_scrollbg=false; |
||
214 | ligi | 41 | public boolean expert_mode=false; |
206 | ligi | 42 | |
222 | ligi | 43 | //#if devicecontrol=="on" |
44 | public boolean keep_lighton=false; |
||
45 | //#endif |
||
206 | ligi | 46 | |
222 | ligi | 47 | int[] act_proxy_ip=default_ip; // { ip , ip , ip , ip , port } |
48 | int[] act_conn_ip=default_ip; // { ip , ip , ip , ip , port } |
||
49 | |||
50 | |||
211 | ligi | 51 | public byte gps_format=GPS_FORMAT_DECIMAL; |
52 | public byte speed_format=SPEED_FORMAT_KMH; |
||
53 | |||
54 | |||
220 | ligi | 55 | int[] settings_field; |
211 | ligi | 56 | |
220 | ligi | 57 | public int get_field_from_act(int pos) { return settings_field[pos];} |
58 | public void set_field_from_act(int pos,int val){ |
||
59 | |||
60 | settings_field[pos]=val; |
||
61 | field2setting(pos,val); |
||
62 | } |
||
63 | |||
64 | public void toggle_fullscreen() |
||
65 | { |
||
66 | // fullscreen=!fullscreen; |
||
67 | set_field_from_act(1,settings_field[1]^1); |
||
68 | // if (fullscreen)canvas.setFullScreenMode(true); |
||
69 | } |
||
222 | ligi | 70 | |
71 | public final static int SETTINGS_POS_SKIN=0; |
||
72 | public final static int SETTINGS_POS_BITFIELD1=1; |
||
73 | public final static int SETTINGS_POS_GPS_FORMAT=2; |
||
74 | public final static int SETTINGS_POS_SPEED_FORMAT=3; |
||
75 | public final static int SETTINGS_POS_EXTERN_NICK=4; |
||
76 | public final static int SETTINGS_POS_EXTERN_ROLL=5; |
||
77 | public final static int SETTINGS_POS_EXTERN_GIER=6; |
||
78 | public final static int SETTINGS_POS_EXTERN_GAS=7; |
||
79 | public final static int SETTINGS_POS_EXTERN_HIGHT=8; |
||
80 | public final static int SETTINGS_POS_KEY_BACK=9; |
||
81 | public final static int SETTINGS_POS_KEY_FULL=10; |
||
82 | public final static int SETTINGS_POS_KEY_CLEAR=11; |
||
83 | |||
84 | |||
220 | ligi | 85 | public void field2setting(int pos,int val) |
86 | { |
||
87 | |||
222 | ligi | 88 | if (pos==SETTINGS_POS_SKIN) |
220 | ligi | 89 | { |
90 | act_skin=(byte)val; |
||
221 | ligi | 91 | canvas.load_skin_images(); |
220 | ligi | 92 | } |
93 | |||
222 | ligi | 94 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==1)&&(!fullscreen)) |
220 | ligi | 95 | { |
96 | fullscreen=true; |
||
97 | canvas.setFullScreenMode(fullscreen); |
||
98 | } |
||
99 | |||
222 | ligi | 100 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&1)==0)&&(fullscreen)) |
220 | ligi | 101 | { |
102 | fullscreen=false; |
||
103 | canvas.setFullScreenMode(fullscreen); |
||
104 | } |
||
105 | |||
222 | ligi | 106 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==2)&&(!do_scrollbg)) |
220 | ligi | 107 | { |
108 | do_scrollbg=true; |
||
221 | ligi | 109 | canvas.load_skin_images(); |
220 | ligi | 110 | } |
111 | |||
222 | ligi | 112 | if ((pos==SETTINGS_POS_BITFIELD1)&&((val&2)==0)&&(do_scrollbg)) |
220 | ligi | 113 | { |
114 | do_scrollbg=false; |
||
221 | ligi | 115 | canvas.load_skin_images(); |
220 | ligi | 116 | } |
117 | |||
222 | ligi | 118 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 119 | do_sound=((val&4)!=0); |
120 | |||
222 | ligi | 121 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 122 | do_vibra=((val&8)!=0); |
123 | |||
222 | ligi | 124 | if (pos==SETTINGS_POS_BITFIELD1) |
220 | ligi | 125 | expert_mode=((val&16)!=0); |
126 | |||
222 | ligi | 127 | if (pos==SETTINGS_POS_BITFIELD1) |
128 | keep_lighton=((val&32)!=0); |
||
129 | |||
130 | if (pos==SETTINGS_POS_GPS_FORMAT) |
||
220 | ligi | 131 | gps_format=(byte)val; |
132 | |||
222 | ligi | 133 | if (pos==SETTINGS_POS_SPEED_FORMAT) |
220 | ligi | 134 | speed_format=(byte)val; |
135 | |||
222 | ligi | 136 | if (pos==SETTINGS_POS_EXTERN_NICK) |
220 | ligi | 137 | default_extern_control[EXTERN_CONTROL_NICK]=(byte)val; |
138 | |||
222 | ligi | 139 | if (pos==SETTINGS_POS_EXTERN_ROLL) |
220 | ligi | 140 | default_extern_control[EXTERN_CONTROL_ROLL]=(byte)val; |
141 | |||
222 | ligi | 142 | if (pos==SETTINGS_POS_EXTERN_GIER) |
220 | ligi | 143 | default_extern_control[EXTERN_CONTROL_GIER]=(byte)val; |
144 | |||
222 | ligi | 145 | if (pos==SETTINGS_POS_EXTERN_GAS) |
220 | ligi | 146 | default_extern_control[EXTERN_CONTROL_GAS]=(byte)val; |
147 | |||
222 | ligi | 148 | if (pos==SETTINGS_POS_EXTERN_HIGHT) |
220 | ligi | 149 | default_extern_control[EXTERN_CONTROL_HIGHT]=(byte)val; |
221 | ligi | 150 | |
151 | |||
222 | ligi | 152 | if (pos==SETTINGS_POS_KEY_BACK) |
221 | ligi | 153 | key_back=val; |
154 | |||
222 | ligi | 155 | if (pos==SETTINGS_POS_KEY_FULL) |
221 | ligi | 156 | key_fullscreen=val; |
157 | |||
222 | ligi | 158 | if (pos==SETTINGS_POS_KEY_CLEAR) |
221 | ligi | 159 | key_clear=val; |
160 | |||
161 | if (pos==12) |
||
162 | remote_cam_stick=val; |
||
220 | ligi | 163 | } |
164 | |||
165 | |||
166 | public byte[] default_extern_control;//=default_extern_keycontrol ; |
||
167 | |||
206 | ligi | 168 | |
169 | /* end of all settings hold here */ |
||
170 | |||
220 | ligi | 171 | public String[] _tab_names={"User Interface","GPS","Keycontrol","Special Keys","Other" }; |
172 | |||
222 | ligi | 173 | public String[][] _field_names={ { "Skin","Fullscreen","Scroll Background" |
174 | //#if devicecontrol=="on" |
||
175 | ,"Permanent Light" |
||
176 | //#endif |
||
177 | } , {"GPS Format","Speed Format"},{"Nick","Roll","Gier","Gas Increase","Height Increase"},{"Back","Fullscreen","Clear"},{"Sound","Vibra","Remote Cam Stick","Expert-Mode"} }; |
||
220 | ligi | 178 | |
221 | ligi | 179 | public String[][] _choice_strings={ { "Dark","Light" } , {"km/h","mp/h","cm/s"},{"decimal","min sec"}} ; |
222 | ligi | 180 | public int[][] _field_positions={ {SETTINGS_POS_SKIN,8,9 |
181 | //#if devicecontrol=="on" |
||
182 | ,13 |
||
183 | //#endif |
||
184 | } , {2,3} , {4,5,6,7,8} , {9,10,11}, {10,11,12,12}}; |
||
185 | public int[][] _field_types={ {PARAMTYPE_CHOICE+0,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH |
||
186 | //#if devicecontrol=="on" |
||
187 | ,PARAMTYPE_BITSWITCH |
||
188 | //#endif |
||
189 | } , {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_STICK,PARAMTYPE_BITSWITCH}}; |
||
220 | ligi | 190 | DUBwiseCanvas canvas; |
191 | |||
192 | |||
193 | public final static int SETTINGS_FIELD_LENGTH=42; |
||
194 | public DUBwiseSettings(DUBwiseCanvas _canvas) |
||
206 | ligi | 195 | { |
220 | ligi | 196 | canvas= _canvas; |
197 | settings_field=new int[SETTINGS_FIELD_LENGTH]; |
||
198 | default_extern_control=new byte[11]; |
||
199 | // set defaults |
||
200 | settings_field[4]=42; // nick |
||
201 | settings_field[5]=42; // roll |
||
202 | settings_field[6]=42; // gier |
||
203 | settings_field[7]=1; // fas |
||
204 | settings_field[8]=1; // hight |
||
205 | |||
221 | ligi | 206 | |
207 | settings_field[9]=-4242; // no key |
||
208 | settings_field[10]=-4242; // no key |
||
209 | settings_field[11]=-4242; // no key |
||
210 | |||
220 | ligi | 211 | } |
212 | |||
213 | public void load() |
||
214 | { |
||
215 | |||
216 | tab_names=_tab_names; |
||
217 | field_names=_field_names; |
||
218 | field_positions=_field_positions; |
||
219 | field_types=_field_types; |
||
220 | choice_strings=_choice_strings; |
||
206 | ligi | 221 | try |
222 | { |
||
223 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME , true ); |
||
224 | |||
225 | if (recStore.getNumRecords()==1) |
||
226 | { |
||
227 | ByteArrayInputStream bin = new ByteArrayInputStream(recStore.getRecord(1)); |
||
228 | DataInputStream din = new DataInputStream( bin ); |
||
229 | |||
230 | |||
231 | connection_url=din.readUTF(); |
||
232 | connection_name=din.readUTF(); |
||
220 | ligi | 233 | // reserve utf's |
234 | din.readUTF(); |
||
235 | din.readUTF(); |
||
236 | din.readUTF(); |
||
206 | ligi | 237 | |
238 | |||
239 | |||
220 | ligi | 240 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
241 | settings_field[i]=din.readInt(); |
||
211 | ligi | 242 | |
220 | ligi | 243 | for ( int i=0;i<5;i++) |
214 | ligi | 244 | |
206 | ligi | 245 | { |
246 | act_proxy_ip[i]=din.readInt(); |
||
247 | act_conn_ip[i]=din.readInt(); |
||
248 | } |
||
249 | |||
250 | } |
||
251 | recStore.closeRecordStore(); |
||
252 | } |
||
253 | catch (Exception e) |
||
254 | { } |
||
255 | |||
220 | ligi | 256 | |
257 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
||
258 | field2setting(i,settings_field[i]); |
||
259 | |||
206 | ligi | 260 | } |
261 | |||
262 | |||
263 | public void save() |
||
264 | { |
||
265 | try |
||
266 | { |
||
267 | RecordStore.deleteRecordStore(RECORD_STORE_NAME); |
||
268 | } |
||
269 | catch (Exception e) |
||
270 | { } |
||
271 | |||
272 | try { |
||
273 | RecordStore recStore = RecordStore.openRecordStore(RECORD_STORE_NAME, true ); |
||
274 | |||
275 | ByteArrayOutputStream bout = new ByteArrayOutputStream(); |
||
276 | DataOutputStream dout = new DataOutputStream( bout ); |
||
277 | |||
278 | dout.writeUTF(connection_url); |
||
279 | dout.writeUTF(connection_name); |
||
280 | |||
211 | ligi | 281 | dout.writeUTF(""); |
282 | dout.writeUTF(""); |
||
283 | dout.writeUTF(""); |
||
284 | |||
285 | |||
220 | ligi | 286 | for ( int i=0;i<SETTINGS_FIELD_LENGTH;i++) |
287 | dout.writeInt(settings_field[i]); |
||
206 | ligi | 288 | for ( int i=0;i<5;i++) |
289 | { |
||
290 | dout.writeInt(act_proxy_ip[i]); |
||
291 | dout.writeInt(act_conn_ip[i]); |
||
292 | } |
||
293 | recStore.addRecord(bout.toByteArray(),0,bout.size()); |
||
294 | |||
295 | recStore.closeRecordStore(); |
||
296 | |||
297 | |||
298 | } |
||
299 | catch (Exception e) |
||
300 | { } |
||
301 | |||
302 | } |
||
303 | |||
304 | } |