diff --git a/BackgroundTasks/BackgroundTasks.csproj b/BackgroundTasks/BackgroundTasks.csproj
index 3a58555..2690f30 100644
--- a/BackgroundTasks/BackgroundTasks.csproj
+++ b/BackgroundTasks/BackgroundTasks.csproj
@@ -17,24 +17,8 @@
512
{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
..\
- 5ff7fa89
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE;NETFX_CORE;WINDOWS_PHONE_APP
- prompt
- 4
+ 3ddbf11a
+ true
true
@@ -58,28 +42,6 @@
prompt
true
-
- true
- bin\x86\Debug\
- DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP
- ;2008
- full
- x86
- false
- prompt
- true
-
-
- bin\x86\Release\
- TRACE;NETFX_CORE;WINDOWS_PHONE_APP
- true
- ;2008
- pdbonly
- x86
- false
- prompt
- true
-
@@ -88,6 +50,12 @@
+
+ 12.0
+
+
+ WindowsPhoneApp
+
False
@@ -98,22 +66,8 @@
..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\lib\portable-wpa81+wp81\x86\Lumia.Sense.Testing.winmd
-
- 12.0
-
-
- WindowsPhoneApp
-
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
-
-
-
@@ -45,13 +41,9 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/Steps/AboutPage.xaml.cs b/Steps/AboutPage.xaml.cs
index 7edb29a..50e1610 100644
--- a/Steps/AboutPage.xaml.cs
+++ b/Steps/AboutPage.xaml.cs
@@ -1,29 +1,45 @@
/*
- * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
- * See the license text file provided with this project for more information.
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Navigation;
using Microsoft.Phone.Controls;
-using Microsoft.Phone.Shell;
+///
+/// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
+///
namespace Steps
{
+ ///
+ /// Displays information about the application
+ ///
public partial class AboutPage : PhoneApplicationPage
{
+ ///
+ /// Constructor
+ ///
public AboutPage()
{
InitializeComponent();
-
this.Loaded += (sender, args) =>
- { var ver = Windows.ApplicationModel.Package.Current.Id.Version;
- VersionNumber.Text = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Revision);
- };
+ {
+ var ver = Windows.ApplicationModel.Package.Current.Id.Version;
+ VersionNumber.Text = string.Format("{0}.{1}.{2}", ver.Major, ver.Minor, ver.Revision);
+ };
}
}
}
\ No newline at end of file
diff --git a/Steps/App.xaml b/Steps/App.xaml
index 9738f5b..6cc1c91 100644
--- a/Steps/App.xaml
+++ b/Steps/App.xaml
@@ -4,17 +4,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
-
-
-
\ No newline at end of file
diff --git a/Steps/App.xaml.cs b/Steps/App.xaml.cs
index 67a1781..4a31f3c 100644
--- a/Steps/App.xaml.cs
+++ b/Steps/App.xaml.cs
@@ -1,10 +1,24 @@
/*
- * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
- * See the license text file provided with this project for more information.
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Diagnostics;
-using System.Resources;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Navigation;
@@ -12,11 +26,17 @@
using Microsoft.Phone.Shell;
using Steps.Resources;
+///
+/// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
+///
namespace Steps
{
+ ///
+ /// Application main class
+ ///
public partial class App : Application
{
-
+ #region Variable declarations
///
/// Access to the engine of the app
///
@@ -28,6 +48,7 @@ public partial class App : Application
///
/// The root frame of the Phone Application.
public static PhoneApplicationFrame RootFrame { get; private set; }
+ #endregion
///
/// Constructor for the Application object.
@@ -36,50 +57,47 @@ public App()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
-
// Standard XAML initialization
InitializeComponent();
-
// Phone-specific initialization
InitializePhoneApplication();
-
// Language display initialization
InitializeLanguage();
-
-
Engine = new StepsEngine();
-
// Show graphics profiling information while debugging.
if (Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = false;
-
// Show the areas of the app that are being redrawn in each frame.
- //Application.Current.Host.Settings.EnableRedrawRegions = true;
-
+ // Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are handed off to GPU with a colored overlay.
- //Application.Current.Host.Settings.EnableCacheVisualization = true;
-
+ // Application.Current.Host.Settings.EnableCacheVisualization = true;
// Prevent the screen from turning off while under the debugger by disabling
// the application's idle detection.
// Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
// and consume battery power when the user is not using the phone.
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
-
}
- // Code to execute when the application is launching (eg, from Start)
- // This code will not execute when the application is reactivated
+ ///
+ /// Code to execute when the application is launching (eg, from Start)
+ /// This code will not execute when the application is reactivated
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
- await Engine.InitializeAsync();
}
- // Code to execute when the application is activated (brought to foreground)
- // This code will not execute when the application is first launched
+ ///
+ /// Code to execute when the application is activated (brought to foreground)
+ /// This code will not execute when the application is first launched
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void Application_Activated(object sender, ActivatedEventArgs e)
{
if (!e.IsApplicationInstancePreserved)
@@ -87,24 +105,33 @@ private async void Application_Activated(object sender, ActivatedEventArgs e)
Engine = new StepsEngine();
await Engine.InitializeAsync();
}
-
}
- // Code to execute when the application is deactivated (sent to background)
- // This code will not execute when the application is closing
+ ///
+ /// Code to execute when the application is deactivated (sent to background)
+ /// This code will not execute when the application is closing
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
-
}
- // Code to execute when the application is closing (eg, user hit Back)
- // This code will not execute when the application is deactivated
+ ///
+ /// Code to execute when the application is closing (eg, user hit Back)
+ /// This code will not execute when the application is deactivated
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void Application_Closing(object sender, ClosingEventArgs e)
{
-
}
- // Code to execute if a navigation fails
+ ///
+ /// Code to execute if a navigation fails
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (Debugger.IsAttached)
@@ -114,7 +141,11 @@ private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs
}
}
- // Code to execute on Unhandled Exceptions
+ ///
+ /// Code to execute on Unhandled Exceptions
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
@@ -125,42 +156,49 @@ private void Application_UnhandledException(object sender, ApplicationUnhandledE
}
#region Phone application initialization
-
- // Avoid double-initialization
+ ///
+ /// Avoid double-initialization
+ ///
private bool phoneApplicationInitialized = false;
- // Do not add any additional code to this method
+ ///
+ /// Do not add any additional code to this method
+ ///
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
-
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
-
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
-
// Handle reset requests for clearing the backstack
RootFrame.Navigated += CheckForResetNavigation;
-
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
- // Do not add any additional code to this method
+ ///
+ /// Do not add any additional code to this method
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
-
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
+ ///
+ /// Checks if the app has received a reset navigation
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void CheckForResetNavigation(object sender, NavigationEventArgs e)
{
// If the app has received a 'reset' navigation, then we need to check
@@ -168,60 +206,56 @@ private void CheckForResetNavigation(object sender, NavigationEventArgs e)
if (e.NavigationMode == NavigationMode.Reset)
RootFrame.Navigated += ClearBackStackAfterReset;
}
-
+
+ ///
+ /// Clears the stack after reset
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
{
// Unregister the event so it doesn't get called again
RootFrame.Navigated -= ClearBackStackAfterReset;
-
// Only clear the stack for 'new' (forward) and 'refresh' navigations
if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
return;
-
// For UI consistency, clear the entire page stack
while (RootFrame.RemoveBackEntry() != null)
{
- ; // do nothing
+ // Do nothing
+ ;
}
}
-
#endregion
- // Initialize the app's font and flow direction as defined in its localized resource strings.
- //
- // To ensure that the font of your application is aligned with its supported languages and that the
- // FlowDirection for each of those languages follows its traditional direction, ResourceLanguage
- // and ResourceFlowDirection should be initialized in each resx file to match these values with that
- // file's culture. For example:
- //
- // AppResources.es-ES.resx
- // ResourceLanguage's value should be "es-ES"
- // ResourceFlowDirection's value should be "LeftToRight"
- //
- // AppResources.ar-SA.resx
- // ResourceLanguage's value should be "ar-SA"
- // ResourceFlowDirection's value should be "RightToLeft"
- //
- // For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072.
- //
+ ///
+ /// Initialize the app's font and flow direction as defined in its localized resource strings.
+ /// To ensure that the font of your application is aligned with its supported languages and that the
+ /// FlowDirection for each of those languages follows its traditional direction, ResourceLanguage
+ /// and ResourceFlowDirection should be initialized in each resx file to match these values with that
+ /// file's culture. For example:
+ /// AppResources.es-ES.resx
+ /// ResourceLanguage's value should be "es-ES"
+ /// ResourceFlowDirection's value should be "LeftToRight"
+ /// AppResources.ar-SA.resx
+ /// ResourceLanguage's value should be "ar-SA"
+ /// ResourceFlowDirection's value should be "RightToLeft"
+ /// For more info on localizing Windows Phone apps see http://go.microsoft.com/fwlink/?LinkId=262072.
+ ///
private void InitializeLanguage()
{
try
{
// Set the font to match the display language defined by the
// ResourceLanguage resource string for each supported language.
- //
// Fall back to the font of the neutral language if the Display
// language of the phone is not supported.
- //
// If a compiler error is hit then ResourceLanguage is missing from
// the resource file.
RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
-
// Set the FlowDirection of all elements under the root frame based
// on the ResourceFlowDirection resource string for each
// supported language.
- //
// If a compiler error is hit then ResourceFlowDirection is missing from
// the resource file.
FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
@@ -233,12 +267,10 @@ private void InitializeLanguage()
// ResourceLangauge not being correctly set to a supported language
// code or ResourceFlowDirection is set to a value other than LeftToRight
// or RightToLeft.
-
if (Debugger.IsAttached)
{
Debugger.Break();
}
-
throw;
}
}
diff --git a/Steps/Assets/Images/appbar.pin.png b/Steps/Assets/Images/appbar.pin.png
deleted file mode 100644
index 0cedf00..0000000
Binary files a/Steps/Assets/Images/appbar.pin.png and /dev/null differ
diff --git a/Steps/Assets/Images/appbar.pin.remove.png b/Steps/Assets/Images/appbar.pin.remove.png
deleted file mode 100644
index a71819f..0000000
Binary files a/Steps/Assets/Images/appbar.pin.remove.png and /dev/null differ
diff --git a/Steps/Assets/Images/pin-48px.png b/Steps/Assets/Images/pin-48px.png
new file mode 100644
index 0000000..3550a0a
Binary files /dev/null and b/Steps/Assets/Images/pin-48px.png differ
diff --git a/Steps/Assets/Images/unpin-48px.png b/Steps/Assets/Images/unpin-48px.png
new file mode 100644
index 0000000..2ec9a09
Binary files /dev/null and b/Steps/Assets/Images/unpin-48px.png differ
diff --git a/Steps/DataConverter.cs b/Steps/DataConverter.cs
index 48bdcfc..a4ab964 100644
--- a/Steps/DataConverter.cs
+++ b/Steps/DataConverter.cs
@@ -1,47 +1,89 @@
/*
- * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
- * See the license text file provided with this project for more information.
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
-using System.Collections.Generic;
using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Windows.Data;
namespace Steps
{
-
+ ///
+ /// Returns the half value of the step graph
+ ///
public class Half : IValueConverter
{
+ ///
+ /// Converts a value.
+ ///
+ /// The value produced by the binding source.
+ /// The type of the binding target property.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ /// A converted value. If the method returns null, the valid null value is used.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
-
return (double)value/2;
}
+
+ ///
+ /// Converts back to the initial value.
+ ///
+ /// The value that is produced by the binding target.
+ /// The type to convert to.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ /// A converted value. If the method returns null, the valid null value is used.
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
-
return "";
}
-
}
+ ///
+ /// Returns the margin o the step graph.
+ ///
public class Margin : IValueConverter
{
+ ///
+ /// Converts a value.
+ ///
+ /// The value produced by the binding source.
+ /// The type of the binding target property.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ /// A converted value. If the method returns null, the valid null value is used.
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
-
return (double)value -6;
}
+
+ ///
+ /// Converts back to the initial value.
+ ///
+ /// The value that is produced by the binding target.
+ /// The type to convert to.
+ /// The converter parameter to use.
+ /// The culture to use in the converter.
+ /// A converted value. If the method returns null, the valid null value is used.
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
-
return "";
}
-
}
-
-
}
diff --git a/Steps/DataModels/MainModel.cs b/Steps/DataModels/MainModel.cs
index 3d1d1b9..20c42be 100644
--- a/Steps/DataModels/MainModel.cs
+++ b/Steps/DataModels/MainModel.cs
@@ -1,49 +1,129 @@
-using System;
+/*
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Steps
{
-
-
+ ///
+ /// Main model used in the application
+ ///
public class MainModel : INotifyPropertyChanged
{
+ #region Variable declarations
+ ///
+ /// Index of day.
+ /// 0 = today, 1 = yesterday, 2 = 2 days ago...
+ ///
+ public int _day = 0;
+
+ ///
+ /// Resolution of graph is 15 min. Can be 5,10,15,20...60
+ ///
+ public const int _resolutionInMinutes = 15;
- public int day = 0; //0 = today, 1 = yesterday, 2 = 2 days ago...
- public const int _resolutionInMinutes = 15; // Resolution of graph is 15 min. Can be 5,10,15,20...60
+ ///
+ /// Array size.
+ ///
public const int _ArrayMaxSize = 1440 / _resolutionInMinutes + 1;
+
+ ///
+ /// Property changed event.
+ ///
public event PropertyChangedEventHandler PropertyChanged;
+ ///
+ /// Number of walking steps.
+ ///
private uint _walkingSteps = 0;
+
+ ///
+ /// Number of running steps.
+ ///
private uint _runningSteps = 0;
+
+ ///
+ /// Number of total steps for the current day.
+ ///
private uint _stepsToday = 0;
- private double _width; //Graph canvas' width in pixels
- private double _height; //Graph canvas' height in pixels
- private const int _margin = 6; //Graph canvas' margin in pixels
- private uint _max = 20000; //Graph canvas max height in steps (can be 20000,10000,5000)
+ ///
+ /// Graph canvas' width in pixels.
+ ///
+ private double _width;
+
+ ///
+ /// Graph canvas' height in pixels.
+ ///
+ private double _height;
+
+ ///
+ /// Graph canvas margin in pixels.
+ ///
+ private const int _margin = 6;
+
+ ///
+ /// Graph canvas max height in steps (can be 20000, 10000, 5000)
+ ///
+ private uint _max = 20000;
+
+ ///
+ /// Maximum array size.
+ ///
private const int _arrayMaxSize = 96;
- private List _steps = new List();
+ ///
+ /// Collection of steps.
+ ///
+ private List _steps = new List();
+ #endregion
+ ///
+ /// Sets graph parameters.
+ ///
+ /// Graph canvas' width in pixels.
+ /// Graph canvas' height in pixels.
public void SetParameters(double width, double height)
{
_width = width;
_height = height;
- NotifyPropertyChanged(null); //We refresh all properties here
-
+ //We refresh all properties here
+ NotifyPropertyChanged(null);
}
+ ///
+ /// Updates graph steps
+ ///
+ /// Steps list
public void UpdateGraphSteps(List steps)
{
_steps = steps;
- NotifyPropertyChanged(null); //We refresh all properties here
+ //We refresh all properties here
+ NotifyPropertyChanged(null);
}
+ ///
+ /// Change steps range in graph
+ ///
public void ChangeMax()
{
if (_max == 20000)
@@ -52,59 +132,71 @@ public void ChangeMax()
_max = 5000;
else
_max = 20000;
- NotifyPropertyChanged(null); //We refresh all properties
+ //We refresh all properties
+ NotifyPropertyChanged(null);
}
+ ///
+ /// Gets maximum steps range for graph
+ ///
public string Max { get { return _max.ToString(); } }
+
+ ///
+ /// Gets half steps range for graph
+ ///
public string Half { get { return (_max / 2).ToString(); } }
+
+ ///
+ /// Gets margin of the step graph
+ ///
public string Margin { get { return (_margin).ToString(); } }
+
+ ///
+ /// Get the datetime for the graph
+ ///
public string Date
{
get
{
CultureInfo ci = new CultureInfo("en-GB");
-
string format = "D";
-
- if (day == 0)
+ if (_day == 0)
return "Today";
- else if (day == 1)
+ else if (_day == 1)
return "Yesterday";
- else if (day == 2)
+ else if (_day == 2)
{
DateTime time = DateTime.Now - TimeSpan.FromDays(2);
return time.ToString(format, ci);
}
- else if (day == 3)
+ else if (_day == 3)
{
DateTime time = DateTime.Now - TimeSpan.FromDays(3);
return time.ToString(format, ci);
}
- else if (day == 4)
+ else if (_day == 4)
{
DateTime time = DateTime.Now - TimeSpan.FromDays(4);
return time.ToString(format, ci);
}
- else if (day == 5)
+ else if (_day == 5)
{
DateTime time = DateTime.Now - TimeSpan.FromDays(5);
return time.ToString(format, ci);
}
- else if (day == 6)
+ else if (_day == 6)
{
DateTime time = DateTime.Now - TimeSpan.FromDays(6);
return time.ToString(format, ci);
}
else
{
-
DateTime time = DateTime.Now - TimeSpan.FromDays(7);
return time.ToString(format, ci);
}
}
}
-
///
/// WalkingSteps property. This property is displayed on the app
///
@@ -116,7 +208,6 @@ public uint WalkingSteps
}
set
{
-
if (value != _walkingSteps)
{
_walkingSteps = value;
@@ -125,7 +216,6 @@ public uint WalkingSteps
}
}
-
///
/// RunningSteps property. This property is displayed on the app
///
@@ -137,7 +227,6 @@ public uint RunningSteps
}
set
{
-
if (value != _runningSteps)
{
_runningSteps = value;
@@ -180,14 +269,16 @@ public string PathString
for (int i = 1; i < _steps.Count; i++)
{
uint stepcount = _max > _steps[i] ? _steps[i] : _max;
-
path += " L " + ((uint)(((double)i / _arrayMaxSize) * (_width - 12)) + 6).ToString() + "," + (_height - (uint)(stepcount * (_height / _max))).ToString() + " ";
}
-
return path;
}
}
+ ///
+ /// Execures when a property has changed
+ ///
+ /// Property which will be changed
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
@@ -196,6 +287,5 @@ private void NotifyPropertyChanged(String propertyName)
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
-
}
}
diff --git a/Steps/LocalizedStrings.cs b/Steps/LocalizedStrings.cs
index a10b44a..aa5ff19 100644
--- a/Steps/LocalizedStrings.cs
+++ b/Steps/LocalizedStrings.cs
@@ -1,6 +1,21 @@
/*
- * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
- * See the license text file provided with this project for more information.
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using Steps.Resources;
@@ -11,8 +26,16 @@ namespace Steps
///
public class LocalizedStrings
{
+ #region Variable declarations
+ ///
+ /// Resource instance.
+ ///
private static AppResources _localizedResources = new AppResources();
+ #endregion
+ ///
+ /// Gets resource from local file.
+ ///
public AppResources LocalizedResources { get { return _localizedResources; } }
}
}
\ No newline at end of file
diff --git a/Steps/MainPage.xaml b/Steps/MainPage.xaml
index d0072ae..9088d0c 100644
--- a/Steps/MainPage.xaml
+++ b/Steps/MainPage.xaml
@@ -15,50 +15,25 @@
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
shell:SystemTray.BackgroundColor="#008A00">
-
-
-
-
-
-
-
-
@@ -70,7 +45,6 @@
-
@@ -79,8 +53,6 @@
-
-
@@ -90,7 +62,6 @@
-
@@ -115,13 +86,11 @@
-
-
-
+
@@ -148,23 +117,15 @@
-
-
-
+
-
\ No newline at end of file
diff --git a/Steps/MainPage.xaml.cs b/Steps/MainPage.xaml.cs
index bdca0d7..8bad144 100644
--- a/Steps/MainPage.xaml.cs
+++ b/Steps/MainPage.xaml.cs
@@ -1,97 +1,137 @@
/*
- * Copyright (c) 2014 Microsoft Mobile. All rights reserved.
- * See the license text file provided with this project for more information.
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
using System.Windows;
-using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
-using Steps.Resources;
using Lumia.Sense;
-using Lumia.Sense.Testing;
using System.Threading.Tasks;
-using System.Windows.Threading;
-using System.Windows.Data;
-using System.Globalization;
using Windows.ApplicationModel.Background;
-using Windows.UI.Notifications;
-using Windows.Data.Xml.Dom;
using Windows.UI.StartScreen;
using Windows.UI;
+///
+/// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
+///
namespace Steps
{
-
+ ///
+ /// Main page of the application
+ ///
public partial class MainPage : PhoneApplicationPage
{
- private const string TileID = "SecondaryTile.Steps";
-
+ ///
+ /// Tile ID
+ ///
+ private const string _TileID = "SecondaryTile.Steps";
- // Constructor
+ ///
+ /// Constructor
+ ///
public MainPage()
{
InitializeComponent();
-
LayoutRoot.DataContext = App.Engine.MainModel;
StepGraph.Loaded += StepGraph_Loaded;
}
+ #region NavigationHelper registration
+ ///
+ /// Called when a page is no longer the active page in a frame.
+ ///
+ /// Provides data for non-cancelable navigation events
protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
await App.Engine.DeactivateAsync();
}
+ ///
+ /// Called when a page becomes the active page in a frame.
+ ///
+ /// Provides data for non-cancelable navigation events
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
await App.Engine.ActivateAsync();
-
UpdateMenuAndAppBarIcons();
}
+ #endregion
+ ///
+ /// Executes when the Step graph finished loading.
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void StepGraph_Loaded(object sender, RoutedEventArgs e)
{
App.Engine.MainModel.SetParameters(StepGraph.ActualWidth, StepGraph.ActualHeight);
}
///
- /// User taps on step graph. This will change max value for the graph
+ /// User taps on step graph. This will change max value for the graph.
///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void StepGraph_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
App.Engine.MainModel.ChangeMax();
}
+ ///
+ /// Navigates to the specified page.
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private void Click_NavigateToAbout(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/AboutPage.xaml", UriKind.Relative));
}
+ ///
+ /// Removes background agent.
+ ///
+ /// Name of task to be removed.
+ /// A task.
private async static Task RemoveBackgroundTaskAsync(String taskName)
{
+ BackgroundAccessStatus result = await BackgroundExecutionManager.RequestAccessAsync();
+ if (result != BackgroundAccessStatus.Denied)
{
- BackgroundAccessStatus result = await BackgroundExecutionManager.RequestAccessAsync();
- if (result != BackgroundAccessStatus.Denied)
+ // Remove previous registration
+ foreach (var task in BackgroundTaskRegistration.AllTasks)
{
- // Remove previous registration
- foreach (var task in BackgroundTaskRegistration.AllTasks)
+ if (task.Value.Name == taskName)
{
- if (task.Value.Name == taskName)
- {
- task.Value.Unregister(true);
- }
+ task.Value.Unregister(true);
}
}
}
}
///
- /// Removes old background agent if exists and adds new background task
+ /// Removes old background agent if exists and adds new background task.
///
+ /// Parameter for triggered events.
+ /// Name of task to be removed.
+ /// Entry point of the task to be removed.
+ /// A task.
private async static Task RegisterBackgroundTaskAsync(IBackgroundTrigger trigger, String taskName, String taskEntryPoint)
{
BackgroundAccessStatus result = await BackgroundExecutionManager.RequestAccessAsync();
@@ -105,7 +145,6 @@ private async static Task RegisterBackgroundTaskAsync(IBackgroundTrigger trigger
task.Value.Unregister(true);
}
}
-
// Register new trigger
BackgroundTaskBuilder myTaskBuilder = new BackgroundTaskBuilder();
myTaskBuilder.SetTrigger(trigger);
@@ -116,8 +155,10 @@ private async static Task RegisterBackgroundTaskAsync(IBackgroundTrigger trigger
}
///
- /// Creates or removes a secondary tile
+ /// Creates or removes a secondary tile.
///
+ /// Variable to determine if a tile exists and needs to be removed.
+ /// A task.
private async Task CreateOrRemoveTileAsync(bool removeTile)
{
if (!removeTile)
@@ -125,96 +166,81 @@ private async Task CreateOrRemoveTileAsync(bool removeTile)
uint stepCount = await App.Engine.GetStepCountAsync();
uint meter = Helper.GetMeter(stepCount);
uint meterSmall = Helper.GetSmallMeter(stepCount);
-
try
{
-
- var secondaryTile = new SecondaryTile(
- TileID,
- "Steps",
- "/MainPage.xaml",
- new Uri("ms-appx:///Assets/Tiles/square" + meterSmall + ".png", UriKind.Absolute),
- TileSize.Square150x150);
-
+ var secondaryTile = new SecondaryTile(_TileID, "Steps", "/MainPage.xaml", new Uri("ms-appx:///Assets/Tiles/square" + meterSmall + ".png", UriKind.Absolute), TileSize.Square150x150);
secondaryTile.VisualElements.Square71x71Logo = new Uri("ms-appx:///Assets/Tiles/small_square" + meterSmall + ".png", UriKind.Absolute);
secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
secondaryTile.VisualElements.ShowNameOnSquare310x310Logo = false;
secondaryTile.VisualElements.ShowNameOnWide310x150Logo = false;
secondaryTile.VisualElements.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
-
secondaryTile.VisualElements.Wide310x150Logo = new Uri("ms-appx:///Assets/Tiles/wide" + meter + ".png", UriKind.Absolute);
secondaryTile.RoamingEnabled = false;
-
await secondaryTile.RequestCreateAsync();
-
}
catch (Exception exp)
{
-
}
return;
}
else
{
-
- SecondaryTile secondaryTile = new SecondaryTile(TileID);
+ SecondaryTile secondaryTile = new SecondaryTile(_TileID);
await secondaryTile.RequestDeleteAsync();
UpdateMenuAndAppBarIcons();
}
}
+ ///
+ /// Updates menu and app bar icons.
+ ///
private void UpdateMenuAndAppBarIcons()
{
- //Show unpin or pin button
-
+ // Show unpin or pin button
ApplicationBarIconButton btn = (ApplicationBarIconButton)ApplicationBar.Buttons[2];
- if (!SecondaryTile.Exists(TileID))
+ if (!SecondaryTile.Exists(_TileID))
{
- btn.IconUri = new Uri("Assets/Images/appbar.pin.png", UriKind.Relative);
+ btn.IconUri = new Uri("Assets/Images/pin-48px.png", UriKind.Relative);
btn.Text = "Pin";
}
else
{
- btn.IconUri = new Uri("Assets/Images/appbar.pin.remove.png", UriKind.Relative);
+ btn.IconUri = new Uri("Assets/Images/unpin-48px.png", UriKind.Relative);
btn.Text = "Unpin";
}
-
-
- //Disable the back button if we show 7th day in the past
+ // Disable the back button if we show 7th day in the past
ApplicationBarIconButton back = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
- if (App.Engine.MainModel.day == 7)
+ if (App.Engine.MainModel._day == 7)
back.IsEnabled = false;
else
back.IsEnabled = true;
-
- //Disable next button if we show today's steps
+ // Disable next button if we show today's steps
ApplicationBarIconButton next = (ApplicationBarIconButton)ApplicationBar.Buttons[1];
- if (App.Engine.MainModel.day == 0)
+ if (App.Engine.MainModel._day == 0)
next.IsEnabled = false;
else
next.IsEnabled = true;
-
}
+ ///
+ /// Registers/Unregisters tile.
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void ApplicationBarRegisterUnRegisterTile(object sender, EventArgs e)
{
-
- //Register background task that updates live tile
- bool removeTile = SecondaryTile.Exists(TileID);
-
+ // Register background task that updates live tile
+ bool removeTile = SecondaryTile.Exists(_TileID);
if (removeTile)
{
await RemoveBackgroundTaskAsync("StepTriggered");
}
else
{
-
if (Microsoft.Devices.Environment.DeviceType != Microsoft.Devices.DeviceType.Emulator)
{
-
ApiSupportedCapabilities caps = await SenseHelper.GetSupportedCapabilitiesAsync();
-
- //Use StepCounterUpdate to trigger live tile update if it is supported. Otherwise we use time trigger
+ // Use StepCounterUpdate to trigger live tile update if it is supported. Otherwise we use time trigger
if (caps.StepCounterTrigger)
{
var myTrigger = new DeviceManufacturerNotificationTrigger(SenseTrigger.StepCounterUpdate, false);
@@ -223,39 +249,42 @@ private async void ApplicationBarRegisterUnRegisterTile(object sender, EventArgs
else
{
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
-
IBackgroundTrigger trigger = new TimeTrigger(15, false);
await RegisterBackgroundTaskAsync(trigger, "StepTriggered", "BackgroundTasks.StepTriggerTask");
}
-
}
else
{
- //On emulator we use always TimeTrigger
+ // On emulator we use always TimeTrigger
BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();
-
IBackgroundTrigger trigger = new TimeTrigger(15, false);
await RegisterBackgroundTaskAsync(trigger, "StepTriggered", "BackgroundTasks.StepTriggerTask");
}
-
}
-
await CreateOrRemoveTileAsync(removeTile);
-
return;
}
+ ///
+ /// Select next day.
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void ApplicationBarIconButton_Click_Next(object sender, EventArgs e)
{
await App.Engine.ChangeDayAsync(-1);
UpdateMenuAndAppBarIcons();
}
+ ///
+ /// Select previous day.
+ ///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void ApplicationBarIconButton_Click_Back(object sender, EventArgs e)
{
await App.Engine.ChangeDayAsync(1);
UpdateMenuAndAppBarIcons();
}
-
}
}
\ No newline at end of file
diff --git a/Steps/Package.appxmanifest b/Steps/Package.appxmanifest
index d8c33de..3a68e83 100644
--- a/Steps/Package.appxmanifest
+++ b/Steps/Package.appxmanifest
@@ -1,10 +1,10 @@

-
+
- Steps
- Nokia Developer
+ Steps – Lumia SensorCore SDK sample
+ Lumia SDK
Assets\StoreLogo.png
@@ -38,6 +38,46 @@
+
+
+
+ CLRHost.dll
+
+
+
+
+
+
+ Lumia.Sense.Testing.dll
+
+
+
+
+
+
+
+
+
+
+
+
+ Lumia.Sense.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Steps/Properties/AssemblyInfo.cs b/Steps/Properties/AssemblyInfo.cs
index ce1079c..a10fb03 100644
--- a/Steps/Properties/AssemblyInfo.cs
+++ b/Steps/Properties/AssemblyInfo.cs
@@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Steps")]
-[assembly: AssemblyCopyright("Copyright © 2014")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/Steps/Properties/WMAppManifest.xml b/Steps/Properties/WMAppManifest.xml
index add634a..afd0f5a 100644
--- a/Steps/Properties/WMAppManifest.xml
+++ b/Steps/Properties/WMAppManifest.xml
@@ -1,7 +1,7 @@

-
+
Assets\steps_launcher.png
diff --git a/Steps/Resources/AppResources.Designer.cs b/Steps/Resources/AppResources.Designer.cs
index 31a7cae..301fef2 100644
--- a/Steps/Resources/AppResources.Designer.cs
+++ b/Steps/Resources/AppResources.Designer.cs
@@ -1,4 +1,23 @@
-//------------------------------------------------------------------------------
+/*
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+//------------------------------------------------------------------------------
//
// This code was generated by a tool.
// Runtime Version:4.0.30319.34014
diff --git a/Steps/Steps.csproj b/Steps/Steps.csproj
index 0865ca1..dc57169 100644
--- a/Steps/Steps.csproj
+++ b/Steps/Steps.csproj
@@ -148,10 +148,10 @@
-
-
+
+
@@ -228,12 +228,6 @@
Microsoft Visual C++ 2013 Runtime Package for Windows Phone
-
-
- {139193f3-9fef-4c44-9655-213648597a09}
- BackgroundTasks
-
-
False
@@ -254,14 +248,6 @@
-->
-
-
- This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
diff --git a/Steps/StepsEngine.cs b/Steps/StepsEngine.cs
index be883bf..9779846 100644
--- a/Steps/StepsEngine.cs
+++ b/Steps/StepsEngine.cs
@@ -1,30 +1,59 @@
-using Lumia.Sense;
+/*
+ * Copyright (c) 2015 Microsoft
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+using Lumia.Sense;
using Lumia.Sense.Testing;
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using System.Windows;
-using System.Windows.Navigation;
using System.Windows.Threading;
namespace Steps
{
+ ///
+ /// Steps engine for the application
+ ///
public class StepsEngine
{
-
+ #region Variable declarations
///
/// Access to the main model of the app
///
/// The MainModel of the app
public MainModel MainModel { get; private set; }
+ ///
+ /// Stepcounter. This will be shown on the main screen
+ ///
private IStepCounter _stepCounter;
+ ///
+ /// Timer which is called at a specified interval
+ ///
private DispatcherTimer _pollTimer;
- private bool _active = false;
+ ///
+ /// Boolean variable
+ ///
+ private bool _active = false;
+ #endregion
///
/// constructor
@@ -45,10 +74,8 @@ public async Task DeactivateAsync()
_pollTimer.Stop();
_pollTimer = null;
}
-
if (_stepCounter != null)
await _stepCounter.DeactivateAsync();
-
}
///
@@ -58,7 +85,6 @@ public async Task ActivateAsync()
{
if (_active)
return;
-
if (_stepCounter != null)
{
await _stepCounter.ActivateAsync();
@@ -75,7 +101,6 @@ public async Task ActivateAsync()
_pollTimer.Start();
}
_active = true;
-
}
///
@@ -88,14 +113,15 @@ public async Task UpdateModelAsync()
}
///
- /// +1 one day back, -1 one day forward.
+ /// +1 one day back, -1 one day forward.
///
+ /// Day selected.
+ /// A task.
public async Task ChangeDayAsync(int day)
{
- if (MainModel.day + day > 7 || MainModel.day + day < 0)
+ if (MainModel._day + day > 7 || MainModel._day + day < 0)
return;
-
- MainModel.day += day;
+ MainModel._day += day;
await UpdateModelAsync();
}
@@ -106,33 +132,23 @@ public async Task UpdateGraphAsync()
{
uint firstWalkingSteps = 0;
uint firstRunningSteps = 0;
-
List steps = new List();
-
for (int i = 0; i < MainModel._ArrayMaxSize; i++)
steps.Add(0);
-
IList results = null;
-
- if (MainModel.day == 0)
+ if (MainModel._day == 0)
results = await _stepCounter.GetStepCountHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);
else
- results = await _stepCounter.GetStepCountHistoryAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel.day), TimeSpan.FromDays(1));
-
-
- //If there is no items available in the history, we pass array with full of 0 items.
- //This happens for example when Motion data has been disabled the whole day
-
+ results = await _stepCounter.GetStepCountHistoryAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel._day), TimeSpan.FromDays(1));
+ // If there is no items available in the history, we pass array with full of 0 items.
+ // This happens for example when Motion data has been disabled the whole day
if (results == null || results.Count == 0)
{
MainModel.UpdateGraphSteps(steps);
return true;
}
-
bool first = true;
-
int currentStep = (results[0].Timestamp.Minute + results[0].Timestamp.Hour * 60) / MainModel._resolutionInMinutes;
-
foreach (StepCounterReading reading in results)
{
if (first)
@@ -147,20 +163,16 @@ public async Task UpdateGraphAsync()
currentStep++;
}
}
-
- //If there are gaps in the array we fill them e.g. 13,15,0,20 will be 13,15,15,20
+ // If there are gaps in the array we fill them e.g. 13,15,0,20 will be 13,15,15,20
for (int i = 0; i < currentStep - 1; i++)
{
if (steps[i] > steps[i + 1])
steps[i + 1] = steps[i];
}
-
- //Removes empty items from end of the array
+ // Removes empty items from end of the array
if (currentStep < MainModel._ArrayMaxSize)
steps.RemoveRange(currentStep, steps.Count - currentStep);
-
MainModel.UpdateGraphSteps(steps);
-
return true;
}
@@ -168,16 +180,15 @@ public async Task UpdateGraphAsync()
/// Updates step counters for selected day.
///
public async Task UpdateStepCountersAsync()
- {
-
+ {
if (_stepCounter != null && _active)
{
- if (MainModel.day == 0) //today's step
+ // Today's step
+ if (MainModel._day == 0)
{
StepCounterReading current = null;
bool res = await CallSensorCoreApiAsync(async () => { current = await _stepCounter.GetCurrentReadingAsync(); });
StepCounterReading beginOfDay = await FirstReadingForTodayAsync();
-
if (current != null && beginOfDay != null && res)
{
MainModel.WalkingSteps = current.WalkingStepCount - beginOfDay.WalkingStepCount;
@@ -185,9 +196,10 @@ public async Task UpdateStepCountersAsync()
MainModel.StepsToday = MainModel.WalkingSteps + MainModel.RunningSteps;
}
}
- else //previous days' steps
+ // Previous days steps
+ else
{
- StepCount count = await _stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel.day), TimeSpan.FromDays(1));
+ StepCount count = await _stepCounter.GetStepCountForRangeAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel._day), TimeSpan.FromDays(1));
if (count != null)
{
MainModel.StepsToday = count.RunningStepCount + count.WalkingStepCount;
@@ -203,7 +215,7 @@ public async Task UpdateStepCountersAsync()
}
///
- /// Returns a total number of steps for today
+ /// Returns a total number of steps for today.
///
public async Task GetStepCountAsync()
{
@@ -214,16 +226,16 @@ public async Task GetStepCountAsync()
return steps.WalkingStepCount + steps.RunningStepCount;
}
catch (Exception e)
- {
-
+ {
}
-
return 0;
}
///
- /// Updates step counters every 5 seconds
+ /// Updates step counters every 5 seconds.
///
+ /// The control that the action is for.
+ /// Parameter that contains the event data.
private async void PollTimerTick(object sender, EventArgs e)
{
await UpdateStepCountersAsync();
@@ -242,7 +254,6 @@ public async Task InitializeAsync()
{
await InitializeSensorAsync();
}
-
await UpdateModelAsync();
}
@@ -253,62 +264,54 @@ private async Task InitializeSensorAsync()
{
if (!await StepCounter.IsSupportedAsync())
{
- MessageBox.Show(
- "Your device doesn't support Motion Data. Application will be closed",
- "Information", MessageBoxButton.OK);
+ MessageBox.Show("Your device doesn't support Motion Data. Application will be closed", "Information", MessageBoxButton.OK);
Application.Current.Terminate();
}
-
if (_stepCounter == null)
{
await CallSensorCoreApiAsync(async () => { _stepCounter = await StepCounter.GetDefaultAsync(); });
-
}
else
{
- await _stepCounter.ActivateAsync();
-
+ await _stepCounter.ActivateAsync();
}
_active = true;
}
///
- /// Initializes StepCounterSimulator
+ /// Initializes StepCounterSimulator.
///
public 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();
-
_active = true;
}
///
- /// Helper function that fetches the first existing item for today
+ /// Helper function that fetches the first existing item for today.
///
private async Task FirstReadingForTodayAsync()
{
- //We look at the first value for today.
- var results = await _stepCounter.GetStepCountHistoryAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel.day), TimeSpan.FromDays(1));
-
+ // We look at the first value for today.
+ var results = await _stepCounter.GetStepCountHistoryAsync(DateTime.Now.Date - TimeSpan.FromDays(MainModel._day), TimeSpan.FromDays(1));
if (results != null)
return results[0];
else
return null;
-
}
///
- /// Helper function that catches SensorCore exceptions
+ /// Helper function that catches SensorCore exceptions.
///
+ /// Action for which the SensorCore should be activated.
+ /// Variable to determine is Sensor core has been activated. If not, gives a second try.
+ /// True if SensorCore has been activated. False otherwise.
private async Task CallSensorCoreApiAsync(Func action, bool secondTry = false)
{
Exception failure = null;
-
try
{
await action();
@@ -317,42 +320,31 @@ private async Task CallSensorCoreApiAsync(Func action, bool secondTr
{
failure = e;
}
-
if (failure != null)
{
-
switch (SenseHelper.GetSenseError(failure.HResult))
{
case SenseError.LocationDisabled:
- MessageBoxResult res = MessageBox.Show(
- "Location has been disabled. Do you want to open Location settings now?",
- "Information",
- MessageBoxButton.OKCancel
- );
+ {
+ MessageBoxResult res = MessageBox.Show("Location has been disabled. Do you want to open Location settings now?", "Information", MessageBoxButton.OKCancel);
if (res == MessageBoxResult.OK)
{
await SenseHelper.LaunchLocationSettingsAsync();
}
-
return false;
-
+ }
case SenseError.SenseDisabled:
-
- MessageBoxResult res2 = MessageBox.Show(
- "Motion data has been disabled. Do you want to open Motion data settings now?",
- "Information",
- MessageBoxButton.OKCancel
- );
-
+ {
+ MessageBoxResult res2 = MessageBox.Show("Motion data has been disabled. Do you want to open Motion data settings now?", "Information", MessageBoxButton.OKCancel);
if (res2 == MessageBoxResult.OK)
{
await SenseHelper.LaunchSenseSettingsAsync();
}
-
return false;
-
+ }
case SenseError.SensorDeactivated:
- //If SensorCore is disabled, try to activate it and call again.
+ {
+ // If SensorCore is disabled, try to activate it and call again.
if (secondTry == false)
{
try
@@ -363,20 +355,15 @@ private async Task CallSensorCoreApiAsync(Func action, bool secondTr
{
return false;
}
- return await CallSensorCoreApiAsync(action,true);
-
+ return await CallSensorCoreApiAsync(action, true);
}
-
return false;
-
-
+ }
default:
- MessageBoxResult res3 = MessageBox.Show(
- "Error:" + SenseHelper.GetSenseError(failure.HResult),
- "Information",
- MessageBoxButton.OK);
-
+ {
+ MessageBoxResult res3 = MessageBox.Show("Error:" + SenseHelper.GetSenseError(failure.HResult), "Information", MessageBoxButton.OK);
return false;
+ }
}
}
else
@@ -386,8 +373,16 @@ private async Task CallSensorCoreApiAsync(Func action, bool secondTr
}
}
+ ///
+ /// Toast helper
+ ///
public sealed class Helper
{
+ ///
+ /// Returns metter based on number of steps.
+ ///
+ /// Number of steps.
+ /// Metter value.
public static uint GetMeter(uint steps)
{
if (steps < 1400) { return 1; }
@@ -400,6 +395,11 @@ public static uint GetMeter(uint steps)
else { return 8; }
}
+ ///
+ /// Returns small metter based on number of steps.
+ ///
+ /// Number of steps.
+ /// Small metter value.
public static uint GetSmallMeter(uint steps)
{
if (steps < 2000) { return 0; }
@@ -409,5 +409,4 @@ public static uint GetSmallMeter(uint steps)
else { return 3; }
}
}
-
}
diff --git a/Steps/app.config b/Steps/app.config
index e42165f..69f3511 100644
--- a/Steps/app.config
+++ b/Steps/app.config
@@ -2,6 +2,10 @@
+
+
+
+