/**
   * Before the playback commands are sent to the aircraft, the camera work mode should be set to
   * playback mode.
   */
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    if (DJIModuleVerificationUtil.isCameraModuleValid()) {
      mCamera = DJISampleApplication.getAircraftInstance().getCamera();

      mCamera.setCameraMode(
          DJICameraSettingsDef.CameraMode.Playback,
          new DJIBaseComponent.DJICompletionCallback() {
            @Override
            public void onResult(DJIError djiError) {}
          });
      if (DJIModuleVerificationUtil.isPlaybackValid()) {
        mPlaybackManager = mCamera.getPlayback();

        mPlaybackManager.setDJICameraPlayBackStateCallBack(
            new DJIPlaybackManager.DJICameraPlayBackStateCallBack() {
              @Override
              public void onResult(
                  DJIPlaybackManager.DJICameraPlaybackState djiCameraPlaybackState) {
                if (djiCameraPlaybackState.playbackMode.equals(
                    DJICameraSettingsDef.CameraPlaybackMode.SinglePhotoPlayback))
                  mPlaybackManager.enterMultiplePreviewMode();

                if (djiCameraPlaybackState.playbackMode.equals(
                    DJICameraSettingsDef.CameraPlaybackMode.MultipleMediaFilesDisplay))
                  mPlaybackManager.enterMultipleEditMode();
              }
            });
      }
    }
  }
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    if (DJIModuleVerificationUtil.isFlightControllerAvailable()) {

      flightController =
          ((DJIAircraft) DJISampleApplication.getProductInstance()).getFlightController();

      intelligentFlightAssistant = flightController.getIntelligentFlightAssistant();

      if (intelligentFlightAssistant != null) {

        intelligentFlightAssistant.setVisionDetectionStateUpdatedCallback(
            new DJIIntelligentFlightAssistant.VisionDetectionStateUpdatedCallback() {
              @Override
              public void onStateUpdated(
                  DJIIntelligentFlightAssistant.DJIVisionDetectionState djiVisionDetectionState) {
                if (null != djiVisionDetectionState) {
                  mStringBuffer.delete(0, mStringBuffer.length());

                  List<DJIIntelligentFlightAssistant.DJIVisionDetectionSector>
                      visionDetectionSectorList = djiVisionDetectionState.getDetectionSectors();

                  for (DJIIntelligentFlightAssistant.DJIVisionDetectionSector
                      visionDetectionSector : visionDetectionSectorList) {

                    visionDetectionSector.getObstacleDistanceInMeters();
                    visionDetectionSector.getWarningLevel();

                    mStringBuffer
                        .append("Obstacle distance: ")
                        .append(visionDetectionSector.getObstacleDistanceInMeters())
                        .append("\n");
                    mStringBuffer
                        .append("Distance warning: ")
                        .append(visionDetectionSector.getWarningLevel())
                        .append("\n");
                  }

                  mStringBuffer
                      .append("WarningLevel: ")
                      .append(djiVisionDetectionState.getWarningLevel().toString())
                      .append("\n");
                  mStringBuffer
                      .append("Braking state: ")
                      .append(djiVisionDetectionState.isBraking())
                      .append("\n");
                  mStringBuffer
                      .append("Sensor state: ")
                      .append(djiVisionDetectionState.isSensorWorking())
                      .append("\n");

                  mHandler.sendEmptyMessage(SET_CHANGE_STATUS);
                }
              }
            });
      }

    } else {
      Log.i("$$$$$$$$$$$$$$$$$$$", "onAttachedToWindow FC NOT Available");
    }
  }
 @Override
 protected void onDetachedFromWindow() {
   super.onDetachedFromWindow();
 }