/* * OnResume - Override for onResume to store in the database when the applications resumes. */ protected override void OnResume() { base.OnResume(); info = database.getRunningInfo(1); info.background = false; database.UpdateRunningInfo(info); }
/* * preventMovement - View session live for more details. */ private async void askLocation() { await Task.Delay(100).ContinueWith(async(arg) => { Task.Delay(GlobalUtilities.locationTime).Wait(); while (getlocation) { gettingLocation = true; var change = GetLocation(); change.Wait(); bool realChange = change.Result; if (!realChange) { getlocation = false; interrupt = new Interrupts(); interrupt.reason = "Change location"; DateTime toBeClonedDateTime = DateTime.Now; interrupt.start = toBeClonedDateTime; var answer = Task.FromResult(false); bool realAnwser = false; RunningInfo info = database.getRunningInfo(1); if (info.background) { info.notificationNeeded = true; database.UpdateRunningInfo(info); } Device.BeginInvokeOnMainThread( async() => { realAnwser = await DisplayAlert("Location Change", "Hey there your location change, are you still working?", "Yes.", "No, pause."); if (!realAnwser) { interrupt.Id = database.SaveInterrupt(interrupt); getlocation = false; } else { getlocation = true; } gettingLocation = false; }); } else { gettingLocation = false; } while (gettingLocation) { ; } Task.Delay(GlobalUtilities.locationTime).Wait(); } }); }
/* * Accelerometer_ReadingAvailable - View session live for more details. */ private async void Accelerometer_ReadingAvailable(object sender, XLabs.EventArgs <XLabs.Vector3> e) { await Task.Delay(100).ContinueWith(async(arg) => { if (!gettingLocation) { if (onlyOne == false) { onlyOne = true; semaphoreObject.WaitOne(); GlobalUtilities.accelerometer.ReadingAvailable -= Accelerometer_ReadingAvailable; XLabs.Vector3 Currentreading = e.Value; if (GlobalUtilities.LastMovement is null) { GlobalUtilities.LastMovement = Currentreading; } else { if (Math.Round(Currentreading.X, 1) != Math.Round(GlobalUtilities.LastMovement.X, 1) || Math.Round(Currentreading.Y, 1) != Math.Round(GlobalUtilities.LastMovement.Y, 1) || Math.Round(Currentreading.Z, 1) != Math.Round(GlobalUtilities.LastMovement.Z, 1)) { GlobalUtilities.moving += 1; if (GlobalUtilities.moving > GlobalUtilities.MovementTicks) { accelworking = true; getlocation = false; GlobalUtilities.moving = 0; GlobalUtilities.still = 0; movement = true; interrupt = new Interrupts(); interrupt.reason = "Movement detected."; DateTime toBeClonedDateTime = DateTime.Now; interrupt.start = toBeClonedDateTime; bool realAnwser = false; RunningInfo info = database.getRunningInfo(1); if (info.background) { info.notificationNeeded = true; database.UpdateRunningInfo(info); } Device.BeginInvokeOnMainThread( async() => { realAnwser = await DisplayAlert("Movement detected", "Are you still working?", "Yes.", "No, pause."); if (!realAnwser) { interrupt.sessionId = live.Id; interrupt.Id = database.SaveInterrupt(interrupt); getlocation = false; accelometeractive = false; } else { getlocation = true; accelometeractive = true; } movement = false; }); accelworking = true; } } else { GlobalUtilities.still += 1; if (GlobalUtilities.still > GlobalUtilities.StillTicks) { GlobalUtilities.moving = 0; GlobalUtilities.still = 0; } } } while (movement) { ; } GlobalUtilities.LastMovement = Currentreading; Thread.Sleep(GlobalUtilities.aceelTime); if (accelometeractive) { GlobalUtilities.accelerometer.ReadingAvailable += Accelerometer_ReadingAvailable; } semaphoreObject.Release(); onlyOne = false; accelworking = false; } } }); }