예제 #1
0
 /// <summary>
 /// Callback for location updates
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 private void onNewLocationUpdate(object sender, LocationEventArgs e)
 {
     setValues(e.Latitude, e.Longitude, e.Altitude, e.Accuracy);
 }
예제 #2
0
 /// <summary>
 /// Callback for send updates
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">E.</param>
 private void onNewSentUpdate(object sender, LocationEventArgs e)
 {
     setValues(e.LastSent);
 }
예제 #3
0
        public override void OnReceive(Context context, Intent intent)
        {
            Bundle intentBundle = intent.Extras;

            if (intentBundle != null)
            {
                // Values
                double?lat = null;
                double?lon = null;
                double?alt = null;
                double?acc = null;

                double   temp;
                DateTime lastSent;

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

                if (Double.TryParse(intentBundle.GetString(AppUtil.LAT_KEY), out temp))
                {
                    lat = temp;
                }
                if (Double.TryParse(intentBundle.GetString(AppUtil.LON_KEY), out temp))
                {
                    lon = temp;
                }
                if (Double.TryParse(intentBundle.GetString(AppUtil.ALT_KEY), out temp))
                {
                    alt = temp;
                }
                if (Double.TryParse(intentBundle.GetString(AppUtil.ACC_KEY), out temp))
                {
                    acc = temp;
                }
                if (!DateTime.TryParse(intentBundle.GetString(AppUtil.LAST_SENT_KEY), out lastSent))
                {
                    lastSent = DateTime.MinValue;
                }

                // Creating event args
                LocationEventArgs arg = null;

                if (intent.Action == AppUtil.LOCATION_UPDATE_ACTION)
                {
                    arg = new LocationEventArgs(lat, lon, alt, acc);

                    try
                    {
                        locationUpdate(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");
                    }
                }
                else if (intent.Action == AppUtil.LOCATION_LAST_SENT_ACTION)
                {
                    arg = new LocationEventArgs(lastSent);

                    try
                    {
                        SendUpdate(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");
                    }
                }
                else if (intent.Action == AppUtil.LOCATION__CONNECT_ACTION)
                {
                    LocationStateEventArgs stateArg = new LocationStateEventArgs(true);
                    ConnectionStateChange(this, stateArg);
                }
                else if (intent.Action == AppUtil.LOCATION__DISCONNECT_ACTION)
                {
                    LocationStateEventArgs stateArg = new LocationStateEventArgs(false);
                    ConnectionStateChange(this, stateArg);
                }
            }
        }