/***********************************************************************
*
* DUBwise == Digital UFO Broadcasting with intelligent service equipment
* main MIDLet Source file
*
* Author: Marcus -LiGi- Bueschleb
* Mailto: LiGi @at@ LiGi DOTT de
*
************************************************************************/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class DUBwiseInstaller
extends MIDlet
implements Runnable,CommandListener
{
public String[] installmethod_strings=
{"online Install",
"show Filename"};//,"email URL"};
public String[] installoption_strings=
{"default",
"full featured",
"minimal",
"custom",
"expert"};
public final static byte INSTALLOPTIONID_DEFAULT=
0;
public final static byte INSTALLOPTIONID_FULL=
1;
public final static byte INSTALLOPTIONID_MINIMAL=
2;
public final static byte INSTALLOPTIONID_CUSTOM=
3;
public final static byte INSTALLOPTIONID_EXPERT=
4;
public final static byte INSTALLMETHODID_ONLINE=
0;
public final static byte INSTALLMETHODID_SHOWURL=
1;
public Display display
;
public DUBwiseInstallerCanvas canvas
;
private DUBwiseProps props
;
public boolean app_running=
false; // to prevent 2 instances
String browser_dest=
"";
String helper_url=
null;
String download_url=
null;
boolean http_possible
;
Form installoptions_form
;
Form install_form
;
ChoiceGroup installmethod_choice
;
ChoiceGroup installoption_choice
;
ChoiceGroup sound_choice
;
ChoiceGroup firmware_choice
;
ChoiceGroup optional_features_choice
;
Form expert_form
;
ChoiceGroup res_choice
;
ChoiceGroup device_features_choice
;
ChoiceGroup installsrc_choice
;
protected void startApp
()
throws MIDletStateChangeException
{
if (app_running
)return;
display = Display.
getDisplay(this);
canvas=
new DUBwiseInstallerCanvas
(this);
// fire up canvas
display.
setCurrent(canvas
);
}
public String getURL
()
{
return download_url+props.
installsrc_str()+
"/"+props.
getFileName();
}
public boolean url_check
()
{
return (InstallHelper.
get_http_string(getURL
()).
startsWith("MIDlet-Jar-URL:"));
}
// fire up browser for online install
public void run
()
{
helper_url=InstallHelper.
get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/helper_url") ;
http_possible=
((!helper_url.
equals("err")));
download_url=InstallHelper.
get_http_string("http://mikrocontroller.cco-ev.de/mikrosvn/Projects/DUBwise/trunk/misc/installer_meta/dl_url") ;
if ((download_url==
null) ||
(!download_url.
startsWith("http")))
download_url=helper_url+
"dl/";
if (http_possible
) System.
out.
println(InstallHelper.
get_http_string(helper_url+
"mail?subject=DUBwiseInstall&text="+InstallHelper.
urlEncode( "Installer Version: 0.8 \nDownload URL:" + getURL
() +
"\nDownload OK:" + url_check
()+
"\nInstall Options:" + installoption_strings
[installoption_choice.
getSelectedIndex()] +
"\n\n------Device Infos---\n" + canvas.
description_str() +
"\n" )));
try
{
Thread.
sleep(500);
platformRequest
(getURL
());
}
catch ( Exception e
) {}
notifyDestroyed
(); //quit
}
public void canvas_hw_detect_finish
()
{
props=
new DUBwiseProps
();
props.
set_res_by_screensize(canvas.
canvas_width,canvas.
canvas_height);
props.
bluetooth=canvas.
bluetooth;
props.
locationprovider=canvas.
locationprovider;
props.
fileapi=canvas.
fileapi;
props.
devicecontrol=canvas.
devicecontrol;
props.
cldc11=canvas.
cldc11;
// create forms
install_form =
new Form
("Install DUBwise");
installoptions_form=
new Form
("Install Options");
expert_form=
new Form
("Expert Settings");
// create widgets
res_choice =
new ChoiceGroup
(
"Resolution (Detected " +canvas.
canvas_full_width +
"x"+ canvas.
canvas_full_height+
")",
Choice.
EXCLUSIVE,
props.
res_strings,
null);
res_choice.
setSelectedIndex(props.
res_select,
true);
expert_form.
append(res_choice
);
device_features_choice =
new ChoiceGroup
(
"Features ",
Choice.
MULTIPLE,
props.
feature_strings,
null);
device_features_choice.
setSelectedIndex(0,props.
bluetooth);
device_features_choice.
setSelectedIndex(1,props.
locationprovider);
device_features_choice.
setSelectedIndex(2,props.
fileapi);
device_features_choice.
setSelectedIndex(3,props.
devicecontrol);
device_features_choice.
setSelectedIndex(4,props.
cldc11);
expert_form.
append(device_features_choice
);
System.
out.
println("install build");
/* Install form */
optional_features_choice =
new ChoiceGroup
(
"Optional Features ",
Choice.
MULTIPLE,
props.
optional_feature_strings,
null);
//
installmethod_choice =
new ChoiceGroup
(
"Install Method",
Choice.
EXCLUSIVE,
installmethod_strings,
null);
installoption_choice =
new ChoiceGroup
(
"Install Options",
Choice.
EXCLUSIVE,
installoption_strings,
null);
/* device_features_choice = new ChoiceGroup(
"Features ",
Choice.MULTIPLE,
feature_strings,
null);
*/
firmware_choice =
new ChoiceGroup
(
"Firmwares:",
Choice.
EXCLUSIVE,
props.
firmware_strings,
null);
firmware_choice.
setSelectedIndex(props.
firmware_select,
true);
sound_choice =
new ChoiceGroup
(
"Sound ",
Choice.
EXCLUSIVE,
props.
sound_strings,
null);
sound_choice.
setSelectedIndex(props.
sound_select,
true);
install_form.
append(installmethod_choice
);
install_form.
append(installoption_choice
);
installoptions_form.
append(optional_features_choice
);
installoptions_form.
append(firmware_choice
);
installoptions_form.
append(sound_choice
);
expert_form.
addCommand(new Command
("OK", Command.
OK,
1));
expert_form.
addCommand(new Command
("Back", Command.
BACK,
2));
installoptions_form.
addCommand(new Command
("OK", Command.
OK,
1));
installoptions_form.
addCommand(new Command
("Back", Command.
BACK,
2));
install_form.
addCommand(new Command
("OK", Command.
OK,
1));
install_form.
addCommand(new Command
("Exit", Command.
EXIT,
2));
// set this class as the command listener
installoptions_form.
setCommandListener(this);
install_form.
setCommandListener(this);
expert_form.
setCommandListener(this);
if (!canvas.
bluetooth)
{
Alert myAlert =
new Alert
("Warning",
"The Bluetooth API (JSR-82) on your Phone was not found. Without this API DUBwise is not very usefull for most users ( You can only connect via TCP/IP or Serial port ). \n If you have a Windows Mobile Phone this issue can be solved by using DUBwise with a diffrent JRE ( PhoneME or J9 ).\n There is Information in the Internet to show you how to do that - just use your preferred search engine.",
null, AlertType.
ERROR);
myAlert.
setTimeout(Alert.
FOREVER);
display.
setCurrent( myAlert,install_form
);
}
else
display.
setCurrent( install_form
);
}
public void show_url_form
()
{
Form url_form =
new Form
("FileName");
TextField txtField =
new TextField(
"FileName", props.
getFileName() ,
250,
TextField.
ANY);
url_form.
append(txtField
);
url_form.
setCommandListener(this);
url_form.
addCommand(new Command
("Exit", Command.
EXIT,
1));
url_form.
addCommand(new Command
("Back", Command.
BACK,
2));
display.
setCurrent(url_form
);
}
public void process_edit_form
()
{
// copy form to props
props.
res_select=res_choice.
getSelectedIndex();
props.
firmware_select=firmware_choice.
getSelectedIndex();
props.
sound_select=sound_choice.
getSelectedIndex();
// installsrc_select= installsrc_choice.getSelectedIndex();
props.
bluetooth= device_features_choice.
isSelected(0);
props.
locationprovider=device_features_choice.
isSelected(1);
props.
fileapi= device_features_choice.
isSelected(2);
props.
devicecontrol= device_features_choice.
isSelected(3);
props.
cldc11 = device_features_choice.
isSelected(4);
props.
j2memaps = optional_features_choice.
isSelected(0);
switch (installmethod_choice.
getSelectedIndex())
{
case INSTALLMETHODID_ONLINE:
// online Install -> fire up browser
new Thread(this).
start();
break;
case INSTALLMETHODID_SHOWURL:
// show URL -> fire up browser
show_url_form
();
break;
}
}
public void commandAction
( Command cmd, Displayable dis
)
{
switch(cmd.
getCommandType())
{
case Command.
BACK:
if(dis==expert_form
)
display.
setCurrent(installoptions_form
);
else
switch(installoption_choice.
getSelectedIndex())
{
case INSTALLOPTIONID_CUSTOM:
display.
setCurrent(installoptions_form
);
case INSTALLOPTIONID_EXPERT:
display.
setCurrent(expert_form
);
break;
default:
display.
setCurrent(install_form
);
}
break;
case Command.
EXIT:
notifyDestroyed
();
break;
case Command.
ITEM:
display.
setCurrent(expert_form
);
break;
case Command.
OK:
if (dis==install_form
)
switch(installoption_choice.
getSelectedIndex())
{
case INSTALLOPTIONID_DEFAULT:
firmware_choice.
setSelectedIndex(0,
true);
sound_choice.
setSelectedIndex(1,
true);
process_edit_form
();
break;
case INSTALLOPTIONID_MINIMAL:
firmware_choice.
setSelectedIndex(0,
true);
sound_choice.
setSelectedIndex(0,
true);
process_edit_form
();
break;
case INSTALLOPTIONID_FULL:
firmware_choice.
setSelectedIndex(1,
true);
sound_choice.
setSelectedIndex(1,
true);
process_edit_form
();
break;
case INSTALLOPTIONID_CUSTOM:
case INSTALLOPTIONID_EXPERT:
display.
setCurrent(installoptions_form
);
break;
}
else if (dis==installoptions_form
)
{
switch(installoption_choice.
getSelectedIndex())
{
case INSTALLOPTIONID_CUSTOM:
process_edit_form
();
break;
case INSTALLOPTIONID_EXPERT:
display.
setCurrent(expert_form
);
break;
}
}
else if (dis==expert_form
)
process_edit_form
();
break;
}
}
protected void pauseApp
() {} // not needed right now
protected void destroyApp
(boolean arg0
) { }
}