/// <summary> /// Start the activity /// </summary> /// <param name="obj"></param> private async void StartActivity(object obj) { if (!Purchased) { return; } var localSettings = ApplicationData.Current.LocalSettings; localSettings.Values[Constants.BackgroundPace] = true; _NotRunning = 0; _Timer.Start(); try { PebbleConnector _pc = PebbleConnector.GetInstance(); await _pc.StartBackgroundTask(PebbleConnector.Initiator.Pace); } catch (Exception exc) { ExtendedEventArgs _e = new ExtendedEventArgs(); _e.Error = exc.Message; OnFatalError(_e); } }
// Invoke the ConnectionError event; protected virtual void OnFatalError(ExtendedEventArgs e) { if (FatalError != null) { FatalError(this, e); } }
/// <summary> /// Timer processing /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _timer_Tick(object sender, object e) { var localSettings = ApplicationData.Current.LocalSettings; Duration = (String)localSettings.Values[Constants.PaceDuration]; Pace = (String)localSettings.Values[Constants.PacePace]; Distance = (String)localSettings.Values[Constants.PaceDistance]; /*if (localSettings.Values.Keys.Contains(Constants.BackgroundCommunicatieIsRunning)) * { * IsRunning = (bool)localSettings.Values[Constants.BackgroundCommunicatieIsRunning]; * }*/ IsRunning = PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Pace); if (localSettings.Values.Keys.Contains(Constants.PacePaused)) { Paused = (bool)localSettings.Values[Constants.PacePaused]; } if (localSettings.Values.Keys.Contains(Constants.PaceGPX)) { Shareable = (bool)localSettings.Values[Constants.PaceGPX]; } if (!IsRunning) { _NotRunning++; if (_NotRunning > 15) { _Timer.Stop(); } } else { _NotRunning = 0; } //Check if error occurred if (localSettings.Values.Keys.Contains(Constants.BackgroundCommunicatieError) && (int)localSettings.Values[Constants.BackgroundCommunicatieError] == (int)BCState.ConnectionFailed) { ExtendedEventArgs _fe = new ExtendedEventArgs(); _fe.Error = "Connection with Pebble Time failed. Try again."; OnFatalError(_fe); _Timer.Stop(); localSettings.Values[Constants.BackgroundCommunicatieError] = (int)BCState.OK; } }