public override void OnDataChanged (DataEventBuffer buffer)
		{
			if (Log.IsLoggable (TAG, LogPriority.Debug))
				Log.Debug (TAG, "OnDataChanged: " + buffer + " for " + PackageName);
			for (int i = 0; i < buffer.Count; i++) {
				IDataEvent e = Android.Runtime.Extensions.JavaCast<IDataEvent> (buffer.Get (i));
				if (e.Type  == DataEvent.TypeDeleted) {
					Log.Info (TAG, e + " deleted");
				} else if (e.Type  == DataEvent.TypeChanged) {
					bool alarmOn = (bool)DataMap.FromByteArray (e.DataItem.GetData ()).Get (FIELD_ALARM_ON);
					if (!alarmOn) {
						orig_volume = audio_manager.GetStreamVolume (Android.Media.Stream.Alarm);
						media_player.Reset ();
						audio_manager.SetStreamVolume (Android.Media.Stream.Alarm, max_volume, 0);
						media_player.SetAudioStreamType (Android.Media.Stream.Alarm);
						try {
							media_player.SetDataSource (ApplicationContext, alarm_sound);
							media_player.Prepare ();
						} catch (IOException ex) {
							Log.Error (TAG, "Failed to prepare media player to play alarm.", ex);
						}
						media_player.Start ();
					} else {
						audio_manager.SetStreamVolume (Android.Media.Stream.Alarm, orig_volume, 0);
						if (media_player.IsPlaying)
							media_player.Stop ();
					}
				}
			}
			buffer.Close ();
		}
		public override void OnDataChanged (DataEventBuffer dataEvents)
		{
			Console.WriteLine ("Data Changed: " + dataEvents.Count);

			for (int i = 0; i < dataEvents.Count; i++) {

				var d = dataEvents.Get (i).JavaCast<IDataEvent> ();

				if (d.Type == DataEvent.TypeChanged) {

					try {
						var settings = Settings.Deserialize (d.DataItem.GetData ());
						Settings = settings;
						Settings.Save ();

						Console.WriteLine ("Saved Settings... " + settings);

						if (WatchfaceActivity != null) {
							try { WatchfaceActivity.UpdateSettings (); }
							catch { }
						}

					} catch (Exception ex) {
						Console.WriteLine ("Bad Message Data: " + ex);
					}
				}

			}
		}
 public override void OnDataChanged(DataEventBuffer dataEvents)
 {
     if (Log.IsLoggable(Constants.TAG, LogPriority.Debug))
     {
         Log.Debug(Constants.TAG, "OnDataChanged: " + dataEvents + " for " + PackageName);
     }
     try
     {
         for (int i = 0; i < dataEvents.Count; i++)
         {
             var et = dataEvents.Get(i).JavaCast <IDataEvent> ();
             if (et.Type == DataEvent.TypeDeleted)
             {
                 DeleteDataItem(et.DataItem);
             }
             else if (et.Type == DataEvent.TypeChanged)
             {
                 UpdateNotificationForDataItem(et.DataItem);
             }
         }
     }
     catch (Exception ex) {
         if (Log.IsLoggable(Constants.TAG, LogPriority.Error))
         {
             Log.Error(Constants.TAG, "OnDataChanged error: " + ex);
         }
     }
 }
        public override void OnDataChanged(DataEventBuffer dataEvents)
        {
            Console.WriteLine("Data Changed: " + dataEvents.Count);

            for (int i = 0; i < dataEvents.Count; i++)
            {
                var d = dataEvents.Get(i).JavaCast <IDataEvent> ();

                if (d.Type == DataEvent.TypeChanged)
                {
                    try {
                        var settings = Settings.Deserialize(d.DataItem.GetData());
                        Settings = settings;
                        Settings.Save();

                        Console.WriteLine("Saved Settings... " + settings);

                        if (WatchfaceActivity != null)
                        {
                            try { WatchfaceActivity.UpdateSettings(); }
                            catch { }
                        }
                    } catch (Exception ex) {
                        Console.WriteLine("Bad Message Data: " + ex);
                    }
                }
            }
        }
