/***************************************************************
*
* Settings related Part of DUBwise
* ( e.g. saving to / reading from RMS )
*
* Author: Marcus -LiGi- Bueschleb
* Mailto: LiGi @at@ LiGi DOTT de
*
***************************************************************/
import javax.microedition.rms.*;
import java.io.*;
public class DUBwiseSettings
extends org.
ligi.
ufo.
ParamsClass
implements org.
ligi.
ufo.
DUBwiseDefinitions,DUBwiseUIDefinitions
{
// name/handle for the recordStore to memorize some stuff
private final static String RECORD_STORE_NAME=
"DUBSETT_V4";
/* all settings hold here */
//holds id of actual skin
public byte act_skin=SKINID_DARK
;
public int key_back
;
public int key_fullscreen
;
public int key_clear
;
public int remote_cam_stick
;
public String connection_name=
"";
public String connection_url=
"";
public boolean do_vibra=
true;
public boolean do_sound=
true;
public boolean fullscreen=
false;
public boolean do_scrollbg=
false;
public boolean expert_mode=
false;
public byte gps_format=GPS_FORMAT_DECIMAL
;
public byte speed_format=SPEED_FORMAT_KMH
;
int[] settings_field
;
public int get_field_from_act
(int pos
) { return settings_field
[pos
];}
public void set_field_from_act
(int pos,
int val
){
settings_field
[pos
]=val
;
field2setting
(pos,val
);
}
public void toggle_fullscreen
()
{
// fullscreen=!fullscreen;
set_field_from_act
(1,settings_field
[1]^
1);
// if (fullscreen)canvas.setFullScreenMode(true);
}
public void field2setting
(int pos,
int val
)
{
if (pos==
0)
{
act_skin=
(byte)val
;
canvas.
load_skin_images();
}
if ((pos==
1)&&((val
&1)==
1)&&(!fullscreen
))
{
fullscreen=
true;
canvas.
setFullScreenMode(fullscreen
);
}
if ((pos==
1)&&((val
&1)==
0)&&(fullscreen
))
{
fullscreen=
false;
canvas.
setFullScreenMode(fullscreen
);
}
if ((pos==
1)&&((val
&2)==
2)&&(!do_scrollbg
))
{
do_scrollbg=
true;
canvas.
load_skin_images();
}
if ((pos==
1)&&((val
&2)==
0)&&(do_scrollbg
))
{
do_scrollbg=
false;
canvas.
load_skin_images();
}
if (pos==
1)
do_sound=
((val
&4)!=
0);
if (pos==
1)
do_vibra=
((val
&8)!=
0);
if (pos==
1)
expert_mode=
((val
&16)!=
0);
if (pos==
2)
gps_format=
(byte)val
;
if (pos==
3)
speed_format=
(byte)val
;
if (pos==
4)
default_extern_control
[EXTERN_CONTROL_NICK
]=
(byte)val
;
if (pos==
5)
default_extern_control
[EXTERN_CONTROL_ROLL
]=
(byte)val
;
if (pos==
6)
default_extern_control
[EXTERN_CONTROL_GIER
]=
(byte)val
;
if (pos==
7)
default_extern_control
[EXTERN_CONTROL_GAS
]=
(byte)val
;
if (pos==
8)
default_extern_control
[EXTERN_CONTROL_HIGHT
]=
(byte)val
;
if (pos==
9)
key_back=val
;
if (pos==
10)
key_fullscreen=val
;
if (pos==
11)
key_clear=val
;
if (pos==
12)
remote_cam_stick=val
;
}
public byte[] default_extern_control
;//=default_extern_keycontrol ;
//#if devicecontrol=="on"
public boolean keep_lighton=
false;
//#endif
int[] act_proxy_ip=default_ip
; // { ip , ip , ip , ip , port }
int[] act_conn_ip=default_ip
; // { ip , ip , ip , ip , port }
/* end of all settings hold here */
public String[] _tab_names=
{"User Interface",
"GPS",
"Keycontrol",
"Special Keys",
"Other" };
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"} };
public String[][] _choice_strings=
{ { "Dark",
"Light" } ,
{"km/h",
"mp/h",
"cm/s"},
{"decimal",
"min sec"}} ;
public int[][] _field_positions=
{ {0,
8,
9} ,
{2,
3} ,
{4,
5,
6,
7,
8} ,
{9,
10,
11},
{10,
11,
12,
12}};
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
}};
DUBwiseCanvas canvas
;
public final static int SETTINGS_FIELD_LENGTH=
42;
public DUBwiseSettings
(DUBwiseCanvas _canvas
)
{
canvas= _canvas
;
settings_field=
new int[SETTINGS_FIELD_LENGTH
];
default_extern_control=
new byte[11];
// set defaults
settings_field
[4]=
42; // nick
settings_field
[5]=
42; // roll
settings_field
[6]=
42; // gier
settings_field
[7]=
1; // fas
settings_field
[8]=
1; // hight
settings_field
[9]=-
4242; // no key
settings_field
[10]=-
4242; // no key
settings_field
[11]=-
4242; // no key
}
public void load
()
{
tab_names=_tab_names
;
field_names=_field_names
;
field_positions=_field_positions
;
field_types=_field_types
;
choice_strings=_choice_strings
;
try
{
RecordStore recStore = RecordStore.
openRecordStore(RECORD_STORE_NAME ,
true );
if (recStore.
getNumRecords()==
1)
{
ByteArrayInputStream bin =
new ByteArrayInputStream(recStore.
getRecord(1));
DataInputStream din =
new DataInputStream( bin
);
connection_url=din.
readUTF();
connection_name=din.
readUTF();
// reserve utf's
din.
readUTF();
din.
readUTF();
din.
readUTF();
for ( int i=
0;i
<SETTINGS_FIELD_LENGTH
;i++
)
settings_field
[i
]=din.
readInt();
for ( int i=
0;i
<5;i++
)
{
act_proxy_ip
[i
]=din.
readInt();
act_conn_ip
[i
]=din.
readInt();
}
}
recStore.
closeRecordStore();
}
catch (Exception e
)
{ }
for ( int i=
0;i
<SETTINGS_FIELD_LENGTH
;i++
)
field2setting
(i,settings_field
[i
]);
}
public void save
()
{
try
{
RecordStore.
deleteRecordStore(RECORD_STORE_NAME
);
}
catch (Exception e
)
{ }
try {
RecordStore recStore = RecordStore.
openRecordStore(RECORD_STORE_NAME,
true );
ByteArrayOutputStream bout =
new ByteArrayOutputStream();
DataOutputStream dout =
new DataOutputStream( bout
);
dout.
writeUTF(connection_url
);
dout.
writeUTF(connection_name
);
dout.
writeUTF("");
dout.
writeUTF("");
dout.
writeUTF("");
for ( int i=
0;i
<SETTINGS_FIELD_LENGTH
;i++
)
dout.
writeInt(settings_field
[i
]);
for ( int i=
0;i
<5;i++
)
{
dout.
writeInt(act_proxy_ip
[i
]);
dout.
writeInt(act_conn_ip
[i
]);
}
recStore.
addRecord(bout.
toByteArray(),
0,bout.
size());
recStore.
closeRecordStore();
}
catch (Exception e
)
{ }
}
}