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