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() ); } }; }
/// <summary> /// Play preinstalled recording button click handler /// </summary> /// <param name="sender">Sender object</param> /// <param name="args">Event arguments</param> private async void LoadButton_Click(object sender, RoutedEventArgs e) { SenseRecording recording = null; WebErrorStatus exceptionDetail = new WebErrorStatus(); try { recording = await SenseRecording.LoadFromUriAsync(new Uri("https://github.com/Microsoft/steps/raw/master/Steps/Simulations/short%20walk.txt")); } catch (Exception ex) { exceptionDetail = WebError.GetStatus(ex.GetBaseException().HResult); } if (exceptionDetail == WebErrorStatus.HostNameNotResolved) { MessageDialog dialog = new MessageDialog("Check your network connection. Host name could not be resolved.", "Information"); await dialog.ShowAsync(); } if (recording != null) { _stepCounter = await StepCounterSimulator.GetDefaultAsync(recording); MessageDialog dialog = new MessageDialog( "Recorded sensor type: " + recording.Type.ToString() + "\r\nDescription: " + recording.Description + "\r\nRecording date: " + recording.StartTime.ToString() + "\r\nDuration: " + recording.Duration.ToString(), "Recording info" ); await dialog.ShowAsync(); } }
/// <summary> /// Gets number of steps for current day /// </summary> /// <returns><c>true</c> if steps were successfully fetched, <c>false</c> otherwise</returns> private async Task <bool> GetStepsAsync() { // First try the pedometer try { var readings = await Pedometer.GetSystemHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromPedometerReadings(readings); return(true); } catch (Exception) { // Continue to the fallback } // Fall back to using Lumia Sensor Core. IStepCounter stepCounter = null; try { //var qualifiers = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().QualifierValues; if (DeviceTypeHelper.GetDeviceFormFactorType() == DeviceFormFactorType.Phone) { stepCounter = await StepCounter.GetDefaultAsync(); StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); } else { var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt"); if (!await CallSensorCoreApiAsync(async() => { stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); StepCount count = await stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date); _steps = StepCountData.FromLumiaStepCount(count); })) { return(false); } } } catch (Exception e) { _lastError = SenseHelper.GetSenseError(e.HResult); return(false); } finally { if (stepCounter != null && typeof(StepCounter) == stepCounter.GetType()) { ((StepCounter)stepCounter).Dispose(); } } return(true); }
/// <summary> /// Initializes StepCounterSimulator (requires Lumia.Sense.Testing) /// </summary> public async Task InitializeSimulatorAsync() { var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt"); if (!await CallSensorCoreApiAsync(async() => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); })) { Application.Current.Exit(); } _sensorActive = true; }
private async Task InitializeSimulatorAsync() { var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt"); bool res = await CallSensorCoreApiAsync(async() => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); }); if (!res) { Application.Current.Terminate(); } }
/// <summary> /// Initializes StepCounter /// </summary> private async Task InitializeSensorAsync() { if (_stepCounter == null) { await CallSensorCoreApiAsync(async() => { _stepCounter = await StepCounter.GetDefaultAsync(); }); } else { await _stepCounter.ActivateAsync(); } _sensorActive = true; }
private async Task InitializeSensorAsync() { Exception failure = null; if (!await StepCounter.IsSupportedAsync()) { MessageBox.Show( "Your device doesn't support Motion Data. Application will be closed", "Information", MessageBoxButton.OK); Application.Current.Terminate(); } try { _stepCounter = await StepCounter.GetDefaultAsync(); } catch (Exception e) { failure = e; } if (failure != null) { switch (SenseHelper.GetSenseError(failure.HResult)) { case SenseError.LocationDisabled: case SenseError.SenseDisabled: NavigationService.Navigate(new Uri("/ActivateSensorCore;component/Pages/ActivateSensorCore.xaml", UriKind.Relative)); break; default: throw (failure); } } else { await _stepCounter.ActivateAsync(); await UpdateModelAsync(); } }
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()); } } }; }
public DailyStepView() { InitializeComponent(); BindingContext = this; stepCounterService = DependencyService.Get <IStepCounter>(); if (stepCounterService.IsAvailable()) { stepCounterService.StepCountChanged += StepCounterService_StepCountChanged; stepCounterService.Start(); } else { if (App.currentSteps != 0) { StepCount = App.currentSteps; } else { StepCount = 15793; } } }
public ISortStrategy CreateSort(SortAlgorithmEnum sortAlgorithm, SortTypeEnum sortType, IStepCounter stepCounter) { ISortType neededSortType = this.sortTypeFactory.CreateSortType(sortType); switch (sortAlgorithm) { case SortAlgorithmEnum.InsertionSort: { return(new InsertionSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.MergeSort: { return(new MergeSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.QuickSort: { return(new QuickSort(neededSortType, stepCounter)); } case SortAlgorithmEnum.SelectionSort: { return(new SelectionSort(neededSortType, stepCounter)); } default: return(null); } }
public ISortResult Handle(string sequence, SortAlgorithmEnum sortAlgorithm, SortTypeEnum sortType, IStepCounter stepCounter) { if (sequence == null) { throw new ArgumentNullException(nameof(sequence)); } if (stepCounter == null) { throw new ArgumentNullException(nameof(sequence)); } IEnumerable <decimal> numbersSequence = this.stringToDecimalCollectionParser.ParseStringToCollection(sequence); ISortResult sortResult = this.sortStrategyFactory.CreateSort(sortAlgorithm, sortType, stepCounter).Sort(numbersSequence); return(sortResult); }
private async Task InitializeSimulatorAsync() { var obj = await SenseRecording.LoadFromFileAsync("Simulations\\short recording.txt"); bool res = await CallSensorCoreApiAsync(async () => { _stepCounter = await StepCounterSimulator.GetDefaultAsync(obj, DateTime.Now - TimeSpan.FromHours(12)); }); if (!res) Application.Current.Terminate(); }
protected override SortStrategyBase GetSortStrategy(ISortType sortType, IStepCounter stepCounter) => new QuickSort(sortType, stepCounter);
protected abstract SortStrategyBase GetSortStrategy(ISortType sortType, IStepCounter stepCounter);
public MergeSort(ISortType sortType, IStepCounter stepCounter) : base(sortType, stepCounter) { }
public SelectionSort(ISortType sortType, IStepCounter stepCounter) : base(sortType, stepCounter) { }
public QuickSort(ISortType sortType, IStepCounter stepCounter) : base(sortType, stepCounter) { }
/// <summary> /// Initializes the step counter /// </summary> private async Task InitializeSensorAsync() { if (_stepCounter == null) { await CallSensorCoreApiAsync(async () => { _stepCounter = await StepCounter.GetDefaultAsync(); }); } else { await _stepCounter.ActivateAsync(); } _sensorActive = true; }
public InsertionSort(ISortType sortType, IStepCounter stepCounter) : base(sortType, stepCounter) { }
public SortStrategyBase(ISortType sortType, IStepCounter stepCounter) { this.sortType = sortType ?? throw new ArgumentNullException(nameof(sortType)); this.stepCounter = stepCounter ?? throw new ArgumentNullException(nameof(stepCounter)); }