Tomi Paananen 2013-05-27 13:30:14 +03:00
Родитель bbb084605d e332a46269
Коммит 61e608e8bf
16 изменённых файлов: 550 добавлений и 272 удалений

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

@ -7,11 +7,30 @@ using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using HardwareInfo.Resources;
using HardwareInfo.ViewModels;
namespace HardwareInfo
{
public partial class App : Application
{
private static MainViewModel viewModel = null;
/// <summary>
/// A static ViewModel used by the views to bind against.
/// </summary>
/// <returns>The MainViewModel object.</returns>
public static MainViewModel ViewModel
{
get
{
// Delay creation of the view model until necessary
if (viewModel == null)
viewModel = new MainViewModel();
return viewModel;
}
}
/// <summary>
///提供对电话应用程序的根框架的轻松访问。
/// </summary>

Двоичные данные
HardwareInfo/Assets/ApplicationIcon.png

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

До

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

После

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

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

До

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

После

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

Двоичные данные
HardwareInfo/Assets/Tiles/FlipCycleTileSmall.png

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

До

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

После

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

Двоичные данные
HardwareInfo/Bin/Debug/HardwareInfo_Debug_AnyCPU.xap Normal file

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

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

@ -109,6 +109,8 @@
<DesignTime>True</DesignTime>
<DependentUpon>AppResources.zh-CN.resx</DependentUpon>
</Compile>
<Compile Include="ViewModels\ItemModel.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
@ -119,9 +121,12 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="ViewModels\MainViewModelTestData.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Properties\AppManifest.xml" />
<None Include="Properties\WMAppManifest.xml">
<SubType>Designer</SubType>
@ -156,11 +161,6 @@
<Content Include="Assets\Tiles\IconicTileSmall.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="README_FIRST.txt" />
<Content Include="Toolkit.Content\ApplicationBar.Cancel.png" />
<Content Include="Toolkit.Content\ApplicationBar.Check.png" />
<Content Include="Toolkit.Content\ApplicationBar.Delete.png" />
<Content Include="Toolkit.Content\ApplicationBar.Select.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\AppResources.resx">
@ -173,11 +173,7 @@
<Generator>PublicResXFileCodeGenerator</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone.Controls.Toolkit">
<HintPath>..\packages\WPtoolkit.4.2012.10.30\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

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

@ -17,6 +17,7 @@ using Windows.Phone.Media.Capture;
using Windows.Phone.Devices.Power;
using Microsoft.Devices.Radio;
using System.Windows.Threading;
namespace HardwareInfo
{
@ -31,7 +32,7 @@ namespace HardwareInfo
/// 对于众多的硬件的访问需要添加Cap如果没有添加当该硬件不存在
/// 或者功能被用户关闭时,会触发 UnauthorizedAccessException 的异常
/// </summary>
class HardwareInfoResolver
public class HardwareInfoResolver
{
public bool AccelerometerExists { get; set; }
public bool BackCameraExists { get; set; }
@ -49,8 +50,9 @@ namespace HardwareInfo
public bool VibrationDeviceExists { get; set; }
public bool FMRadioExists { get; set; }
public string ScreenResolution { get; set; }
public string MemoryCurrentUsed { get; set; }
public string MemoryMaxAvailable { get; set; }
public string MemoryMaxAvailable { get; set; }
/// <summary>
/// Resolves the supported harware. Note executing this method may take
@ -69,9 +71,11 @@ namespace HardwareInfo
GetMotionApiInfo();
GetOrientationSensorInfo();
GetProximityInfo();
GetMemoryInfo();
GetSDCardInfo();
GetVibrationDeviceInfo();
GetFMRadioInfo();
GetScreenResolution();
}
/// <summary>
@ -305,5 +309,40 @@ namespace HardwareInfo
}
}
/// <summary>
/// Resolves the screen resolution.
/// </summary>
private void GetScreenResolution()
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
switch (App.Current.Host.Content.ScaleFactor)
{
case 100:
{
// Wide VGA, 480x800
ScreenResolution = "WVGA, 480x800";
break;
}
case 150:
{
// HD, 720x1280
ScreenResolution = "HD, 720x1280";
break;
}
case 160:
{
// Wide Extended Graphics Array (WXGA), 768x1280
ScreenResolution = "WXGA, 768x1280";
break;
}
default:
{
ScreenResolution = "Unknown";
break;
}
}
});
}
}
}

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