Beispiel #5
0
 public override void OnDataChanged(DataEventBuffer dataEvents)
 {
     for (int i = 0; i < dataEvents.Count; i++)
     {
         var dataEvent = dataEvents.Get(i).JavaCast <IDataEvent> ();
         if (dataEvent.Type == DataEvent.TypeChanged)
         {
             DataMap dataMap = DataMapItem.FromDataItem(dataEvent.DataItem).DataMap;
             var     content = dataMap.GetString(Constants.KeyContent);
             var     title   = dataMap.GetString(Constants.KeyTitle);
             if (Constants.WatchOnlyPath.Equals(dataEvent.DataItem.Uri.Path))
             {
                 BuildWearableOnlyNotification(title, content, false);
             }
             else if (Constants.BothPath.Equals(dataEvent.DataItem.Uri.Path))
             {
                 BuildWearableOnlyNotification(title, content, true);
             }
         }
         else if (dataEvent.Type == DataEvent.TypeDeleted)
         {
             if (Log.IsLoggable(Tag, LogPriority.Debug))
             {
                 Log.Debug(Tag, "DataItem deleted: " + dataEvent.DataItem.Uri.Path);
             }
             if (Constants.BothPath.Equals(dataEvent.DataItem.Uri.Path))
             {
                 ((NotificationManager)GetSystemService(NotificationService)).Cancel(Constants.BothId);
             }
         }
     }
 }
Beispiel #6
0
        public override void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent>())
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(syncPath));

            if (dataEvent == null)
            {
                return;
            }

            //get data from wearable
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map         = dataMapItem.DataMap;
            int heartRate   = dataMapItem.DataMap.GetInt("heartratedata");

            System.Diagnostics.Debug.WriteLine("luku: " + heartRate);

            //send data to MainActivity
            Intent intent = new Intent();

            intent.SetAction(Intent.ActionSend);
            intent.PutExtra("HeartRateFromWear", heartRate);
            LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
        }
Beispiel #7
0
    public void OnDataChanged(DataEventBuffer dataEvents)
    {
      var dataEvent = Enumerable.Range(0, dataEvents.Count)
        .Select(i => dataEvents.Get(i).JavaCast<IDataEvent>())
        .FirstOrDefault(de => de.Type == DataEvent.TypeChanged && de.DataItem.Uri.Path == TweetsPath + "/Answer");
      if (dataEvent == null)
        return;
      var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
      var map = dataMapItem.DataMap;

      var tweets = new List<Tweet>();
      var data = map.GetDataMapArrayList("Tweets");
      foreach (var d in data)
      {
        tweets.Add(new Tweet
        {
          ScreenName = d.GetString("ScreenName", "<no name>"),
          Text = d.GetString("Text", "<no name>"),
          CreatedAt = new DateTime(d.GetLong("CreatedAt", DateTime.Now.Ticks))
        });
      }

      if (tweets.Any())
      {
        handler.Post(() =>
        {
          var adapter = new TweetAdapter(FragmentManager,
                                            tweets);
          viewPager.Adapter = adapter;
          viewPager.OffscreenPageCount = 5;
          progress.Visibility = ViewStates.Gone;
          viewPager.Visibility = ViewStates.Visible;
        });
      }
    }
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                                      .Select(i => dataEvents.Get(i).JavaCast<IDataEvent>())
                                      .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(_syncPath));
            if (dataEvent == null)
                return;

            //do stuffs here
        }
Beispiel #9
0
 public void OnDataChanged(DataEventBuffer p0)
 {
     Console.WriteLine(string.Format("Communicator: Data changed ({0} data events)", p0.Count));
     for (var i = 0; i < p0.Count; i++)
     {
         var dataEvent = p0.Get(i).JavaCast <IDataEvent>();
         if (dataEvent.Type == DataEvent.TypeChanged && dataEvent.DataItem.Uri.Path == path)
         {
             DataReceived(DataMapItem.FromDataItem(dataEvent.DataItem).DataMap);
         }
     }
 }
Beispiel #10
0
 // Implementing IDataApiDataListener interface
 // On data changed we want invoke event
 public void OnDataChanged(DataEventBuffer p0)
 {
     Log.Info("my_log", "Communicator: Data changed (" + p0.Count + " data events)");
     for (var i = 0; i < p0.Count; i++)
     {
         var dataEvent = p0.Get(i).JavaCast <IDataEvent>();
         if (dataEvent.Type == DataEvent.TypeChanged && dataEvent.DataItem.Uri.Path == path)
         {
             DataReceived(DataMapItem.FromDataItem(dataEvent.DataItem).DataMap);
         }
     }
 }
		public override void OnDataChanged (DataEventBuffer dataEvents)
		{
			for (int i = 0; i < dataEvents.Count; i++) {
				IDataEvent dataEvent = Java.Interop.JavaObjectExtensions.JavaCast<IDataEvent>(dataEvents.Get (i));
				if (dataEvent.Type == DataEvent.TypeDeleted) {
					if (Constants.BothPath.Equals (dataEvent.DataItem.Uri.Path)) {
						// Notification on the phone should be dismissed
						NotificationManagerCompat.From (this).Cancel (Constants.BothId);
					}
				}
			}
		}
Beispiel #12
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)))
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(MessagePath));

            if (dataEvent == null)
            {
                return;
            }

            //do stuffs here
        }
Beispiel #13
0
        public override void OnDataChanged(DataEventBuffer buffer)
        {
            if (Log.IsLoggable(TAG, LogPriority.Debug))
            {
                Log.Debug(TAG, "OnDataChanged: " + buffer + " for " + PackageName);
            }
            for (int i = 0; i < buffer.Count; i++)
            {
                IDataEvent e = Android.Runtime.Extensions.JavaCast <IDataEvent>(buffer.Get(i));
                if (e.Type == DataEvent.TypeDeleted)
                {
                    Log.Info(TAG, e + " deleted");
                }
                else if (e.Type == DataEvent.TypeChanged)
                {
                    bool alarmOn = (bool)DataMap.FromByteArray(e.DataItem.GetData()).Get(FIELD_ALARM_ON);
                    if (!alarmOn)
                    {
                        orig_volume = audio_manager.GetStreamVolume(Android.Media.Stream.Alarm);
                        media_player.Reset();

                        max_volume = 0;

                        audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, max_volume, 0);
                        media_player.SetAudioStreamType(Android.Media.Stream.Alarm);
                        try
                        {
                            media_player.SetDataSource(ApplicationContext, alarm_sound);
                            media_player.Prepare();
                        }
                        catch (IOException ex)
                        {
                            Log.Error(TAG, "Failed to prepare media player to play alarm.", ex);
                        }
                        media_player.Start();
                    }
                    else
                    {
                        audio_manager.SetStreamVolume(Android.Media.Stream.Alarm, orig_volume, 0);
                        if (media_player.IsPlaying)
                        {
                            media_player.Stop();
                        }
                    }
                }
            }
            buffer.Close();
        }
		/// <summary>
		/// Listens for DataItems added/deleted from the geofence service running on the companion
		/// </summary>
		public override void OnDataChanged (DataEventBuffer dataEvents)
		{
			if (Log.IsLoggable (Constants.TAG, LogPriority.Debug))
				Log.Debug (Constants.TAG, "OnDataChanged: " + dataEvents + " for " + PackageName);

			for (int i = 0; i < dataEvents.Count; i++) {
				var dEvent = dataEvents.Get (i).JavaCast<IDataEvent> ();
				if (dEvent.Type == DataEvent.TypeDeleted) {
					CancelNotificationForDataItem (dEvent.DataItem);
				} else if (dEvent.Type == DataEvent.TypeChanged) {
					// The user has entered a geofence - post a notification!
					String geofenceId = DataMap.FromByteArray (dEvent.DataItem.GetData ()).GetString (Constants.KEY_GEOFENCE_ID);
					PostNotificationForGeofenceId (geofenceId, dEvent.DataItem.Uri);
				}
			}
		}
Beispiel #15
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent> ())
                            .FirstOrDefault(de => de.Type == DataEvent.TypeChanged && de.DataItem.Uri.Path == SearchStationPath + "/Answer");

            if (dataEvent == null)
            {
                return;
            }
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map         = dataMapItem.DataMap;
            var data        = map.GetDataMapArrayList("Stations");

            ProcessRawStationData(data);
        }
Beispiel #16
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent> ())
                            .FirstOrDefault(de => de.Type == DataEvent.TypeChanged && de.DataItem.Uri.Path == SearchStationPath + "/Answer");

            if (dataEvent == null)
            {
                return;
            }
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map         = dataMapItem.DataMap;

            var stations = new List <SimpleStation> ();
            var data     = map.GetDataMapArrayList("Stations");

            foreach (var d in data)
            {
                stations.Add(new SimpleStation {
                    Id         = d.GetInt("Id", 0),
                    Primary    = d.GetString("Primary", "<no name>"),
                    Secondary  = d.GetString("Secondary", "<no name>"),
                    Background = GetBitmapForAsset(d.GetAsset("Background")),
                    Bikes      = d.GetInt("Bikes", 0),
                    Racks      = d.GetInt("Racks", 0),
                    Distance   = d.GetDouble("Distance", 0),
                    Lat        = d.GetDouble("Lat", 0),
                    Lon        = d.GetDouble("Lon", 0),
                    IsFavorite = d.GetBoolean("IsFavorite", false),
                });
            }

            if (stations.Any())
            {
                handler.Post(() => {
                    adapter = new StationGridAdapter(FragmentManager,
                                                     stations,
                                                     this);
                    pager.Adapter            = adapter;
                    pager.OffscreenPageCount = 5;
                    loading.Visibility       = ViewStates.Invisible;
                    pager.Visibility         = ViewStates.Visible;
                    countSwitch.Visibility   = ViewStates.Visible;
                    dotsIndicator.Visibility = ViewStates.Visible;
                });
            }
        }
Beispiel #17
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent>())
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(SYNC_PATH));

            if (dataEvent == null)
            {
                return;
            }

            //get data from watch
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map         = dataMapItem.DataMap;

            tapCount           = int.Parse(dataMapItem.DataMap.GetString("TapCounter"));
            lblTapCounter.Text = tapCount.ToString();
        }
        public override void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                                      .Select(i => dataEvents.Get(i).JavaCast<IDataEvent>())
                                      .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(_syncPath));
            if (dataEvent == null)
                return;

            //get data from wearable
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map = dataMapItem.DataMap;
            string message = dataMapItem.DataMap.GetString("Message");

            Intent intent = new Intent();
            intent.SetAction(Intent.ActionSend);
            intent.PutExtra("WearMessage", message);
            LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
        }
		public override async void OnDataChanged (DataEventBuffer dataEvents)
		{
			if (Log.IsLoggable (Constants.TAG, LogPriority.Debug))
				Log.Debug (Constants.TAG, "OnDataChanged: " + dataEvents + " for " + PackageName);
			try 
			{
				for (int i = 0; i < dataEvents.Count; i++) {
					var et = dataEvents.Get (i).JavaCast <IDataEvent> ();
					if (et.Type == DataEvent.TypeDeleted)
						DeleteDataItem (et.DataItem);
					else if (et.Type == DataEvent.TypeChanged)
						await UpdateNotificationForDataItem (et.DataItem);
				}
			}
			catch (Exception ex) {
				if (Log.IsLoggable (Constants.TAG, LogPriority.Error))
					Log.Error (Constants.TAG, "OnDataChanged error: " + ex);
			}
		}
Beispiel #20
0
        /// <summary>
        /// Receives data from handheld; this isn't really used, but is handy for connection tests and such
        /// </summary>
        /// <param name="dataEvents"></param>
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            debugLog("Data changed");
            dataStatusHandler.updateStatus("Data changed");
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)))
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(TestDataPath));

            if (dataEvent == null)
            {
                return;
            }
            else
            {
                var    dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
                var    map         = dataMapItem.DataMap;
                string message     = dataMapItem.DataMap.GetString("Message");
                debugLog("Test data actually received! message: " + message);
            }
        }
		public override void OnDataChanged (DataEventBuffer dataEvents)
		{
			for (int i = 0; i < dataEvents.Count; i++) {
				var dataEvent = dataEvents.Get (i).JavaCast<IDataEvent> ();
				if (dataEvent.Type == DataEvent.TypeChanged) {
					DataMap dataMap = DataMapItem.FromDataItem (dataEvent.DataItem).DataMap;
					var content = dataMap.GetString (Constants.KeyContent);
					var title = dataMap.GetString (Constants.KeyTitle);
					if (Constants.WatchOnlyPath.Equals (dataEvent.DataItem.Uri.Path))
						BuildWearableOnlyNotification (title, content, false);
					else if (Constants.BothPath.Equals (dataEvent.DataItem.Uri.Path))
						BuildWearableOnlyNotification (title, content, true);
				} else if (dataEvent.Type == DataEvent.TypeDeleted) {
					if (Log.IsLoggable (Tag, LogPriority.Debug))
						Log.Debug (Tag, "DataItem deleted: " + dataEvent.DataItem.Uri.Path);
					if (Constants.BothPath.Equals (dataEvent.DataItem.Uri.Path))
						((NotificationManager)GetSystemService (NotificationService)).Cancel (Constants.BothId);
				}
			}
		}
