Exemplo n.º 1
0
        public override void OnReceive(Context context, Intent intent)
        {
            Bundle intentBundle = intent.Extras;
            string action       = intent.Action;

            if (intentBundle != null)
            {
                // Values
                string       address, dataXML = "";
                SensorDetail det = null;


                Log.Debug(TAG, "Update Received");

                address = intentBundle.GetString(AppUtil.ADDRESS_KEY);
                dataXML = intentBundle.GetString(AppUtil.DETAIL_KEY);

                // deserializing the data xml
                XmlSerializer serializer = new XmlSerializer(typeof(SensorDetail));

                StringReader  stringReader = new StringReader(dataXML);
                XmlTextReader xmlReader    = new XmlTextReader(stringReader);

                det = (SensorDetail)serializer.Deserialize(xmlReader);
                xmlReader.Close();
                stringReader.Close();

                DateTime readTime = DateTime.MinValue;

                if (intentBundle.ContainsKey(AppUtil.TIME_KEY))
                {
                    string timeString = intentBundle.GetString(AppUtil.TIME_KEY);
                    DateTime.TryParse(timeString, out readTime);
                }

                // Creating event args
                SensorEventArgs arg = new SensorEventArgs(address, det, readTime);

                try
                {
                    OnSensorReading(this, arg);
                }
                catch (NullReferenceException e)
                {
                    // This exception occurs when nothign is subscribed to this event, it can be safely ignored
                    Log.Debug(TAG, "Nothing is subscribed to the event");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Callback for new sensor detail
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Sensor event args</param>
        private void onNewReading(object sender, SensorEventArgs e)
        {
            // check if the address is the one we want
            if (selectedDevice != null && selectedDevice.Address == e.Address)
            {
                ((MainActivity)Activity).RunOnUiThread(delegate
                {
                    hrRate.SetText("" + e.Detail.PhysiologicalDetails.HeartRate, TextView.BufferType.Normal);

                    // If this is a hexoskin and the reading time is not the minmum
                    if ((AppUtil.isHexoSkin(selectedDevice)) && (e.ReadingTime != DateTime.MinValue))
                    {
                        hrLastUpdate.SetText(e.ReadingTime.ToString(), TextView.BufferType.Normal);
                    }
                    else
                    {
                        hrLastUpdate.SetText(DateTime.Now.ToString(), TextView.BufferType.Normal);
                    }
                });
            }
        }