public override void OnActivityCreated(Android.OS.Bundle savedInstanceState) { base.OnActivityCreated(savedInstanceState); if (savedInstanceState != null && savedInstanceState.GetInt(RUN_ID, -1) != -1) { CurrentRun = mRunManager.GetRun(savedInstanceState.GetInt(RUN_ID)); } else if (Activity.Intent.GetIntExtra(RUN_ID, -1) != -1) { CurrentRun = mRunManager.GetRun(Activity.Intent.GetIntExtra(RUN_ID, -1)); } else if (CurrentRun == null) { Run run = mRunManager.GetActiveRun(); if (run != null) { CurrentRun = run; } } }
protected override void OnLocationReceived(Context context, Android.Locations.Location loc) { //base.OnLocationReceived(context, loc); RunManager rm = RunManager.Get(mRunLocationListFragment.Activity); Run activeRun = rm.GetActiveRun(); if (activeRun != null && activeRun.Id == mRunLocationListFragment.mRunId) { RunLocationListAdapter adapter = ((RunLocationListAdapter)mRunLocationListFragment.ListAdapter); List <RunLocation> runLocations = rm.GetLocationsForRun(activeRun.Id); RunLocation runLocation = runLocations[runLocations.Count - 1]; adapter.Add(runLocation); adapter.NotifyDataSetChanged(); mRunLocationListFragment.ListView.SmoothScrollToPosition(runLocations.Count); } }
protected virtual void OnLocationReceived(Context context, Location loc) { // Console.WriteLine("[{0}] {1} Got location from {2}: {3}, {4}", TAG, this, loc.Provider, loc.Latitude, loc.Longitude); RunManager rm = RunManager.Get(context); Run run = rm.GetActiveRun(); if (rm.IsTrackingRun() && run != null) { RunLocation rl = new RunLocation(); rl.RunId = run.Id; rl.Latitude = loc.Latitude; rl.Longitude = loc.Longitude; rl.Altitude = loc.Altitude; rl.Time = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(loc.Time); rl.Provider = loc.Provider; rm.InsertItem <RunLocation>(rl); if ((DateTime.UtcNow - run.StartDate).Minutes % 5 == 0 && (DateTime.UtcNow - run.StartDate).Seconds % 60 == 0) { // Open activity on click notification. (Need to handle properly so off for now) Intent intent = new Intent(context, typeof(RunActivity)); intent.AddFlags(ActivityFlags.SingleTop); const int pendingIntentId = 0; PendingIntent pendingIntent = PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.OneShot); Notification notification = new Notification.Builder(context) .SetTicker(context.Resources.GetString(Resource.String.tracking_run_notification_title)) .SetSmallIcon(Android.Resource.Drawable.IcMenuView) .SetContentTitle(context.Resources.GetString(Resource.String.tracking_run_notification_title)) .SetContentText(context.Resources.GetString(Resource.String.tracking_run_notification_text)) .SetContentIntent(pendingIntent) .SetAutoCancel(true) .Build(); NotificationManager notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager; const int notificationId = 0; notificationManager.Notify(notificationId, notification); } } }