Beispiel #22
0
        public override void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i)))
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(MessagePath));

            if (dataEvent == null)
            {
                return;
            }

            //get data from wearable
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var message     = dataMapItem.DataMap.GetString("Message");

            var intent = new Intent();

            intent.SetAction(Intent.ActionSend);
            intent.PutExtra("WearMessage", message);
            LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
        }
        /// <summary>
        /// Listens for DataItems added/deleted from the geofence service running on the companion
        /// </summary>
        public override void OnDataChanged(DataEventBuffer dataEvents)
        {
            if (Log.IsLoggable(Constants.TAG, LogPriority.Debug))
            {
                Log.Debug(Constants.TAG, "OnDataChanged: " + dataEvents + " for " + PackageName);
            }

            for (int i = 0; i < dataEvents.Count; i++)
            {
                var dEvent = dataEvents.Get(i).JavaCast <IDataEvent> ();
                if (dEvent.Type == DataEvent.TypeDeleted)
                {
                    CancelNotificationForDataItem(dEvent.DataItem);
                }
                else if (dEvent.Type == DataEvent.TypeChanged)
                {
                    // The user has entered a geofence - post a notification!
                    String geofenceId = DataMap.FromByteArray(dEvent.DataItem.GetData()).GetString(Constants.KEY_GEOFENCE_ID);
                    PostNotificationForGeofenceId(geofenceId, dEvent.DataItem.Uri);
                }
            }
        }
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent>())
                            .FirstOrDefault(de => de.Type == DataEvent.TypeChanged && de.DataItem.Uri.Path == TweetsPath + "/Answer");

            if (dataEvent == null)
            {
                return;
            }
            var dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
            var map         = dataMapItem.DataMap;

            var tweets = new List <Tweet>();
            var data   = map.GetDataMapArrayList("Tweets");

            foreach (var d in data)
            {
                tweets.Add(new Tweet
                {
                    ScreenName = d.GetString("ScreenName", "<no name>"),
                    Text       = d.GetString("Text", "<no name>"),
                    CreatedAt  = new DateTime(d.GetLong("CreatedAt", DateTime.Now.Ticks))
                });
            }

            if (tweets.Any())
            {
                handler.Post(() =>
                {
                    var adapter = new TweetAdapter(FragmentManager,
                                                   tweets);
                    viewPager.Adapter            = adapter;
                    viewPager.OffscreenPageCount = 5;
                    progress.Visibility          = ViewStates.Gone;
                    viewPager.Visibility         = ViewStates.Visible;
                });
            }
        }
