Example #1
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        public static async Task ValidateSettingsAsync()
        {
            if (await StepCounter.IsSupportedAsync())
            {
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable Motion data in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
            }
        }
        /// <summary>
        /// Check motion data settings
        /// </summary>
        private async void CheckMotionDataSettings()
        {
            if (!(await StepCounter.IsSupportedAsync()))
            {
                MessageDialog dlg = new MessageDialog("Unfortunately this device does not support step counting");
                await dlg.ShowAsync();

                Application.Current.Exit();
            }
            else
            {
                // MotionDataSettings settings = await SenseHelper.GetSettingsAsync();
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (apiSet > 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = null;
                        if (settings.Version < 2)
                        {
                            dlg = new MessageDialog("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("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");
                        }
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No", new UICommandInvokedHandler((cmd) => { Application.Current.Exit(); })));
                        await dlg.ShowAsync();
                    }
                }
            }
        }
Example #3
0
        public async void isSupported(string options)
        {
            PluginResult result = new PluginResult(PluginResult.Status.OK);

            result.KeepCallback = true;

            try
            {
                bool available = await StepCounter.IsSupportedAsync();

                result.Message = JsonHelper.Serialize(available);
                DispatchCommandResult(result);
            }
            catch (Exception ex)
            {
                result.Message = JsonHelper.Serialize(new { error = "isSupported", message = ex.Message });
                DispatchCommandResult(result);
            }
        }
Example #4
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        public async Task ValidateSettingsAsync()
        {
            if (!await StepCounter.IsSupportedAsync())
            {
                MessageBoxResult dlg = MessageBox.Show("Unfortunately this device does not support step counting");
                Application.Current.Terminate();
            }
            else
            {
                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageBoxResult dlg = MessageBox.Show("In order to count steps you need to enable location in system settings. Do you want to open settings now? If not, application will exit.", "Information", MessageBoxButton.OKCancel);
                        if (dlg == MessageBoxResult.OK)
                        {
                            await SenseHelper.LaunchLocationSettingsAsync();
                        }
                        else
                        {
                            Application.Current.Terminate();
                        }
                    }
                    if (!settings.PlacesVisited)
                    {
                        MessageBoxResult rc = 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? If not, application will exit.", "Information", MessageBoxButton.OKCancel);
                        if (rc == MessageBoxResult.OK)
                        {
                            await SenseHelper.LaunchSenseSettingsAsync();
                        }
                        else
                        {
                            Application.Current.Terminate();
                        }
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Initializes sensor
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task Initialize()
        {
            if (!await StepCounter.IsSupportedAsync())
            {
                MessageDialog dlg = new MessageDialog("Unfortunately this device does not support step counting");
                await dlg.ShowAsync();
            }
            else
            {
                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                // Starting from version 2 of Motion data settings Step counter and Acitivity monitor are always available. In earlier versions system
                // location setting and Motion data had to be enabled.
                if (settings.Version < 2)
                {
                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable location in system settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchLocationSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                    else if (!settings.PlacesVisited)
                    {
                        MessageDialog dlg = new MessageDialog("In order to count steps you need to enable Motion data collection in Motion data settings. Do you want to open settings now?", "Information");
                        dlg.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(cmd) => await SenseHelper.LaunchSenseSettingsAsync())));
                        dlg.Commands.Add(new UICommand("No"));
                        await dlg.ShowAsync();
                    }
                }
            }

            if (!await CallSenseApiAsync(async() =>
            {
                _stepCounter = await StepCounter.GetDefaultAsync();
            }))
            {
                Application.Current.Exit();
            }
            await SetSelectedDayAsync(_selectedDay);
        }
Example #6
0
        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();
            }
        }
Example #7
0
        public async void initialize(string options)
        {
            PluginResult result = new PluginResult(PluginResult.Status.OK);

            result.KeepCallback = true;

            try
            {
                if (await StepCounter.IsSupportedAsync())
                {
                    stepCounter = await StepCounter.GetDefaultAsync();

                    isReady = true;
                }

                DispatchCommandResult(result);
            }
            catch (Exception ex)
            {
                result.Message = JsonHelper.Serialize(new { error = "init", message = ex.Message });
                DispatchCommandResult(result);
            }
        }
Example #8
0
        /// <summary>
        /// Check motion data settings
        /// </summary>
        private async void CheckMotionDataSettings()
        {
            if (!(await TrackPointMonitor.IsSupportedAsync()) || !(await PlaceMonitor.IsSupportedAsync()) || !(await StepCounter.IsSupportedAsync()) || !(await ActivityMonitor.IsSupportedAsync()))
            {
                MessageBoxResult dlg = MessageBox.Show("Unfortunately this device does not support SensorCore service");
                Application.Current.Terminate();
            }
            else
            {
                uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                // Devices with old location settings
                if (!settings.LocationEnabled)
                {
                    MessageBoxResult dlg = MessageBox.Show("In order to recognize activities and view visited places you need to enable location in system settings. Do you want to open settings now? if no, applicatoin will exit", "Information", MessageBoxButton.OKCancel);
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchLocationSettingsAsync();
                    }
                }
                if (!settings.PlacesVisited)
                {
                    MessageBoxResult dlg = new MessageBoxResult();
                    if (settings.Version < 2)
                    {
                        //device which has old motion data settings.
                        //this is equal to motion data settings on/off in old system settings(SDK1.0 based)
                        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);
                        if (dlg == MessageBoxResult.Cancel)
                        {
                            Application.Current.Terminate();
                        }
                    }
                    else
                    {
                        dlg = MessageBox.Show("In order to recognize activities you need to 'enable Places visited' and 'DataQuality to detailed' in Motion data settings. Do you want to open settings now? ", "Information", MessageBoxButton.OKCancel);
                    }
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchSenseSettingsAsync();
                    }
                }
                else if (apiSet >= 3 && settings.DataQuality == DataCollectionQuality.Basic)
                {
                    MessageBoxResult dlg = MessageBox.Show("In order to recognize biking activity you need to enable detailed data collection in Motion data settings. Do you want to open settings now?", "Information", MessageBoxButton.OKCancel);
                    if (dlg == MessageBoxResult.OK)
                    {
                        await SenseHelper.LaunchSenseSettingsAsync();
                    }
                }
            }
        }