@ -10,6 +10,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:src="clr-namespace:HardwareInfo"
d:DataContext="{d:DesignData ViewModels/MainViewModelTestData.xaml}"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
@ -18,277 +19,112 @@
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<Style x:Name="ListItemTextBlockStyle" TargetType="TextBlock">
<Setter Property="Margin" Value="18"/>
<Setter Property="FontSize" Value="30"/>
<Style x:Name="ListItemTextBlockStyleLarge" TargetType="TextBlock">
<Setter Property="Margin" Value="10,0,0,10"/>
<Setter Property="FontFamily" Value="Segoe WP Semilight"/>
<Setter Property="FontSize" Value="42"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<Style x:Name="ListItemTextBlockStyleSmall" TargetType="TextBlock">
<Setter Property="Margin" Value="10,0,0,0"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="Foreground" Value="White"/>
</Style>
<src:BooleanToIconUriConverter x:Key="IconUriConverter" />
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Background>
<ImageBrush ImageSource="Assets/Images/Background.png"></ImageBrush>
</Grid.Background>
<!-- 本地化说明:
若要本地化显示的字符串,请将其值复制到应用程序的非特定语言资源文件(AppResources.resx)
中的适当命名的键,然后
将属性的引号之间的硬编码文本值
替换为其路径指向该字符串名称的绑定子句。
例如:
Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
此绑定指向模板的名为“ApplicationTitle”的字符串资源。
在“项目属性”选项卡中添加受支持的语言将会为
每种语言创建一个新的 resx 文件,该文件可以包含 UI 字符串的翻译值
。这些示例中的绑定将导致在运行时从
与应用程序的 CurrentUICulture 匹配的 .resx 文件中
提取属性的值。
-->
<!--TitlePanel 包含应用程序的名称和页标题-->
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock
Text="{Binding Path=LocalizedResources.ApplicationTitle,
Source={StaticResource LocalizedStrings}}"
Style="{StaticResource PhoneTextNormalStyle}"
/>
</StackPanel>
<ProgressBar
x:Name="MyProgressBar"
Margin="0,24,0,0"
Margin="0,-760,0,0"
Height="10"
Foreground="White"
IsIndeterminate="True"
/>
<!--ContentPanel - 在此处放置其他内容-->
<Grid x:Name="ContentPanel" Grid.Row="2" Margin="12,0,12,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1">
<Grid x:Name="ContentLayout" Background="Transparent">
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<TextBlock FontWeight="Bold">
<Run Text="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" />
<Run Text="{Binding Path=LocalizedResources.VersionNumberString, Source={StaticResource LocalizedStrings}}" />
</TextBlock>
</StackPanel>
<!-- Pivot control -->
<phone:Pivot Title=" ">
<!-- Pivot item for hardware characteristics with simple boolean properties -->
<phone:PivotItem Header="{Binding Path=LocalizedResources.AvailabilityTitle, Source={StaticResource LocalizedStrings}}">
<phone:LongListSelector Margin="0,0,-12,0" ItemsSource="{Binding Items}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,17" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image
Grid.Row="0"
Grid.Column="0"
Source="{Binding BooleanValue, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyleLarge}"
Text="{Binding HardwareFeatureText}"
/>
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</phone:PivotItem>
<phone:PivotItem Header="{Binding Path=LocalizedResources.CharacteristicsTitle, Source={StaticResource LocalizedStrings}}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image
Grid.Row="0"
Grid.Column="0"
Source="{Binding Path=AccelerometerExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="0"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.Accelerometer, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="1"
Grid.Column="0"
Source="{Binding Path=BackCameraExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="1"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.PrimaryCamera, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="2"
Grid.Column="0"
Source="{Binding Path=BackCameraFlashExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="2"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.PrimaryCameraFlash, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="3"
Grid.Column="0"
Source="{Binding Path=BatterySensorExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="3"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.BatterySensor, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="4"
Grid.Column="0"
Source="{Binding Path=CompassExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="4"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.Compass, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="5"
Grid.Column="0"
Source="{Binding Path=FrontCameraExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="5"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.FrontCamera, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="6"
Grid.Column="0"
Source="{Binding Path=FrontCameraFlashExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="6"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.FrontCameraFlash, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="7"
Grid.Column="0"
Source="{Binding Path=GyroscopeExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="7"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.Gyroscope, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="8"
Grid.Column="0"
Source="{Binding Path=InclinometerExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="8"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.Inclinometer, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="9"
Grid.Column="0"
Source="{Binding Path=MotionApiAvailable, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="9"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.MotionApi, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="10"
Grid.Column="0"
Source="{Binding Path=OrientationSensorExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="10"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.OrientationSensor, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="11"
Grid.Column="0"
Source="{Binding Path=ProximityExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="11"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.NFC, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="12"
Grid.Column="0"
Source="{Binding Path=SDCardExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="12"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.SDCard, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="13"
Grid.Column="0"
Source="{Binding Path=VibrationDeviceExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="13"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.VibrationDevice, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<Image
Grid.Row="14"
Grid.Column="0"
Source="{Binding Path=FMRadioExists, Converter={StaticResource IconUriConverter}}"
/>
<TextBlock
Grid.Row="14"
Grid.Column="1"
Style="{StaticResource ListItemTextBlockStyle}"
Text="{Binding LocalizedResources.FMRadio, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
/>
<StackPanel Grid.Row="0" Margin="0,0,0,17">
<TextBlock
Text="{Binding Path=LocalizedResources.ScreenResolution, Source={StaticResource LocalizedStrings}}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}"
/>
<TextBlock
Text="{Binding ScreenResolution}"
TextWrapping="Wrap"
Style="{StaticResource ListItemTextBlockStyleSmall}"
/>
</StackPanel>
<StackPanel Grid.Row="1" Margin="0,10,0,17">
<TextBlock
Text="{Binding Path=LocalizedResources.Memory, Source={StaticResource LocalizedStrings}}"
TextWrapping="Wrap"
Style="{StaticResource PhoneTextExtraLargeStyle}"
/>
<TextBlock
Text="{Binding MemoryStatus}"
TextWrapping="Wrap"
Style="{StaticResource ListItemTextBlockStyleSmall}"
/>
<ProgressBar
Margin="0,5,0,0"
Value="{Binding MemoryUsedInPercentages}"
/>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
</phone:PivotItem>
</phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>

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

@ -7,6 +7,7 @@ using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
@ -16,6 +17,8 @@ using System.Windows.Data;
using System.Windows.Navigation;
using HardwareInfo.Resources;
using HardwareInfo.ViewModels;
namespace HardwareInfo
{
@ -24,8 +27,23 @@ namespace HardwareInfo
/// </summary>
public partial class MainPage : PhoneApplicationPage
{
// Constants
private const int ProgressBarDelay = 2500; // Milliseconds
private HardwareInfoResolver hwInfo = null;
// Members
private HardwareInfoResolver _resolver = null;
public HardwareInfoResolver Resolver
{
get
{
return _resolver;
}
private set
{
_resolver = value;
}
}
/// <summary>
/// Constructor.
@ -34,7 +52,8 @@ namespace HardwareInfo
public MainPage()
{
InitializeComponent();
hwInfo = new HardwareInfoResolver();
DataContext = App.ViewModel;
Resolver = new HardwareInfoResolver();
Loaded += MainPage_Loaded;
}
@ -45,9 +64,9 @@ namespace HardwareInfo
/// <param name="e"></param>
private async void MainPage_Loaded(object sender, RoutedEventArgs e)
{
await Task.Factory.StartNew(hwInfo.ResolveInfo);
await Task.Factory.StartNew(_resolver.ResolveInfo);
System.Threading.Thread.Sleep(ProgressBarDelay);
ContentLayout.DataContext = hwInfo;
App.ViewModel.LoadData(ref _resolver);
MyProgressBar.Visibility = Visibility.Collapsed;
}
}

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

@ -6,7 +6,7 @@
<Language code="en" />
<Language code="zh-CN" />
</Languages>
<App xmlns="" ProductID="{530da7b7-e7ee-4b1e-99a2-ab28e0c54782}" Title="Hardware Info" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal" Author="Nokia" Description="A simple example application demonstrating how to resolve certain hardware specifications in runtime." Publisher="Nokia" PublisherID="{316924b3-f818-40f1-873e-aa8a34d085d7}">
<App xmlns="" ProductID="{530da7b7-e7ee-4b1e-99a2-ab28e0c54782}" Title="Hardware Info" RuntimeType="Silverlight" Version="1.1.0.0" Genre="apps.normal" Author="Nokia" Description="A simple example application demonstrating how to resolve certain hardware specifications in runtime." Publisher="Nokia" PublisherID="{316924b3-f818-40f1-873e-aa8a34d085d7}">
<IconPath IsRelative="true" IsResource="false">Assets\ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_ISV_CAMERA" />
@ -42,5 +42,9 @@
<ScreenResolution Name="ID_RESOLUTION_WXGA" />
<ScreenResolution Name="ID_RESOLUTION_HD720P" />
</ScreenResolutions>
<!-- Uncomment the following to get extended memory for app use -->
<!-- <FunctionalCapabilities>
<FunctionalCapability Name="ID_FUNCCAP_EXTEND_MEM"/>
</FunctionalCapabilities> -->
</App>
</Deployment>

67
HardwareInfo/Resources/AppResources.Designer.cs сгенерированный
Просмотреть файл

@ -96,6 +96,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Availability.
/// </summary>
public static string AvailabilityTitle {
get {
return ResourceManager.GetString("AvailabilityTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Battery sensor.
/// </summary>
@ -105,6 +114,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Characteristics.
/// </summary>
public static string CharacteristicsTitle {
get {
return ResourceManager.GetString("CharacteristicsTitle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Resolve hardware information.
/// </summary>
@ -168,6 +186,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to App memory.
/// </summary>
public static string Memory {
get {
return ResourceManager.GetString("Memory", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Motion API.
/// </summary>
@ -186,6 +213,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Not available.
/// </summary>
public static string NotAvailable {
get {
return ResourceManager.GetString("NotAvailable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Orientation sensor.
/// </summary>
@ -196,7 +232,7 @@ namespace HardwareInfo.Resources {
}
/// <summary>
/// Looks up a localized string similar to Primary camera.
/// Looks up a localized string similar to Back camera.
/// </summary>
public static string PrimaryCamera {
get {
@ -205,7 +241,7 @@ namespace HardwareInfo.Resources {
}
/// <summary>
/// Looks up a localized string similar to Primary camera flash.
/// Looks up a localized string similar to Back camera flash.
/// </summary>
public static string PrimaryCameraFlash {
get {
@ -231,6 +267,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Screen resolution.
/// </summary>
public static string ScreenResolution {
get {
return ResourceManager.GetString("ScreenResolution", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to SD card present.
/// </summary>
@ -240,6 +285,15 @@ namespace HardwareInfo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to 1.1.
/// </summary>
public static string VersionNumberString {
get {
return ResourceManager.GetString("VersionNumberString", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Vibration device.
/// </summary>
@ -248,5 +302,14 @@ namespace HardwareInfo.Resources {
return ResourceManager.GetString("VibrationDevice", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Waiting....
/// </summary>
public static string Waiting {
get {
return ResourceManager.GetString("Waiting", resourceCulture);
}
}
}
}

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

@ -165,10 +165,10 @@
<value>Orientation sensor</value>
</data>
<data name="PrimaryCamera" xml:space="preserve">
<value>Primary camera</value>
<value>Back camera</value>
</data>
<data name="PrimaryCameraFlash" xml:space="preserve">
<value>Primary camera flash</value>
<value>Back camera flash</value>
</data>
<data name="SDCard" xml:space="preserve">
<value>SD card present</value>
@ -182,4 +182,25 @@
<data name="FMRadio" xml:space="preserve">
<value>FM Radio</value>
</data>
<data name="VersionNumberString" xml:space="preserve">
<value>1.1</value>
</data>
<data name="AvailabilityTitle" xml:space="preserve">
<value>Availability</value>
</data>
<data name="CharacteristicsTitle" xml:space="preserve">
<value>Characteristics</value>
</data>
<data name="Memory" xml:space="preserve">
<value>App memory</value>
</data>
<data name="ScreenResolution" xml:space="preserve">
<value>Screen resolution</value>
</data>
<data name="NotAvailable" xml:space="preserve">
<value>Not available</value>
</data>
<data name="Waiting" xml:space="preserve">
<value>Waiting...</value>
</data>
</root>

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

@ -182,4 +182,7 @@
<data name="FMRadio" xml:space="preserve">
<value>FM调频</value>
</data>
<data name="VersionNumberString" xml:space="preserve">
<value>1.0</value>
</data>
</root>

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

@ -0,0 +1,67 @@
/**
* Copyright (c) 2013 Nokia Corporation.
*/
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace HardwareInfo.ViewModels
{
/// <summary>
/// Container class for the property values bound to the pivot view.
/// </summary>
public class ItemModel : INotifyPropertyChanged
{
private bool _booleanValue;
private string _textValue;
public bool BooleanValue
{
get
{
return _booleanValue;
}
set
{
if (value != _booleanValue)
{
_booleanValue = value;
NotifyPropertyChanged("BooleanValue");
}
}
}
public string HardwareFeatureText
{
get
{
return _textValue;
}
set
{
if (value != _textValue)
{
_textValue = value;
NotifyPropertyChanged("HardwareFeatureText");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

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

@ -0,0 +1,199 @@
/**
* Copyright (c) 2013 Nokia Corporation.
*/
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using HardwareInfo.Resources;
namespace HardwareInfo.ViewModels
{
/// <summary>
/// Generates and holds the items for the pivot page.
/// </summary>
public class MainViewModel : INotifyPropertyChanged
{
/// <summary>
/// A collection for ItemViewModel objects.
/// </summary>
public ObservableCollection<ItemModel> Items { get; private set; }
public bool IsDataLoaded
{
get;
private set;
}
private string _screenResolution;
public string ScreenResolution
{
get
{
return _screenResolution;
}
private set
{
_screenResolution = value;
NotifyPropertyChanged("ScreenResolution");
}
}
private int _memoryUsedInPercentages;
public int MemoryUsedInPercentages
{
get
{
return _memoryUsedInPercentages;
}
set
{
_memoryUsedInPercentages = value;
NotifyPropertyChanged("MemoryUsedInPercentages");
}
}
private string _memoryStatus;
public string MemoryStatus
{
get
{
return _memoryStatus;
}
set
{
_memoryStatus = value;
NotifyPropertyChanged("MemoryStatus");
}
}
/// <summary>
/// Constructor.
/// </summary>
public MainViewModel()
{
Items = new ObservableCollection<ItemModel>();
CreateItems();
}
/// <summary>
/// Sets the values of the items.
/// </summary>
/// <param name="resolver">An instance of hardware resolver class.</param>
public void LoadData(ref HardwareInfoResolver resolver)
{
foreach (ItemModel item in Items)
{
if (item.HardwareFeatureText.Equals(AppResources.Accelerometer))
{
item.BooleanValue = resolver.AccelerometerExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.PrimaryCamera))
{
item.BooleanValue = resolver.BackCameraExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.PrimaryCameraFlash))
{
item.BooleanValue = resolver.BackCameraFlashExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.Compass))
{
item.BooleanValue = resolver.CompassExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.FMRadio))
{
item.BooleanValue = resolver.FMRadioExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.FrontCamera))
{
item.BooleanValue = resolver.FrontCameraExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.FrontCameraFlash))
{
item.BooleanValue = resolver.FrontCameraFlashExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.Gyroscope))
{
item.BooleanValue = resolver.GyroscopeExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.Inclinometer))
{
item.BooleanValue = resolver.InclinometerExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.MotionApi))
{
item.BooleanValue = resolver.MotionApiAvailable;
}
else if (item.HardwareFeatureText.Equals(AppResources.OrientationSensor))
{
item.BooleanValue = resolver.OrientationSensorExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.NFC))
{
item.BooleanValue = resolver.ProximityExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.SDCard))
{
item.BooleanValue = resolver.SDCardExists;
}
else if (item.HardwareFeatureText.Equals(AppResources.VibrationDevice))
{
item.BooleanValue = resolver.VibrationDeviceExists;
}
}
ScreenResolution = resolver.ScreenResolution;
try
{
MemoryUsedInPercentages =
(int)Math.Round(100 * Double.Parse(resolver.MemoryCurrentUsed)
/ Double.Parse(resolver.MemoryMaxAvailable));
MemoryStatus =
(int.Parse(resolver.MemoryCurrentUsed) / (1024 * 1024)) + " MB used of "
+ (int.Parse(resolver.MemoryMaxAvailable) / (1024 * 1024)) + " MB";
}
catch (Exception)
{
MemoryStatus = AppResources.NotAvailable;
}
IsDataLoaded = true;
}
/// <summary>
/// Creates the items.
/// </summary>
private void CreateItems()
{
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.Accelerometer });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.PrimaryCamera });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.PrimaryCameraFlash });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.Compass });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.FMRadio });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.FrontCamera });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.FrontCameraFlash });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.Gyroscope });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.Inclinometer });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.MotionApi });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.OrientationSensor });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.NFC });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.SDCard });
Items.Add(new ItemModel() { BooleanValue = false, HardwareFeatureText = AppResources.VibrationDevice });
ScreenResolution = AppResources.Waiting;
MemoryStatus = AppResources.Waiting;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

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

@ -0,0 +1,12 @@
<vm:MainViewModel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:HardwareInfo.ViewModels">
<vm:MainViewModel.Items>
<vm:ItemModel BooleanValue="false" HardwareFeatureText="Test item 1"/>
<vm:ItemModel BooleanValue="true" HardwareFeatureText="Test item 2"/>
<vm:ItemModel BooleanValue="false" HardwareFeatureText="Test item 3"/>
</vm:MainViewModel.Items>
</vm:MainViewModel>