Beispiel #25
0
        /// <summary>
        /// get's called when data from the wearable is received
        /// needs to be different from earlier data, which is why you need the timestamps as part of the data if you want each data point
        /// </summary>
        /// <param name="dataEvents"></param>
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            HeartDebugHandler.debugLog("Data changed");

            var dataEvent = Enumerable.Range(0, dataEvents.Count)
                            .Select(i => dataEvents.Get(i).JavaCast <IDataEvent>())
                            .FirstOrDefault(x => x.Type == DataEvent.TypeChanged && x.DataItem.Uri.Path.Equals(DataPointsPath));

            if (dataEvent == null)
            {
                return;
            }
            else
            {
                var    dataMapItem = DataMapItem.FromDataItem(dataEvent.DataItem);
                var    map         = dataMapItem.DataMap;
                string message     = dataMapItem.DataMap.GetString("Message");
                HeartDebugHandler.debugLog("Data received! message: " + message);

                string[] allDataPoints;
                if (message.Contains("|"))
                {
                    allDataPoints = message.Split("|");
                }
                else
                {
                    allDataPoints = new[] { message };
                }

                int  teller       = 0;
                bool stepReceived = false;
                bool hbReceived   = false;
                bool hrReceived   = false;
                foreach (string pointData in allDataPoints)
                {
                    HeartDataPoint p = decodeDataPoint(pointData);
                    if (p != null)
                    {
                        teller++;
                    }

                    if (p.heartType == HeartDataType.HeartBeat)
                    {
                        if (!hbReceived)
                        {
                            hbReceived = true;
                        }
                        hdata_Beat.Enqueue(p);

                        if (hdata_Beat.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Beat, HeartFileHandler.FILENAME_HEARTBEAT, dataStatusHandler);
                        }
                    }
                    else if (p.heartType == HeartDataType.HeartRate)
                    {
                        if (!hrReceived)
                        {
                            hrReceived = true;
                        }
                        hdata_Rate.Enqueue(p);

                        if (hdata_Rate.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Rate, HeartFileHandler.FILENAME_HEARTRATE, dataStatusHandler);
                        }
                    }
                    else if (p.heartType == HeartDataType.StepCount)
                    {
                        if (!stepReceived)
                        {
                            stepReceived = true;
                        }
                        hdata_Steps.Enqueue(p);
                        if (hdata_Steps.Count > 50)
                        {
                            HeartFileHandler.saveData(hdata_Steps, HeartFileHandler.FILENAME_STEPS, dataStatusHandler);
                        }
                    }
                }

                if (teller > 0)
                {
                    string types = "";
                    if (hrReceived)
                    {
                        types += "HR,";
                    }
                    if (hbReceived)
                    {
                        types += "HB,";
                    }
                    if (stepReceived)
                    {
                        types += "St";
                    }
                    //updateStatusString("Data received, Types: {"+ types + "}, Amount: " + teller + ".");
                    connectionStatusHandler.updateStatus("Data received, Types: {" + types + "}, Amount: " + teller + ".");
                    //saveStepData();//bør nok kjøres på en mer intelligent måte
                }
                else
                {
                    //updateStatusString("Invalid data received.");
                    connectionStatusHandler.updateStatus("Invalid data received.");
                }
            }
        }
Beispiel #26
0
 public override void OnDataChanged(DataEventBuffer dataEvents)
 {
     for (int i = 0; i < dataEvents.Count; i++)
     {
         IDataEvent dataEvent = Java.Interop.JavaObjectExtensions.JavaCast <IDataEvent>(dataEvents.Get(i));
         if (dataEvent.Type == DataEvent.TypeDeleted)
         {
             if (Constants.BothPath.Equals(dataEvent.DataItem.Uri.Path))
             {
                 // Notification on the phone should be dismissed
                 NotificationManagerCompat.From(this).Cancel(Constants.BothId);
             }
         }
     }
 }
Beispiel #27
0
        public void OnDataChanged(DataEventBuffer dataEvents)
        {
            var dataEvent = Enumerable.Range (0, dataEvents.Count)
                .Select (i => dataEvents.Get (i).JavaCast<IDataEvent> ())
                .FirstOrDefault (de => de.Type == DataEvent.TypeChanged && de.DataItem.Uri.Path == SearchStationPath + "/Answer");
            if (dataEvent == null)
                return;
            var dataMapItem = DataMapItem.FromDataItem (dataEvent.DataItem);
            var map = dataMapItem.DataMap;

            var stations = new List<SimpleStation> ();
            var data = map.GetDataMapArrayList ("Stations");
            foreach (var d in data) {
                stations.Add (new SimpleStation {
                    Id = d.GetInt ("Id", 0),
                    Primary = d.GetString ("Primary", "<no name>"),
                    Secondary = d.GetString ("Secondary", "<no name>"),
                    Background = GetBitmapForAsset (d.GetAsset ("Background")),
                    Bikes = d.GetInt ("Bikes", 0),
                    Racks = d.GetInt ("Racks", 0),
                    Distance = d.GetDouble ("Distance", 0),
                    Lat = d.GetDouble ("Lat", 0),
                    Lon = d.GetDouble ("Lon", 0),
                    IsFavorite = d.GetBoolean ("IsFavorite", false),
                });
            }

            if (stations.Any ()) {
                handler.Post (() => {
                    adapter = new StationGridAdapter (FragmentManager,
                                                      stations,
                                                      this);
                    pager.Adapter = adapter;
                    pager.OffscreenPageCount = 5;
                    loading.Visibility = ViewStates.Invisible;
                    pager.Visibility = ViewStates.Visible;
                    countSwitch.Visibility = ViewStates.Visible;
                    dotsIndicator.Visibility = ViewStates.Visible;
                });
            }
        }