Esempio n. 1
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();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Makes sure necessary settings are enabled in order to use SensorCore
        /// </summary>
        /// <returns>Asynchronous task</returns>
        private async Task ValidateSettingsAsync()
        {
            try
            {
                if (!(await TrackPointMonitor.IsSupportedAsync()))
                {
                    MessageDialog dlg = new MessageDialog("Unfortunately this device does not support viewing tracks");
                    await dlg.ShowAsync();

                    Application.Current.Exit();
                }
                else
                {
                    _apiSet = await SenseHelper.GetSupportedApiSetAsync();

                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to collect and view visited tracks 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 = null;
                        if (settings.Version < 2)
                        {
                            // Device has old Motion data settings
                            dlg = new MessageDialog("In order to collect and view visited tracks you need to enable 'Motion data collection' in Motion data settings. Do you want to open settings now? If not, application will exit.", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("In order to collect and view visited tracks you need to enable 'Places visited' 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();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initialize SensorCore 
 /// </summary>
 /// <param name="rec">Recording instance</param>
 /// <param name="type">Sense type</param>
 /// <returns>Asynchronous task</returns>
 private async Task HandleSensorActivity(Recording rec, SenseType type)
 {           
     if (rec.Recorder == null)
     {
         if (await CallSensorcoreApiAsync(async () =>
         {
             switch (type)
             {
                 case SenseType.Activity:
                     _aMonitor = await ActivityMonitor.GetDefaultAsync();
                     break;
                 case SenseType.Places:
                     _pMonitor = await PlaceMonitor.GetDefaultAsync();
                     break;
                 case SenseType.Route:
                     _rTracker = await TrackPointMonitor.GetDefaultAsync();
                     break;
                 case SenseType.Steps:
                     _sCounter = await StepCounter.GetDefaultAsync();
                     break;
             }
         }))
         {
             Debug.WriteLine("Recorder initialized.");
             switch (type)
             {
                 case SenseType.Activity:
                     rec.Recorder = new SenseRecorder(_aMonitor);
                     break;
                 case SenseType.Places:
                     rec.Recorder = new SenseRecorder(_pMonitor);
                     break;
                 case SenseType.Route:
                     rec.Recorder = new SenseRecorder(_rTracker);
                     break;
                 case SenseType.Steps:
                     rec.Recorder = new SenseRecorder(_sCounter);
                     break;
             }
         }
         else return;
     }
     if (rec.Recorder == null)
         return;
     else
     {
         await ActivateAsync();
         switch (rec.ItemState)
         {
             case Status.Recording:
                 await rec.Recorder.StartAsync();
                 break;
             case Status.Stopped:
                 await rec.Recorder.StopAsync();
                 break;
             case Status.Empty:
                 await rec.Recorder.GetRecording().SaveAsync();
                 break;
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// initializes the sensor services
        /// </summary>
        /// <returns></returns>
        private async Task Initialize()
        {
            //following code assumes that device has new software(SensorCoreSDK1.1 based)
            try
            {
                if (!(await TrackPointMonitor.IsSupportedAsync()))
                {
                    MessageDialog dlg = new MessageDialog("Unfortunately this device does not support Trackpoints of visited places");
                    await dlg.ShowAsync();

                    Application.Current.Exit();
                }
                else
                {
                    uint apiSet = await SenseHelper.GetSupportedApiSetAsync();

                    MotionDataSettings settings = await SenseHelper.GetSettingsAsync();

                    if (!settings.LocationEnabled)
                    {
                        MessageDialog dlg = new MessageDialog("In order to collect and view tracks of visited places you need to enable location in system settings. Do you want to open settings now? if no, applicatoin will close", "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 = null;
                        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 = new MessageDialog("In order to collect and view tracks of visited places you need to enable Motion data in Motion data settings. Do you want to open settings now? if no, application will close", "Information");
                        }
                        else
                        {
                            dlg = new MessageDialog("In order to collect and view tracks of visited places you need to 'enable Places visited' and 'DataQuality to detailed' in Motion data settings. Do you want to open settings now? if no, application will close", "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();
                    }
                }
            }
            catch (Exception)
            {
            }

            //in case if the device has old software(earlier than SDK1.1) or system settings changed after sometime, CallSenseApiAsync() method handles the system settings prompts.
            if (_trackMonitor == null)
            {
                if (!await CallSenseApiAsync(async() =>
                {
                    _trackMonitor = await TrackPointMonitor.GetDefaultAsync();
                }))
                {
                    Application.Current.Exit();
                }
            }

            //setting current loation in the map
            try
            {
                TracksMapControl.MapServiceToken = "4eSgIBUeMtjFyJP6YxkyPQ";
                Geoposition geoposition = await new Geolocator().GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(5), timeout: TimeSpan.FromSeconds(5));
                TracksMapControl.Center = geoposition.Coordinate.Point;
            }
            catch (Exception)
            {
                // if current position can't get, setting default position to Espoo, Finland.
                TracksMapControl.Center = new Geopoint(new BasicGeoposition()
                {
                    Latitude  = 60.17,
                    Longitude = 24.83
                });
            }
            await GetHistory();

            UpdateScreenAsync();
        }
Esempio n. 5
0
        /// <summary>
        /// Initialize SensorCore
        /// </summary>
        /// <param name="rec">Recording instance</param>
        /// <param name="type">Sense type</param>
        /// <returns>Asynchronous task</returns>
        private async Task HandleSensorActivity(Recording rec, SenseType type)
        {
            if (rec.Recorder == null)
            {
                if (await CallSensorcoreApiAsync(async() =>
                {
                    switch (type)
                    {
                    case SenseType.Activity:
                        _aMonitor = await ActivityMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Places:
                        _pMonitor = await PlaceMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Route:
                        _rTracker = await TrackPointMonitor.GetDefaultAsync();
                        break;

                    case SenseType.Steps:
                        _sCounter = await StepCounter.GetDefaultAsync();
                        break;
                    }
                }))
                {
                    Debug.WriteLine("Recorder initialized.");
                    switch (type)
                    {
                    case SenseType.Activity:
                        rec.Recorder = new SenseRecorder(_aMonitor);
                        break;

                    case SenseType.Places:
                        rec.Recorder = new SenseRecorder(_pMonitor);
                        break;

                    case SenseType.Route:
                        rec.Recorder = new SenseRecorder(_rTracker);
                        break;

                    case SenseType.Steps:
                        rec.Recorder = new SenseRecorder(_sCounter);
                        break;
                    }
                }
                else
                {
                    return;
                }
            }
            if (rec.Recorder == null)
            {
                return;
            }
            else
            {
                await ActivateAsync();

                switch (rec.ItemState)
                {
                case Status.Recording:
                    await rec.Recorder.StartAsync();

                    break;

                case Status.Stopped:
                    await rec.Recorder.StopAsync();

                    break;

                case Status.Empty:
                    await rec.Recorder.GetRecording().SaveAsync();

                    break;
                }
            }
        }