diff --git a/Samples/PenHaptics/cppwinrt/SampleConfiguration.cpp b/Samples/PenHaptics/cppwinrt/SampleConfiguration.cpp index ad46c11930..9beffa5ce6 100644 --- a/Samples/PenHaptics/cppwinrt/SampleConfiguration.cpp +++ b/Samples/PenHaptics/cppwinrt/SampleConfiguration.cpp @@ -48,6 +48,7 @@ std::map const& SDKTemplate::WaveformNamesMap() { L"InkContinuous", KnownSimpleHapticsControllerWaveforms::InkContinuous() }, { L"MarkerContinuous", KnownSimpleHapticsControllerWaveforms::MarkerContinuous() }, { L"PencilContinuous", KnownSimpleHapticsControllerWaveforms::PencilContinuous() }, + { L"Press", KnownSimpleHapticsControllerWaveforms::Press() }, { L"Release", KnownSimpleHapticsControllerWaveforms::Release() }, { L"RumbleContinuous", KnownSimpleHapticsControllerWaveforms::RumbleContinuous() }, { L"Success", KnownSimpleHapticsControllerWaveforms::Success() }, diff --git a/Samples/PenHaptics/cs/SampleConfiguration.cs b/Samples/PenHaptics/cs/SampleConfiguration.cs index abeb9fc1e3..ea499aa2c4 100644 --- a/Samples/PenHaptics/cs/SampleConfiguration.cs +++ b/Samples/PenHaptics/cs/SampleConfiguration.cs @@ -43,6 +43,7 @@ public partial class MainPage : Page ["InkContinuous"] = KnownSimpleHapticsControllerWaveforms.InkContinuous, ["MarkerContinuous"] = KnownSimpleHapticsControllerWaveforms.MarkerContinuous, ["PencilContinuous"] = KnownSimpleHapticsControllerWaveforms.PencilContinuous, + ["Press"] = KnownSimpleHapticsControllerWaveforms.Press, ["Release"] = KnownSimpleHapticsControllerWaveforms.Release, ["RumbleContinuous"] = KnownSimpleHapticsControllerWaveforms.RumbleContinuous, ["Success"] = KnownSimpleHapticsControllerWaveforms.Success, diff --git a/Samples/RadioManager/README.md b/Samples/RadioManager/README.md index eac0296d82..826366cc7a 100644 --- a/Samples/RadioManager/README.md +++ b/Samples/RadioManager/README.md @@ -3,7 +3,7 @@ page_type: sample languages: - csharp - cpp -- cppcx +- cppwinrt products: - windows - windows-uwp @@ -35,6 +35,12 @@ toggle radio state changes, and register for state changes on individual radios. > the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq). > For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center. +## Related topics + +### Related samples + +[RadioManager](/archived/RadioManager) for C++/CX (archived) + ## System requirements **Client:** Windows 10 diff --git a/Samples/RadioManager/cppwinrt/Package.appxmanifest b/Samples/RadioManager/cppwinrt/Package.appxmanifest new file mode 100644 index 0000000000..745f7b0a3f --- /dev/null +++ b/Samples/RadioManager/cppwinrt/Package.appxmanifest @@ -0,0 +1,42 @@ + + + + + + RadioManager C++/WinRT Sample + Microsoft Corporation + Assets\storelogo-sdk.png + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Samples/RadioManager/cppwinrt/Project.idl b/Samples/RadioManager/cppwinrt/Project.idl new file mode 100644 index 0000000000..f1a282cc11 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/Project.idl @@ -0,0 +1,27 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +namespace SDKTemplate +{ + [default_interface] + runtimeclass Scenario1_Toggle : Windows.UI.Xaml.Controls.Page + { + Scenario1_Toggle(); + } + + [Windows.UI.Xaml.Data.Bindable] + runtimeclass RadioModel : Windows.UI.Xaml.Data.INotifyPropertyChanged + { + String Name { get; }; + Boolean IsEnabled{ get; }; + Boolean IsRadioOn; + } +} diff --git a/Samples/RadioManager/cppwinrt/RadioManager.sln b/Samples/RadioManager/cppwinrt/RadioManager.sln new file mode 100644 index 0000000000..dc7a5f2132 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/RadioManager.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31702.278 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RadioManager", "RadioManager.vcxproj", "{A2D33437-5635-4832-AD71-08D653A37053}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|ARM.ActiveCfg = Debug|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|ARM.Build.0 = Debug|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|ARM.Deploy.0 = Debug|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x64.ActiveCfg = Debug|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x64.Build.0 = Debug|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x64.Deploy.0 = Debug|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x86.ActiveCfg = Debug|Win32 + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x86.Build.0 = Debug|Win32 + {A2D33437-5635-4832-AD71-08D653A37053}.Debug|x86.Deploy.0 = Debug|Win32 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|ARM.ActiveCfg = Release|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Release|ARM.Build.0 = Release|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Release|ARM.Deploy.0 = Release|ARM + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x64.ActiveCfg = Release|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x64.Build.0 = Release|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x64.Deploy.0 = Release|x64 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x86.ActiveCfg = Release|Win32 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x86.Build.0 = Release|Win32 + {A2D33437-5635-4832-AD71-08D653A37053}.Release|x86.Deploy.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {188076BF-8AB0-4B34-82D3-BCDA00EFE46F} + EndGlobalSection +EndGlobal diff --git a/Samples/RadioManager/cppwinrt/RadioManager.vcxproj b/Samples/RadioManager/cppwinrt/RadioManager.vcxproj new file mode 100644 index 0000000000..916adca913 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/RadioManager.vcxproj @@ -0,0 +1,188 @@ + + + + + $([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), LICENSE))\SharedContent + + + true + true + {A2D33437-5635-4832-AD71-08D653A37053} + RadioManager + SDKTemplate + en-US + 15.0 + true + Windows Store + 10.0 + 10.0.19041.0 + $(WindowsTargetPlatformVersion) + + + + + Debug + ARM + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + Win32 + + + Release + x64 + + + + Application + Unicode + + + true + true + + + false + true + false + + + + + + + + $(VC_IncludePath);$(UniversalCRT_IncludePath);$(WindowsSDK_IncludePath);$(SharedContentDir)\cppwinrt + true + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + 4453;28204 + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + + + $(SharedContentDir)\xaml\App.xaml + + + $(SharedContentDir)\xaml\MainPage.xaml + + + + + ..\shared\Scenario1_Toggle.xaml + + + + + + Designer + + + Designer + + + + Styles\Styles.xaml + + + + + $(SharedContentDir)\xaml\App.xaml + + + $(SharedContentDir)\xaml\MainPage.xaml + + + RadioModel.h + + + SampleConfiguration.h + + + ..\shared\Scenario1_Toggle.xaml + + + Create + pch.h + + + Project.idl + + + + + $(SharedContentDir)\xaml\MainPage.xaml + + + + + + Designer + + + + + Assets\microsoft-sdk.png + + + Assets\smallTile-sdk.png + + + Assets\splash-sdk.png + + + Assets\squareTile-sdk.png + + + Assets\storeLogo-sdk.png + + + Assets\tile-sdk.png + + + Assets\windows-sdk.png + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/Samples/RadioManager/cppwinrt/RadioManager.vcxproj.filters b/Samples/RadioManager/cppwinrt/RadioManager.vcxproj.filters new file mode 100644 index 0000000000..2ed4d4a65e --- /dev/null +++ b/Samples/RadioManager/cppwinrt/RadioManager.vcxproj.filters @@ -0,0 +1,60 @@ + + + + + 4416d50a-7676-4d0a-9b2c-91ff70c6047f + bmp;fbx;gif;jpg;jpeg;tga;tiff;tif;png + + + + + + + + + + + + + + + + + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + + + + \ No newline at end of file diff --git a/Samples/RadioManager/cppwinrt/RadioModel.cpp b/Samples/RadioManager/cppwinrt/RadioModel.cpp new file mode 100644 index 0000000000..2af837531c --- /dev/null +++ b/Samples/RadioManager/cppwinrt/RadioModel.cpp @@ -0,0 +1,67 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include +#include "RadioModel.h" +#include "RadioModel.g.cpp" + +using namespace winrt; +using namespace winrt::Windows::Devices::Radios; +using namespace winrt::Windows::Foundation::Collections; +using namespace winrt::Windows::UI::Core; +using namespace winrt::Windows::UI::Xaml::Data; +using namespace winrt::SDKTemplate; + +namespace winrt::SDKTemplate::implementation +{ + RadioModel::RadioModel(Radio const& radio, CoreDispatcher const& dispatcher) : + radio(radio), dispatcher(dispatcher), + // Controlling the mobile broadband radio requires the cellularDeviceControl restricted capability, which we do not have. + isEnabled(radio.Kind() != RadioKind::MobileBroadband) + { + radio.StateChanged({ get_weak(), &RadioModel::Radio_StateChanged }); + } + + fire_and_forget RadioModel::Radio_StateChanged(Radio const&, IInspectable const&) + { + // The Radio StateChanged event doesn't run from the UI thread, so we must use the dispatcher + // to run NotifyPropertyChanged + auto lifetime = get_strong(); + co_await resume_foreground(dispatcher); + NotifyPropertyChanged(L"IsRadioOn"); + } + + void RadioModel::NotifyPropertyChanged(hstring const& propertyName) + { + propertyChanged(*this, PropertyChangedEventArgs(propertyName)); + } + + void RadioModel::SetEnabled(bool value) + { + isEnabled = value; + NotifyPropertyChanged(L"IsEnabled"); + } + + fire_and_forget RadioModel::SetRadioState(bool value) + { + if (value != IsRadioOn()) + { + auto lifetime = get_strong(); + RadioState newState = value ? RadioState::On : RadioState::Off; + SetEnabled(false); + co_await radio.SetStateAsync(newState); + SetEnabled(true); + NotifyPropertyChanged(L"IsRadioOn"); + } + } + +} diff --git a/Samples/RadioManager/cppwinrt/RadioModel.h b/Samples/RadioManager/cppwinrt/RadioModel.h new file mode 100644 index 0000000000..c381d07e27 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/RadioModel.h @@ -0,0 +1,63 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once +#include "pch.h" +#include "RadioModel.g.h" + +namespace winrt::SDKTemplate::implementation +{ + struct RadioModel : RadioModelT + { + RadioModel(Windows::Devices::Radios::Radio const& radio, Windows::UI::Core::CoreDispatcher const& dispatcher); + + hstring Name() + { + return radio.Name(); + } + + bool IsEnabled() + { + return isEnabled; + } + + bool IsRadioOn() + { + return radio.State() == Windows::Devices::Radios::RadioState::On; + } + + void IsRadioOn(bool value) + { + SetRadioState(value); + } + + event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& handler) + { + return propertyChanged.add(handler); + } + + void PropertyChanged(winrt::event_token const& token) + { + propertyChanged.remove(token); + } + + private: + Windows::Devices::Radios::Radio radio; + Windows::UI::Core::CoreDispatcher dispatcher; + event propertyChanged; + bool isEnabled; + + fire_and_forget Radio_StateChanged(Windows::Devices::Radios::Radio const&, Windows::Foundation::IInspectable const&); + void NotifyPropertyChanged(hstring const& propertyName); + void SetEnabled(bool value); + fire_and_forget SetRadioState(bool value); + }; +} diff --git a/Samples/RadioManager/cppwinrt/SampleConfiguration.cpp b/Samples/RadioManager/cppwinrt/SampleConfiguration.cpp new file mode 100644 index 0000000000..8c9c917e35 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/SampleConfiguration.cpp @@ -0,0 +1,29 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include +#include "MainPage.h" +#include "SampleConfiguration.h" + +using namespace winrt; +using namespace Windows::Foundation::Collections; +using namespace SDKTemplate; + +hstring implementation::MainPage::FEATURE_NAME() +{ + return L"RadioManager C++/WinRT Sample"; +} + +IVector implementation::MainPage::scenariosInner = winrt::single_threaded_observable_vector( +{ + Scenario{ L"Toggle Radios", xaml_typename() }, +}); diff --git a/Samples/RadioManager/cppwinrt/SampleConfiguration.h b/Samples/RadioManager/cppwinrt/SampleConfiguration.h new file mode 100644 index 0000000000..ba0eb7c8c2 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/SampleConfiguration.h @@ -0,0 +1,17 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once +#include "pch.h" + +namespace winrt::SDKTemplate +{ +} diff --git a/Samples/RadioManager/cppwinrt/Scenario1_Toggle.cpp b/Samples/RadioManager/cppwinrt/Scenario1_Toggle.cpp new file mode 100644 index 0000000000..6671c5535d --- /dev/null +++ b/Samples/RadioManager/cppwinrt/Scenario1_Toggle.cpp @@ -0,0 +1,48 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include "RadioModel.h" +#include "Scenario1_Toggle.h" +#include "Scenario1_Toggle.g.cpp" + +using namespace winrt; +using namespace Windows::Devices::Radios; +using namespace Windows::Foundation; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Navigation; + +namespace winrt::SDKTemplate::implementation +{ + Scenario1_Toggle::Scenario1_Toggle() + { + InitializeComponent(); + } + + fire_and_forget Scenario1_Toggle::OnNavigatedTo(NavigationEventArgs const&) + { + // RequestAccessAsync must be called at least one from the UI thread. + RadioAccessStatus accessLevel = co_await Radio::RequestAccessAsync(); + if (accessLevel != RadioAccessStatus::Allowed) + { + rootPage.NotifyUser(L"App is not allowed to control radios.", NotifyType::ErrorMessage); + } + else + { + // An alternative to Radio.GetRadiosAsync is to use the Windows.Devices.Enumeration pattern, + // passing Radio.GetDeviceSelector as the AQS string. + for (Radio radio : co_await Radio::GetRadiosAsync()) + { + RadioSwitchList().Items().Append(make(radio, Dispatcher())); + } + } + } +} diff --git a/Samples/RadioManager/cppwinrt/Scenario1_Toggle.h b/Samples/RadioManager/cppwinrt/Scenario1_Toggle.h new file mode 100644 index 0000000000..d61464a257 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/Scenario1_Toggle.h @@ -0,0 +1,35 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once + +#include "Scenario1_Toggle.g.h" +#include "MainPage.h" + +namespace winrt::SDKTemplate::implementation +{ + struct Scenario1_Toggle : Scenario1_ToggleT + { + Scenario1_Toggle(); + + fire_and_forget OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const&); + + private: + SDKTemplate::MainPage rootPage{ SDKTemplate::implementation::MainPage::Current() }; + }; +} + +namespace winrt::SDKTemplate::factory_implementation +{ + struct Scenario1_Toggle : Scenario1_ToggleT + { + }; +} diff --git a/Samples/RadioManager/cppwinrt/packages.config b/Samples/RadioManager/cppwinrt/packages.config new file mode 100644 index 0000000000..fb20a4e613 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Samples/RadioManager/cppwinrt/pch.cpp b/Samples/RadioManager/cppwinrt/pch.cpp new file mode 100644 index 0000000000..01484ff5aa --- /dev/null +++ b/Samples/RadioManager/cppwinrt/pch.cpp @@ -0,0 +1,6 @@ +// +// pch.cpp +// Include the standard header and generate the precompiled header. +// + +#include "pch.h" diff --git a/Samples/RadioManager/cppwinrt/pch.h b/Samples/RadioManager/cppwinrt/pch.h new file mode 100644 index 0000000000..8221767c52 --- /dev/null +++ b/Samples/RadioManager/cppwinrt/pch.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include "winrt/Windows.Foundation.h" +#include "winrt/Windows.Foundation.Collections.h" +#include "winrt/Windows.ApplicationModel.Activation.h" +#include "winrt/Windows.Devices.Radios.h" +#include "winrt/Windows.System.h" +#include "winrt/Windows.UI.Core.h" +#include "winrt/Windows.UI.Xaml.h" +#include "winrt/Windows.UI.Xaml.Automation.Peers.h" +#include "winrt/Windows.UI.Xaml.Controls.h" +#include "winrt/Windows.UI.Xaml.Controls.Primitives.h" +#include "winrt/Windows.UI.Xaml.Documents.h" +#include "winrt/Windows.UI.Xaml.Interop.h" +#include "winrt/Windows.UI.Xaml.Markup.h" +#include "winrt/Windows.UI.Xaml.Media.h" +#include "winrt/Windows.UI.Xaml.Navigation.h" diff --git a/Samples/RadioManager/cs/RadioManager.csproj b/Samples/RadioManager/cs/RadioManager.csproj index 7edb578823..64a2366aab 100644 --- a/Samples/RadioManager/cs/RadioManager.csproj +++ b/Samples/RadioManager/cs/RadioManager.csproj @@ -104,8 +104,8 @@ - - Scenario1.xaml + + Scenario1_Toggle.xaml @@ -124,7 +124,8 @@ MSBuild:Compile Designer - + + Scenario1_Toggle.xaml MSBuild:Compile Designer diff --git a/Samples/RadioManager/cs/RadioModel.cs b/Samples/RadioManager/cs/RadioModel.cs index 166036e5d9..6a5bdd44a8 100644 --- a/Samples/RadioManager/cs/RadioModel.cs +++ b/Samples/RadioManager/cs/RadioModel.cs @@ -12,25 +12,24 @@ using System; using System.ComponentModel; using System.Runtime.CompilerServices; -using Windows.ApplicationModel.Core; using Windows.Devices.Radios; using Windows.UI.Core; using Windows.UI.Xaml; -namespace RadioManagerSample +namespace SDKTemplate { public class RadioModel : INotifyPropertyChanged { private Radio radio; private bool isEnabled; - private UIElement parent; + private CoreDispatcher dispatcher; - public RadioModel(Radio radio, UIElement parent) + public RadioModel(Radio radio, CoreDispatcher dispatcher) { this.radio = radio; // Controlling the mobile broadband radio requires the cellularDeviceControl restricted capability, which we do not have. this.isEnabled = (radio.Kind != RadioKind.MobileBroadband); - this.parent = parent; + this.dispatcher = dispatcher; this.radio.StateChanged += Radio_StateChanged; } @@ -38,7 +37,7 @@ private async void Radio_StateChanged(Radio sender, object args) { // The Radio StateChanged event doesn't run from the UI thread, so we must use the dispatcher // to run NotifyPropertyChanged - await this.parent.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => + await this.dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { NotifyPropertyChanged("IsRadioOn"); }); @@ -89,21 +88,14 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") private async void SetRadioState(bool isRadioOn) { - var radioState = isRadioOn ? RadioState.On : RadioState.Off; - Disable(); - await this.radio.SetStateAsync(radioState); - NotifyPropertyChanged("IsRadioOn"); - Enable(); - } - - private void Enable() - { - IsEnabled = true; - } - - private void Disable() - { - IsEnabled = false; + if (isRadioOn != IsRadioOn) + { + var radioState = isRadioOn ? RadioState.On : RadioState.Off; + IsEnabled = false; + await this.radio.SetStateAsync(radioState); + NotifyPropertyChanged("IsRadioOn"); + IsEnabled = true; + } } } } diff --git a/Samples/RadioManager/cs/SampleConfiguration.cs b/Samples/RadioManager/cs/SampleConfiguration.cs index 44243ac2f1..bc10e2e3d5 100644 --- a/Samples/RadioManager/cs/SampleConfiguration.cs +++ b/Samples/RadioManager/cs/SampleConfiguration.cs @@ -12,7 +12,7 @@ using System; using System.Collections.Generic; using Windows.UI.Xaml.Controls; -using RadioManagerSample; +using SDKTemplate; namespace SDKTemplate { @@ -22,7 +22,7 @@ public partial class MainPage : Page List scenarios = new List { - new Scenario() { Title="Toggle Radios", ClassType=typeof(Scenario1)} + new Scenario() { Title="Toggle Radios", ClassType=typeof(Scenario1_Toggle)} }; } diff --git a/Samples/RadioManager/cs/Scenario1.xaml.cs b/Samples/RadioManager/cs/Scenario1_Toggle.xaml.cs similarity index 63% rename from Samples/RadioManager/cs/Scenario1.xaml.cs rename to Samples/RadioManager/cs/Scenario1_Toggle.xaml.cs index 7e23a6cc76..f56e58b0dd 100644 --- a/Samples/RadioManager/cs/Scenario1.xaml.cs +++ b/Samples/RadioManager/cs/Scenario1_Toggle.xaml.cs @@ -15,21 +15,19 @@ using Windows.Devices.Radios; using System; -namespace RadioManagerSample +namespace SDKTemplate { - public sealed partial class Scenario1 : Page + public sealed partial class Scenario1_Toggle : Page { - private MainPage rootPage; + private MainPage rootPage = MainPage.Current; - public Scenario1() + public Scenario1_Toggle() { this.InitializeComponent(); } protected override async void OnNavigatedTo(NavigationEventArgs e) { - rootPage = MainPage.Current; - // RequestAccessAsync must be called at least once from the UI thread var accessLevel = await Radio.RequestAccessAsync(); if (accessLevel != RadioAccessStatus.Allowed) @@ -38,18 +36,12 @@ protected override async void OnNavigatedTo(NavigationEventArgs e) } else { - InitializeRadios(); - } - } - - private async void InitializeRadios() - { - // An alternative to Radio.GetRadiosAsync is to use the Windows.Devices.Enumeration pattern, - // passing Radio.GetDeviceSelector as the AQS string - var radios = await Radio.GetRadiosAsync(); - foreach (var radio in radios) - { - RadioSwitchList.Items.Add(new RadioModel(radio, this)); + // An alternative to Radio.GetRadiosAsync is to use the Windows.Devices.Enumeration pattern, + // passing Radio.GetDeviceSelector as the AQS string + foreach (var radio in await Radio.GetRadiosAsync()) + { + RadioSwitchList.Items.Add(new RadioModel(radio, this.Dispatcher)); + } } } } diff --git a/Samples/RadioManager/cs/Scenario1.xaml b/Samples/RadioManager/shared/Scenario1_Toggle.xaml similarity index 80% rename from Samples/RadioManager/cs/Scenario1.xaml rename to Samples/RadioManager/shared/Scenario1_Toggle.xaml index 3001c9e9e2..8c0420810a 100644 --- a/Samples/RadioManager/cs/Scenario1.xaml +++ b/Samples/RadioManager/shared/Scenario1_Toggle.xaml @@ -11,10 +11,10 @@ //********************************************************* --> @@ -36,24 +36,19 @@ - + - - + + - - - - diff --git a/archived/RadioManager/README.md b/archived/RadioManager/README.md new file mode 100644 index 0000000000..61063f7a8c --- /dev/null +++ b/archived/RadioManager/README.md @@ -0,0 +1,64 @@ +--- +topic: sample +languages: +- cpp +- cppcx +products: +- windows +- windows-uwp +urlFragment: RadioManager +extendedZipContent: +- path: SharedContent + target: SharedContent +- path: LICENSE + target: LICENSE +description: "Shows how to enumerate radios on a device, toggle radio state changes, and register for state changes on individual radios." +--- + + + +# Radios sample + +Shows how to use the [Windows.Devices.Radios](https://msdn.microsoft.com/library/windows/apps/windows.devices.radios.aspx) API to enumerate radios on a device, +toggle radio state changes, and register for state changes on individual radios. + +> **Note:** This sample is part of a large collection of UWP feature samples. +> You can download this sample as a standalone ZIP file +> [from docs.microsoft.com](https://docs.microsoft.com/samples/microsoft/windows-universal-samples/radiomanager/), +> or you can download the entire collection as a single +> [ZIP file](https://github.com/Microsoft/Windows-universal-samples/archive/master.zip), but be +> sure to unzip everything to access shared dependencies. For more info on working with the ZIP file, +> the samples collection, and GitHub, see [Get the UWP samples from GitHub](https://aka.ms/ovu2uq). +> For more samples, see the [Samples portal](https://aka.ms/winsamples) on the Windows Dev Center. + +## System requirements + +**Client:** Windows 10 + +**Server:** Windows Server 2016 Technical Preview + +**Phone:** Windows 10 + +## Build the sample + +1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build. +2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**. +3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file. +4. Press Ctrl+Shift+B, or select **Build** \> **Build Solution**. + +## Run the sample + +The next steps depend on whether you just want to deploy the sample or you want to both deploy and run it. + +### Deploying the sample + +- Select **Build** \> **Deploy Solution**. + +### Deploying and running the sample + +- To debug the sample and then run it, press F5 or use **Debug** \> **Start Debugging**. To run the sample without debugging, press Ctrl+F5 or use **Debug** \> **Start Without Debugging**. + +The scenario has buttons you can use to perform the actions described in the scenario text. If you do not have any radios on your system, you will not be able to experience the scenario. diff --git a/Samples/RadioManager/cpp/Package.appxmanifest b/archived/RadioManager/cpp/Package.appxmanifest similarity index 100% rename from Samples/RadioManager/cpp/Package.appxmanifest rename to archived/RadioManager/cpp/Package.appxmanifest diff --git a/Samples/RadioManager/cpp/RadioManager.sln b/archived/RadioManager/cpp/RadioManager.sln similarity index 100% rename from Samples/RadioManager/cpp/RadioManager.sln rename to archived/RadioManager/cpp/RadioManager.sln diff --git a/Samples/RadioManager/cpp/RadioManager.vcxproj b/archived/RadioManager/cpp/RadioManager.vcxproj similarity index 100% rename from Samples/RadioManager/cpp/RadioManager.vcxproj rename to archived/RadioManager/cpp/RadioManager.vcxproj diff --git a/Samples/RadioManager/cpp/RadioManager.vcxproj.filters b/archived/RadioManager/cpp/RadioManager.vcxproj.filters similarity index 100% rename from Samples/RadioManager/cpp/RadioManager.vcxproj.filters rename to archived/RadioManager/cpp/RadioManager.vcxproj.filters diff --git a/Samples/RadioManager/cpp/RadioModel.cpp b/archived/RadioManager/cpp/RadioModel.cpp similarity index 100% rename from Samples/RadioManager/cpp/RadioModel.cpp rename to archived/RadioManager/cpp/RadioModel.cpp diff --git a/Samples/RadioManager/cpp/RadioModel.h b/archived/RadioManager/cpp/RadioModel.h similarity index 100% rename from Samples/RadioManager/cpp/RadioModel.h rename to archived/RadioManager/cpp/RadioModel.h diff --git a/Samples/RadioManager/cpp/SampleConfiguration.cpp b/archived/RadioManager/cpp/SampleConfiguration.cpp similarity index 100% rename from Samples/RadioManager/cpp/SampleConfiguration.cpp rename to archived/RadioManager/cpp/SampleConfiguration.cpp diff --git a/Samples/RadioManager/cpp/SampleConfiguration.h b/archived/RadioManager/cpp/SampleConfiguration.h similarity index 100% rename from Samples/RadioManager/cpp/SampleConfiguration.h rename to archived/RadioManager/cpp/SampleConfiguration.h diff --git a/Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml b/archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml similarity index 100% rename from Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml rename to archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml diff --git a/Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml.cpp b/archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml.cpp similarity index 100% rename from Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml.cpp rename to archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml.cpp diff --git a/Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml.h b/archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml.h similarity index 100% rename from Samples/RadioManager/cpp/Scenario1_ToggleRadios.xaml.h rename to archived/RadioManager/cpp/Scenario1_ToggleRadios.xaml.h diff --git a/Samples/RadioManager/cpp/pch.cpp b/archived/RadioManager/cpp/pch.cpp similarity index 100% rename from Samples/RadioManager/cpp/pch.cpp rename to archived/RadioManager/cpp/pch.cpp diff --git a/Samples/RadioManager/cpp/pch.h b/archived/RadioManager/cpp/pch.h similarity index 100% rename from Samples/RadioManager/cpp/pch.h rename to archived/RadioManager/cpp/pch.h