📄 main.java
字号:
package no.auc.one.portableplayer;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Gauge;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
//import no.auc.one.portableplayer.communication.UPnPPresenceAdvertisementHandling;
import no.auc.one.portableplayer.communication.upnphosting.UPnPHosting;
import no.auc.one.portableplayer.lmr.MediaRenderer;
import no.auc.one.portableplayer.lms.ServerDevice;
import no.auc.one.portableplayer.settings.Settings;
import no.auc.one.portableplayer.userinterface.UI;
import org.apache.log4j.LogActivator;
import org.apache.log4j.Logger;
import ch.ethz.jadabs.osgi.j2me.OSGiContainer;
/**
* Main is the startup class and responsible for starting the user interface
* subsystem which controls the rest of the application.
*
*/
public class Main extends MIDlet {
public static Logger LOG;
//private UPnPPresenceAdvertisementHandling pah;
private boolean isPaused = false;
public Main() {
// create OSGi container and set container
// properties from the MIDP application properties
OSGiContainer osgicontainer = OSGiContainer.Instance();
String priority = getAppProperty("ONEPP-Log4J-Priority");
if (priority == null) {
priority = "DEBUG";
}
osgicontainer.setProperty(
"log4j.priority",
priority);
osgicontainer.startBundle(new LogActivator());
// obtain a Logger from the logger factory for this class
LOG = Logger.getLogger("Main");
}
/**
* Pass control over to the user interface subsystem.
*/
protected void startApp() throws MIDletStateChangeException {
if (!isPaused) {
try {
Display d = javax.microedition.lcdui.Display.getDisplay(this);
Logger.getLogCanvas().setDisplay(d);
StartScreen sc = new StartScreen("Starting...");
d.setCurrent(sc);
Settings settings = Settings.createInstance(this);
UI ui = UI.getInstance(this);
System.out.println("UI initialized");
UPnPHosting hosting = UPnPHosting.getInstance();
hosting.start();
sc.progress.setValue(10);
System.out.println("Hosting started");
LOG.debug("Registering LMS");
ServerDevice sd = ServerDevice.getInstance();
hosting.registerDevice(sd);
sc.progress.setValue(20);
System.out.println("LMS registered");
LOG.debug("Registering LMR");
MediaRenderer mr = MediaRenderer.getInstance();
hosting.registerDevice(mr);
sc.progress.setValue(40);
System.out.println("LMR registered");
LOG.debug("Adding LMR to MR list");
settings.addMediaRendererByLocationUrl(
"http://" + hosting.getLocalAddress() + ":" +
hosting.getLocalPort() + "/ssdp/" + mr.udn() +
"/devicedescription.xml");
sc.progress.setValue(50);
LOG.debug("Adding LMS to MS list");
settings.addMediaServerByLocationUrl(
"http://" + hosting.getLocalAddress() + ":" +
hosting.getLocalPort() + "/ssdp/" + sd.udn() +
"/devicedescription.xml");
sc.progress.setValue(60);
settings.loadSettings();
sc.progress.setValue(100);
/* PAH commented out due to lack of multicast support in J2ME :/
// Start UPnP Presence Advertisement Handling thread
pah = new UPnPPresenceAdvertisementHandling();
pah.registerHandler(
new no.auc.one.portableplayer.communication.mediarenderer.MediaRendererPAH());
pah.setPriority(Thread.MIN_PRIORITY);
pah.start();
*/
d.setCurrent(ui.getMainMenu());
sc = null;
} catch (Exception e) {
LOG.fatal("Main unhandled Exception occured...");
LOG.fatal(e);
e.printStackTrace();
} finally {
System.out.println("Main start finished");
}
} else {
isPaused = false;
// pah.start();
}
}
/**
* Called by the Application Management Software (AMS) when the
* application should enter 'Pause mode', and shut down as much of its
* activity as possible.
*
* Currently this method does nothing.
*/
protected void pauseApp() {
// Pause the PAH thread
// pah.
isPaused = true;
}
/**
* Called by the Application Management Software (AMS) when the
* application is destroyed.
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// Notify Settings...
Settings.getInstance().saveSettings();
}
/**
* Terminates the application.
*/
public void quit() {
try {
destroyApp(true);
notifyDestroyed();
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
}
private class StartScreen extends Form implements CommandListener {
private Gauge progress = null;
public StartScreen(String title) {
super(title);
try {
//addCommand(showLogCommand);
setCommandListener(this);
Image imgLogo = Image.createImage("/aml_noalpha.png");
ImageItem logo = new ImageItem(
"Agder University College",
imgLogo,
Item.LAYOUT_CENTER |
// (ahaeber) Not supported by J9: Item.LAYOUT_VCENTER |
Item.LAYOUT_NEWLINE_AFTER |
Item.PLAIN,
"Agder Mobility Lab");
append(logo);
append("ONE Portable Player v1.0.5000");
progress = new Gauge("Progress", false, 100, 0);
append(progress);
} catch (/*IO*/Exception io) {
LOG.fatal(io);
}
}
public void commandAction(Command c, Displayable d) {
/*
Display disp = Display.getDisplay((MIDlet)this);
org.apache.log4j.LogCanvas lc = Logger.getLogCanvas();
lc.setPreviousScreen(disp.getCurrent());
disp.setCurrent(lc);
*/
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -