-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1839cc
commit d1ce8a6
Showing
3 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/SamplesApp/UITests.Shared/Windows_Devices/CompassTests.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<UserControl x:Class="UITests.Shared.Windows_Devices.CompassTests" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Shared.Windows_Devices" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:valueconverters="using:UITests.ValueConverters" | ||
mc:Ignorable="d" | ||
d:DesignHeight="300" | ||
d:DesignWidth="400"> | ||
|
||
<UserControl.Resources> | ||
<valueconverters:BoolNegationValueConverter x:Key="BoolNegation" /> | ||
</UserControl.Resources> | ||
|
||
<ContentControl IsEnabled="{Binding CompassAvailable}"> | ||
<StackPanel> | ||
<TextBlock Text="{Binding SensorStatus}" /> | ||
|
||
<Button Command="{Binding AttachReadingChangedCommand}" | ||
Content="Attach ReadingChanged" | ||
IsEnabled="{Binding ReadingChangedAttached, Converter={StaticResource BoolNegation}}" /> | ||
<Button Command="{Binding DetachReadingChangedCommand}" | ||
Content="Detach ReadingChanged" | ||
IsEnabled="{Binding ReadingChangedAttached}" /> | ||
|
||
<TextBlock Text="Last reading" | ||
Style="{ThemeResource SubtitleTextBlockStyle}" /> | ||
<TextBlock> | ||
<Run FontWeight="Bold">HeadingMagneticNorth:</Run> | ||
<Run Text="{Binding HeadingMagneticNorth}" /> | ||
</TextBlock> | ||
<TextBlock> | ||
<Run FontWeight="Bold">Timestamp: </Run> | ||
<Run Text="{Binding Timestamp}" /> | ||
</TextBlock> | ||
</StackPanel> | ||
</ContentControl> | ||
</UserControl> |
132 changes: 132 additions & 0 deletions
132
src/SamplesApp/UITests.Shared/Windows_Devices/CompassTests.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Uno.Disposables; | ||
using Uno.UI.Samples.Controls; | ||
using Uno.UI.Samples.UITests.Helpers; | ||
using Windows.Devices.Sensors; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Core; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
|
||
namespace UITests.Shared.Windows_Devices | ||
{ | ||
[Sample( | ||
"Windows.Devices", | ||
Name = "Compass", | ||
Description = "Demonstrates use of Windows.Devices.Sensors.Compass", | ||
ViewModelType = typeof(CompassTestsViewModel), | ||
IgnoreInSnapshotTests = true)] | ||
public sealed partial class CompassTests : UserControl | ||
{ | ||
public CompassTests() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
} | ||
|
||
[Bindable] | ||
internal class CompassTestsViewModel : ViewModelBase | ||
{ | ||
private Compass _compass; | ||
private bool _readingChangedAttached; | ||
private string _sensorStatus; | ||
private double _headingMagneticNorth; | ||
private string _timestamp; | ||
|
||
public CompassTestsViewModel(CoreDispatcher dispatcher) : base(dispatcher) | ||
{ | ||
|
||
_compass = Compass.GetDefault(); | ||
if (_compass != null) | ||
{ | ||
_compass.ReportInterval = 250; | ||
SensorStatus = "Compass created"; | ||
} | ||
else | ||
{ | ||
SensorStatus = "Compass not available on this device"; | ||
} | ||
Disposables.Add(Disposable.Create(() => | ||
{ | ||
if (_compass != null) | ||
{ | ||
_compass.ReadingChanged -= Compass_ReadingChanged; | ||
} | ||
})); | ||
} | ||
|
||
public Command AttachReadingChangedCommand => new Command((p) => | ||
{ | ||
_compass.ReadingChanged += Compass_ReadingChanged; | ||
ReadingChangedAttached = true; | ||
}); | ||
|
||
public Command DetachReadingChangedCommand => new Command((p) => | ||
{ | ||
_compass.ReadingChanged -= Compass_ReadingChanged; | ||
ReadingChangedAttached = false; | ||
}); | ||
|
||
public bool CompassAvailable => _compass != null; | ||
|
||
public string SensorStatus | ||
{ | ||
get => _sensorStatus; | ||
private set | ||
{ | ||
_sensorStatus = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public bool ReadingChangedAttached | ||
{ | ||
get => _readingChangedAttached; | ||
private set | ||
{ | ||
_readingChangedAttached = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public double HeadingMagneticNorth | ||
{ | ||
get => _headingMagneticNorth; | ||
private set | ||
{ | ||
_headingMagneticNorth = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public string Timestamp | ||
{ | ||
get => _timestamp; | ||
private set | ||
{ | ||
_timestamp = value; | ||
RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
private async void Compass_ReadingChanged(Compass sender, CompassReadingChangedEventArgs args) | ||
{ | ||
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => | ||
{ | ||
HeadingMagneticNorth = args.Reading.HeadingMagneticNorth; | ||
Timestamp = args.Reading.Timestamp.ToString("R"); | ||
}); | ||
} | ||
} | ||
} | ||
} |