/**
  * Stops the recording.
  *
  * @param context the context
  * @param trackRecordingServiceConnection the track recording service connection
  * @param showEditor true to show the editor
  */
 public static void stopRecording(
     Context context,
     TrackRecordingServiceConnection trackRecordingServiceConnection,
     boolean showEditor) {
   ITrackRecordingService trackRecordingService =
       trackRecordingServiceConnection.getServiceIfBound();
   if (trackRecordingService != null) {
     try {
       if (showEditor) {
         /*
          * Need to remember the recordingTrackId before calling
          * endCurrentTrack. endCurrentTrack sets the value to -1L.
          */
         long recordingTrackId =
             PreferencesUtils.getLong(context, R.string.recording_track_id_key);
         trackRecordingService.endCurrentTrack();
         if (recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
           Intent intent =
               IntentUtils.newIntent(context, TrackEditActivity.class)
                   .putExtra(TrackEditActivity.EXTRA_TRACK_ID, recordingTrackId)
                   .putExtra(TrackEditActivity.EXTRA_NEW_TRACK, true);
           context.startActivity(intent);
         }
       } else {
         trackRecordingService.endCurrentTrack();
       }
     } catch (Exception e) {
       Log.e(TAG, "Unable to stop recording.", e);
     }
   } else {
     resetRecordingState(context);
   }
   trackRecordingServiceConnection.unbindAndStop();
 }
 /**
  * Pauses the recording track.
  *
  * @param trackRecordingServiceConnection the track recording service connection
  */
 public static void pauseTrack(TrackRecordingServiceConnection trackRecordingServiceConnection) {
   try {
     ITrackRecordingService service = trackRecordingServiceConnection.getServiceIfBound();
     if (service != null) {
       service.pauseCurrentTrack();
     }
   } catch (RemoteException e) {
     Log.e(TAG, "Unable to resume track.", e);
   }
 }
 /**
  * Updates the calorie of current recording track.
  *
  * @param trackRecordingServiceConnection
  */
 public static void updateCalorie(
     TrackRecordingServiceConnection trackRecordingServiceConnection) {
   ITrackRecordingService trackRecordingService =
       trackRecordingServiceConnection.getServiceIfBound();
   if (trackRecordingService == null) {
     Log.d(TAG, "Unable to update calorie, no track recording service");
   } else {
     try {
       trackRecordingService.updateCalorie();
     } catch (RemoteException e) {
       Log.e(TAG, "Unable to update calorie", e);
     } catch (IllegalStateException e) {
       Log.e(TAG, "Unable to update calorie.", e);
     }
   }
 }
 /** Adds a marker. */
 public static long addMarker(
     Context context,
     TrackRecordingServiceConnection trackRecordingServiceConnection,
     WaypointCreationRequest waypointCreationRequest) {
   ITrackRecordingService trackRecordingService =
       trackRecordingServiceConnection.getServiceIfBound();
   if (trackRecordingService == null) {
     Log.d(TAG, "Unable to add marker, no track recording service");
   } else {
     try {
       long markerId = trackRecordingService.insertWaypoint(waypointCreationRequest);
       if (markerId != -1L) {
         Toast.makeText(context, R.string.marker_add_success, Toast.LENGTH_SHORT).show();
         return markerId;
       }
     } catch (RemoteException e) {
       Log.e(TAG, "Unable to add marker", e);
     } catch (IllegalStateException e) {
       Log.e(TAG, "Unable to add marker.", e);
     }
   }
   Toast.makeText(context, R.string.marker_add_error, Toast.LENGTH_LONG).show();
   return -1L;
 }