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