1 // Copyright 2016 by Samsung Electronics, Inc.,
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
11 namespace Tizen.Sensor
14 /// RunningActivityDetector Class. Used for registering callbacks for running activity detector and getting the running state
16 public class RunningActivityDetector : ActivityDetector
18 private static string ActivityDetectorKey = "http://tizen.org/feature/sensor.activity_recognition";
21 /// Gets the state of running activity detector
23 public DetectorState Running { get; private set; }
26 /// Returns true or false based on whether running activity detector is supported by device.
28 public static bool IsSupported
32 Log.Info(Globals.LogTag, "Checking if the running activity detector is supported");
33 return CheckIfSupported(SensorType.RunningActivityDetector, ActivityDetectorKey);
38 /// Returns the number of running activity detector available on the device.
40 public static int Count
44 Log.Info(Globals.LogTag, "Getting the count of running activity detectors");
50 /// Initializes a new instance of the <see cref="Tizen.Sensor.RunningActivityDetector"/> class.
52 /// <param name='index'>
53 /// Index. Default value for this is 0. Index refers to a particular running activity detector in case of multiple sensors.
55 public RunningActivityDetector(int index = 0) : base(index)
57 SetAttribute((SensorAttribute)ActivityAttribute, (int)ActivityType.Running);
58 Log.Info(Globals.LogTag, "Creating running activity detector object");
61 private static int GetCount()
65 int error = Interop.SensorManager.GetSensorList(SensorType.RunningActivityDetector, out list, out count);
66 if (error != (int)SensorError.None)
68 Log.Error(Globals.LogTag, "Error getting sensor list for running activity detector");
72 Interop.Libc.Free(list);
77 /// Event Handler for storing the callback functions for event corresponding to change in running activity detector data.
79 public event EventHandler<RunningActivityDetectorDataUpdatedEventArgs> DataUpdated;
81 protected override void SensorEventCallback(IntPtr sensorHandle, IntPtr sensorPtr, IntPtr data)
83 Interop.SensorEventStruct sensorData = Interop.IntPtrToEventStruct(sensorPtr);
84 TimeSpan = new TimeSpan((Int64)sensorData.timestamp);
85 Running = (DetectorState)sensorData.values[0];
86 ActivityAccuracy = (SensorDataAccuracy) sensorData.accuracy;
88 DataUpdated?.Invoke(this, new RunningActivityDetectorDataUpdatedEventArgs(sensorData.values[0]));
91 internal override SensorType GetSensorType()
93 return SensorType.RunningActivityDetector;