コード例 #1
0
ファイル: MyActivity.java プロジェクト: nhodgy/EasySpheroAI
  @Override
  public void handleRobotChangedState(
      Robot robot, RobotChangedStateListener.RobotChangedStateNotificationType type) {
    switch (type) {
      case Online:
        {
          view.setCurrentCondition("Online");
          // If robot uses Bluetooth LE, Developer Mode can be turned on.
          // This turns off DOS protection. This generally isn't required.
          if (robot instanceof RobotLE) {
            ((RobotLE) robot).setDeveloperMode(true);
          }

          // Save the robot as a ConvenienceRobot for additional utility methods
          mRobot = new ConvenienceRobot(robot);
          mRobot.enableCollisions(true); // starts collision detection

          long sensorFlag =
              SensorFlag.VELOCITY.longValue()
                  | SensorFlag.LOCATOR
                      .longValue(); // use OR bitwise operator to enable velocity and position
          mRobot.enableSensors(
              sensorFlag,
              SensorControl.StreamingRate
                  .STREAMING_RATE10); // enable the sensors using the streaming rate

          mRobot.addResponseListener(thread); // add the thread to respond to the options

          thread.setmRobot(mRobot); // give the robot to the thread
          thread.setRunning(true); // start the thread
          thread.start(); // start the AI
          view.repaint(); // update the UI
          break;
        }
      case Connected:
        { // update the view for each condition
          view.setCurrentCondition("Connected");
          view.repaint();
          break;
        }
      case Connecting:
        {
          view.setCurrentCondition("Connecting");
          view.repaint();
          break;
        }
      case Disconnected:
        {
          view.setCurrentCondition("Disconnected");
          view.repaint();
          break;
        }
      case FailedConnect:
        {
          view.setCurrentCondition("Failed Connect");
          view.repaint();
          break;
        }
    }
  }