public void stopTracking(@Observes StopTrackingEvent event) { Context context = event.getContext(); if (trackingService != null) { UUID tripUuid = UUID.fromString(trackingService.getStringExtra(TrackingService.TRIP_UUID)); Collection<Trip> trips = (Collection<Trip>) mainController.getSingleDocument("trip", sessionManager.getSession(), tripUuid); if (trips.iterator().hasNext()) { Trip t = trips.iterator().next(); t.setEndDate(System.currentTimeMillis()); mainController.creatDocument("trip", t, sessionManager.getSession()); if (waypointBroadcastReceiver != null) { context.unregisterReceiver(waypointBroadcastReceiver); } context.stopService(trackingService); eventManager.fire( new RequestWaypointsZoom( context, map, TRACKING_MARKER_OPTIONS, TRACKING_POLYLINE_OPTIONS)); trackingService = null; Toast.makeText(context, "Tracking Stopped", Toast.LENGTH_SHORT).show(); } else { Toast.makeText( context, "Somehow the trip tracking did not create a trip, maybe you started tracking for a crew ship.", Toast.LENGTH_SHORT) .show(); } } else { Toast.makeText(context, "Tracking not Started", Toast.LENGTH_SHORT).show(); } }
public void startTracking(@Observes StartTrackingEvent event) { final Context context = event.getContext(); map = event.getMap(); SharedPreferences s = context.getSharedPreferences(LogbookTabsActivity.LOGBOOK_PREFS, 0); final String boatString = s.getString(LogbookTabsActivity.LOGBOOK_BOAT_FAVOURED, ""); if (!StringUtils.isEmpty(boatString) && trackingService == null) { Collection<? extends IModel> boat = mainController.getSingleDocument( "boat", sessionManager.getSession(), UUID.fromString(boatString)); if (!boat.isEmpty()) { eventManager.fire( new AddWaypointPolylineEvent( context, map, TRACKING_MARKER_OPTIONS, TRACKING_POLYLINE_OPTIONS)); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.inflate(R.layout.start_tracking_dialog, null); AlertDialog.Builder builder = new AlertDialog.Builder(context); builder .setMessage(R.string.enter_some_trip_info) .setView(view) .setPositiveButton( R.string.tracking_start, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EditText name = (EditText) view.findViewById(R.id.tracking_trip_name); EditText from = (EditText) view.findViewById(R.id.tracking_trip_from); EditText to = (EditText) view.findViewById(R.id.tracking_trip_to); Trip t = new Trip(); t.setStartDate(System.currentTimeMillis()); t.setName(name.getText().toString()); t.setTo(to.getText().toString()); t.setFrom(from.getText().toString()); t.setBoat(boatString); t = (Trip) mainController.creatDocument("trip", t, sessionManager.getSession()); trackingService = new Intent(context, TrackingService.class); UUID tripUuid = t.getUUID(); trackingService.putExtra(TrackingService.TRIP, t); trackingService.putExtra(TrackingService.TRIP_UUID, tripUuid.toString()); trackingService.putExtra(TrackingService.BOAT_UUID, boatString); waypointBroadcastReceiver = new TrackingServiceWaypointBroadcastReceiver(); context.registerReceiver( waypointBroadcastReceiver, new IntentFilter(TrackingService.WAYPOINT_BROADCAST_RECEIVER)); Toast.makeText(context, "Tracking Started", Toast.LENGTH_SHORT).show(); context.startService(trackingService); } }) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // Create the AlertDialog object and show it. builder.create().show(); } else { Toast.makeText(context, "You probably favoured a boat of your crew", Toast.LENGTH_SHORT) .show(); } } else { Toast.makeText(context, "No favoured boat or tracking already started", Toast.LENGTH_SHORT) .show(); } }