|
1 | 1 | /* |
| 2 | + * The MIT License (MIT) |
2 | 3 | * Copyright (c) 2015 Microsoft |
3 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
4 | 5 | * of this software and associated documentation files (the "Software"), to deal |
@@ -69,11 +70,53 @@ protected async override void OnNavigatedFrom(NavigationEventArgs e) |
69 | 70 | /// <param name="e">Provides data for non-cancelable navigation events</param> |
70 | 71 | protected async override void OnNavigatedTo(NavigationEventArgs e) |
71 | 72 | { |
| 73 | + await InitCore(); |
72 | 74 | await App.Engine.ActivateAsync(); |
73 | 75 | UpdateMenuAndAppBarIcons(); |
74 | 76 | } |
75 | 77 | #endregion |
76 | 78 |
|
| 79 | + private async Task InitCore() |
| 80 | + { |
| 81 | + if (!await StepCounter.IsSupportedAsync()) |
| 82 | + { |
| 83 | + MessageBoxResult dlg = MessageBox.Show("Unfortunately this device does not support step counting"); |
| 84 | + } |
| 85 | + else |
| 86 | + { |
| 87 | + // MotionDataSettings settings = await SenseHelper.GetSettingsAsync(); |
| 88 | + // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system |
| 89 | + // location setting and Motion data had to be enabled. |
| 90 | + uint apiSet = await SenseHelper.GetSupportedApiSetAsync(); |
| 91 | + MotionDataSettings settings = await SenseHelper.GetSettingsAsync(); |
| 92 | + if (apiSet > 2) |
| 93 | + { |
| 94 | + if (!settings.LocationEnabled) |
| 95 | + { |
| 96 | + MessageBoxResult dlg = MessageBox.Show("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information", MessageBoxButton.OKCancel); |
| 97 | + if (dlg == MessageBoxResult.OK) |
| 98 | + await SenseHelper.LaunchLocationSettingsAsync(); |
| 99 | + } |
| 100 | + if (!settings.PlacesVisited) |
| 101 | + { |
| 102 | + MessageBoxResult dlg = new MessageBoxResult(); |
| 103 | + if (settings.Version < 2) |
| 104 | + { |
| 105 | + dlg = MessageBox.Show("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information", MessageBoxButton.OKCancel); |
| 106 | + } |
| 107 | + else |
| 108 | + { |
| 109 | + dlg = MessageBox.Show("In order to collect and view visited places you need to enable Places visited in Motion data settings. Do you want to open settings now? if no, application will exit", "Information", MessageBoxButton.OKCancel); |
| 110 | + } |
| 111 | + if (dlg == MessageBoxResult.OK) |
| 112 | + await SenseHelper.LaunchSenseSettingsAsync(); |
| 113 | + else |
| 114 | + Application.Current.Terminate(); |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
77 | 120 | /// <summary> |
78 | 121 | /// Executes when the Step graph finished loading. |
79 | 122 | /// </summary> |
|
0 commit comments