⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applications.java

📁 Java编写的蓝牙手机遥控器
💻 JAVA
字号:
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
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.List;

final class Applications
  implements CommandListener
{
  private final Command APP_BACK_CMD = new Command("Back", 2, 1);
  private final Command SCR_MAIN_OK_CMD = new Command("OK", 4, 1);
  private List controls = new List("Bluetooth RC", 3);
  private BluetoothRemoteControl parent;
  private BluetoothClient bt_client;
  private GUIInput mouseUI;
  private GUIGeneral generalUI;
  private String startString = "Waiting for PC...";
  private byte versionNum = 1;
  public int maxScreenX;
  public int maxScreenY;
  private boolean isInRange;

  public Applications(BluetoothRemoteControl paramBluetoothRemoteControl, BluetoothClient paramBluetoothClient)
  {
    this.parent = paramBluetoothRemoteControl;
    this.bt_client = paramBluetoothClient;
    this.mouseUI = new GUIInput(this, paramBluetoothRemoteControl);
    this.generalUI = new GUIGeneral(this, paramBluetoothRemoteControl, "Bluetooth RC");
    this.controls.addCommand(this.APP_BACK_CMD);
    this.controls.addCommand(this.SCR_MAIN_OK_CMD);
    this.controls.setCommandListener(this);
    this.isInRange = false;
  }

  public void show()
  {
    Display.getDisplay(this.parent).setCurrent(this.controls);
  }

  public void write(byte[] paramArrayOfByte)
  {
    this.isInRange = true;
    this.bt_client.write(paramArrayOfByte);
  }

  public void receive(byte[] paramArrayOfByte, int paramInt)
  {
    try
    {
      this.isInRange = true;
      switch (paramArrayOfByte[0])
      {
      case 0:
        executeCommand(paramArrayOfByte, paramInt);
        break;
      case 1:
        this.mouseUI.execute(paramArrayOfByte, paramInt);
        label57: break label57:
      }
    }
    catch (Exception localException)
    {
      this.parent.informError("Applications " + localException.toString());
    }
    catch (Error localError)
    {
      this.parent.informError("Applications " + localError.toString());
    }
  }

  private void executeCommand(byte[] paramArrayOfByte, int paramInt)
    throws Exception, Error
  {
    label172: Object localObject1;
    try
    {
      switch (paramArrayOfByte[1])
      {
      case 0:
        BluetoothRemoteControl.debug("Disconnect");
        this.controls.deleteAll();
        this.parent.startDiconnectTimer(1000);
        break;
      case 1:
        showMainMenu(paramArrayOfByte, paramInt);
        break;
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
        this.generalUI.execute(paramArrayOfByte, paramInt);
        break;
      case 10:
        respondAlive();
        break;
      case 11:
        respondVersion();
        break;
      case 12:
        this.generalUI.execute(paramArrayOfByte, paramInt);
        break;
      case 13:
        this.generalUI.execute(paramArrayOfByte, paramInt);
        break;
      case 14:
        this.generalUI.execute(paramArrayOfByte, paramInt);
        break label172:
      }
    }
    catch (Exception localException)
    {
      localObject1 = new Exception("executeCommand " + localException.toString());
      throw ((Throwable)localObject1);
    }
    catch (Error localError)
    {
      localObject1 = new Error("executeCommand " + localError.toString());
      throw ((Throwable)localObject1);
    }
  }

  private void showMainMenu(byte[] paramArrayOfByte, int paramInt)
    throws Exception, Error
  {
    Object localObject1;
    try
    {
      BluetoothRemoteControl.debug("showMainMenu");
      int i = GUIGeneral.getLengthAtPos(paramArrayOfByte, 2);
      BluetoothRemoteControl.debug("L: " + Integer.toString(i));
      this.controls.deleteAll();
      for (int k = 4; k <= i; k = k + 2 + j)
      {
        int j = GUIGeneral.getLengthAtPos(paramArrayOfByte, k);
        String str = new String(paramArrayOfByte, k + 2, j, "UTF-8");
        this.controls.append(str, null);
        BluetoothRemoteControl.debug("L: " + Integer.toString(j));
        BluetoothRemoteControl.debug("Row: " + str);
      }
      show();
    }
    catch (Exception localException)
    {
      localObject1 = new Exception("showMainMenu " + localException.toString());
      throw ((Throwable)localObject1);
    }
    catch (Error localError)
    {
      localObject1 = new Error("showMainMenu " + localError.toString());
      throw ((Throwable)localObject1);
    }
  }

  public void requestApp()
  {
    this.controls.deleteAll();
    this.controls.append(this.startString, null);
    byte[] arrayOfByte = new byte[4];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 1;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 0;
    write(arrayOfByte);
  }

  public void setMaxScreenSize(int paramInt1, int paramInt2)
  {
    Font localFont = Font.getFont(0, 0, 8);
    this.maxScreenX = paramInt1;
    this.maxScreenY = (paramInt2 - localFont.getHeight() + 4);
  }

  private void respondAlive()
  {
    byte[] arrayOfByte = new byte[4];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 13;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 0;
    write(arrayOfByte);
  }

  private void respondVersion()
  {
    byte[] arrayOfByte = new byte[5];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 14;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 1;
    arrayOfByte[4] = this.versionNum;
    write(arrayOfByte);
  }

  private void userDisconnect()
  {
    byte[] arrayOfByte = new byte[4];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 15;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 0;
    write(arrayOfByte);
  }

  public void sendBack()
  {
    BluetoothRemoteControl.debug("BACK");
    byte[] arrayOfByte = new byte[4];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 7;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 0;
    write(arrayOfByte);
  }

  public void sendOK()
  {
    BluetoothRemoteControl.debug("OK");
    byte[] arrayOfByte = new byte[4];
    arrayOfByte[0] = 0;
    arrayOfByte[1] = 9;
    arrayOfByte[2] = 0;
    arrayOfByte[3] = 0;
    write(arrayOfByte);
  }

  public void commandAction(Command paramCommand, Displayable paramDisplayable)
  {
    if (paramCommand == this.APP_BACK_CMD)
    {
      userDisconnect();
      this.bt_client.disconnect();
      this.controls.deleteAll();
      this.parent.show();
      return;
    }
    if ((paramDisplayable == this.controls) || (paramCommand == this.SCR_MAIN_OK_CMD))
      try
      {
        int i = ((List)paramDisplayable).getSelectedIndex();
        byte[] arrayOfByte = new byte[6];
        BluetoothRemoteControl.debug("Menu selected: " + Integer.toString(i));
        arrayOfByte[0] = 0;
        arrayOfByte[1] = 3;
        arrayOfByte[2] = 0;
        arrayOfByte[3] = 2;
        GUIGeneral.setLengthAtPos(arrayOfByte, 4, i);
        write(arrayOfByte);
      }
      catch (Exception localException)
      {
      }
  }

  public void pollConnectionLost()
  {
    int i = this.bt_client.getState();
    if (i == 2)
      if (!(this.isInRange))
      {
        this.bt_client.disconnect();
        this.parent.show();
      }
      else
      {
        this.isInRange = false;
      }
  }

  void informError(String paramString)
  {
    show();
    Alert localAlert = new Alert("Error", paramString, null, AlertType.ERROR);
    localAlert.setTimeout(4000);
    Display.getDisplay(this.parent).setCurrent(localAlert, this.controls);
  }

  void informInformation(String paramString)
  {
    show();
    Alert localAlert = new Alert("Information", paramString, null, AlertType.INFO);
    localAlert.setTimeout(4000);
    Display.getDisplay(this.parent).setCurrent(localAlert, this.controls);
  }

  public boolean leftSoftKey(int paramInt)
  {
    if (paramInt == -6)
      return true;
    if ((paramInt == 21) || (paramInt == -21))
      return true;
    return (paramInt == -1);
  }

  public boolean rightSoftKey(int paramInt)
  {
    if (paramInt == -7)
      return true;
    if ((paramInt == 22) || (paramInt == -22))
      return true;
    return (paramInt == -4);
  }

  public boolean clearKey(int paramInt)
  {
    return (paramInt == -8);
  }

  public int debugMouseKeyRelease()
  {
    return this.mouseUI.debugKeyRelease;
  }

  public int debugMouseKeyPress()
  {
    return this.mouseUI.debugKeyPress;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -