Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
bug fixes + coding format
Browse files Browse the repository at this point in the history
  • Loading branch information
satyambandarapu committed Jan 29, 2015
1 parent 9745718 commit c77d4a6
Show file tree
Hide file tree
Showing 25 changed files with 688 additions and 543 deletions.
62 changes: 8 additions & 54 deletions BackgroundTasks/BackgroundTasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,8 @@
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<NuGetPackageImportStamp>5ff7fa89</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NuGetPackageImportStamp>3ddbf11a</NuGetPackageImportStamp>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -58,28 +42,6 @@
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="OEMTask.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -88,6 +50,12 @@
<None Include="Help\LumiaSensorCoreSDK.chm" />
<None Include="packages.config" />
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetPlatformIdentifier)' == '' ">
<TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier>
</PropertyGroup>
<ItemGroup>
<Reference Include="Lumia.Sense, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -98,22 +66,8 @@
<HintPath>..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\lib\portable-wpa81+wp81\x86\Lumia.Sense.Testing.winmd</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '12.0' ">
<VisualStudioVersion>12.0</VisualStudioVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetPlatformIdentifier)' == '' ">
<TargetPlatformIdentifier>WindowsPhoneApp</TargetPlatformIdentifier>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\$(TargetPlatformVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets'))" />
<Error Condition="!Exists('..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets'))" />
</Target>
<Import Project="..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets" Condition="Exists('..\packages\LumiaSensorCoreSDK.1.0.3.263\build\wpa81\LumiaSensorCoreSDK.targets')" />
<Import Project="..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets" Condition="Exists('..\packages\LumiaSensorCoreSDKTesting.1.0.3.263\build\wpa81\LumiaSensorCoreSDKTesting.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
86 changes: 52 additions & 34 deletions BackgroundTasks/OEMTask.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@

/*
* 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.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Background;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Lumia.Sense;
using Windows.UI.StartScreen;


namespace BackgroundTasks
{
Expand All @@ -20,6 +31,11 @@ namespace BackgroundTasks
/// </summary>
public sealed class Helper
{
/// <summary>
/// Returns metter based on number of steps.
/// </summary>
/// <param name="steps">Number of steps.</param>
/// <returns>Metter value.</returns>
public static uint GetMeter(uint steps)
{
if (steps < 1400) { return 1; }
Expand All @@ -32,6 +48,11 @@ public static uint GetMeter(uint steps)
else { return 8; }
}

/// <summary>
/// Returns small metter based on number of steps.
/// </summary>
/// <param name="steps">Number of steps.</param>
/// <returns>Small metter value.</returns>
public static uint GetSmallMeter(uint steps)
{
if (steps < 2000) { return 0; }
Expand All @@ -47,10 +68,22 @@ public static uint GetSmallMeter(uint steps)
/// </summary>
public sealed class StepTriggerTask : IBackgroundTask
{
private const string TileID = "SecondaryTile.Steps";
#region Variable declarations
/// <summary>
/// Tile ID
/// </summary>
private const string _TileID = "SecondaryTile.Steps";

/// <summary>
/// Number o steps
/// </summary>
StepCount _steps;

/// <summary>
/// Sens error code
/// </summary>
SenseError _lastError;
#endregion

/// <summary>
/// Performs the work of a background task. The system calls this method when
Expand All @@ -60,19 +93,20 @@ public sealed class StepTriggerTask : IBackgroundTask
public async void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

if (await GetStepsAsync())
{
UpdateTile(_steps.RunningStepCount + _steps.WalkingStepCount);
}

deferral.Complete();
}

/// <summary>
/// Gets number of steps for current day
/// </summary>
/// <returns>True</returns>
private async Task<bool> GetStepsAsync()
{
StepCounter stepCounter = null;

try
{
stepCounter = await StepCounter.GetDefaultAsync();
Expand All @@ -91,65 +125,49 @@ private async Task<bool> GetStepsAsync()
return true;
}

/// <summary>
/// Updates the tile from the home screen
/// </summary>
/// <param name="stepCount">Step count</param>
/// <returns>True if tile has been upated.</returns>
private bool UpdateTile(uint stepCount)
{
uint meter = Helper.GetMeter(stepCount);
uint meter_small = Helper.GetSmallMeter(stepCount);

var smallTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare71x71Image);

XmlNodeList imageAttribute = smallTile.GetElementsByTagName("image");
((XmlElement)imageAttribute[0]).SetAttribute("src", "ms-appx:///Assets/Tiles/small_square" + meter_small + ".png");

var bindingSmall = (XmlElement)smallTile.GetElementsByTagName("binding").Item(0);


// Square tile
var SquareTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01);
var tileTextAttributes = SquareTile.GetElementsByTagName("text");
tileTextAttributes[0].AppendChild(SquareTile.CreateTextNode((_steps.WalkingStepCount + _steps.RunningStepCount).ToString() + " steps"));
tileTextAttributes[1].AppendChild(SquareTile.CreateTextNode(_steps.RunningStepCount.ToString() + " running steps"));
tileTextAttributes[2].AppendChild(SquareTile.CreateTextNode(_steps.WalkingStepCount.ToString() + " walking steps"));

var bindingSquare = (XmlElement)SquareTile.GetElementsByTagName("binding").Item(0);
bindingSquare.SetAttribute("branding", "none");

XmlNodeList img = SquareTile.GetElementsByTagName("image");
((XmlElement)img[0]).SetAttribute("src", "ms-appx:///Assets/Tiles/square" + meter_small + ".png");

// Provide a wide tile

var wideTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText02);
var squareTileTextAttributes = wideTileXml.GetElementsByTagName("text");
squareTileTextAttributes[0].AppendChild(wideTileXml.CreateTextNode(stepCount.ToString() + " steps today"));

imageAttribute = wideTileXml.GetElementsByTagName("image");
((XmlElement)imageAttribute[0]).SetAttribute("src", "ms-appx:///Assets/Tiles/wide"+meter+".png");



var bindingWide = (XmlElement)wideTileXml.GetElementsByTagName("binding").Item(0);
bindingWide.SetAttribute("branding", "none");


// Add the wide tile to the notification.
var nodeWide = smallTile.ImportNode(bindingWide, true);
var nodeSquare = smallTile.ImportNode(bindingSquare, true);
smallTile.GetElementsByTagName("visual").Item(0).AppendChild(nodeWide);
smallTile.GetElementsByTagName("visual").Item(0).AppendChild(nodeSquare);

// Create the notification based on the XML content.
var tileNotification = new TileNotification(smallTile);

// Create a secondary tile updater and pass it the secondary tileId
var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TileID);

var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(_TileID);
// Send the notification to the secondary tile.
tileUpdater.Update(tileNotification);

return true;
}
}
}

// end of file
45 changes: 0 additions & 45 deletions License.txt

This file was deleted.

20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ Steps is a Lumia SensorCore SDK sample application demonstrating the usage of St
sample application, history data is used to display a graph of user’s steps during
current day, and up to 7 days in the past.

For more information on implementation, visit Lumia Developer's Library:
http://developer.nokia.com/resources/library/Lumia/sensorcore-sdk/samples.html
http://developer.nokia.com/resources/library/Lumia/sensorcore-sdk/step-counter-api.html

1. Instructions
--------------------------------------------------------------------------------

Expand Down Expand Up @@ -58,32 +54,28 @@ from the value of GetCurrentReadingAsync.
To draw the graph we use the same array that the above call to GetStepCountHistoryAsync
returns.

3. Licence
--------------------------------------------------------------------------------

See the licence text file delivered with this project. The licence file is also
available online at https://github.com/Microsoft/steps/blob/master/Licence.txt


4. Version history
3. Version history
--------------------------------------------------------------------------------
* Version 1.1.0.2:
* Some bug fixes made in this release.
* Version 1.1:
* Step counter on live tile gets updated using triggers for background tasks.
* Besides today up to 7 days of step history made available.
* Update to use Lumia SensorCore SDK 1.0
* Version 1.0: The first release.


5. Downloads
4. Downloads
---------

| Project | Release | Download |
| ------- | --------| -------- |
| Steps | v1.1.0.2 | [steps-1.1.0.2.zip](https://github.com/Microsoft/steps/archive/v1.1.0.2.zip) |
| Steps | v1.1 | [steps-1.1.zip](https://github.com/Microsoft/steps/archive/v1.1.zip) |
| Steps | v1.0 | [steps-1.0.zip](https://github.com/Microsoft/steps/archive/v1.0.zip) |


6. See also
5. See also
--------------------------------------------------------------------------------

The projects listed below are exemplifying the usage of the SensorCore APIs
Expand Down
Loading

0 comments on commit c77d4a6

Please sign in to comment.