📄 .#ui.java.1.8.2.2
字号:
package no.auc.one.portableplayer.userinterface;
import no.auc.one.portableplayer.*;
import no.auc.one.portableplayer.communication.*;
import no.auc.one.portableplayer.communication.mediaserver.*;
import no.auc.one.portableplayer.communication.mediarenderer.*;
import no.auc.one.portableplayer.librarymanager.*;
import no.auc.one.portableplayer.userinterface.*;
import no.auc.one.portableplayer.utils.*;
import java.io.IOException;
import java.util.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
import org.apache.log4j.*;
// XXX Really UserInterfaceController.
// Should control the other user interface elements.
public class UI implements CommandListener, MenuEventListener {
private static Logger LOG;
//Commands
private Command homeCommand = null;
private Command playCommand = null;
private Command showLogCommand = null;
// Menu & elements
Menu oneppMenu;
MenuElement meBrowse;
MenuElement meSetup;
MenuElement meSetupBack;
MenuElementComboShift meSetupRepeat;
MenuElementComboShift meSetupShuffle;
MenuElementComboShift meServers;
MenuElement meServersRefresh;
MenuElementComboShift meRenderers;
MenuElement meRenderersRefresh;
MenuElement meExit;
StartScreen sc = null;
PlayScreen ps = null;
Main m = null;
private static UI ref;
LibraryMgr lib = LibraryMgr.getInstance();
Settings oneppSettings = Settings.getInstance();
static MediaServer currentMS = null;
//Constructor
private UI() {
LOG = Logger.getLogger("UI");
}
public static UI getInstance() {
if (ref == null) {
// it's ok, we can call this constructor
ref = new UI();
}
return ref;
}
public void setOwner(Main m) {
this.m = m;
}
// XXX EVIL method... to be removed later (using Settings instead)
public Main getOwner() {
return m;
}
public void show() throws Exception {
if (m == null) {
// XXX Should throw some more appropriate Exception class
throw new Exception("Main has not been specified");
}
LOG.debug("UI::show");
Display d = Display.getDisplay(m);
LOG.getLogCanvas().setPreviousScreen(oneppMenu);
d.setCurrent(LOG.getLogCanvas());
showLogCommand = new Command("Show Log", Command.SCREEN, 1);
// Display splash screen...
LOG.debug("UI::show Creating StartScreen");
sc = new StartScreen("Starting...");
if (sc != null) {
LOG.debug("UI::show StartScreen created");
d.setCurrent(sc);
d.flashBacklight(1000);
} else {
LOG.fatal("UI::show Startscreen is NULL");
return;
}
ps = new PlayScreen("Now Playing", oneppMenu, d);
initializeMenu();
sc.progress.setValue(100);
d.setCurrent(oneppMenu);
}
private void initializeMenu() {
try {
oneppMenu = new Menu();
homeCommand = new Command("Home", Command.BACK, 1);
playCommand = new Command("Play Screen", Command.SCREEN, 1);
oneppMenu.setCommandListener(this);
oneppMenu.addCommand(homeCommand);
oneppMenu.addCommand(playCommand);
oneppMenu.addCommand(showLogCommand);
// XXX Browse needs special treatment...
// 1) When browsing it should check what the currently
// selected server is.
// 2) Will always have the 'Back' MenuElement. But when the
// user invokes menuAction for meBrowse then it will
// try to fetch the content for the root of the current
// server.
// 3) If the current server is null or refresh then do not
// add more elements.
// 4) The children of meBrowse will be of two kinds:
// i) Normal MenuElement for containers. These will
// use their 'id' for the objectid.
// ii) MenuElementMediaContent for all media content.
// Will have a MediaContent element associated
// with it. Using something like:
// if (element instanceof MediaContentTrack) {
// playMusic(element);
// } else if (element instanceof MediaContentVideo) {
// showVideo(element);
// } ... etc.
//
meBrowse = new MenuElement("Browse media", this);
oneppMenu.addRootMenuElement(meBrowse);
sc.progress.setValue(10);
// Update media server and renderer lists
// TODO Add servers and renderers to settings too
meServers = new MenuElementComboShift("Media Server", this);
meServersRefresh = new MenuElement("Refresh", this);
meServers.addChild(meServersRefresh);
//updateMediaServerMenu();
sc.progress.setValue(50);
meRenderers = new MenuElementComboShift("Media Renderer", this);
meRenderersRefresh = new MenuElement("Refresh", this);
meRenderers.addChild(meRenderersRefresh);
//updateMediaRendererMenu();
meSetup = new MenuElement("Settings");
meSetupRepeat = new MenuElementComboShift("Repeat", this);
meSetupRepeat.addChild(
new MenuElement[]{
new MenuElement("Off"),
new MenuElement("On")});
meSetupShuffle = new MenuElementComboShift("Shuffle", this);
meSetupShuffle.addChild(
new MenuElement[]{
new MenuElement("Off"),
new MenuElement("On")});
meSetupBack = new MenuElement("Back", this);
meSetup.addChild(
new MenuElement[]{
meSetupBack,
meSetupRepeat,
meSetupShuffle,
meServers,
meRenderers});
oneppMenu.addRootMenuElement(meSetup);
meExit = new MenuElement("Exit", this);
oneppMenu.addRootMenuElement(new MenuElement[]{
meServers,
meRenderers,
meExit
});
sc.progress.setValue(90);
} catch (NullPointerException npe) {
LOG.fatal("NullPointerException");
LOG.fatal(npe);
} catch (Exception e) {
LOG.fatal("Exception occured finding MS or MR.");
LOG.fatal(e);
}
}
private void updateMediaServerMenu() throws IOException, InterruptedException {
LOG.debug("updateMediaServerMenu");
meServers.removeAllChildren();
MediaServerMenuUpdate msupdateThread = new MediaServerMenuUpdate();
msupdateThread.start();
/*
LOG.debug("updateMediaServerMenu waiting for thread to finish");
msupdateThread.join();
if (d.getCurrent() == mua) {
LOG.debug("Current displayable is MUA");
d.setCurrent(mua.getPrevDisplayable());
}
LOG.debug("updateMediaServerMenu Update thread finished");
*/
}
private class MediaServerMenuUpdate extends Thread implements CancelAction {
MediaServer servers = null;
MenuUpdateAlert mua = null;
public void run() {
try {
mua = new MenuUpdateAlert(
"Updating media servers",
(CancelAction)this,
this);
mua.start();
servers = new MediaServer();
LOG.debug("Updating media server list");
servers.updateMediaServerList();
LOG.debug("Starting to enum MS");
for(Enumeration e = servers.getMediaServers();
e.hasMoreElements(); )
{
MediaServer ms = (MediaServer)e.nextElement();
LOG.debug("MS Name: " + ms.getFriendlyName());
meServers.addChild(new MenuElement(ms.getFriendlyName()));
}
} catch (/*IO*/Exception e) {
LOG.fatal(
"IOException occured while updating media server menu");
LOG.fatal(e);
} finally {
LOG.debug("Finished updating media server menu");
servers = null;
meServers.addChild(meServersRefresh);
Display d = Display.getDisplay(m);
if (d.getCurrent() == mua) {
LOG.debug("Current displayable is MUA");
d.setCurrent(mua.getPrevDisplayable());
} else {
LOG.debug("Current displayable is " + d.getCurrent());
}
}
}
public void cancel() throws IOException {
if (servers != null) {
servers.cancel();
} else {
throw new IllegalStateException("Currently no discovery going on");
}
}
}
private void updateMediaRendererMenu() throws IOException, InterruptedException {
LOG.debug("updateMediaRendererMenu");
meRenderers.removeAllChildren();
MediaRendererMenuUpdate mrupdateThread = new MediaRendererMenuUpdate();
mrupdateThread.start();
LOG.debug("updateMediaRendererMenu waiting for thread to finish");
/*
msupdateThread.join();
LOG.debug("updateMediaRendererMenu Update thread finished");
// Probably kill the MUA here too, if it wasn't already killed.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -