/// <summary> /// Constructor /// </summary> public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; TopLimitLabel.Text = (MaxSteps[_currentZoomLevel].ToString()); CenterLimitLabel.Text = ((MaxSteps[_currentZoomLevel] / 2).ToString()); Window.Current.VisibilityChanged += async(oo, ee) => { if (!ee.Visible && _stepCounter != null) { await CallSenseApiAsync(async() => { await _stepCounter.DeactivateAsync(); }); } else if (_stepCounter != null) { await CallSenseApiAsync(async() => { await _stepCounter.ActivateAsync(); }); // Refresh screen await SetSelectedDayAsync(_selectedDay); } }; }
/// <summary> /// Constructor /// </summary> public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; Window.Current.VisibilityChanged += async(oo, ee) => { if (!ee.Visible && _activityMonitor != null) { await CallSenseApiAsync(async() => { await _activityMonitor.DeactivateAsync(); }); await CallSenseApiAsync(async() => { await _stepCounter.DeactivateAsync(); }); } else if (_activityMonitor != null) { await CallSenseApiAsync(async() => { await _activityMonitor.ActivateAsync(); }); await CallSenseApiAsync(async() => { await _stepCounter.ActivateAsync(); }); // Refresh screen await UpdateScreenAsync(); } }; }
/// <summary> /// Re-establishes the communication channel with underlying sensor, if it doesn't /// already exist. Connection needs to be re-established when the application /// is brought to foreground. /// </summary> /// <returns>Returns an IAsyncAction object that is used to control the asynchronous operation.</returns> public async Task ActivateAsync() { if (_aMonitor != null) { await _aMonitor.ActivateAsync(); } if (_sCounter != null) { await _sCounter.ActivateAsync(); } if (_rTracker != null) { await _rTracker.ActivateAsync(); } if (_pMonitor != null) { await _pMonitor.ActivateAsync(); } }
public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required; Window.Current.VisibilityChanged += async(oo, ee) => { if (ee.Visible) { if (await CallSensorcoreApiAsync(async() => { if (_stepCounter == null) { // Get sensor instance if needed... _stepCounter = await StepCounter.GetDefaultAsync(); } else { // ... otherwise just activate it await _stepCounter.ActivateAsync(); } })) { // Display current reading whenever application is brought to foreground await ShowCurrentReading(); } } else { // Sensor needs to be deactivated when application is put to background if (_stepCounter != null) { await CallSensorcoreApiAsync(async() => await _stepCounter.DeactivateAsync()); } } }; }