コード例 #1
0
        @Override
        public void onReceive(Context context, Intent intent) {
          final String action = intent.getAction();
          switch (action) {
            case AttributeEvent.STATE_ARMING:
            case AttributeEvent.STATE_CONNECTED:
            case AttributeEvent.STATE_DISCONNECTED:
            case AttributeEvent.STATE_UPDATED:
              setupButtonsByFlightState();
              break;

            case AttributeEvent.STATE_VEHICLE_MODE:
              updateFlightModeButtons();
              break;

            case AttributeEvent.FOLLOW_START:
            case AttributeEvent.FOLLOW_STOP:
              final FollowState followState = getDrone().getAttribute(AttributeType.FOLLOW_STATE);
              if (followState != null) {
                String eventLabel = null;
                switch (followState.getState()) {
                  case FollowState.STATE_START:
                    eventLabel = "FollowMe enabled";
                    break;

                  case FollowState.STATE_RUNNING:
                    eventLabel = "FollowMe running";
                    break;

                  case FollowState.STATE_END:
                    eventLabel = "FollowMe disabled";
                    break;

                  case FollowState.STATE_INVALID:
                    eventLabel = "FollowMe error: invalid state";
                    break;

                  case FollowState.STATE_DRONE_DISCONNECTED:
                    eventLabel = "FollowMe error: drone not connected";
                    break;

                  case FollowState.STATE_DRONE_NOT_ARMED:
                    eventLabel = "FollowMe error: drone not armed";
                    break;
                }

                if (eventLabel != null) {
                  HitBuilders.EventBuilder eventBuilder =
                      new HitBuilders.EventBuilder()
                          .setCategory(GAUtils.Category.FLIGHT)
                          .setAction(ACTION_FLIGHT_ACTION_BUTTON)
                          .setLabel(eventLabel);
                  GAUtils.sendEvent(eventBuilder);

                  Toast.makeText(getActivity(), eventLabel, Toast.LENGTH_SHORT).show();
                }
              }

              /* FALL - THROUGH */
            case AttributeEvent.FOLLOW_UPDATE:
              updateFlightModeButtons();
              updateFollowButton();
              break;
          }
        }
コード例 #2
0
  @Override
  public void onClick(View v) {
    final Drone drone = getDrone();
    HitBuilders.EventBuilder eventBuilder =
        new HitBuilders.EventBuilder().setCategory(GAUtils.Category.FLIGHT);

    switch (v.getId()) {
      case R.id.mc_connectBtn:
        ((SuperUI) getActivity()).toggleDroneConnection();
        break;

      case R.id.mc_armBtn:
        getArmingConfirmation();
        eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Arm");
        break;

      case R.id.mc_disarmBtn:
        getDrone().arm(false);
        eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Disarm");
        break;

      case R.id.mc_homeBtn:
        drone.changeVehicleMode(VehicleMode.PLANE_RTL);
        eventBuilder
            .setAction(ACTION_FLIGHT_ACTION_BUTTON)
            .setLabel(VehicleMode.PLANE_RTL.getLabel());
        break;

      case R.id.mc_pause:
        {
          final FollowState followState = drone.getAttribute(AttributeType.FOLLOW_STATE);
          if (followState.isEnabled()) {
            drone.disableFollowMe();
          }

          drone.pauseAtCurrentLocation();
          eventBuilder.setAction(ACTION_FLIGHT_ACTION_BUTTON).setLabel("Pause");
          break;
        }

      case R.id.mc_TakeoffInAutoBtn:
      case R.id.mc_autoBtn:
        drone.changeVehicleMode(VehicleMode.PLANE_AUTO);
        eventBuilder
            .setAction(ACTION_FLIGHT_ACTION_BUTTON)
            .setLabel(VehicleMode.PLANE_AUTO.getLabel());
        break;

      case R.id.mc_follow:
        {
          toggleFollowMe();
          break;
        }

      default:
        eventBuilder = null;
        break;
    }

    if (eventBuilder != null) {
      GAUtils.sendEvent(eventBuilder);
    }
  }