📄 bluetoothremotecontrol.java
字号:
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.io.StreamConnection;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
public class BluetoothRemoteControl extends MIDlet
implements CommandListener
{
static final int ALERT_TIMEOUT = 4000;
private final String helpText = "Bluetooth Remote Control is a universal PC remote controller.\n\nReconnect -> Connect to the last connected computer\n\nSearch -> Search for Bluetooth equiped computers\n\nConnect Settings -> If you have to set the COM port in the PC program select \"COM Port\" otherwise \"Direct (Default)\"\n\nCopyright www.blueshareware.com";
private final String noSupport = "Bluetooht Remote Control do not support this phone!\n\nThis is because the phone do not support the JAVA Bluetooth API JSR-82";
private final Command backCommand = new Command("Back", 2, 2);
private final Command exitCommand = new Command("Exit", 7, 2);
private final Command SCR_MAIN_OK_CMD = new Command("OK", 4, 2);
private final Command SCR_MAIN_SAVE_CMD = new Command("Save", 4, 2);
private final Command debug = new Command("debug1", 1, 1);
private final Command debug2 = new Command("debug2", 1, 1);
private List menu = new List("Bluetooth RC", 3);
private List settings_menu;
private final Alert helpScreen = new Alert("Help");
private GUISearch findPhone;
private BluetoothClient bt_client;
private BluetoothServer bt_server;
private Applications apps;
private boolean supportBluetooth = true;
private BluetoothRemoteControl.StartUpCanvas startScreen;
private BluetoothRemoteControl.KillConnectionTimerTask killTimer;
private Timer timer;
private BluetoothRemoteControl.AliveTimerTask aliveTimer;
private Timer aTimer;
private boolean isInactive = false;
public BluetoothRemoteControl()
{
try
{
Class.forName("javax.bluetooth.LocalDevice");
}
catch (Exception localException)
{
this.supportBluetooth = false;
}
if (this.supportBluetooth)
{
this.helpScreen.addCommand(this.backCommand);
this.helpScreen.setTimeout(-2);
this.helpScreen.setString("Bluetooth Remote Control is a universal PC remote controller.\n\nReconnect -> Connect to the last connected computer\n\nSearch -> Search for Bluetooth equiped computers\n\nConnect Settings -> If you have to set the COM port in the PC program select \"COM Port\" otherwise \"Direct (Default)\"\n\nCopyright www.blueshareware.com");
this.helpScreen.setCommandListener(this);
this.menu.addCommand(this.exitCommand);
this.menu.addCommand(this.SCR_MAIN_OK_CMD);
String str = new String("ReConnect...");
this.menu.append(str, null);
str = new String("Search...");
this.menu.append(str, null);
str = new String("Connect Settings");
this.menu.append(str, null);
str = new String("Help");
this.menu.append(str, null);
this.menu.setCommandListener(this);
this.findPhone = new GUISearch(this);
this.bt_client = new BluetoothClient(this);
this.apps = new Applications(this, this.bt_client);
this.findPhone.registerBluetoothClient(this.bt_client);
this.bt_client.registerConnectUI(this.findPhone);
this.startScreen = new BluetoothRemoteControl.StartUpCanvas(this, this);
Image[] arrayOfImage = null;
String[] arrayOfString = { "Direct (Default)", "COM Port" };
this.settings_menu = new List("Connect Settings", 1, arrayOfString, arrayOfImage);
this.settings_menu.addCommand(this.backCommand);
this.settings_menu.addCommand(this.SCR_MAIN_SAVE_CMD);
this.settings_menu.setCommandListener(this);
startAliveTimer(7000);
}
else
{
this.helpScreen.addCommand(this.backCommand);
this.helpScreen.setTimeout(-2);
this.helpScreen.setString("Bluetooht Remote Control do not support this phone!\n\nThis is because the phone do not support the JAVA Bluetooth API JSR-82");
this.helpScreen.setCommandListener(this);
this.menu.addCommand(this.exitCommand);
this.menu.setCommandListener(this);
}
}
void completeInitialization(boolean paramBoolean)
{
debug("CompleteInitialization");
if (paramBoolean)
return;
Alert localAlert = new Alert("Error", "Can't inititialize bluetooth", null, AlertType.ERROR);
localAlert.setTimeout(4000);
Display.getDisplay(this).setCurrent(localAlert, getDisplayable());
}
public void startApp()
{
if (!(this.isInactive))
if (this.supportBluetooth == true)
{
this.startScreen.showStartUp();
}
else if (!(this.supportBluetooth))
{
show();
Display.getDisplay(this).setCurrent(this.helpScreen);
}
else
this.isInactive = false;
}
void show()
{
Display.getDisplay(this).setCurrent(this.menu);
}
Displayable getDisplayable()
{
return this.menu;
}
public void receive(byte[] paramArrayOfByte, int paramInt)
{
this.apps.receive(paramArrayOfByte, paramInt);
}
private void disconnect()
{
this.bt_client.disconnect();
}
public void pauseApp()
{
this.isInactive = true;
}
protected void destroyApp(boolean paramBoolean)
{
if (this.supportBluetooth == true)
try
{
killAliveTimer();
this.bt_client.destroy();
this.bt_server.destroy();
if (this.findPhone != null)
this.findPhone.destroy();
}
catch (Exception localException)
{
}
}
public void commandAction(Command paramCommand, Displayable paramDisplayable)
{
debug("OK");
if ((paramCommand == this.exitCommand) && (paramDisplayable == this.menu))
{
destroyApp(true);
notifyDestroyed();
return;
}
if ((paramCommand == this.backCommand) && (paramDisplayable == this.helpScreen))
{
Display.getDisplay(this).setCurrent(this.menu);
return;
}
if ((paramCommand == this.SCR_MAIN_SAVE_CMD) && (paramDisplayable == this.settings_menu))
{
this.bt_client.deleteRecord();
if (this.settings_menu.getSelectedIndex() == 0)
this.bt_client.storeConnectMethod(0);
else
this.bt_client.storeConnectMethod(1);
Display.getDisplay(this).setCurrent(this.menu);
return;
}
if ((paramCommand == this.backCommand) && (paramDisplayable == this.settings_menu))
{
Display.getDisplay(this).setCurrent(this.menu);
return;
}
if (paramCommand == this.debug)
{
String str1 = "Key Press: " + Integer.toString(this.apps.debugMouseKeyPress()) + " ";
str1 = str1 + "Key Release: " + Integer.toString(this.apps.debugMouseKeyRelease());
informInformation(str1);
return;
}
if (paramCommand == this.debug2)
{
debug("debug2...");
return;
}
if (paramDisplayable == this.menu)
try
{
int i = ((List)paramDisplayable).getSelectedIndex();
String str2 = this.menu.getString(i);
if (str2.compareTo("ReConnect...") == 0)
{
debug("ReConnecting...");
this.findPhone.reConnect();
}
else if (str2.compareTo("Search...") == 0)
{
debug("Connecting...");
this.findPhone.startSearching();
}
else if (str2.compareTo("Connect Settings") == 0)
{
debug("Connect Settings");
if (this.bt_client.readConnectMethod() == 0)
this.settings_menu.setSelectedIndex(0, true);
else
this.settings_menu.setSelectedIndex(1, true);
Display.getDisplay(this).setCurrent(this.settings_menu);
}
else if (str2.compareTo("Help") == 0)
{
Display.getDisplay(this).setCurrent(this.helpScreen);
}
return;
}
catch (Exception localException)
{
}
}
void informError(String paramString)
{
show();
Alert localAlert = new Alert("Error", paramString, null, AlertType.ERROR);
localAlert.setTimeout(4000);
Display.getDisplay(this).setCurrent(localAlert, this.menu);
}
void informInformation(String paramString)
{
show();
Alert localAlert = new Alert("Information", paramString, null, AlertType.INFO);
localAlert.setTimeout(4000);
Display.getDisplay(this).setCurrent(localAlert, this.menu);
}
void connectSuccess()
{
this.apps.requestApp();
this.apps.show();
}
void connectServerSuccess(StreamConnection paramStreamConnection)
{
this.bt_client.incomingConnection(paramStreamConnection);
}
public void startDiconnectTimer(int paramInt)
{
this.killTimer = new BluetoothRemoteControl.KillConnectionTimerTask(this);
this.timer = new Timer();
this.timer.schedule(this.killTimer, paramInt);
}
public void startAliveTimer(int paramInt)
{
this.aliveTimer = new BluetoothRemoteControl.AliveTimerTask(this);
this.aTimer = new Timer();
this.aTimer.schedule(this.aliveTimer, paramInt, paramInt);
}
public void killAliveTimer()
{
try
{
this.aliveTimer.cancel();
this.aTimer.cancel();
}
catch (Exception localException)
{
}
catch (Error localError)
{
}
}
static void debug(String paramString)
{
}
static void debugError(String paramString)
{
}
static void access$000(BluetoothRemoteControl paramBluetoothRemoteControl)
{
paramBluetoothRemoteControl.disconnect();
}
static Applications access$100(BluetoothRemoteControl paramBluetoothRemoteControl)
{
return paramBluetoothRemoteControl.apps;
}
static BluetoothServer access$302(BluetoothRemoteControl paramBluetoothRemoteControl, BluetoothServer paramBluetoothServer)
{
return (paramBluetoothRemoteControl.bt_server = paramBluetoothServer);
}
public class StartUpCanvas extends Canvas
{
private BluetoothRemoteControl parent;
public int fullWith;
public int fullHeight;
private Image img;
private final BluetoothRemoteControl this$0;
public StartUpCanvas(, BluetoothRemoteControl paramBluetoothRemoteControl2)
{
this.this$0 = paramBluetoothRemoteControl1;
this.parent = paramBluetoothRemoteControl2;
this.fullWith = getWidth();
this.fullHeight = getHeight();
try
{
this.img = null;
this.img = Image.createImage("/images/StartUp.png");
}
catch (Exception localException)
{
}
}
protected void keyPressed()
{
BluetoothRemoteControl.access$100(this.this$0).setMaxScreenSize(this.fullWith, this.fullHeight);
this.parent.show();
}
public void showStartUp()
{
Timer localTimer = new Timer();
localTimer.schedule(new BluetoothRemoteControl.StartUpCanvas.ExitStartUp(this), 4000L);
Display.getDisplay(this.parent).setCurrent(this);
repaint();
}
public void paint()
{
try
{
setFullScreenMode(true);
String str1 = "Bluetooth RC";
String str2 = "Loading...";
int i = paramGraphics.getClipX();
int j = paramGraphics.getClipY();
int k = paramGraphics.getClipWidth();
int l = paramGraphics.getClipHeight();
paramGraphics.setColor(16777215);
paramGraphics.fillRect(i, j, k, l);
Font localFont = paramGraphics.getFont();
int i1 = localFont.getHeight();
int i2 = localFont.stringWidth(str1);
int i3 = localFont.stringWidth(str2);
paramGraphics.setColor(0);
paramGraphics.setFont(localFont);
if (this.img != null)
{
paramGraphics.drawString(str2, (k - i3) / 2, 20, 20);
paramGraphics.drawImage(this.img, (this.fullWith - this.img.getWidth()) / 2, (this.fullHeight - this.img.getHeight()) / 2, 20);
}
else
{
paramGraphics.drawString(str1, (k - i2) / 2, (l - i1) / 2, 20);
paramGraphics.drawString(str2, (k - i3) / 2, (l - i1) / 2 + i1, 20);
}
}
}
protected void sizeChanged(, int paramInt2)
{
this.fullWith = paramInt1;
this.fullHeight = paramInt2;
}
static BluetoothRemoteControl access$200(StartUpCanvas paramStartUpCanvas)
{
return paramStartUpCanvas.this$0;
}
static BluetoothRemoteControl access$400(StartUpCanvas paramStartUpCanvas)
{
return paramStartUpCanvas.parent;
}
public class ExitStartUp extends TimerTask
{
private final BluetoothRemoteControl.StartUpCanvas this$1;
public ExitStartUp()
{
this.this$1 = paramStartUpCanvas;
}
public void run()
{
BluetoothRemoteControl.access$302(BluetoothRemoteControl.StartUpCanvas.access$200(this.this$1), new BluetoothServer(BluetoothRemoteControl.StartUpCanvas.access$400(this.this$1)));
BluetoothRemoteControl.access$100(BluetoothRemoteControl.StartUpCanvas.access$200(this.this$1)).setMaxScreenSize(this.this$1.fullWith, this.this$1.fullHeight);
BluetoothRemoteControl.StartUpCanvas.access$400(this.this$1).show();
}
}
}
public class AliveTimerTask extends TimerTask
{
private final BluetoothRemoteControl this$0;
public AliveTimerTask()
{
this.this$0 = paramBluetoothRemoteControl;
}
public void run()
{
BluetoothRemoteControl.access$100(this.this$0).pollConnectionLost();
}
}
public class KillConnectionTimerTask extends TimerTask
{
private final BluetoothRemoteControl this$0;
public KillConnectionTimerTask()
{
this.this$0 = paramBluetoothRemoteControl;
}
public void run()
{
BluetoothRemoteControl.access$000(this.this$0);
this.this$0.show();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -