You can now look at up to 10 days of recorded data (if available) by
using arrow buttons to navigate back and forth.
This commit is contained in:
Lucian Tomuta 2014-10-02 15:09:32 +03:00
Родитель 978380c537
Коммит 844212d103
13 изменённых файлов: 175 добавлений и 20 удалений

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>

Двоичные данные
Activities/Assets/back.png Normal file

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

После

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

Двоичные данные
Activities/Assets/next.png Normal file

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

После

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

Двоичные данные
Activities/Assets/refresh.png Normal file

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

После

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

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

@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.UI.Xaml.Data;
namespace ActivitiesExample.Converters
{
class TimeWindowToString : IValueConverter
{
private readonly ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("Resources");
public object Convert(object value, Type targetType, object parameter, string language)
{
string twString = "";
if ((double)value == 0)
{
twString = this.resourceLoader.GetString("TimeWindow/Today");
}
else if ((double)value == -1)
{
twString = this.resourceLoader.GetString("TimeWindow/Yesterday");
}
else
{
var sdatefmt = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("shortdate");
twString = sdatefmt.Format(DateTime.Now.Date.AddDays((double)value));
}
return twString;
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
string result = "";
return result;
}
}
}

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

@ -21,6 +21,9 @@ namespace ActivitiesExample.Data
private IList<ActivityMonitorReading> _history;
private Activity _activity = Activity.Idle;
// time window index, 0 = today, -1 = yesterday
private double timeWindowIndex = 0;
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
@ -60,6 +63,32 @@ namespace ActivitiesExample.Data
}
}
public double TimeWindow
{
get
{
return timeWindowIndex;
}
}
public void NextDay()
{
if (timeWindowIndex < 0)
{
timeWindowIndex++;
NotifyPropertyChanged("TimeWindow");
}
}
public void PreviousDay()
{
if (timeWindowIndex >= -9)
{
timeWindowIndex--;
NotifyPropertyChanged("TimeWindow");
}
}
public IList<ActivityMonitorReading> History
{
get

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

@ -17,6 +17,9 @@ namespace ActivitiesExample.Data
private List<MyQuantifiedData> _ListData = null;
private static MyDesignData _self;
// time window index, 0 = today, -1 = yesterday
private double timeWindowIndex = 0;
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
@ -63,6 +66,15 @@ namespace ActivitiesExample.Data
return _ListData;
}
}
public double TimeWindow
{
get
{
return timeWindowIndex;
}
}
}
}

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

@ -10,21 +10,22 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="#FF1bA1E2">
<Page.Resources>
<converters:ElipsisVisible x:Key="VisibleElipsis"/>
<converters:TimeSpanToString x:Key="TimeToString"/>
<converters:TimeSpanToWidth x:Key="TimeToWidth"/>
<converters:ActivityToImage x:Key="ActivityToIcon"/>
<converters:ActivityToActivityHint x:Key="ActivityToHint"/>
<converters:TimeWindowToString x:Key="TimeWindowToString"/>
</Page.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="24,24,24,0" >
<TextBlock x:Uid="ApplicationSuite" Text="_SensorCore Example" Style="{ThemeResource TitleTextBlockStyle}" Typography.Capitals="SmallCaps" Foreground="White"/>
@ -39,7 +40,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- current activity text -->
<StackPanel Grid.Row="0" Margin="24,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Left">
<TextBlock x:Uid="CurrentActivityHeader" Text="_Current activity:" FontSize="{StaticResource TextStyleMediumFontSize}" VerticalAlignment="Center"/>
@ -50,28 +51,29 @@
<Image Source="{Binding CurrentActivity, Converter={StaticResource ActivityToIcon}}" Grid.Row="2" Opacity=".1" Height="300" Width="300"/>
<!-- List of activities -->
<TextBlock x:Uid="ActivitiesListHeader" Text="_Today's activities" Grid.Row="1" Margin="24,0,0,6" FontSize="{StaticResource TextStyleMediumFontSize}"/>
<TextBlock Text="{Binding Path=TimeWindow, Converter={StaticResource ResourceKey=TimeWindowToString}, Mode=OneWay}" Grid.Row="1" Margin="24,0,0,6" FontSize="{StaticResource TextStyleMediumFontSize}"/>
<ListView x:Name="ActivityListView" Grid.Row="2" Margin="24,0" ItemsSource="{Binding Path=ListData, Mode=OneWay}" Background="#3FFFFFFF" SelectionMode="None" Height="310">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0" Height="60">
<Grid.RowDefinitions >
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="95*"/>
<ColumnDefinition Width="227*"/>
<ColumnDefinition Width="30"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Row="01" Grid.ColumnSpan="2" Orientation="Horizontal" Margin="12,0,0,0" >
<StackPanel Grid.ColumnSpan="3" Orientation="Horizontal" Margin="12,8,-0.333,0" Grid.RowSpan="2" >
<TextBlock Text="{Binding Path=ActivityName}" FontSize="{StaticResource TextStyleMediumFontSize}" Foreground="White" VerticalAlignment="Center"/>
<TextBlock Text="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToString}}" FontSize="{StaticResource TextStyleMediumFontSize}" Foreground="White" Margin="12,0,0,0" VerticalAlignment="Center"/>
</StackPanel>
<TextBlock Grid.Row="2" Text="{Binding Path=ActivityName, Converter={StaticResource ResourceKey=ActivityToHint}}" FontSize="{StaticResource TextStyleSmallFontSize}" Foreground="White" VerticalAlignment="Center" Margin="12,0,0,6"/>
<Rectangle Margin="0" Grid.Row="3" Grid.Column="0" Width="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToWidth}}" Height="6" Fill="White" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" Visibility="{Binding ActivityTime, Converter={StaticResource VisibleElipsis}}">
<TextBlock Grid.Row="2" Text="{Binding Path=ActivityName, Converter={StaticResource ResourceKey=ActivityToHint}}" FontSize="{StaticResource TextStyleSmallFontSize}" Foreground="White" VerticalAlignment="Center" Margin="12,0,29.667,5.833" Grid.ColumnSpan="3"/>
<Rectangle Margin="0,0.167,-29.333,0" Grid.Row="3" Grid.Column="0" Width="{Binding Path=ActivityTime, Converter={StaticResource ResourceKey=TimeToWidth}}" Height="6" Fill="White" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.ColumnSpan="3"/>
<StackPanel Grid.Row="3" Grid.Column="2" Orientation="Horizontal" Visibility="{Binding ActivityTime, Converter={StaticResource VisibleElipsis}}" Margin="0.333,0.167,-0.333,0">
<Rectangle Margin="6,0,0,0" Width="6" Height="6" Fill="White" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Rectangle Margin="6,0,0,0" Width="6" Height="6" Fill="White" HorizontalAlignment="Right" VerticalAlignment="Top"/>
</StackPanel>
@ -79,9 +81,9 @@
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<!-- x coordinates -->
<Grid Grid.Row="4" Margin="24,0,24,24" Height="24">
<Grid Grid.Row="4" Margin="24,0,24,12" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="3*"/>
@ -99,12 +101,27 @@
</Grid>
<Page.BottomAppBar>
<CommandBar ClosedDisplayMode="Minimal" Opacity="0.5">
<CommandBar Opacity="0.5">
<AppBarButton x:Uid="PrevButton" x:Name="prevButton" Label="_previous" IsEnabled="True" Click="prevButton_Click" >
<AppBarButton.Icon>
<BitmapIcon UriSource="/Assets/back.png"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton x:Uid="RefreshButton" x:Name="refreshButton" Label="_refresh" IsEnabled="True" Click="RefreshButton_Click" >
<AppBarButton.Icon>
<BitmapIcon UriSource="/Assets/refresh.png"/>
</AppBarButton.Icon>
</AppBarButton>
<AppBarButton x:Uid="NextButton" x:Name="nextButton" Label="_next" IsEnabled="False" Click="nextButton_Click" >
<AppBarButton.Icon>
<BitmapIcon UriSource="/Assets/next.png"/>
</AppBarButton.Icon>
</AppBarButton>
<CommandBar.SecondaryCommands>
<AppBarButton x:Uid="Refresh" Label="_refresh _todays' _activities" Click="RefreshButton_Click"/>
<!-- <AppBarButton x:Uid="Refresh" Label="_refresh _todays' _activities" Click="RefreshButton_Click"/> -->
<AppBarButton x:Uid="About" Label="_about" Click="AboutButton_Click"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.BottomAppBar>
</Page>

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

