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