This commit is contained in:
Satyam Bandarapu 2015-03-03 11:53:55 +02:00
Родитель 9a3338a431
Коммит 789bdb9b01
19 изменённых файлов: 1080 добавлений и 1 удалений

6
.nuget/NuGet.Config Normal file
Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>

Двоичные данные
.nuget/NuGet.exe Normal file

Двоичный файл не отображается.

144
.nuget/NuGet.targets Normal file
Просмотреть файл

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
</PropertyGroup>
<PropertyGroup>
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
</PropertyGroup>
<PropertyGroup>
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
</PropertyGroup>
<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>
<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>
<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>

Просмотреть файл

@ -1 +1,76 @@
# SimpleTracks
SimpleTracks
==========
SimpleTracks is a sample application which demonstrates the usage of the
TrackPoint Monitor API in Windows Phone 8.1. This application visualizes the
tracks on the map. The user is able to see the tracks from the last seven
days as well as tracks history by using the application bar buttons.
1. Instructions
--------------------------------------------------------------------------------
Learn about the Lumia SensorCore SDK from the Lumia Developer's Library. The
example requires the Lumia SensorCore SDK's NuGet package but will retrieve it
automatically (if missing) on first build.
To build the application you need to have Windows 8.1 and Windows Phone SDK 8.1
installed.
Using the Windows Phone 8.1 SDK:
1. Open the SLN file: File > Open Project, select the file `SimpleTracks.sln`
2. Remove the "AnyCPU" configuration (not supported by the Lumia SensorCore SDK)
or simply select ARM
3. Select the target 'Device'.
4. Press F5 to build the project and run it on the device.
Please see the official documentation for
deploying and testing applications on Windows Phone devices:
http://msdn.microsoft.com/en-us/library/gg588378%28v=vs.92%29.aspx
2. Implementation
--------------------------------------------------------------------------------
The application supports compatibility between new and old phone. On start it makes a call to the SDK to get the supported
API. Based on the response it continues to run and if services are disabled, the corresponding error messages will be
shown.
For the next step the application checks if the track monitor is null and if the condition is satisfied it makes a
call to the Sense SDK to initialize the trackpoint monitor by getting the default async. for this, the location and motion
data have to be enabled.
If the trackpoint monitor cannot be instantiated, the application wil throw an error message and will exit.
After instantiating the trackpoint monitor the map will load on the screen showing the current location of the
user if this can be found, otherwise it will show a static location. Next, it makes a call to the trackpoint history
getting all the recorded tracks for the current day o, a day from the past or in the last case, for all the days that have
tracks in the history drawing a connecting line between all of them.
In order to display the tracks, a push pin is drawn on the map for each track, this containing information about the place
for the track. The application also records activities that have been launched from one trackpoint to another.
Tapping on a push pin will open a new page in the app displaying additional information for the track such as latitude
and longitude, duration of stay and place information.
Navigation between days is possible with the back and forward buttons.
3. Version history
--------------------------------------------------------------------------------
* Version 1.1.0.0: The first release.
4. Downloads
---------
| Project | Release | Download |
| ------- | --------| -------- |
| SimpleTracks | v1.1.0.0 | [simpletracks-1.1.0.0.zip](https://github.com/Microsoft/SimpleTracks/archive/v1.1.0.0.zip) |
5. See also
--------------------------------------------------------------------------------
The projects listed below are exemplifying the usage of the SensorCore APIs
* SimpleActivity - https://github.com/Microsoft/SimpleActivity
* SimpleSteps - https://github.com/Microsoft/SimpleSteps
* SimplePlaces - https://github.com/Microsoft/SimplePlaces

47
SimpleTracks.sln Normal file
Просмотреть файл

@ -0,0 +1,47 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleTracks", "SimpleTracks\SimpleTracks.csproj", "{7385ECB2-7C64-4B66-A566-879509A52135}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{984BDE59-B7CA-41BB-B61B-A13C5C7EEABF}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.exe = .nuget\NuGet.exe
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|ARM.ActiveCfg = Debug|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|ARM.Build.0 = Debug|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|ARM.Deploy.0 = Debug|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|x86.ActiveCfg = Debug|x86
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|x86.Build.0 = Debug|x86
{7385ECB2-7C64-4B66-A566-879509A52135}.Debug|x86.Deploy.0 = Debug|x86
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|Any CPU.Build.0 = Release|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|Any CPU.Deploy.0 = Release|Any CPU
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|ARM.ActiveCfg = Release|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|ARM.Build.0 = Release|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|ARM.Deploy.0 = Release|ARM
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|x86.ActiveCfg = Release|x86
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|x86.Build.0 = Release|x86
{7385ECB2-7C64-4B66-A566-879509A52135}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

7
SimpleTracks/App.xaml Normal file
Просмотреть файл

@ -0,0 +1,7 @@
<Application
x:Class="SimpleTracks.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SimpleTracks">
</Application>

144
SimpleTracks/App.xaml.cs Normal file
Просмотреть файл

@ -0,0 +1,144 @@
/*
The MIT License (MIT)
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 Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Navigation;
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace SimpleTracks
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public sealed partial class App : Application
{
private TransitionCollection transitions;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += this.OnSuspending;
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
this.DebugSettings.EnableFrameRateCounter = true;
}
#endif
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
// TODO: change this value to a cache size that is appropriate for your application
rootFrame.CacheSize = 1;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (rootFrame.Content == null)
{
// Removes the turnstile navigation for startup.
if (rootFrame.ContentTransitions != null)
{
this.transitions = new TransitionCollection();
foreach (var c in rootFrame.ContentTransitions)
{
this.transitions.Add(c);
}
}
rootFrame.ContentTransitions = null;
rootFrame.Navigated += this.RootFrame_FirstNavigated;
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), e.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
}
/// <summary>
/// Restores the content transitions after the app has launched.
/// </summary>
/// <param name="sender">The object where the handler is attached.</param>
/// <param name="e">Details about the navigation event.</param>
private void RootFrame_FirstNavigated(object sender, NavigationEventArgs e)
{
var rootFrame = sender as Frame;
rootFrame.ContentTransitions = this.transitions ?? new TransitionCollection() { new NavigationThemeTransition() };
rootFrame.Navigated -= this.RootFrame_FirstNavigated;
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
// TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}

Двоичные данные
SimpleTracks/Assets/Logo.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.5 KiB

Двоичные данные
SimpleTracks/Assets/SmallLogo.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 753 B

Двоичные данные
SimpleTracks/Assets/SplashScreen.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 14 KiB

Двоичные данные
SimpleTracks/Assets/Square71x71Logo.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

Двоичные данные
SimpleTracks/Assets/StoreLogo.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.1 KiB

Двоичные данные
SimpleTracks/Assets/WideLogo.scale-240.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 4.4 KiB

Просмотреть файл

@ -0,0 +1,34 @@
<Page
x:Class="SimpleTracks.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SimpleTracks"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="#FF9900">
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TopPanel" Grid.Row="0" Margin="24,7,0,8" >
<TextBlock Text="SimpleTracks" Margin="0,12,0,0" Style="{ThemeResource HeaderTextBlockStyle}" Foreground="Black"/>
</StackPanel>
<Grid Grid.Row="1">
<Maps:MapControl x:Name="TracksMapControl" ZoomLevel="13" Margin="0,0,0,0" />
<TextBlock x:Name="FilterTime" FontSize="24" TextAlignment="Right" Width="480" Height="30" HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="#7F000000" Margin="5,5"/>
</Grid>
</Grid>
<Page.BottomAppBar>
<CommandBar x:Name="CmdBar" Background="#FF9900" Foreground="Black">
<AppBarButton Label="PreviousDay" x:Uid="PreviousButton" x:Name="PreviousButton" Icon="Previous" Click="GoToPreviousDay"/>
<AppBarButton Label="NextDay" x:Uid="NextButton" x:Name="NextButton" Icon="Next" Click="GoToNextDay"/>
<AppBarButton Label="Show History" x:Uid="HistoryButton" x:Name="HistoryButton" Icon="ShowResults" Click="ShowHistory"/>
</CommandBar>
</Page.BottomAppBar>
</Page>

Просмотреть файл

@ -0,0 +1,420 @@
/*
The MIT License (MIT)
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 System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
using Windows.UI;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Navigation;
namespace SimpleTracks
{
/// <summary>
/// Class to display tracks from visited places on the map.
/// </summary>
public sealed partial class MainPage : Page
{
#region Private members
/// <summary>
/// Place monitor instance
/// </summary>
private TrackPointMonitor _trackMonitor = null;
/// <summary>
/// Current date for moving between next and previous days
/// </summary>
private DateTime _iCurrentDate = DateTime.Today;
/// <summary>
/// check to see launching finished or not
/// </summary>
private bool iLaunched = false;
/// <summary>
/// visited places history
/// </summary>
private IList<TrackPoint> _trackPointList = null;
/// <summary>
/// Lines for drawing the Tracks.
/// </summary>
private IList<MapPolyline> _routeLines = new List<MapPolyline>();
#endregion
/// <summary>
/// constructor
/// </summary>
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
Window.Current.VisibilityChanged += async ( oo, ee ) =>
{
if( !ee.Visible && _trackMonitor != null )
{
await CallSenseApiAsync( async () =>
{
await _trackMonitor.DeactivateAsync();
} );
}
else if( _trackMonitor != null )
{
await CallSenseApiAsync( async () =>
{
await _trackMonitor.ActivateAsync();
} );
UpdateScreenAsync();
}
};
}
/// <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();
}
/// <summary>
/// Gets the history of trackpoints places visited on a day.
/// </summary>
private async Task GetHistory()
{
//gets the places visited on that day
await CallSenseApiAsync( async () =>
_trackPointList = await _trackMonitor.GetTrackPointsAsync( _iCurrentDate, TimeSpan.FromDays( 1 ) ) );
}
/// <summary>
/// Updates visualization
/// </summary>
private void UpdateScreenAsync()
{
if( _trackMonitor != null )
{
if( _trackPointList != null && _trackPointList.Count > 0 )
{
TracksMapControl.MapElements.Clear();
FilterTime.Text = _iCurrentDate.ToString( "MMM dd yyyy", CultureInfo.InvariantCulture );
DrawTrackPoints(_trackPointList);
}
}
}
/// <summary>
/// Draws the track points.
/// </summary>
/// <param name="trackPoints">track points</param>
private void DrawTrackPoints(IList<TrackPoint> trackPoints)
{
var previous = new BasicGeoposition();
bool first = true;
if( _routeLines != null )
{
_routeLines.Clear();
_routeLines = null;
}
_routeLines = new List<MapPolyline>();
int i = -1;
foreach( var point in trackPoints )
{
// Create a line connecting to the previous map point
if( !first )
{
_routeLines.Add( new MapPolyline());
_routeLines[ i ].Path = new Geopath( new List<BasicGeoposition> { previous, point.Position } );
_routeLines[ i ].StrokeThickness = 3;
_routeLines[ i ].StrokeColor = Color.FromArgb( 255, 100, 100, 255 );
_routeLines[ i ].StrokeDashed = false;
TracksMapControl.MapElements.Add( _routeLines[ i ] );
}
else
{
TracksMapControl.Center = new Geopoint( point.Position );
TracksMapControl.ZoomLevel = 13;
first = false;
}
previous = point.Position;
i++;
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
// Make sure the sensors are instantiated
if( !iLaunched )
{
iLaunched = true;
await Initialize();
}
}
/// <summary>
/// Displays tracks of previous day visited places
/// </summary>
/// <param name="sender">sender of the event</param>
/// <param name="e">Event arguments </param>
private async void GoToPreviousDay( object sender, RoutedEventArgs e )
{
if( ( DateTime.Now.Date - _iCurrentDate ) < TimeSpan.FromDays( 6 ) )
{
_iCurrentDate = _iCurrentDate.AddDays( -1 );
FilterTime.Text = _iCurrentDate.ToString( "MMM dd yyyy", CultureInfo.InvariantCulture );
await GetHistory();
// if no tracks for a day, remove other day tracks from the map
if( ( _trackPointList == null || _trackPointList.Count <= 0 ) )
{
if( _routeLines != null )
{
_routeLines.Clear();
_routeLines = null;
}
TracksMapControl.MapElements.Clear();
}
else
{
UpdateScreenAsync();
}
}
else
{
MessageDialog dialog = new MessageDialog( "This application displays only tracks of last seven days visited places.", "Tracks" );
await dialog.ShowAsync();
}
}
/// <summary>
/// Displays next day visited places
/// </summary>
/// <param name="sender">sender of the event</param>
/// <param name="e">Event arguments</param>
private async void GoToNextDay( object sender, RoutedEventArgs e )
{
if( _iCurrentDate.Date < DateTime.Now.Date )
{
_iCurrentDate = _iCurrentDate.AddDays( 1 );
FilterTime.Text = _iCurrentDate.ToString( "MMM dd yyyy", CultureInfo.InvariantCulture );
await GetHistory();
// if no tracks for a day, remove other day tracks from the map
if( ( _trackPointList == null || _trackPointList.Count <= 0 ) )
{
if(_routeLines != null)
{
_routeLines.Clear();
_routeLines = null;
}
TracksMapControl.MapElements.Clear();
}
else
{
// if there are any tracks update the screen
UpdateScreenAsync();
}
}
else
{
MessageDialog dialog = new MessageDialog( "Can't display future Tracks", "Tracks" );
await dialog.ShowAsync();
}
}
/// <summary>
/// Gets history of places visited from last seven days.
/// </summary>
/// <param name="sender">sender of the event</param>
/// <param name="e">Event arguments</param>
private async void ShowHistory( object sender, RoutedEventArgs e )
{
await CallSenseApiAsync( async () => _trackPointList =
await _trackMonitor.GetTrackPointsAsync( DateTime.Today.AddDays( -7 ), TimeSpan.FromDays( 8 ) ) );
FilterTime.Text = DateTime.Today.ToString( "MMM dd yyyy", CultureInfo.InvariantCulture ) + " - " + DateTime.Today.AddDays( -7 ).ToString( "MMM dd yyyy", CultureInfo.InvariantCulture );
// update tracks on the map
if( _trackPointList != null && _trackPointList.Count > 0 )
{
//clear previous tracks
if( _routeLines != null )
{
_routeLines.Clear();
_routeLines = null;
TracksMapControl.MapElements.Clear();
}
//add all tracks
DrawTrackPoints( _trackPointList );
}
}
/// <summary>
/// Performs asynchronous SensorCore SDK operation and handles any exceptions
/// </summary>
/// <param name="action"></param>
/// <returns><c>true</c> if call was successful, <c>false</c> otherwise</returns>
private async Task<bool> CallSenseApiAsync( Func<Task> action )
{
Exception failure = null;
try
{
await action();
}
catch( Exception e )
{
failure = e;
}
if( failure != null )
{
bool status = false;
MessageDialog dialog = null;
switch( SenseHelper.GetSenseError( failure.HResult ) )
{
case SenseError.LocationDisabled:
dialog = 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 Location settings now? if no, application will close", "Information" );
dialog.Commands.Add( new UICommand( "Yes", new UICommandInvokedHandler( async ( cmd ) =>
{
status = true;
await SenseHelper.LaunchLocationSettingsAsync();
} ) ) );
dialog.Commands.Add( new UICommand( "No" ) );
await dialog.ShowAsync();
return status;
case SenseError.SenseDisabled:
dialog = new MessageDialog( "In order to collect and view tracks of visited places you need to enable Places visited in Motion data settings. Do you want to open Motion data settings now? if no, application will close", "Information" );
dialog.Commands.Add( new UICommand( "Yes", new UICommandInvokedHandler( async ( cmd ) =>
{
status = true;
await SenseHelper.LaunchSenseSettingsAsync();
} ) ) );
dialog.Commands.Add( new UICommand( "No" ) );
await dialog.ShowAsync();
return status;
case SenseError.IncompatibleSDK:
dialog = new MessageDialog( "This application has become outdated. Please update to the latest version.", "Information" );
await dialog.ShowAsync();
return false;
default:
return false;
}
}
else
{
return true;
}
}
}
}

Просмотреть файл

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest" xmlns:m3="http://schemas.microsoft.com/appx/2014/manifest" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest">
<Identity Name="LumiaDeveloper.SimpleTracksSensorCoreSDKsample" Publisher="CN=4AD6DA08-6C39-4A10-98CC-3243374DA59C" Version="1.1.0.0" />
<mp:PhoneIdentity PhoneProductId="c55e98e9-6325-4c53-a214-52559b7d0d17" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties>
<DisplayName>SimpleTracks</DisplayName>
<PublisherDisplayName>Lumia SDK</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.3.1</OSMinVersion>
<OSMaxVersionTested>6.3.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="SimpleTracks.App">
<m3:VisualElements DisplayName="SimpleTracks– Lumia SensorCore SDK sample" Square150x150Logo="Assets\Logo.png" Square44x44Logo="Assets\SmallLogo.png" Description="SimpleTracks" ForegroundText="light" BackgroundColor="transparent">
<m3:DefaultTile Wide310x150Logo="Assets\WideLogo.png" Square71x71Logo="Assets\Square71x71Logo.png">
</m3:DefaultTile>
<m3:SplashScreen Image="Assets\SplashScreen.png" />
</m3:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClientServer" />
<DeviceCapability Name="location" />
<m2:DeviceCapability Name="humaninterfacedevice">
<m2:Device Id="vidpid:0421 0716">
<m2:Function Type="usage:ffaa 0001" />
<m2:Function Type="usage:ffee 0001" />
<m2:Function Type="usage:ffee 0002" />
<m2:Function Type="usage:ffee 0003" />
<m2:Function Type="usage:ffee 0004" />
</m2:Device>
</m2:DeviceCapability>
</Capabilities>
</Package>

Просмотреть файл

@ -0,0 +1,29 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SimpleTracks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SimpleTracks")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: ComVisible(false)]

Просмотреть файл

@ -0,0 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7385ECB2-7C64-4B66-A566-879509A52135}</ProjectGuid>
<OutputType>AppContainerExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SimpleTracks</RootNamespace>
<AssemblyName>SimpleTracks</AssemblyName>
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformVersion>8.1</TargetPlatformVersion>
<MinimumVisualStudioVersion>12</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{76F1466A-8B6D-4E39-A767-685A06062A39};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>e7a8de6e</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\ARM\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<NoWarn>;2008</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
<OutputPath>bin\ARM\Release\</OutputPath>
<DefineConstants>TRACE;NETFX_CORE;WINDOWS_PHONE_APP</DefineConstants>
<Optimize>true</Optimize>
<NoWarn>;2008</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>ARM</PlatformTarget>
<UseVSHostingProcess>false</UseVSHostingProcess>
<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>
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
<None Include="Help\LumiaSensorCoreSDK.chm" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Assets\Logo.scale-240.png" />
<Content Include="Assets\SmallLogo.scale-240.png" />
<Content Include="Assets\SplashScreen.scale-240.png" />
<Content Include="Assets\Square71x71Logo.scale-240.png" />
<Content Include="Assets\StoreLogo.scale-240.png" />
<Content Include="Assets\WideLogo.scale-240.png" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</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)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
</Project>

Просмотреть файл

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
</packages>