@ -39,6 +39,7 @@ namespace ActivitiesExample
private IActivityMonitor _activityMonitor = null;
private bool _runningInEmulator = false;
private readonly ResourceLoader resourceLoader = ResourceLoader.GetForCurrentView("Resources");
#endregion
/// <summary>
@ -245,8 +246,8 @@ namespace ActivitiesExample
{
if (!await CallSensorCoreApiAsync(async () =>
{
// read all the activities recorded today by the Lumia SensorCore
MyData.Instance().History = await _activityMonitor.GetActivityHistoryAsync(DateTime.Now.Date, DateTime.Now - DateTime.Now.Date);
// get the data for the current 24h time window
MyData.Instance().History = await _activityMonitor.GetActivityHistoryAsync(DateTime.Now.Date.AddDays(MyData.Instance().TimeWindow), new TimeSpan(24,0,0 ));
}))
{
Debug.WriteLine("Reading the history failed.");
@ -263,6 +264,27 @@ namespace ActivitiesExample
{
PollHistory();
}
private void prevButton_Click(object sender, RoutedEventArgs e)
{
// move the time window 24 to the past
MyData.Instance().PreviousDay();
nextButton.IsEnabled = true;
prevButton.IsEnabled = MyData.Instance().TimeWindow > -10;
refreshButton.IsEnabled = false;
PollHistory();
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
// move the time window 24h to the present
MyData.Instance().NextDay();
nextButton.IsEnabled = MyData.Instance().TimeWindow < 0;
prevButton.IsEnabled = true;
refreshButton.IsEnabled = MyData.Instance().TimeWindow == 0;
PollHistory();
}
}
}

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

@ -1,6 +1,6 @@
<?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="74dcbd9a-3772-41a5-b7d4-f1e511e6b0cd" Publisher="CN=sujesh" Version="1.0.0.0" />
<Identity Name="74dcbd9a-3772-41a5-b7d4-f1e511e6b0cd" Publisher="CN=sujesh" Version="1.0.0.1" />
<Properties>
<DisplayName>Activities</DisplayName>
<PublisherDisplayName>Nokia Developer</PublisherDisplayName>

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

@ -186,9 +186,24 @@ The application will now exit.</value>
<data name="Hint.Walking" xml:space="preserve">
<value>The user was walking with the phone.</value>
</data>
<data name="NextButton.Label" xml:space="preserve">
<value>next day</value>
</data>
<data name="PrevButton.Label" xml:space="preserve">
<value>previous day</value>
</data>
<data name="Refresh.Label" xml:space="preserve">
<value>refresh todays' activities</value>
</data>
<data name="RefreshButton.Label" xml:space="preserve">
<value>update history</value>
</data>
<data name="TimeWindow.Today" xml:space="preserve">
<value>Today</value>
</data>
<data name="TimeWindow.Yesterday" xml:space="preserve">
<value>Yesterday</value>
</data>
<data name="Version.Text" xml:space="preserve">
<value>Version: </value>
<comment>.</comment>

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

@ -22,6 +22,7 @@
<NuGetPackageImportStamp>8de5a172</NuGetPackageImportStamp>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
<RestorePackages>true</RestorePackages>
<AppxBundle>Never</AppxBundle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -74,6 +75,8 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
<DocumentationFile>
</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
@ -97,6 +100,7 @@
<Compile Include="Converters\ActivityToImage.cs" />
<Compile Include="Converters\TimeSpanToWidth.cs" />
<Compile Include="Converters\TimeSpanToString.cs" />
<Compile Include="Converters\TimeWindowToString.cs" />
<Compile Include="Data\MyDesignData.cs" />
<Compile Include="Data\MyData.cs" />
<Compile Include="MainPage.xaml.cs">
@ -138,6 +142,9 @@
<Content Include="Assets\Activities\walking.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Assets\back.png" />
<Content Include="Assets\next.png" />
<Content Include="Assets\refresh.png" />
<Content Include="Assets\Square150x150Logo.scale-240.png" />
<Content Include="Assets\Square44x44Logo.scale-240.png" />
<Content Include="Assets\Square71x71Logo.scale-140.png" />

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

@ -1,11 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "activities", "Activities\activities.csproj", "{613082E5-767C-439B-93E1-0B7968ADE746}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{912DA981-476B-4FA7-8BB4-64F6D8DF0177}"
ProjectSection(SolutionItems) = preProject
.nuget\NuGet.Config = .nuget\NuGet.Config
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution