Bumping the sample to version 2.0.0.0 and removing ValidateSettingsAsync() from IActivitySensor. This is only applicable to LumiaActivitySensor. It's used by ActivitySensorFactory to check if all the settings are valid before getting the ActivityMonitor instance.
Also removed extra line feeds in ActivitySensor.cs
This commit is contained in:
Родитель
0c8922e8fa
Коммит
64100c744a
|
@ -37,7 +37,8 @@ namespace ActivitiesExample
|
|||
{
|
||||
public delegate void ReadingChangedEventHandler(object sender, object args);
|
||||
/// <summary>
|
||||
/// Platform agnostic Activity Sensor interface.
|
||||
/// Platform agnostic Activity Sensor interface.
|
||||
/// This interface is implementd by OSActivitySensor and LumiaActivitySensor.
|
||||
/// </summary>
|
||||
public interface IActivitySensor
|
||||
{
|
||||
|
@ -59,12 +60,6 @@ namespace ActivitiesExample
|
|||
/// <returns>Asynchronous task</returns>
|
||||
Task DeactivateAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Validates if all the settings and permissions are in place to use the sensor.
|
||||
/// </summary>
|
||||
/// <returns>Asynchronous task</returns>
|
||||
Task ValidateSettingsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Pull activity entries from history database and populate the internal list.
|
||||
/// </summary>
|
||||
|
@ -83,22 +78,33 @@ namespace ActivitiesExample
|
|||
/// the history entries that gets displayed in the UI.
|
||||
/// </summary>
|
||||
object GetActivityDataInstance();
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for receving reading changed events.
|
||||
/// </summary>
|
||||
event ReadingChangedEventHandler ReadingChanged;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Factory class for instantiating Activity Sensor. If OS Activity Sensor is not available, SensorCore Activity Sensor is used.
|
||||
/// Factory class for instantiating Activity Sensor. If there an activity sensor surfaced
|
||||
/// through Windows.Devices.Sensor then the factory creates an instance of OSActivitySensor
|
||||
/// otherwise this falls back to using LumiaActivitySensor.
|
||||
/// </summary>
|
||||
public static class ActivitySensorFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Static method to get the default activity sensor present in the system.
|
||||
/// </summary>
|
||||
public static async Task<IActivitySensor> GetDefaultAsync()
|
||||
{
|
||||
IActivitySensor sensor = null;
|
||||
|
||||
try
|
||||
{
|
||||
// Check if there is an activity sensor in the system
|
||||
ActivitySensor activitySensor = await ActivitySensor.GetDefaultAsync();
|
||||
|
||||
// If there is one then create OSActivitySensor.
|
||||
if (activitySensor != null)
|
||||
{
|
||||
sensor = new OSActivitySensor(activitySensor);
|
||||
|
@ -106,6 +112,8 @@ namespace ActivitiesExample
|
|||
}
|
||||
catch (System.UnauthorizedAccessException)
|
||||
{
|
||||
// If there is an activity sensor but the user has disabled motion data
|
||||
// then check if the user wants to open settngs and enable motion data.
|
||||
MessageDialog dialog = new MessageDialog("Motion access has been disabled in system settings. Do you want to open settings now?", "Information");
|
||||
dialog.Commands.Add(new UICommand("Yes", async cmd => await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-motion"))));
|
||||
dialog.Commands.Add(new UICommand("No"));
|
||||
|
@ -114,8 +122,13 @@ namespace ActivitiesExample
|
|||
return null;
|
||||
}
|
||||
|
||||
// If the OS activity sensor is not present then create the LumiaActivitySensor.
|
||||
// This will use ActivityMonitor from SensorCore.
|
||||
if (sensor == null)
|
||||
{
|
||||
// Check if all the required settings have been configured correctly
|
||||
await LumiaActivitySensor.ValidateSettingsAsync();
|
||||
|
||||
sensor = new LumiaActivitySensor();
|
||||
}
|
||||
return sensor;
|
||||
|
@ -127,7 +140,6 @@ namespace ActivitiesExample
|
|||
/// </summary>
|
||||
public class OSActivitySensor : IActivitySensor
|
||||
{
|
||||
|
||||
#region Private members
|
||||
/// <summary>
|
||||
/// Singleton instance.
|
||||
|
@ -194,15 +206,6 @@ namespace ActivitiesExample
|
|||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do nothing.
|
||||
/// </summary>
|
||||
/// <returns>Asynchronous task/returns>
|
||||
public Task ValidateSettingsAsync()
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activate the sensor. For activity sensor exposed through
|
||||
/// Windows.Devices.Sensor register reading changed handler.
|
||||
|
@ -475,6 +478,9 @@ namespace ActivitiesExample
|
|||
/// <returns>Asynchronous task/returns>
|
||||
public async Task InitializeSensorAsync()
|
||||
{
|
||||
// Make sure all necessary settings are enabled
|
||||
await ValidateSettingsAsync();
|
||||
|
||||
if (_runningInEmulator)
|
||||
{
|
||||
// await CallSensorCoreApiAsync( async () => { _activityMonitor = await ActivityMonitorSimulator.GetDefaultAsync(); } );
|
||||
|
@ -498,7 +504,7 @@ namespace ActivitiesExample
|
|||
/// Validate if settings have been configured correctly to run SensorCore.
|
||||
/// </summary>
|
||||
/// <returns>Asynchronous task/returns>
|
||||
public async Task ValidateSettingsAsync()
|
||||
public static async Task ValidateSettingsAsync()
|
||||
{
|
||||
if (!(await ActivityMonitor.IsSupportedAsync()))
|
||||
{
|
||||
|
@ -618,7 +624,7 @@ namespace ActivitiesExample
|
|||
|
||||
await CallSensorCoreApiAsync(async () =>
|
||||
{
|
||||
await _activityMonitor.GetCurrentReadingAsync();
|
||||
reading = await _activityMonitor.GetCurrentReadingAsync();
|
||||
});
|
||||
|
||||
if (reading != null)
|
||||
|
|
|
@ -83,9 +83,6 @@ namespace ActivitiesExample
|
|||
DataContext = _sensor.GetActivityDataInstance();
|
||||
}
|
||||
|
||||
// Check if all the required settings have been configured correctly
|
||||
await _sensor.ValidateSettingsAsync();
|
||||
|
||||
// Register delegate to get reading changes
|
||||
_sensor.ReadingChanged += activity_ReadingChanged;
|
||||
|
||||
|
@ -98,16 +95,6 @@ namespace ActivitiesExample
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes activity monitor sensor
|
||||
/// </summary>
|
||||
/// <returns>Asynchronous task</returns>
|
||||
private async Task InitializeSensorAsync()
|
||||
{
|
||||
// Initialize sensor core
|
||||
await _sensor.InitializeSensorAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when navigating to this page
|
||||
/// </summary>
|
||||
|
@ -116,9 +103,6 @@ namespace ActivitiesExample
|
|||
{
|
||||
if( e.NavigationMode == NavigationMode.Back )
|
||||
{
|
||||
// Make sure all necessary settings are enabled
|
||||
await _sensor.ValidateSettingsAsync();
|
||||
|
||||
// Register for reading change notifications if we have already not registered.
|
||||
_sensor.ReadingChanged += activity_ReadingChanged;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
IgnorableNamespaces="uap mp">
|
||||
|
||||
|
||||
<Identity Name="NokiaDeveloper.ActivitiesLumiaSensorCoreSDKsample" Publisher="CN=4AD6DA08-6C39-4A10-98CC-3243374DA59C" Version="1.0.0.0" />
|
||||
<Identity Name="NokiaDeveloper.ActivitiesLumiaSensorCoreSDKsample" Publisher="CN=4AD6DA08-6C39-4A10-98CC-3243374DA59C" Version="2.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="faa8e717-e1ec-436b-b32a-68b85c0550dd" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||
|
||||
<Properties>
|
||||
|
|
|
@ -24,6 +24,6 @@ using System.Runtime.InteropServices;
|
|||
// 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: AssemblyVersion("2.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("2.0.0.0")]
|
||||
[assembly: ComVisible(false)]
|
|
@ -83,6 +83,10 @@ These are present by default in the manifest file
|
|||
|
||||
3. Version history
|
||||
--------------------------------------------------------------------------------
|
||||
* Version 2.0:
|
||||
* Refactoring the sample to use ActivitySensor from Windows.Devices.Sensors namespace
|
||||
(if it's available). The sample will fallback to SensorCore if there is no
|
||||
ActivitySensor surfaced by the OS.
|
||||
* Version 1.1.0.17:
|
||||
* Updated to use latest Lumia SensorCore SDK 1.1 Preview
|
||||
* Version 1.1.0.13:
|
||||
|
|
Загрузка…
Ссылка в новой задаче