/***************************************************************
*
* 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,org.
ligi.
ufo.
DUBwiseLangDefs
{
// 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 voice_delay
;
public int voice_volume
;
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 boolean reload_settings=
false;
public boolean graph_legend
;
public boolean graph_scale
;
//#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 }
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 final static int SETTINGS_POS_SKIN=
0;
public final static int SETTINGS_POS_BITFIELD1=
1;
public final static int SETTINGS_POS_GPS_FORMAT=
2;
public final static int SETTINGS_POS_SPEED_FORMAT=
3;
public final static int SETTINGS_POS_EXTERN_NICK=
4;
public final static int SETTINGS_POS_EXTERN_ROLL=
5;
public final static int SETTINGS_POS_EXTERN_GIER=
6;
public final static int SETTINGS_POS_EXTERN_GAS=
7;
public final static int SETTINGS_POS_EXTERN_HIGHT=
8;
public final static int SETTINGS_POS_KEY_BACK=
9;
public final static int SETTINGS_POS_KEY_FULL=
10;
public final static int SETTINGS_POS_KEY_CLEAR=
11;
public final static int SETTINGS_POS_VOICEVOLUME=
12;
public final static int SETTINGS_POS_VOICEDELAY=
13;
public final static int SETTINGS_POS_BITFIELD2=
14;
public final static int SETTINGS_POS_LANG=
15;
public void field2setting
(int pos,
int val
)
{
if (pos==SETTINGS_POS_LANG
)
{
canvas.
act_lang=
(byte)val
;
canvas.
load_strings();
}
if (pos==SETTINGS_POS_SKIN
)
{
act_skin=
(byte)val
;
canvas.
load_skin_images();
}
if ((pos==SETTINGS_POS_BITFIELD1
)&&((val
&1)==
1)&&(!fullscreen
))
{
fullscreen=
true;
canvas.
setFullScreenMode(fullscreen
);
}
if ((pos==SETTINGS_POS_BITFIELD1
)&&((val
&1)==
0)&&(fullscreen
))
{
fullscreen=
false;
canvas.
setFullScreenMode(fullscreen
);
}
if ((pos==SETTINGS_POS_BITFIELD1
)&&((val
&2)==
2)&&(!do_scrollbg
))
{
do_scrollbg=
true;
canvas.
load_skin_images();
}
if ((pos==SETTINGS_POS_BITFIELD1
)&&((val
&2)==
0)&&(do_scrollbg
))
{
do_scrollbg=
false;
canvas.
load_skin_images();
}
if (pos==SETTINGS_POS_BITFIELD1
)
do_sound=
((val
&4)!=
0);
if (pos==SETTINGS_POS_BITFIELD1
)
do_vibra=
((val
&8)!=
0);
if (pos==SETTINGS_POS_BITFIELD1
)
expert_mode=
((val
&16)!=
0);
if (pos==SETTINGS_POS_BITFIELD1
)
keep_lighton=
((val
&32)!=
0);
if (pos==SETTINGS_POS_BITFIELD1
)
graph_legend=
((val
&64)!=
0);
if (pos==SETTINGS_POS_BITFIELD1
)
graph_scale=
((val
&128)!=
0);
if (pos==SETTINGS_POS_GPS_FORMAT
)
gps_format=
(byte)val
;
if (pos==SETTINGS_POS_SPEED_FORMAT
)
speed_format=
(byte)val
;
if (pos==SETTINGS_POS_EXTERN_NICK
)
default_extern_control
[EXTERN_CONTROL_NICK
]=
(byte)val
;
if (pos==SETTINGS_POS_EXTERN_ROLL
)
default_extern_control
[EXTERN_CONTROL_ROLL
]=
(byte)val
;
if (pos==SETTINGS_POS_EXTERN_GIER
)
default_extern_control
[EXTERN_CONTROL_GIER
]=
(byte)val
;
if (pos==SETTINGS_POS_EXTERN_GAS
)
default_extern_control
[EXTERN_CONTROL_GAS
]=
(byte)val
;
if (pos==SETTINGS_POS_EXTERN_HIGHT
)
default_extern_control
[EXTERN_CONTROL_HIGHT
]=
(byte)val
;
if (pos==SETTINGS_POS_KEY_BACK
)
key_back=val
;
if (pos==SETTINGS_POS_KEY_FULL
)
key_fullscreen=val
;
if (pos==SETTINGS_POS_KEY_CLEAR
)
key_clear=val
;
if (pos==
12)
remote_cam_stick=val
;
if(pos==SETTINGS_POS_VOICEVOLUME
)
{
voice_volume=val
;
//#if voice_mode!="no_voice"
canvas.
status_voice.
volume=voice_volume
;
//#endif
}
if(pos==SETTINGS_POS_VOICEDELAY
)
{
voice_delay=val
;
//#if voice_mode!="no_voice"
canvas.
status_voice.
delay=voice_delay
;
//#endif
}
if (pos==SETTINGS_POS_BITFIELD2
)
do_sound=
((val
&1)!=
0); // TODO: FIXME - extra var
if (pos==SETTINGS_POS_BITFIELD2
)
reload_settings=
((val
&2)!=
0);
}
public byte[] default_extern_control
;//=default_extern_keycontrol ;
/* end of all settings hold here */
// public String[] _tab_names={"User Interface","GPS","Keycontrol","Special Keys","Graph","Voice","Other" };
public int[] _tab_stringids=
{STRINGID_USERINTERFACE,STRINGID_GPS,STRINGID_KEYCONTROL,STRINGID_SPECIALKEYS,STRINGID_GRAPH,STRINGID_VOICE,STRINGID_OTHER
};
public int[][] _field_stringids =
{
{
STRINGID_LANGUAGE,
STRINGID_SKIN,
STRINGID_FULLSCREEN,
STRINGID_SCROLLBG
//#if devicecontrol=="on"
,STRINGID_PERMALIGHT
//#endif
},
{ STRINGID_GPSFORMAT, STRINGID_SPEEDFORMAT
},
{ STRINGID_NICK ,STRINGID_ROLL,STRINGID_GIER,STRINGID_GASINCREASE,STRINGID_HEIGHTINCREASE
},
{STRINGID_BACKTOMAINMENU,STRINGID_FULLSCREEN,STRINGID_CLEAR
},
{STRINGID_LEGEND,STRINGID_SCALEGRID
},
{STRINGID_VOLTS,STRINGID_DELAYINS,STRINGID_VOLUME
},
{STRINGID_SOUND,STRINGID_VIBRA,STRINGID_REMOTECAMSTICK,STRINGID_ALWAYSRELOADPARAMS,STRINGID_EXPERTMODE
}};
// public String[][] _choice_strings={ { "Dark","Light" } , {"km/h","mp/h","cm/s"},{"decimal","min sec"},{"English","Deutsch"} } ;
public int[][] _choice_stringids=
{ {STRINGID_LANG0,STRINGID_LANG1
},
/* FIXME - make dynamic */{ STRINGID_DARK,STRINGID_LIGHT
} ,
{STRINGID_KMH,STRINGID_MPH,STRINGID_CMS
},
{STRINGID_DECIMAL,STRINGID_MINSEC
} } ;
public int[][] _field_positions=
{ {SETTINGS_POS_LANG,SETTINGS_POS_SKIN,
8,
9
//#if devicecontrol=="on"
,
13
//#endif
} ,
{2,
3} ,
{4,
5,
6,
7,
8} ,
{9,
10,
11},
{SETTINGS_POS_BITFIELD1
*8 +
6,SETTINGS_POS_BITFIELD1
*8 +
7} ,
{SETTINGS_POS_BITFIELD2
*8+
0,SETTINGS_POS_VOICEDELAY,SETTINGS_POS_VOICEVOLUME
},
{10,
11,
12,SETTINGS_POS_BITFIELD2
*8+
1,
12}};
public int[][] _field_types=
{ {PARAMTYPE_CHOICE+
0,PARAMTYPE_CHOICE+
1,PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH
//#if devicecontrol=="on"
,PARAMTYPE_BITSWITCH
//#endif
} ,
{PARAMTYPE_CHOICE+
2,PARAMTYPE_CHOICE+
3} ,
{PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_KEY,PARAMTYPE_KEY,PARAMTYPE_KEY
} ,
{PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH
},
{PARAMTYPE_BITSWITCH,PARAMTYPE_BYTE,PARAMTYPE_BYTE
},
{PARAMTYPE_BITSWITCH,PARAMTYPE_BITSWITCH,PARAMTYPE_STICK,PARAMTYPE_BITSWITCH,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; // gas
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_stringids=_tab_stringids
;
// tab_names=_tab_names;
field_positions=_field_positions
;
field_types=_field_types
;
choice_stringids=_choice_stringids
;
field_stringids=_field_stringids
;
//choice_strings=new String[_choice_strings.length+1][];
/*
// FIXME
choice_strings[0]=new String[2];
choice_strings[0][0]="English";
choice_strings[0][1]="Deutsch";
for ( int i=1; i<_choice_strings.length+1;i++)
{
choice_strings[i]=new String[_choice_strings[i-1].length+1];
for ( int ii=0; ii<_choice_strings[i-1].length;ii++)
choice_strings[i][ii]=canvas.l(_choice_strings[i-1][ii]);
}
*/
// 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
)
{ }
}
}